// Global Variables
var bool = false;
var globalErrorString = "";
var globalDivID = "";
var xmlHttp;

//------------ ajax portion (start) -------------//
function GetXmlHttpObject(handler) {
var objXmlHttp=null;

if (navigator.userAgent.indexOf("Opera")>=0) {
	alert("This example doesn't work in Opera");
	return;
}

if (navigator.userAgent.indexOf("MSIE")>=0) {

	var strName="Msxml2.XMLHTTP";

	if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
		strName="Microsoft.XMLHTTP";;
	}

	try {
		objXmlHttp=new ActiveXObject(strName);
		objXmlHttp.onreadystatechange=handler;
		return objXmlHttp;
	}
	catch(e) {
		alert("Error. Scripting for ActiveX might be disabled");
		return;
	}
}

if (navigator.userAgent.indexOf("Mozilla")>=0) {
	objXmlHttp=new XMLHttpRequest();
	objXmlHttp.onload=handler;
	objXmlHttp.onerror=handler;
	return objXmlHttp;
	}
}


//------------ ajax portion (end) -------------//

//------------ dynamic dropdown (start) -------------//

function SelectCity(){
// ON selection of category this function will work

	removeAllOptions(document.info_form.city);
	addOption(document.info_form.city, "", "Select City", "");

	if(document.info_form.state.value == 'Alabama'){
		addOption(document.info_form.city,"Auburn", "Auburn");
		addOption(document.info_form.city,"Troy", "Troy");
		addOption(document.info_form.city,"Florence", "Florence");
		addOption(document.info_form.city,"Watson", "Watson");
		addOption(document.info_form.city,"Madison", "Madison");
	}
	if(document.info_form.state.value == 'Arkansas'){
		addOption(document.info_form.city,"Ashdown", "Ashdown");
		addOption(document.info_form.city,"Black Oak", "Black Oak");
		addOption(document.info_form.city,"Diamond City", "Diamond City");
		addOption(document.info_form.city,"Eudora", "Eudora");
		addOption(document.info_form.city,"Greenwood", "Greenwood");
		addOption(document.info_form.city,"Harrisburg", "Harrisburg");
	}
	if(document.info_form.state.value == 'California'){
		addOption(document.info_form.city,"Los Angeles", "Los Angeles");
		addOption(document.info_form.city,"Kings", "Kings");
		addOption(document.info_form.city,"Beaumont", "Beaumont");
		addOption(document.info_form.city,"Blue Lake", "Blue Lake");
		addOption(document.info_form.city,"Campbell", "Campbell");
		addOption(document.info_form.city,"Canyon Lake ", "Canyon Lake");
	}

	if(document.info_form.state.value == 'Illinois'){
		addOption(document.info_form.city,"Bridgeport", "Bridgeport");
		addOption(document.info_form.city,"Carthage", "Carthage");
		addOption(document.info_form.city,"Chicago", "Chicago");
		addOption(document.info_form.city,"Columbia", "Columbia");
		addOption(document.info_form.city,"Delavan", "Delavan");
		addOption(document.info_form.city,"Edwardsville", "Edwardsville");
		addOption(document.info_form.city,"Georgetown", "Georgetown");
		addOption(document.info_form.city,"Harrisburg", "Harrisburg");
		addOption(document.info_form.city,"Metropolis", "Metropolis");
		addOption(document.info_form.city,"Mason City", "Mason City");
	}

	if(document.info_form.state.value == 'Indiana'){
		addOption(document.info_form.city,"Columbus", "Columbus");
		addOption(document.info_form.city,"Delphi", "Delphi");
		addOption(document.info_form.city,"Hartford City", "Hartford City");
		addOption(document.info_form.city,"Madison", "Madison");
		addOption(document.info_form.city,"Michigan City", "Michigan City");
		addOption(document.info_form.city,"Oakland City", "Oakland City");
		addOption(document.info_form.city,"Portland", "Portland");
		addOption(document.info_form.city,"South Bend", "South Bend");
	}

	if(document.info_form.state.value == 'Minnesota'){
		addOption(document.info_form.city,"Breezy Point", "Breezy Point");
		addOption(document.info_form.city,"Clements", "Clements");
		addOption(document.info_form.city,"Cleveland", "Cleveland");
		addOption(document.info_form.city,"Dalton", "Dalton");
	}

	if(document.info_form.state.value == 'New Jersey'){
		addOption(document.info_form.city,"New Brunswick", "New Brunswick");
		addOption(document.info_form.city,"Hudson", "Hudson");
		addOption(document.info_form.city,"Cape May", "Cape May");
	}

	if(document.info_form.state.value == 'Ohio'){
		addOption(document.info_form.city,"Bedford", "Bedford");
		addOption(document.info_form.city,"Cincinnati", "Cincinnati");
		addOption(document.info_form.city,"Jamestown", "Jamestown");
	}

	if(document.info_form.state.value == 'Utah'){
		addOption(document.info_form.city,"Fairview", "Fairview");
		addOption(document.info_form.city,"Wallsburg", "Wallsburg");
		addOption(document.info_form.city,"Salt Lake City", "Salt Lake City");
	}

	if(document.info_form.state.value == 'Washington'){
		addOption(document.info_form.city,"Davenport", "Davenport");
		addOption(document.info_form.city,"Harrington", "Harrington");
		addOption(document.info_form.city,"Royal City", "Royal City");
	}


}

