// JavaScript Document


//<![CDATA[

var map;
var gdir;
var geocoder = null;
var addressMarker;

function setDirections(fromAddress, toAddress) {
  gdir.load("from: " + fromAddress + " to: " + toAddress);
}

function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	
   else alert("An unknown error occurred.");
   
}

function onGDirectionsLoad(){ 
	  // Use this function to access information about the latest load()
	  // results.

	  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  // and yada yada yada...
}


//]]>
<!--
start = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
 
 kill = document.getElementById("map");
 if (kill != null) {
   if (GBrowserIsCompatible()) {
	   var here = document.googleMap.fromAddress.value;
	   var there = document.googleMap.toAddress.value;
	map = new GMap2(document.getElementById("map"));
	gdir = new GDirections(map, document.getElementById("directions"));
	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	setDirections(here, there);
	//map.setCenter(new GLatLng(34.118925, -83.5737410), 15);
	//map.openInfoWindowHtml(map.getCenter(), '<STRONG>Covenant Faith woc</STRONG><BR>92 College Street<BR>Jefferson, Ga. 30459');
  }
 }
 
 
}
window.onload=start;


function swapLocation(){
	var to = document.googleMap.to.value;
	var from = document.googleMap.from.value;
	if (from && to != null) {
		document.googleMap.to.value = from;
		document.googleMap.from.value = to;
		document.googleMap.swap.click= setDirections(to, from);
		return false;
	} else {
			alert('you must enter both a start and end location');
	}
}
/*
function messageValidate() {
	var email = document.contact.email;
	var comments = document.contact.comments;
	
// comments checker
	if (comments.value == 0) {
		alert("Please enter your message.");
		comments.focus();
		return false;
	}
// Email Checker
	if (email.value != 0) {
		 if (email.value.indexOf("@") < 0) {
			alert("Incorrect email address. Please re-enter");
			email.focus();
			return false;
		} else if (email.value.indexOf(".") < 0) {
			alert("Incorrect email address. Please re-enter");
			email.focus();
			return false;
		} else if (email.value.indexOf(" ") >= 0) {
			alert("Incorrect email address. Please re-enter");
			email.focus();
			return false;
		}
	}
}

function boxDeactivate(marker) {
	//var del = document.adminForm.deleteBox.value;
	//alert(document.adminForm.elements.length);
	//alert(marker);
		//for(var k=0; k<50 k++) {
			//if (elms[k].checked = true)
				//alert("delete checked");
		//}
		
	//if (del.checked == true) {
		//active.checked = false;
		//active.disabled = true;
	//}
}
*/
-->
function cautionMe() {
	alert("You are trying to delete something that is currently active, are you sure you want to continue with this?");	
}


if (document.images) 
{
   img1 = new Image();
   img2 = new Image();
   img3 = new Image();
   img4 = new Image();
   img1.src = "images/foot_kids_2.jpg";
   img2.src = "images/foot_youth_2.jpg";
   img3.src = "images/foot_women_2.jpg";
   img4.src = "images/foot_men_2.jpg";
}


//get new captcha image
function refreshImg(){
	var rightnow = new Date();
	document.getElementById("captImg").src='capt.php?'+rightnow.getTime();
	document.getElementById("code").value="";
}


var xmlHttp;

function sendMail(){
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null){
		  document.alert ("Your browser does not support AJAX!");
	  	return;
	} 
	xmlHttp.onreadystatechange=contactStateChanged;
	
	var cc = null;
	if (document.getElementById("ccMe").checked){
		cc = "1";
	}
	
  	xmlHttp.open("GET", "sendMail.php?name="+encodeURIComponent(document.getElementById("name").value)+
									"&email="+encodeURIComponent(document.getElementById("email").value)+
									"&comment="+encodeURIComponent(document.getElementById("comment").value)+
									"&subject="+encodeURIComponent(document.getElementById("subject").value)+
									"&code="+encodeURIComponent(document.getElementById("code").value)+
									"&cc="+cc, true);
 	xmlHttp.send(null);
	
}
/*
function sermonUploadState(){
	if (xmlHttp.readyState < 3){
		document.getElementById("status").innerHTML="Connecting";
	}
	if (xmlHttp.readyState == 3){
		document.getElementById("status").innerHTML="Uploading";
	}
	if (xmlHttp.readyState < 4 || xmlHttp.readyState != "complete"){ 
		document.getElementById("status").innerHTML="Complete";
	}
}

function abortProtocol() {
	document.getElementById("sentDiv").innerHTML="Error: Could not send message!";
	document.getElementById("formDiv").style.visibility = "show";	
	document.getElementById("formDiv").style.display = "block";
	xmlHttp.abort()
}
*/
function contactStateChanged(){ 
	if (xmlHttp.readyState < 4 || xmlHttp.readyState != "complete"){ 
		document.getElementById("formDiv").style.visibility = "hidden";	
		document.getElementById("formDiv").style.display = "none";
		document.getElementById("sentDiv").innerHTML="sending<img src='images/loading.gif' />";
		
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		
		if (xmlHttp.responseText == ''){
			document.getElementById("sentDiv").innerHTML="<br /><br /><strong>Your Message has been sent.</strong>"+
														"<br /> We will get back to you as soon as possible.";
			document.getElementById("sendBTN").disabled = "true";
		} else {
			refreshImg();
			document.getElementById("sentDiv").innerHTML="";
			document.getElementById("errors").innerHTML=xmlHttp.responseText;
			document.getElementById("formDiv").style.visibility = "visible";	
			document.getElementById("formDiv").style.display = "block";
		}
	}
}

//Browser Support Code
function GetXmlHttpObject(){
	var xmlHttp = null;  // The variable that makes Ajax possible!
	
		try{
		  // Firefox, Opera 8.0+, Safari
		 	 xmlHttp=new XMLHttpRequest();
		  } catch (e){
			  // Internet Explorer
			  try{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  } catch (e){
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
	  	}
	return xmlHttp;
}



