var xmlHttp
var data

///HTTP REQUEST FUNCTIONS
function GetXmlHttpObject()
{
var xmlHttp=null;
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;
}


function check_email(email)
{
		///http request
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
		  } 
		var url="register_check.php";
		url=url+"?email="+email;
		xmlHttp.onreadystatechange=stateChanged_b;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function check_email_pass(email)
{
		///http request
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
		  } 
		var url="register_check_pass.php";
		url=url+"?email="+email;
		xmlHttp.onreadystatechange=stateChanged_b;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function check_email_student(email)
{
		///http request
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
		  } 
		var url="register_check_student.php";
		url=url+"?email="+email;
		xmlHttp.onreadystatechange=stateChanged_b;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function check_email_pass_student(email)
{
		///http request
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
		  } 
		var url="register_check_student_pass.php";
		url=url+"?email="+email;
		xmlHttp.onreadystatechange=stateChanged_b;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function stateChanged_b() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		data = xmlHttp.responseText;
		if (data!="clear") {
			document.getElementById('email').focus();
			document.getElementById('email_error').innerHTML = data;
			document.getElementById('Continue').disabled=true;
		}
		else {
			document.getElementById('email_error').innerHTML = "";
			document.getElementById('Continue').disabled=false;
		}

	}
}

function enable_submit() {
	if (document.getElementById('agree').checked==true) {
		document.getElementById('Continue').disabled=false;
	}
	else {
		document.getElementById('Continue').disabled=true;
	}
}
function check_pass() {
	if (document.getElementById("pass1").value!="" && document.getElementById("pass2").value!="") {
		if (document.getElementById("pass1").value==document.getElementById("pass2").value) {
			document.getElementById('pass_error').innerHTML="";
		}
		else {
			document.getElementById('pass_error').innerHTML = "Passwords do not match. Please re-enter them.";
			document.getElementById("pass2").focus();		
		}
	}
}

function check_form() {
	if (document.getElementById('email').value!='' && document.getElementById("pass1").value!="" && document.getElementById("pass2").value!="" && document.getElementById("pass1").value==document.getElementById("pass2").value) {
		return true;
	}
	else {
		if (document.getElementById('email').value=='') {
			alert("Please fill in your email address");
			document.getElementById('email').focus();
		}
		else if (document.getElementById("pass1").value=="") {
			alert("Please fill in your password");
		}
		else if (document.getElementById("pass2").value=="") {
			alert("Please confirm your password");
		}
		return false;
	}
}

function check_form2s() {
	if (document.getElementById('student_name').value!='') {
		return true;
	}
	else {
		if (document.getElementById('student_name').value=='') {
			alert("Please fill in your name");
			document.getElementById('student_name').focus();
		}
		return false;
	}
}

function check_form2h() {
	if (document.getElementById('address').value!='') {
		return true;
	}
	else {
		if (document.getElementById('address').value=='') {
			alert("Please fill in your address");
			document.getElementById('address').focus();
		}
		return false;
	}
}


/// REGISTER PAGE 2
function get_state()
{
		var select_country = document.getElementById('country');
		var selected_country = select_country.options[select_country.selectedIndex].value;
		///http request
		xmlHttpa=GetXmlHttpObject();
		if (xmlHttpa==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
		  } 
		var urla="register_getstate.php";
		urla=urla+"?country="+selected_country;
		xmlHttpa.onreadystatechange=stateChanged_ba;
		xmlHttpa.open("GET",urla,true);
		xmlHttpa.send(null);
}

function stateChanged_ba() 
{ 
	if (xmlHttpa.readyState==4)
	{ 
		dataa = xmlHttpa.responseText;
		document.getElementById('statediv').innerHTML = dataa;
	}
}

function addAddress(response) {
      //map.clearOverlays();
      if (!response || response.Status.code != 200) {
        document.getElementById('zip_error').innerHTML="Sorry, we were unable to geocode that address. Please correct it, otherwise your listing won't show on the map.";
      } else {
		document.getElementById('zip_error').innerHTML="";
	  	placest = response.Placemark[0];
		document.getElementById('latx').value=placest.Point.coordinates[1];
		document.getElementById('longx').value=placest.Point.coordinates[0];
		//alert(document.getElementById('latx').value);
      }
    }

function get_geocode() {
  var select_country = document.getElementById('country');
  var selected_country = select_country.options[select_country.selectedIndex].value;
  var address=document.getElementById('address').value+" "+selected_country+" "+document.getElementById('zip').value;
  geocoder = new GClientGeocoder();
  geocoder.getLocations(address, addAddress);	  
}
	
//REGISTER PAGE 3
function validate_upload(form) {
	document.getElementById("uploading").style.visibility="visible";
	document.getElementById("uploading").style.height="250px";
	return true;
}

function check_extension(file) {
	if (file!='') {
	if (file.lastIndexOf(".jpg")==-1 && file.lastIndexOf(".JPG")==-1) {
		alert("Please upload JPG files only");
		document.getElementById('Continue').disabled=true;
	}
	else {
		document.getElementById('Continue').disabled=false;
	}
	}
}

function delete_pic(id,num) {
	///http request
	xmlHttpa=GetXmlHttpObject();
	if (xmlHttpa==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 
	var urla="provider_deletepic.php";
	urla=urla+"?id="+id+"&pic="+num;
	xmlHttpa.onreadystatechange=function test() { window.location="provider_edit4.php" };
	xmlHttpa.open("GET",urla,true);
	xmlHttpa.send(null);
}

function delete_pic_student(id,num) {
	///http request
	xmlHttpa=GetXmlHttpObject();
	if (xmlHttpa==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 
	var urla="student_deletepic.php";
	urla=urla+"?id="+id+"&pic="+num;
	xmlHttpa.onreadystatechange=function test() { window.location="student_edit3.php" };
	xmlHttpa.open("GET",urla,true);
	xmlHttpa.send(null);
}