function removeAllOptions(selectbox) {
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


//------------ dynamic dropdown (end) -------------//
//-------------------- <AJAX> ------------------------//
function submitInformation(strInput, strURL, divName){

	var url=strURL+"?"+strInput;
	//alert(url);
	document.getElementById(divName).innerHTML="";
	document.getElementById(divName).innerHTML='<center><div style="text-align: center; padding-left: 120px;"><br><br><br><br><br><br><br><br><br><br><br><br><br><span style="font-size:10pt; color: white;">Please wait...</span><br><img name="loading" id="loading" src="images/progressbar_green.gif"><br><br><br><br><br><br><br><br><br><br><br><br><br></div></center>';
	globalDivID = divName;
	xmlHttp=GetXmlHttpObject(processInfo);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

function processInfo() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(globalDivID).innerHTML=xmlHttp.responseText;		
	}
}

function submitFavorite(strInput, strURL, divName) {
 try {
	var url=strURL+"?"+strInput;

	document.getElementById(divName).innerHTML="<center>please wait...</center>";

} catch(e) {
	alert(e);
}

	//document.getElementById(divName).style.background="#94a27b";
	xmlHttp=GetXmlHttpObject(processFavorite);
	globalDivID = divName;
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

function processFavorite() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(globalDivID).innerHTML=xmlHttp.responseText;
	}
}

function newAjaxHomeRequest(strInput, strURL, divname) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	document.getElementById(divname).innerHTML = '<br /><br /><br /><br /><br /><br /><br /><center><br />please wait...<br /><br /><img name="loading" id="loading" src="images/green-rotation-loading.gif"></center>';

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {

	        document.getElementById(divname).innerHTML = self.xmlHttpReq.responseText;
        }
    }
    self.xmlHttpReq.send(strInput);
}


function ajaxHomeRequest(strInput, strURL, divName) {
 try {
	var url=strURL+"?"+strInput;
	document.getElementById(divName).innerHTML="<center>please wait...</center>";

} catch(e) {
	alert(e);
}
	//document.getElementById(divName).style.background="#94a27b";
	xmlHttp=GetXmlHttpObject(processHomeRequest);
	globalDivID = divName;
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

function processHomeRequest() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(globalDivID).innerHTML=xmlHttp.responseText;
	}
}

function ajaxDeleteHomeRequest(strInput, strURL, divName) {
	var url=strURL+"?"+strInput;

	document.getElementById(divName).innerHTML= '<center><img name="loading" id="loading" src="images/ajax-loader-admin.gif"><br />please wait...</center>';

	globalDivID = divName;
	xmlHttp=GetXmlHttpObject(processInfoDelete);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

function processInfoDelete() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(globalDivID).innerHTML=xmlHttp.responseText;
	}
}

