
function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}

var http = getHTTPObject();

function refreshCombo(country,region,subregion,category,subcategory){
	var path = new String();
	//alert(country);
	path = 'include/searchfields.php?country='+country;
	if(region != null){
		path += '&region='+region;
	}
	if(subregion != null){
		path += '&subregion='+subregion;
	}
	if(category != null){
		path += '&cat='+category;	
	}
	if(subcategory != null){
		path += '&subcat='+subcategory;	
	}
	path += '&action=send&rand='+Math.random();
	http.open('get', path );
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function compare(id,status){
	var path = new String();
	path = 'include/compareinsert.php?id='+id;
	
	if(status != null){
		path += '&status=remove';
	}
	
	path += '&action=send&rand='+Math.random();
	http.open('get', path );
	
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function wishlist(id,cid,status){
	var path = new String();
	path = 'include/wishlist.php?id='+id;
	
	if(status != null){
		path += '&status=remove';
	}
	if(cid != null){
		path += '&cid='+cid;
	}
	
	path += '&action=send&rand='+Math.random();
	http.open('get', path );
	
    http.onreadystatechange = handleResponse;
    http.send(null);
}



function refreshpostpropertycombo(id,type){
	var path = new String();
	//alert(country);
	path = 'include/refcombo.php?id='+id;
	if(type != null){
		path += '&type='+type;
	}
	path += '&action=send&rand='+Math.random();
	http.open('get', path );
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function checkpassconfirm(){
var newpass = document.editpassword.newpass.value;
var confirmpass = document.editpassword.confirmpass.value;	
	if ( newpass ==confirmpass){
		return true;
	}else{
		alert("Your New Password do not match");
		return false;
		
	}
}

function checkemailconfirm(){
	if(document.editemail.oldemail.value.length == 0){ alert("Old Email required"); return false;}
	if(document.editemail.newemail.value.length == 0){ alert("New Email required"); return false;}
	if(document.editemail.confirmemail.value.length == 0){ alert("Confirm required"); return false;}
	
var newemail = document.editemail.newemail.value;
var confirmemail = document.editemail.confirmemail.value;	
	if ( newemail ==confirmemail){
		return true;
	}else{
		alert("Your New Email do not match");
		return false;
		
	}
}


function signupcheck(){
	if(document.signup.fname.value.length == 0){ alert("First Name required"); return false;}
	if(document.signup.lname.value.length == 0){ alert("Last Name required"); return false;}
	//if(document.signup.email.value.length == 0){ alert("Email required"); return false;}
	//if(echeck(document.signup.email.value) ==false){ alert("Email Address not valid"); return false;}
	if(document.signup.pass.value.length < 6){ alert("Password too short"); return false;}
	if(document.signup.pass.value != document.signup.confirm.value){ alert("Password not confirmed"); return false;}
	if(document.signup.terms.checked == false){ alert("Please read the terms and conditions"); return false;} 
	return true;	
}
//email validation check

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("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

 		 return true;					
	}

function checkeditaccountlength(){
	if(document.editaccount.fname.value.length == 0){ alert("First Name required"); return false;}
	if(document.editaccount.lname.value.length == 0){ alert("Last Name required"); return false;}
	return true;
}

function checkeditpropertylength(){
	if(document.editproperty.price.value == 0){ alert("Price required"); return false;}
	if(document.editproperty.price.length == 0){ alert("Price required"); return false;}
	if(document.editproperty.area.value == 0){ alert("Area required"); return false;}
	if(document.editproperty.area.length == 0){ alert("Area required"); return false;}
	
	return true;
}

function checkpostaccount(){
	if(document.postproperty.title.value.length == 0){ alert("Title required"); return false;}
	//alert(document.postproperty.country.options[document.postproperty.country.selectedIndex].value);
	if(document.postproperty.country.options[document.postproperty.country.selectedIndex].value == 0){ alert("Country required"); return false;}
	if(document.postproperty.region.options[document.postproperty.region.selectedIndex].value == 0){ alert("Region required"); return false;}
	if(document.postproperty.subregion.options[document.postproperty.subregion.selectedIndex].value == 0){ alert("Sub Region required"); return false;}
	if(document.postproperty.category.options[document.postproperty.category.selectedIndex].value == 0){ alert("Category required"); return false;}
	if(document.postproperty.area.value == 0){ alert("Area required"); return false;}
	if(document.postproperty.area.length == 0){ alert("Area required"); return false;}
	if(document.postproperty.price.value == 0){ alert("Price required"); return false;}
	if(document.postproperty.price.length == 0){ alert("Price required"); return false;}
	return true;
}


function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
		
         if(response.indexOf('|' != -1)) {
			//alert(response);
            update = response.split('|');
			//alert(update);
			if( document.getElementById(update[0]) ){
           	 document.getElementById(update[0]).innerHTML = update[1];
			}
			if(document.getElementById('F'+update[0]) ){
				document.getElementById('F'+update[0]).innerHTML = update[1];
			}
        }
	}
 
}

function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}



