// JavaScript Document
var content				= "";
var progress			= "";

window.onload		= function(){
content			= document.getElementById('CONTENT');
progress		= document.getElementById('PROGRESS');
makeRequest('PAGES/mainPage.php',true);
}

	
function showContents(text) {   
   content.innerHTML	= text;
   hideLoader(); 
}

function makeRequest(url,showProgressDiv) {
  if(showProgressDiv){
   showLoader();
   }
  makeHttpRequest(url + "?r=" + new Date().getTime(), 'showContents');    
}

//this function fixes the problem of loading the map into an empty 
//map div. The function checks to see if the map div exisit and obnly loads the
//map if it does.

//function delayGload(){
//	mapSect		= document.getElementById("map");	
//	if(mapSect == null){
//		getWin	= window.setInterval(delayGload,100);
//	}	
//	else{
//		clearInterval(getWin);
//		Gload();
//		}
//	}
//
//function Gload() {
//	var WINDOW_HTML = '<div><b>Advance Global Communications</b><br>2651 N Harwood St, Suite 370<br>Dallas, Texas 75201, USA</div>';
//      if (GBrowserIsCompatible()) {
//        var map = new GMap2(document.getElementById("map"));
//        map.addControl(new GSmallMapControl());
//        map.setCenter(new GLatLng(32.792386, -96.806686), 17);
//		var marker = new GMarker(new GLatLng(32.792306, -96.806818));
//      map.addOverlay(marker);
//	  GEvent.addListener(marker, "click", function() {
//       marker.openInfoWindowHtml(WINDOW_HTML);
//      });
//      marker.openInfoWindowHtml(WINDOW_HTML);
//      }
//    }

function makeRequestGlobal(url,callbackFunction) {
  makeHttpRequest(url, callbackFunction);    
}

function contactCallback(text){
	sect				= document.getElementById('contactForm');
	//sect.innerHTML		= text;
	if(text == "1"){
		alert("Message has been succesfully sent!");
		}
		
	else if(text == "-1"){
		alert("There was a problem sending your message. Please try again!");
		}
		
	else if(text == "-440"){
		alert("Your message seems to be invalid. Please try again!");
		}
		
	else{
		alert("Status unknown!");
		}
		
		//alert(text);
	}

function showLoader(){
	content.innerHTML		= progress.innerHTML;
}

function hideLoader(){
	progress.style.visibility    = "hidden";
	}
	
function spawnWindow(URL,Name,features) {
        window.open(URL,Name,features);
}

function setStatus(message){
window.status		= message;
return true;
}


function validateContactInfo(ajxValAddr){
//let the fun begin
//declare the varibales to hold the fields
var fName				= document.getElementById('name');
var eMail				= document.getElementById('email');
var message				= document.getElementById('mess');

var Errs				= 0;

//check name
if (fName.value == ""){
document.getElementById('nError').innerHTML		= "<font color='red'><i>Name cannot be empty</i></font>";
Errs++;
}

else{
document.getElementById('nError').innerHTML		= "";
}

//check email
if (eMail.value == ""){
document.getElementById('eError').innerHTML		= "<font color='red'><i>Email cannot be empty</i></font>";
Errs++;
}

else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eMail.value))){
document.getElementById('eError').innerHTML		= "<font color='red'><i>Invalid Email</i></font>";
Errs++;
}

else{
document.getElementById('eError').innerHTML		= "";
}

//check message
if (message.value == ""){
document.getElementById('mError').innerHTML		= "<font color='red'><i>Message cannot be empty</i></font>";
Errs++;
}

else{
document.getElementById('mError').innerHTML		= "";
}

if(Errs > 0){
//return false;
}

else{
	makeRequestGlobal(ajxValAddr+"?mess=" + escape(message.value) + "&name=" + escape(fName.value) + "&email=" + escape(eMail.value),'contactCallback');
	}

//end of validate function
}

function openBrWindow(theURL,winName,features) { 
  win		= window.open(theURL,winName,features);
  
  if(!win){
	  alert("Your popup blocker may have blocked an important window. please add this site to your list of trusted sites!");
	  }
}