function processProfileSubmitReply(id, userID, houseID, agentID, emailAddress, message, whopostedID, divname) {
	var messageVar = 'emailAdd='+emailAddress+'&message='+message+'&id='+id+'&userid='+userID+'&houseID='+houseID+'&agentID='+agentID+'&whoPostedID='+whopostedID;
	var thisDivname = divname;

	ajaxDeleteHomeRequest(messageVar, 'processReplyEmail.php', thisDivname);

}

//-------------------- </AJAX> ------------------------//

function getInfo() {
//	alert('getInfo');

  	var infoString = "";

  	if(document.info_form.firstname.value != "") {
		infoString += "firstname="+document.info_form.firstname.value+"&";
	}
	if(document.info_form.lastname.value != "") {
	    infoString += "lastname="+document.info_form.lastname.value+"&";
	}
	if(document.info_form.email.value != "") {
	    infoString += "email="+document.info_form.email.value+"&";
	}
	if(document.info_form.d_phonenumber1.value != "" || document.info_form.d_phonenumber2.value != "" || document.info_form.d_phonenumber3.value != "") {
	    infoString += "dayphonenumber="+document.info_form.d_phonenumber1.value+document.info_form.d_phonenumber2.value+document.info_form.d_phonenumber3.value+"&";
	}
	if(document.info_form.n_phonenumber1.value != "" || document.info_form.n_phonenumber2.value != "" || document.info_form.n_phonenumber3.value != "") {
	    infoString += "nightphonenumber="+document.info_form.n_phonenumber1.value+document.info_form.n_phonenumber2.value+document.info_form.n_phonenumber3.value+"&";
	}
	if(document.info_form.address1.value != "") {
	    infoString += "address1="+document.info_form.address1.value+"&";
	}
	
	
	
	if(document.info_form.current_state.options[document.info_form.current_state.selectedIndex].value.length > 1) {
	    infoString += "current_state="+document.info_form.current_state.options[document.info_form.current_state.selectedIndex].value+"&";
	}
	if(document.info_form.zip.value != "") {
	    infoString += "zip="+document.info_form.zip.value+"&";
	}
	if(document.info_form.mycity.value != "") {
	    infoString += "mycity="+document.info_form.mycity.value+"&";
	}
  	if(document.info_form.state.options[document.info_form.state.selectedIndex].value.length > 1) {
	    infoString += "lookingfor_state="+document.info_form.state.options[document.info_form.state.selectedIndex].value+"&";
	}
	if(document.info_form.lookingfor_city.value.length != "") {
	    infoString += "lookingfor_city="+document.info_form.lookingfor_city.value+"&";
	}
	if(document.info_form.min_bedroom.options[document.info_form.min_bedroom.selectedIndex].value != "") {
	    infoString += "min_bedroom="+document.info_form.min_bedroom.options[document.info_form.min_bedroom.selectedIndex].value+"&";
	}
	if(document.info_form.min_bathroom.options[document.info_form.min_bathroom.selectedIndex].value != "") {
	    infoString += "min_bathroom="+document.info_form.min_bathroom.options[document.info_form.min_bathroom.selectedIndex].value+"&";
	}
	if(document.info_form.max_price.options[document.info_form.max_price.selectedIndex].value != "") {
	    infoString += "max_price="+document.info_form.max_price.options[document.info_form.max_price.selectedIndex].value+"&";
	}
	for(var i = 0; i < document.info_form.preapproved_mortgage.length; i++) {
	  	if(document.info_form.preapproved_mortgage[i].checked) {
		 	infoString += "preapproved_mortgage="+document.info_form.preapproved_mortgage[i].value+"&";
		}
	}
	for(var i = 0; i < document.info_form.with_HUDapproved_realtor.length; i++) {
	  	if(document.info_form.with_HUDapproved_realtor[i].checked) {
		 	infoString += "with_HUDapproved_realtor="+document.info_form.with_HUDapproved_realtor[i].value+"&";
		}
	}
	infoString += "message="+document.info_form.message.value+"&";
	infoString += "address2="+document.info_form.address2.value+"&";

	document.getElementById("error").innerHTML = "";
 	return infoString;
}

