function changeCitiesHTMLEditProfile(SetDefault){
	
	FillCities('http://www.lifetopia.com/testDD.asp?state=' + document.getElementById('state').value,'');
}

var vCityID = '';
var xmlhttp;


function ValidateUser(TargetRequest){
	xmlhttp=null;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){

		//alert(TargetRequest);
		xmlhttp.onreadystatechange=ValidateUserHTML;
		xmlhttp.open("GET",TargetRequest,true);			
		xmlhttp.send(null);	
		

	}
	else{
		alert("Oopss! An error ocurred while trying to get the suburbs list, please try again.\nIf problem persists please contact our Customer Service.");
		
	}

}
	
function ValidateUserHTML(){
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4){
		// if "OK"
		//alert(xmlhttp.status);
		if (xmlhttp.status==200){
			//document.getElementById('dvCities').innerHTML = xmlhttp.responseText;
			//SelectCity();
			/*alert(xmlhttp.responseText.length);
			alert(xmlhttp.responseText);
			if (String(xmlhttp.responseText) == "1")
				IsUserValid = true;
			else
				IsUserValid = false;	*/
				//alert(xmlhttp.responseText);
				SubmitFrom(xmlhttp.responseText);
		}else{
			alert("An error ocurred while trying to get the suburbs list. Please try choosing another location and then try again.\nIf problem persists please contact our Customer Service." + xmlhttp.status);
			
		}
	}
}
			
function FillCities(TargetRequest,CityID){
	document.getElementById('dvCities').innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr valign="middle"><td><img src="/images/loader.gif" /></td><td>Loading...</td></tr></table><table > '
	document.getElementById('state').disabled = true;
	vCityID = CityID;
	xmlhttp=null;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){

		//alert(TargetRequest);
		xmlhttp.onreadystatechange=DumpCitiesHTML;
		xmlhttp.open("GET",TargetRequest,true);			
		xmlhttp.send(null);							

	}
	else{
			document.getElementById('state').disabled = false;
		alert("Oopss! An error ocurred while trying to get the suburbs list, please try again.\nIf problem persists please contact our Customer Service.");
		
	}
}

function DumpCitiesHTML(){
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4){
		// if "OK"
		//alert(xmlhttp.status);
		if (xmlhttp.status==200){
				document.getElementById('state').disabled = false;
			document.getElementById('dvCities').innerHTML = xmlhttp.responseText;
			SelectCity();
		}else{
			alert("An error ocurred while trying to get the suburbs list. Please try choosing another location and then try again.\nIf problem persists please contact our Customer Service." + xmlhttp.status);
			
		}
	}
}
function SelectCity(){
	//CityID = "<%=Head_MetroID%>";
	//alert(vCityID)
	if (vCityID.length>0){
		var option = document.getElementById(vCityID);
		//alert(option )
		if(option != null){
			option.selected = true;
		}	
	}
} 

function FillSchools(){
	var ddlSchools  = document.getElementById('ddlSchools');
	
	ddlSchools.options.length = 0;
	
	var SchoolsArray = new Array();
	SchoolsArray[0] = new Array('http://arizona.roommateclick.com/','Arizona');
	SchoolsArray[1] = new Array('http://baruch.roommateclick.com/','Baruch');
	SchoolsArray[2] = new Array('http://boisestate.roommateclick.com/','Boise State');
	SchoolsArray[3] = new Array('http://depaul.roommateclick.com/','DePaul');
	SchoolsArray[4] = new Array('http://georgiasouthern.roommateclick.com/','Georgia Southern');
	SchoolsArray[5] = new Array('http://hres.roommateclick.com/','Harvard');
	SchoolsArray[6] = new Array('http://uidaho.roommateclick.com/','Idaho');
	SchoolsArray[7] = new Array('http://mcphs.apartmentsource.com/','MCPHS');
	SchoolsArray[8] = new Array('http://missouristate.roommateclick.com/','Missouri State');
	SchoolsArray[9] = new Array('http://mountida.roommateclick.com/','Mount IDA');
	SchoolsArray[10] = new Array('http://rutgers.roommateclick.com/','Rutgers');
	SchoolsArray[11] = new Array('http://sacredheart.roommateclick.com/','Sacred Heart');
	SchoolsArray[12] = new Array('http://sfsu.roommateclick.com/','San Francisco');
	SchoolsArray[13] = new Array('http://southeastmissouri.roommateclick.com/','Southeast Missouri');
	SchoolsArray[14] = new Array('http://tulane.roommateclick.com/','Tulane');
	SchoolsArray[15] = new Array('http://umaine.roommateclick.com/','University of Maine');
	SchoolsArray[16] = new Array('http://uwrf.roommateclick.com/','UW - River Falls');
	SchoolsArray[17] = new Array('http://wintergreen.roommateclick.com/','Wintergreen');
	var option;
	option = new Option("Select Your School","");
	ddlSchools.options[0] = new Option("Select Your School","#");
	ddlSchools.options[1] = new Option("------------------","#");
	for(i=0;i<SchoolsArray.length;i++){
		ddlSchools.options[i+2] = new Option(SchoolsArray[i][1],SchoolsArray[i][0]);
	}
	ddlSchools.options[SchoolsArray.length+1] = new Option("------------------","#");
	ddlSchools.options[SchoolsArray.length+2] = new Option("Don't see my school","other");
	
	//ddlSchools.onchange = OpenUni;
}
var newwindow;
function OpenUni(){
	var UniSelected = document.getElementById('ddlSchools');
	URL = UniSelected.options[UniSelected.selectedIndex].value;
	name = UniSelected.options[UniSelected.selectedIndex].text
	
	
	if(URL != "#"){
		if( URL == 'other'){
			location.href = 'write_us.html';
			//URL = 'OtherUni.asp';
			//window.close();
			//self.close();
			//window.close();
			//newwindow=window.open(URL,'name','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=480,height=370,left = 0,top = 0');
		 	//if (window.focus) {newwindow.focus()}
		}
		else{
			newwindow=window.open(URL,'name','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,left = 0,top = 0,status=1');
		 if (window.focus) {newwindow.focus()}
		} 
		//window.open(URL);
	}
	else{
		alert('Please select University');
	}
}