function areFieldsFilled() {
	var errorString = "";
	var ok = true;

	if(document.info_form.firstname.value.length < 1) {
		errorString += '<div class="boxcontent">Please enter your Firstname</div>';
		ok = false;
	} 
	if(document.info_form.lastname.value.length < 1) {
		errorString += '<div class="boxcontent">Please enter your Lastname</div>';
		ok = false;
	}
	if(document.info_form.email.value == "") {
		errorString += '<div class="boxcontent">Please enter your Email Address</div>';
	 	ok = false;
	}
	if(isNotValidEmail(document.info_form.email.value)) {
	  	errorString += '<div class="boxcontent">Invalid Email Address</div>';
		ok = false;
	} 
	if(document.info_form.d_phonenumber1.value == "" || document.info_form.d_phonenumber2.value == "" || document.info_form.d_phonenumber3.value == "") {
		errorString += '<div class="boxcontent">Invalid Phone Number</div>';
	 	ok = false;
	}
	if(document.info_form.address1.value == "") {
		errorString += '<div class="boxcontent">Please enter your Address</div>';
	 	ok = false;
	}
	if(document.info_form.current_state.options[document.info_form.current_state.selectedIndex].value.length < 1) {
		errorString += '<div class="boxcontent">Please Select your current state</div>';
	 	ok = false;
	}
	if(document.info_form.zip.value == "") {
		errorString += '<div class="boxcontent">Please enter your zip code</div>';
	 	ok = false;
	}
	if(document.info_form.mycity.value == "") {
		errorString += '<div class="boxcontent">Please enter your zip code</div>';
	 	ok = false;
	}
	if(document.info_form.state.options[document.info_form.state.selectedIndex].value == "") {
		errorString += '<div class="boxcontent">Please Select your choice of state</div>';
	 	ok = false;
	}
	if(document.info_form.lookingfor_city.value == "") {
		errorString += '<div class="boxcontent">Please Select your choice of city</div>';
	 	ok = false;
	}
	if(document.info_form.max_price.options[document.info_form.max_price.selectedIndex].value == "") {
		errorString += '<div class="boxcontent">Please Select your choice of max price of houses</div>';
		ok = false;
	}
		
	if(errorString.length > 1) {
		document.getElementById("errorbox").innerHTML = '<div class="headerError">Error:</div>'+errorString;
		document.getElementById("errorbox").style.backgroundColor = "#435e20";
		//435e20

		ok = false;
	}
		
	return ok;
}

function setBool(booleanInput) {
 	 bool = booleanInput;
}

function getBool() {
//  	alert('bool: '+bool);
	return bool;
}

function advance(currentField,nextField) {
    if(currentField == 'd_phonenumber3' || currentField == 'n_phonenumber3' || currentField == 'phonenumber3'){
		if(document.getElementById(currentField).value.length==4){
			document.getElementById(nextField).focus();
		}
	}else{
		if(document.getElementById(currentField).value.length==3){
			document.getElementById(nextField).focus();
		}
	}

}

function patternCheck(e){
	if (e == null) e = window.event;
	var key = (e.which)?e.which:e.keyCode

	if ((key >=48 && key <=57)||(key == 9)||(key == 8)||(key == 13)||(key == 15)||(key == 127)){
		//alert("good" + key);
		return true;
	}else{
	//alert("You can only enter valid characters in this field:\n\n Numbers: 0-9");
		return false;
	}

}

function res(t){
	v = "0123456789";
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
			w += x;
	}
	   t.value = w;
}

function isNotValidEmail(str) {
   return (str.indexOf(".") < 2) && (str.indexOf("@") < 1);

}
/*-----      register      ------*/
function regCheck(){
	var errorString = "";
	var ok = true;
	document.getElementById("errorbox").innerHTML = "";

	if(document.register_form.firstname.value == "") {
		errorString += '<div class="boxcontent">Please enter your Firsname</div>';
		ok = false;
	}
	if(document.register_form.lastname.value == "") {
	 	errorString += '<div class="boxcontent">Please enter your Lastname</div>';
	 	ok = false;
	}
	if(validate_email(document.register_form.emailAddress) == false) {
	 	errorString += '<div class="boxcontent">Invalid Email</div>';
	 	ok = false;
	}
	if(document.register_form.c_password.value == "" || document.register_form.password.value == "") {
		errorString += '<div class="boxcontent">Password field required</div>';
		ok = false;
	}
	if(document.register_form.address.value == "") {
		errorString += '<div class="boxcontent">Please enter your Address</div>';
		ok = false;
	}
	if(document.register_form.zipcode.value == "") {
		errorString += '<div class="boxcontent">Please enter your Zipcode</div>';
		ok = false;
	}
	
	if(document.register_form.phonenumber1.value.length < 1 || document.register_form.phonenumber2.value.length < 1 || document.register_form.phonenumber3.value.length < 1 ) {
		errorString += '<div class="boxcontent">Please enter a correct phone number format</div>';
		ok = false;
	}
	
	
	if(document.register_form.imageBox.value == "") {
		errorString += '<div class="boxcontent">You Forgot to enter the image code below</div>';
		ok = false;
	}

	if(document.register_form.country.value == "0") {
		errorString += '<div class="boxcontent">Please select a country</div>';
		ok = false;
	}
	
	if(document.register_form.mystate.value == "0") {
		errorString += '<div class="boxcontent">Please select your current State</div>';
		ok = false;
	}
	
	if(document.register_form.mycity.value == "") {
		errorString += '<div class="boxcontent">Please enter your City</div>';
		ok = false;
	}

	if(document.register_form.c_password.value != document.register_form.password.value) {
		errorString += '<div class="boxcontent">Passwords are not identical</div>';
		document.register_form.c_password.value = "";
		document.register_form.password.value = "";
		ok = false;
	}


	if(errorString.length != 0) {
		document.getElementById("errorbox").innerHTML = '<div class="headerError">Error:</div>'+errorString;
		document.getElementById("errorbox").style.backgroundColor = "#435e20";
		//435e20

		ok = false;
	}

	return ok;

}

function validate_email(field){

	with (field) {
	 	if(value==null || value=="") {
			return false;
		}
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");

		if (apos<1||dotpos-apos<2) {
		 	return false;
		 } else {
		  	return true;
		}
	}
}

/* registration form*/

function getRegistrationInfo() {
  var infoString = "";

  if(document.register_form.firstname.value != "") {
		infoString += "firstname="+document.register_form.firstname.value+"&";
	}
  if(document.register_form.lastname.value != "") {
		infoString += "lastname="+document.register_form.lastname.value+"&";
	}  
  if(document.register_form.password.value != "") {
		infoString += "password="+document.register_form.password.value+"&";
	}
  if(document.register_form.emailAddress.value != "") {
		infoString += "emailAddress="+document.register_form.emailAddress.value+"&";
	}
  if(document.register_form.address.value != "") {
		infoString += "address="+document.register_form.address.value+" "+document.register_form.address2.value+"&";
	}
  if(document.register_form.zipcode.value != "") {
		infoString += "zipcode="+document.register_form.zipcode.value+"&";
	}
  if(document.register_form.imageBox.value != "") {
		infoString += "imageBox="+document.register_form.imageBox.value+"&";
	}
  if(document.register_form.country.value != "0") {
   		infoString += "country="+document.register_form.country.options[document.register_form.country.selectedIndex].value+"&";
	}
  if(document.register_form.mystate.value != "0") {
   		infoString += "mystate="+document.register_form.mystate.options[document.register_form.mystate.selectedIndex].value+"&";
	}
  if(document.register_form.mycity.value != "") {
		infoString += "mycity="+document.register_form.mycity.value+"&";
	}

  for(var i = 0; i < document.register_form.preapproved_mortgage.length; i++) {
	  	if(document.register_form.preapproved_mortgage[i].checked) {
		 	infoString += "preapproved_mortgage="+document.register_form.preapproved_mortgage[i].value+"&";
		}
	}
  for(var i = 0; i < document.register_form.with_HUDapproved_realtor.length; i++) {
	  	if(document.register_form.with_HUDapproved_realtor[i].checked) {
		 	infoString += "with_HUDapproved_realtor="+document.register_form.with_HUDapproved_realtor[i].value+"&";
		}
	}
	
	var phoneNumber = document.register_form.phonenumber1.value+"-"+document.register_form.phonenumber2.value+"-"+document.register_form.phonenumber3.value;
  	infoString += "phoneNumber="+phoneNumber+"&";
	infoString += "max_price="+document.register_form.max_price.options[document.register_form.max_price.selectedIndex].value+"&";
	infoString += "min_bedroom="+document.register_form.min_bedroom.options[document.register_form.min_bedroom.selectedIndex].value+"&";
	infoString += "min_bathroom="+document.register_form.min_bathroom.options[document.register_form.min_bathroom.selectedIndex].value+"&";
	infoString += "state="+document.register_form.state.options[document.register_form.state.selectedIndex].value+"&";
	infoString += "city="+document.register_form.city.value+"&";

	document.getElementById("error").innerHTML = "";

	return infoString;

}