function SelectedStateAjax(e)
{
	//cursor_wait();
	document.getElementById('UniversityDiv').innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr valign="middle"><td><img src="/images/loader.gif" /></td><td>Loading...</td></tr></table><table > '
	var str = e.options[e.selectedIndex].value;

	if (str == "-1")
  	{ 
		//cursor_clear();
		//alert('Select a valid State');
			var objdiv = document.getElementById('universityName');
			objdiv.innerHTML = DrawSelect;
		//e.selectedIndex = oldStateSelected;
		
  		//document.getElementById("txtHint").innerHTML="";
  		return;
  	}
	//show();
	oldStateSelected = e.selectedIndex;
	xmlHttp=GetXmlHttpObject();
	//alert(xmlHttp);
	if (xmlHttp==null)
  	{
	
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	
	var url="OtherUniversities/OtherUniversitiesStates.asp";
	url=url+"?state="+str;
	//alert(url);
	xmlHttp.onreadystatechange=stateChangedVerify;
	xmlHttp.open("POST",url,true);
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //test for MSIE x.x;
		xmlHttp.send(null);
	else
		xmlHttp.send(url);
		
	//cursor_clear();
			

 }


//function used to return the object of XMLHTTP.
//detect which borowser are using.
//to be used in ajax funtionality
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;
}
//this function is called when the state of the ajax object is changed
// not metter the the state
function stateChangedVerify() 
{ 
	//In JavaScript, possible readyState values after sending an XMLHttpRequest are:
		//0 = open has not yet been called
		//1 = send has not yet been called but open has been called
		//2 = send has been called but no response from server
		//3 = data is in the process of being received from the server
		//4 = response from server has arrived


	if (xmlHttp.readyState==4)
	{ 
		//alert(xmlHttp.responseText)
		var results = xmlHttp.responseText;
		//alert(xmlHttp.responseText)
		if(results.length > 0){
			//alert(results)
			//document.write(results);
			var objdiv = document.getElementById('UniversityDiv');
			objdiv.innerHTML = results;
			 //hide();
		}	
		//document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
		
		//cursor_clear();
	}
}
function OnSelectuniversity(e){
	var str = e.options[e.selectedIndex].value;
	var otherfield = document.getElementById("OtherUniversityName");
	//var OtherUniLabel = document.getElementById("OtherUniversityLabel");
	//var OtherUniReq = document.getElementById("OtherRequired");

	
	if (str == "+1"){
		otherfield.style.display = "block";
		//OtherUniLabel.style.display = "block";
		//OtherUniReq.style.display = "block";
		
	}
	else{
		otherfield.style.display = "none";
		//OtherUniLabel.style.display = "none";	
		//OtherUniReq.style.display = "none";
	}
	
}
function hide() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("LoadingUniversity")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("LoadingUniversity")');
  else
     document.poppedLayer =   
        eval('document.layers["LoadingUniversity"]');
  document.poppedLayer.style.visibility = "hidden";
}

function show() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("LoadingUniversity")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("LoadingUniversity")');
  else
     document.poppedLayer = 
         eval('document.layers["LoadingUniversity"]');
  document.poppedLayer.style.visibility = "visible";
}

function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="")	{alert(alerttxt);return false;}
		else {return true}
	}
}
function validate_selected(field,alerttxt)
{
	with (field)
	{
		//alert(value);
		if (value=="-1")	{alert(alerttxt);return false;}
		else {return true}
	}
}

function validate_University(field,textfield,alerttxt)
{
	if(validate_selected(field,alerttxt)==true){
		with (field)
		{
			selectValue = value;
		}
		if(selectValue == "+1"){ 
			with(textfield){
				if (value==null||value==""){alert("Please specify your university name in the 'Other' field");return false;}
				else {return true;}
			}
		}
		else
		{
			return true;
		}
	}
	else {return false;}
	
}

function validate_form(thisform)
{
	with (thisform)
	{
		
		if (validate_required(email,"Please specify your email address")==false){
			email.focus();
			return false;
		}
		if (echeck(email.value)==false){
			email.value="";
			email.focus();
			return false
		}
		if (validate_selected(UniversityState,"Please specify the university's State")==false){
			UniversityState.focus();
			return false;
		}
		if (validate_University(University,Other," Please specify the university name")==false){
			University.focus();
			return false;
		}
		

	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){

		   alert("Your email is invalid, please retype your email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Your email is invalid, please retype your email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Your email is invalid, please retype your email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Your email is invalid, please retype your email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Your email is invalid, please retype your email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Your email is invalid, please retype your email")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Your email is invalid, please retype your email")
		    return false
		 }

 		 return true
	}