/*--- Gallery ---*/
function changeImage(filename) {
  document.getElementById("mainimage").src = filename;

}


//------------------- show/hide functions -------------------//
function showDiv(cinput) {

  try {
   var content = document.getElementById(cinput);
  } catch(e) {
    alert(e);
  }
	var contentStatus = 'block';
	content.style.display = contentStatus;
}

function hideDiv(cinput) {

  try {
   var content = document.getElementById(cinput);
  } catch(e) {
    alert(e);
  }
	var contentStatus = 'none';
	content.style.display = contentStatus;
}

function hideAllDiv(str, tagName, exceptionID) {
	
	var inputNodes = document.getElementsByTagName(tagName);
	
	for(var i=0; i < inputNodes.length; i++) {
		eval("var pattern = new RegExp(\"^\"+str);");
		
		if(pattern.test(inputNodes[i].id)) {
			if(inputNodes[i].id == exceptionID) {
				//do nothing
			} else {				
				hideDiv(inputNodes[i].id);			
			}
		}
			
		 	
	}
}

//------------------- /show/hide functions -------------------//

//-------------------- Dynamic Tab Panes --------------------//
var panes = new Array();

function setupPanes(containerId, defaultTabId) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible

    for (var con in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      var tabs = container.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none"
      }
    }
  }
  return false;
}

//-------------------- /Dynamic Tab Panes --------------------//

function addOption(selectbox, value, text, is_selected) {
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	optn.id = value+"ID";
	if (is_selected == 1)
		optn.selected = true;

	selectbox.options.add(optn);
}

function toggleDiv(divname) {
   try {
   	var content = document.getElementById(divname);
  } catch(e) {
    alert(e);
  }
	if(content.style.display == 'none') {
		showDiv(divname);
	} else {
		hideDiv(divname);
	}
}

//-----------------------/ARCHIVE/DELETE INBOX MESSAGES/--------------------------//

function ifCheckedBox(checkBoxName) {
	var count = 0;

	for(var i = 0; i < document.getElementsByName(checkBoxName).length; i++) {
	  	if(document.getElementsByName(checkBoxName)[i].checked) {
		 	count++;
		}
	}
	
	if(count > 0) {
		return true;
	} else
		return false;
}

function gatherCheckedBoxes(checkBoxName) {
	var checkedArray = "IDlist=";

	for(var i = 0; i < document.getElementsByName(checkBoxName).length; i++) {
	  	if(document.getElementsByName(checkBoxName)[i].checked) {
		 	checkedArray += document.getElementsByName(checkBoxName)[i].value+"-";

		}
	}

	return checkedArray;
}

function setUpStringURL(checkBoxName, flag, divName, strURL, userID) {
	var IDstring = gatherCheckedBoxes(checkBoxName);
	var stringURL = IDstring+"&flagPost="+flag+"&currentuserid="+userID;


	newAjaxInboxMsg(stringURL, strURL, divName);
}

function ajaxInboxMsg(strInput, strURL, divname) {

	try {
		var url=strURL+"?"+strInput;
		document.getElementById(divname).innerHTML="<center>please wait...<br /><img name=\"loading\" id=\"loading\" src=\"images/ajax-loader.gif\"></center>";

	} catch(e) {
		alert(e);
	}
		xmlHttp=GetXmlHttpObject(processAjaxInboxMsg);
		globalDivID = divname;
		xmlHttp.open("GET", url , true);
		xmlHttp.send(null);
}

function processAjaxInboxMsg() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var URLstr = "user_id="+xmlHttp.responseText;

		ajaxHomeRequest(URLstr, 'processHomeRequestProfile.php', 'pane3');

	}
}


function toggleCheckedBoxes(checkBoxName, chBox) {

	for(var i = 0; i < document.getElementsByName(checkBoxName).length; i++) {
	  	if(!document.getElementById(chBox).checked) {
		 	document.getElementsByName(checkBoxName)[i].checked = false;
		} else {
			document.getElementsByName(checkBoxName)[i].checked = true;
		}
	}

}

function newAjaxInboxMsg(strInput, strURL, divname) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	document.getElementById(divname).innerHTML = '<br /><br /><br /><br /><br /><br /><br /><center>please wait...<img name="loading" id="loading" src="images/ajax-loader.gif"><br /></center>';

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {

	        document.getElementById(divname).innerHTML = self.xmlHttpReq.responseText;
        }
    }
    self.xmlHttpReq.send(strInput);
    
}

function populateCityDropdown(strInput, strURL, divname) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
    try {		
		document.getElementById(divname).innerHTML = '<center><span style="text-align: center; vertical-align: middle; background: #CFCFCF; color: black;">please wait... <img name="loading" id="loading" src="images/ajax-loader-radar.gif"></span></center>';    
 	} catch(e) {
	 	alert(e);
 	}
    

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {

	        document.getElementById(divname).innerHTML = self.xmlHttpReq.responseText;
        }
    }
    self.xmlHttpReq.send(strInput);
    
}

function trimAll( strValue ) {

 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function selectImage(imgName) {
	
   if (document.images) {
   	
   	try { 
		var imgOn=eval(imgName + "On.src");
		document[imgName].src= imgOn;
	} catch(err) {
		alert(err);
	}
      
      
    }
 }

function unselectImage(imgName) {
	
	 if (document.images) {
	 	
	 	try {
			var imgOff=eval(imgName + "Off.src");
			document[imgName].src= imgOff;
		} catch(err) {
			alert(err);
		}
	 	
			
		}
 }

function targetsite(start, statevar, cityvar, fromPriceRange, toPriceRange, address, bath, bed, eligibility, fha, hasImage) {
	
	
	var url = "gallery.php?start="+start+"&s="+statevar+"&c="+cityvar;
	if((fromPriceRange.length != 0) && (typeof(fromPriceRange) != 'undefined')) {
		url += "&fpr="+fromPriceRange;
	}
	
	if((toPriceRange.length != 0) && (typeof(toPriceRange) != 'undefined')) {
		url += "&tpr="+toPriceRange;
	}
	
	if((address.length != 0) && (typeof(address) != 'undefined')) {
		url += "&a="+address;
	}
	
	if((bath.length != 0)  && (typeof(bath) != 'undefined')) {
		url += "&ba="+bath;	
	}
	
	if((bed.length != 0) && (typeof(bed) != 'undefined')) {
		url += "&be="+bed;
	}
	
	if((eligibility.length != 0) && (typeof(eligibility) != 'undefined')) {
		url += "&eleg="+eligibility;
	}
	
	if((fha.length != 0) && (typeof(fha) != 'undefined')) {
		url += "&fha="+fha;
	}
	
	if((hasImage.length != 0) && (typeof(hasImage) != 'undefined')) {
		url += "&hi="+hasImage;
	}
	
	window.location = url;
}

function checkEmailField(strInput, strURL, divname) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
    try {		
		document.getElementById(divname).innerHTML = '<img name="loading" id="loading" src="images/ajax-loader-gallery.gif">';    
 	} catch(e) {
	 	alert(e);
 	}
    

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {

	        document.getElementById(divname).innerHTML = self.xmlHttpReq.responseText;
        }
    }
    self.xmlHttpReq.send("add="+strInput);    
}
