function GetXmlHttpObject888888() 
{	
	var xmlHttp=null;
	try {
 		xmlHttp=new XMLHttpRequest();		// Firefox, Opera 8.0+, Safari
 	}
	catch (e)								// Internet Explorer
 	{
 		try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		} catch (e) {
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
	}
	return xmlHttp;
}

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)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

function registerationValidation()
{	
	var txtfname = document.getElementById("first_name").value;
	var txtlname = document.getElementById("last_name").value;
	//var txtaddress = document.getElementById("street_address").value;
	//var txtcity = document.getElementById("city").value;
	//var txtcode = document.getElementById("postal_code").value;
	//var txtphone = document.getElementById("primary_phone").value;

	var txtuser = document.getElementById("user_name").value;
	//var txtemail = document.getElementById("email").value;
	var txtpwd1 = document.getElementById("user_pass").value;
	var txtpwd2 = document.getElementById("user_pass2").value;	
	var terms = document.getElementById("terms");
	var temp = true;
	
	//Check First Name
	if(txtfname=="")
	{
		document.getElementById('error_fname').innerHTML = 'Please enter your first name.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtfname))
		{
			document.getElementById('error_fname').innerHTML = 'Invalid your first name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_fname').innerHTML = ' ';
		}
	}
	//Check Last Name
	if(txtlname=="")
	{
		document.getElementById('error_lname').innerHTML = 'Please enter your last name.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtlname))
		{
			document.getElementById('error_lname').innerHTML = 'Invalid your last name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_lname').innerHTML = ' ';
		}
	}
	//Check Address
	/*if(txtaddress=="")
	{
		document.getElementById('error_address').innerHTML = 'Please enter your street address.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtaddress))
		{
			document.getElementById('error_address').innerHTML = 'Invalid your street address.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_address').innerHTML = ' ';
		}
	}*/
	//Check City
/*	if(txtcity=="")
	{
		document.getElementById('error_city').innerHTML = 'Please enter your city.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtcity))
		{
			document.getElementById('error_city').innerHTML = 'Invalid your city name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_city').innerHTML = ' ';
		}
	}
*/	//Check Postal code
	/*if(txtcode=="")
	{
		document.getElementById('error_postal_code').innerHTML = 'Please enter your postal code.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtcode))
		{
			document.getElementById('error_postal_code').innerHTML = 'Invalid your postal code.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_postal_code').innerHTML = ' ';
		}
	}*/
	//Check Postal code
/*	if(txtphone=="")
	{
		document.getElementById('error_pphone').innerHTML = 'Please enter your primary phone.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtphone))
		{
			document.getElementById('error_pphone').innerHTML = 'Invalid your postal code.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_pphone').innerHTML = ' ';
		}
	}
	// Check Username
	if(txtuser!="")
	{
		if(!isAlphanumeric(txtuser) || (txtuser.length<4))
		{
			document.getElementById('error_username').innerHTML = 'Invalid username.';
			temp=false;
		}
		else
		{
			if(CheckUserName(txtuser,'usernm')=="yes")
			{
				document.getElementById('error_username').innerHTML = 'Username already exists.';
				temp = false;
			}
			else
			{
				document.getElementById('error_username').innerHTML = ' ';
			}
		}
	}
	else
	{
		document.getElementById('error_username').innerHTML = 'Please enter username.';
		temp = false;
	}
*/	
	//Check Password 1
	if(txtpwd1=="")
	{
		document.getElementById('error_pass').innerHTML = 'Please enter your password.';
		temp = false;
	}
	else
	{
		if(txtpwd1.length < 6 || txtpwd1.length > 30)
		{
			document.getElementById('error_pass').innerHTML = 'Password min 6 charaters long.';
			temp = false;			
		}
		else
		{
			document.getElementById('error_pass').innerHTML = ' ';
		}
	}
	//Check Password 2
	if(txtpwd2=="")
	{
		document.getElementById('error_pass2').innerHTML = 'Confirm your password.';
		temp = false;
	}
	else
	{
		if(txtpwd1!=txtpwd2)
		{
			document.getElementById('error_pass2').innerHTML = 'Password does not match.';
			temp = false;			
		}
		else
		{
			document.getElementById('error_pass2').innerHTML = ' ';
		}
	}
	// Check Email
	if(!isnull(txtuser))
	{
		if(!isemail(txtuser))
		{
			document.getElementById('error_useremail').innerHTML = 'Invalid email address.';
			temp = false;
		}
		else if(CheckUserName(txtuser,'usermail')=="yes")
		{
			document.getElementById('error_useremail').innerHTML = 'Email address already exists.';
			temp = false;
		}
		else
		{
			document.getElementById('error_useremail').innerHTML = ' ';
		}
	}
	else
	{
		document.getElementById('error_useremail').innerHTML = 'Please enter email address.';
		temp = false;
	}	
	if (!terms.checked)
	{
		document.getElementById('error_terms').innerHTML = 'Please select terms and conditions agreement.';
		temp = false;		
	}
	else
	{
		document.getElementById('error_terms').innerHTML = ' ';
	}
	
	//temp = false; // temporary
	if(temp == false)
	{	return false; }
	else { return true; }
	
}
function isAlphanumeric(x)
{
	var reAlphanumeric = /^[a-zA-Z0-9-_ ]+$/;
	return reAlphanumeric.test(x);
}
function isemail(x)
{
	var reEmail = /^.+\@.+\..+$/;
	if(isnull(x))
	return false;
	else
	return reEmail.test(x);
}
function isnull(x)
{
	if(x==null || x=="")
	return true;
	else
	return false;
}

function CheckUserName(str,f)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request")
			return
	}
	if(f=='usernm')
	{
		var url=baseURL+"ajax.php?type=chkusr&uname="+str;
	}
	if(f=='usermail')
	{
		var url=baseURL+"ajax.php?type=chkemail&email="+str;
	}
	//alert(url);
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
	//alert(xmlHttp.responseText);
	result=xmlHttp.responseText;
	return result;
}


//Forget Password
function forgetpwd(){	
	var uname=document.getElementById('user_email').value;
	if(uname==""){
		document.getElementById('error_useremail').innerHTML ="Please enter username or email.";
		return false;
	} else {
			document.getElementById('error_useremail').innerHTML ="";
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null) {
					alert ("Browser does not support HTTP Request")
					return
			}
			var url=baseURL+"ajax.php?type=lostuser_request&username="+uname;
			xmlHttp.open("GET",url,false)
			xmlHttp.send(null)
			//alert(xmlHttp.responseText);
			result=xmlHttp.responseText;
			if(result==1){
			document.getElementById('error_useremail').innerHTML ="<span class='success'>Please check your email address. That's where you'll recieve your login password.</span>";
			document.getElementById('fname').value="";
			return false;
			} else if(result==0){
				document.getElementById('error_useremail').innerHTML ="ERROR: Invalid username or e-mail.";
			}	
			return false;
	}
	
	return false;
}
//LOGIN Validation
function LoginValid()
{	
	var txtuser = document.getElementById("user-name").value;
	var txtpass = document.getElementById("password").value;
	var remember = document.getElementById("remember");
	var temp = true;	
	// Check Username
	if (remember.checked) 
		{ toMem(); }
	
	if(txtuser=="")
	{
		document.getElementById('error_username').innerHTML = 'Please enter your email.';
		temp=false;		
	}else{ document.getElementById('error_username').innerHTML = "";}
	if(txtpass=="")
	{
		document.getElementById('error_password').innerHTML = 'Please enter pasword.';
		temp=false;		
	}else{ document.getElementById('error_password').innerHTML = "";}
	if(temp == false)
	{	return false; }
	else { return true; }

}
//Reset Password Form
function ResetPasswordValid(){
	var usrnm=document.getElementById('usernm').value;
	var usrpw=document.getElementById('newpwd').value;
	if(usrnm==""){
		document.getElementById('error_username').innerHTML ="Please enter username";
		return false;
	} else {
		document.getElementById('error_username').innerHTML ="";
	}
	if(usrpw==""){
		document.getElementById('error_password').innerHTML ="Please enter new password";
		return false;
	} else {
		document.getElementById('error_password').innerHTML ="";
	}
}
/*=============================*/
function ValidContactForm()
{	
	var cnt_name = document.getElementById("cnt_name").value;
	var cnt_email = document.getElementById("cnt_email").value;
	var cnt_phone = document.getElementById("cnt_phone").value;
	var cnt_message = document.getElementById("cnt_message").value;
	var temp = true;
	
	//Check First Name
	if(cnt_name=="")
	{
		document.getElementById('error_name').innerHTML = 'Please enter your name.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(cnt_name))
		{
			document.getElementById('error_name').innerHTML = 'Invalid your name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_name').innerHTML = ' ';
		}
	}
	// Check Email
	if(!isnull(cnt_email))
	{
		if(!isemail(cnt_email))
		{
			document.getElementById('error_email').innerHTML = 'Invalid email address.';
			temp = false;
		}
		else
		{
			document.getElementById('error_email').innerHTML = ' ';
		}
	}
	else
	{
		document.getElementById('error_email').innerHTML = 'Please enter email address.';
		temp = false;
	}
	// Check Phone	
	if(cnt_phone=="")
	{
		document.getElementById('error_phone').innerHTML = 'Please enter your phone number.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(cnt_phone))
		{
			document.getElementById('error_phone').innerHTML = 'Invalid your phone number.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_phone').innerHTML = ' ';
		}
	}
	// Check Message	
	if(cnt_message=="")
	{
		document.getElementById('error_message').innerHTML = 'Please enter your message.';
		temp = false;
	}
	else
	{
		document.getElementById('error_message').innerHTML = ' ';
	}

	
	//temp = false; // temporary
	if(temp == false)
	{	return false; }
	else { return true; }
	
}
/*=================================  CALC*/
function checkForZero(field)
{
    if (field.value == 0 || field.value.length == 0) {
        //alert ("This field can't be 0!");
        field.focus(); }
    else
        calculatePayment(field.form);
}

function cmdCalc_Click(form)
{
	var temp = true;
    if (form.price.value == 0 || form.price.value.length == 0) 
	{
        document.getElementById('error_pr').innerHTML = "The Price field can't be 0!";
        form.price.focus(); 
		temp = false;
	}else{ document.getElementById('error_pr').innerHTML = ' '; }
    if (form.ir.value == 0 || form.ir.value.length == 0) 
	{
        document.getElementById('error_ir').innerHTML = "The Price field can't be 0!";		
        form.ir.focus();
		temp = false;
	}else{ document.getElementById('error_ir').innerHTML = ' '; }
    if (form.term.value == 0 || form.term.value.length == 0) 
	{
			document.getElementById('error_tr').innerHTML = "The Term field can't be 0!";
	        form.term.focus(); 
			temp = false;
	}else{ document.getElementById('error_tr').innerHTML = ' '; }
	
	
    if(temp)
	{ 
		document.getElementById('error_tr').innerHTML= ' ';
		document.getElementById('error_ir').innerHTML= ' ';	
		calculatePayment(form); 
	}
	
}

function calculatePayment(form)
{
    princ = form.price.value - form.dp.value;
    intRate = (form.ir.value/100) / 12;
    months = form.term.value * 12;
    //form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
	document.getElementById('result').innerHTML= '$'+Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
    ////////form.principle.value = princ;
    ///////form.payments.value = months;
}
function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 //alert(charCode);
 if (charCode > 31 && (charCode < 46 || charCode > 57))
	return false;

 return true;
}

/*================================================= */
function UpdateValidation()
{	
	var txtfname = document.getElementById("first_name").value;
	var txtlname = document.getElementById("last_name").value;
	var txtaddress = document.getElementById("street_address").value;
	var txtcity = document.getElementById("city").value;
	var txtcode = document.getElementById("postal_code").value;
	var txtphone = document.getElementById("primary_phone").value;

	var txtemail = document.getElementById("email").value;
	var txtpwd1 = document.getElementById("user_pass").value;
	var txtpwd2 = document.getElementById("user_pass2").value;	
	var temp = true;
	
	//Check First Name
	if(txtfname=="")
	{
		document.getElementById('error_fname').innerHTML = 'Please enter your first name.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtfname))
		{
			document.getElementById('error_fname').innerHTML = 'Invalid your first name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_fname').innerHTML = ' ';
		}
	}
	//Check Last Name
	if(txtlname=="")
	{
		document.getElementById('error_lname').innerHTML = 'Please enter your last name.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtlname))
		{
			document.getElementById('error_lname').innerHTML = 'Invalid your last name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_lname').innerHTML = ' ';
		}
	}
	//Check Address
	if(txtaddress=="")
	{
		document.getElementById('error_address').innerHTML = 'Please enter your street address.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtaddress))
		{
			document.getElementById('error_address').innerHTML = 'Invalid your street address.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_address').innerHTML = ' ';
		}
	}
	//Check City
	if(txtcity=="")
	{
		document.getElementById('error_city').innerHTML = 'Please enter your city.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtcity))
		{
			document.getElementById('error_city').innerHTML = 'Invalid your city name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_city').innerHTML = ' ';
		}
	}
	//Check Postal code
	if(txtcode=="")
	{
		document.getElementById('error_postal_code').innerHTML = 'Please enter your postal code.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtcode))
		{
			document.getElementById('error_postal_code').innerHTML = 'Invalid your postal code.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_postal_code').innerHTML = ' ';
		}
	}
	//Check Postal code
	if(txtphone=="")
	{
		document.getElementById('error_pphone').innerHTML = 'Please enter your postal code.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtphone))
		{
			document.getElementById('error_pphone').innerHTML = 'Invalid your postal code.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_pphone').innerHTML = ' ';
		}
	}
	//Check Password 1
	if(txtpwd1!="")
	{
		if(txtpwd1.length < 6 || txtpwd1.length > 30)
		{
			document.getElementById('error_pass').innerHTML = 'Password min 6 charaters long.';
			temp = false;			
		}
		else
		{
			document.getElementById('error_pass').innerHTML = ' ';
		}
	}
	//Check Password 2
	if(txtpwd2!="" || txtpwd1!="")
	{
		if(txtpwd1!=txtpwd2)
		{
			document.getElementById('error_pass2').innerHTML = 'Password does not match.';
			temp = false;			
		}
		else
		{
			document.getElementById('error_pass2').innerHTML = ' ';
		}
	}
	// Check Email
	if(!isnull(txtemail))
	{
		if(!isemail(txtemail))
		{
			document.getElementById('error_useremail').innerHTML = 'Invalid email address.';
			temp = false;
		}
	}
	else
	{
		document.getElementById('error_useremail').innerHTML = 'Please enter email address.';
		temp = false;
	}
	
	//temp = false; // temporary
	if(temp == false)
	{	return false; }
	else { return true; }
	
}
function RemoveSubImages(removeId,options_val,li_id){
	//alert(li_id);
	var confirmme = confirm("Are you sure you want to delete image?");	
	if(confirmme)
	{
		CallMe_DeleteImage(removeId,options_val,li_id);	 
	}	
	else
	{
		return false;	
	}
	
}
function SetImagesAsMain(removeId,post_id,li_id){
	
	var confirmme = confirm("Are you sure you want to set this image as main image?");	
	if(confirmme)
	{		
		CallMe_SetMainImage(removeId,post_id,li_id);	 
	}
	else
	{
		return false;	
	}
}
/*====================*/
function CallMe_DeleteImage(removeId,options_val,li_id)
{
	//alert(li_id);	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request")
			return
	}
	var url=baseURL+"ajax.php?type=removeimages&removeId="+removeId;
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
	//alert(xmlHttp.responseText);
	//alert(result);
	result=xmlHttp.responseText;
	if(result=='yes')
	{ 
		//alert("Delete"); 
		if(options_val=='newdata'){
			//alert("Wah");
			//alert(li_id);
			document.getElementById(li_id).style.display="none";
		}
		return false; 
	}
	else
	{
		//alert("Delete Error"); 
		return false; 		
	}	
}
/*====================*/
function CallMe_SetMainImage(removeId,post_id)
{
	var xmlHttp =  null;	
	xmlHttp = new GetXmlHttpObject();
	//alert(xmlHttp);
	if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request")
			return;
	}
	//alert(baseURL);
	var url=baseURL+"ajax.php?type=setmainimage&removeId="+removeId+"&post_id="+post_id;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	//alert(xmlHttp.responseText);
	//alert(result);
	result=xmlHttp.responseText;
	if(result=='yes')
	{ 		
		return false; 
	}
	else
	{
		return false; 		
	}	
}
function MarkAsSold(val,post_id)
{
	//alert("Current Val"+val+"   "+post_id );
	if(val=='1')
	{		
		var confirmme = confirm("Are you sure you want to mark as unsold for this property?");	
		if(confirmme)
		{
			CallMe_MarkAsSoldUnsold(val,post_id);
			document.getElementById("mark_sold"+post_id).value = '0';			
		}
		else
		{
			document.getElementById("mark_sold"+post_id).checked = false;	
			document.getElementById("mark_sold"+post_id).value = '1';	
		}
		
	}
	if(val=='0')
	{		
		var confirmme = confirm("Are you sure you want to mark as sold for this property?");	
		if(confirmme)
		{
			document.getElementById("mark_sold"+post_id).value = '1';
			CallMe_MarkAsSoldUnsold(val,post_id);						
		}
		else
		{
			document.getElementById("mark_sold"+post_id).checked = true;
			document.getElementById("mark_sold"+post_id).value = '0';
		}
	}		
}
function CallMe_MarkAsSoldUnsold(val,post_id)
{
	//alert(val);
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request")
			return
	}
	
	if(val=='1')
	{
		//alert("Sold this: " +post_id );	
		var url=baseURL+"ajax.php?type=MarkMeAsSold&val="+val+"&post_id="+post_id;
	}
	else
	{
		//alert("UnSold this: " +post_id );	
		var url=baseURL+"ajax.php?type=MarkMeAsUnSold&val="+val+"&post_id="+post_id;
	}
	//alert(url);
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
	//alert(xmlHttp.responseText);
	//alert(result);
	result=xmlHttp.responseText;
	//alert("MarkMeAs"+post_id);
	if(result=='sold')
	{ 		
		var element = document.getElementById("MarkMeAs"+post_id);	
		element.innerHTML = 'Mark listing as sold';
		element.setAttribute("class", 'UnSold'); //For Most Browsers
		//element.setAttribute("className", 'Sold'); //For IE; harmless to other browsers.	
	
	}
	if(result=='unsold')
	{ 		
		var element = document.getElementById("MarkMeAs"+post_id);	
		element.innerHTML = 'Has been Sold';
		element.setAttribute("class", 'Sold'); //For Most Browsers
		//element.setAttribute("className", 'UnSold'); //For IE; harmless to other browsers.	
	}
	if(result=='error')
	{ 		
		return false;
	}
}
function PostValidation()
{
	var temp = true;	
	//var txtpost_title = document.getElementById("post_title").value;
	var txtprice = document.getElementById("price").value;
	//var txtsnumber = document.getElementById("unit").value;
	var txtstreet = document.getElementById("street").value;
	var txtpostcode = document.getElementById("postcode").value;
	var txtstate = document.getElementById("city").value;
	var year_built = document.getElementById("year_built").value;
	var txtproArea = document.getElementById("proArea").value;
	var txtrooftype = document.getElementById("roof_type").value;   
	var txtheatingtype = document.getElementById("heating_type").value;
	//var year_construction = document.getElementById("year_construction").value;
	//var txtbedrooms = document.getElementById("bedrooms").value;
	//var txtbathorooms = document.getElementById("bathrooms").value;

	if(txtprice=="")
	{
		document.getElementById('error_price').innerHTML = 'Please enter your price.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_price').innerHTML = ' ';
	}
	
/*	if(txtsnumber=="")
	{
		document.getElementById('error_streetno').innerHTML = 'Please enter unit.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_streetno').innerHTML = ' ';
	}
*/	if(txtstreet=="")
	{
		document.getElementById('error_street').innerHTML = 'Please enter street address.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_street').innerHTML = ' ';
	}
	
	if(txtrooftype=="")
	{
		document.getElementById('error_roof_type').innerHTML = 'Please select roof type.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_roof_type').innerHTML = ' ';
	}
	
	if(txtheatingtype=="")
	{
		document.getElementById('error_heating_type').innerHTML = 'Please select heating type.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_heating_type').innerHTML = ' ';
	}
	
	if(txtpostcode=="")
	{
		document.getElementById('error_postcode').innerHTML = 'Please enter postcode.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_postcode').innerHTML = ' ';
	}
	if(txtstate=="")
	{
		document.getElementById('error_city').innerHTML = 'Please enter city name.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_city').innerHTML = ' ';
	}
	if(txtproArea=="")
	{
		document.getElementById('error_proArea').innerHTML = 'Please enter square footage.';
		temp = false;
	}	
	else
	{
		document.getElementById('error_proArea').innerHTML = ' ';
	}
	if(year_built=="")
	{
		document.getElementById('error_year_built').innerHTML = 'Please enter year of construction.';
		temp = false;
	}	
	else
	{	
		if(!Number(year_built))
		{
			document.getElementById('error_year_built').innerHTML = 'Please enter year of construction (eg.2012).';	
			temp = false;
		}
		else
		{
			document.getElementById('error_year_built').innerHTML = ' ';
		}
	}
/*	if(year_construction=="")
	{
		document.getElementById('error_year_construction').innerHTML = 'Please enter year of construction.';
		temp = false;
	}	
	else
	{	
		if(!Number(year_construction))
		{
			document.getElementById('error_year_construction').innerHTML = 'Please enter construction(eg.2010).';	
			temp = false;
		}
		else
		{
			document.getElementById('error_year_construction').innerHTML = ' ';
		}
	}
*/
if(temp == false)
		{ return false; }
	else 
		{ return true; }
}
function GetAddress(ans,userID)
{
	//alert(userID);
	if( ans == "Yes" )
	{
		document.getElementById("chkGetAddress").value = 'No';
		document.getElementById("chkGetAddress").checked = true;
		
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) {
				alert ("Browser does not support HTTP Request")
				return
		}
		var url=baseURL+"ajax.php?type=GetPersonalAddress&userID="+userID;
		xmlHttp.open("GET",url,false);
		xmlHttp.send(null);
		//alert(xmlHttp.responseText);		
		var myObject = eval('(' + xmlHttp.responseText + ')');		
		
		document.getElementById("province").style.display = 'none';
		document.getElementById("province2").style.display = '';
		
		document.getElementById("street").value = myObject.address;
		document.getElementById("unit").value = myObject.unit;	
		
		document.getElementById("postcode").value = myObject.postcode;
		document.getElementById("city").value = myObject.city;
		
		document.getElementById("province2").value = myObject.province;
		
	}
	if( ans == "No" )
	{
		document.getElementById("chkGetAddress").value = 'Yes';
		document.getElementById("street").value = "";
		document.getElementById("unit").value = "";		
		
		document.getElementById("postcode").value = "";
		document.getElementById("city").value = "";		
		
		document.getElementById("province2").style.display = 'none';
		document.getElementById("province").style.display = '';
		
		document.getElementById("chkGetAddress").checked = false;
	}
}
//Print Propwery
function CommPrintElem(elem)
{
	CommPopup($j(elem).html());
}

function CommPopup(data) 
{
	var mywindow = window.open('', 'SellYourHome Print', 'height=500,width=900,resizable=1,scrollbars=1');
	mywindow.document.write('<html><head><title>SellYourHome.ca</title>');
	/*optional stylesheet*/ 
	//mywindow.document.write('<link rel="stylesheet" media="screen,projection" type="text/css" href="css/reset.css" />');
	mywindow.document.write('</head><body >');
	mywindow.document.write(data);
	mywindow.document.write('</body></html>');
	mywindow.document.close();
	mywindow.print();
	return true;
}
function SetMenuItems(menu,current_user)
{
	if(menu!="")
	{		
		var total="";
		for(var i=0; i < document.frmlistings.DoWork.length; i++)
		{
			if(document.frmlistings.DoWork[i].checked)
				total += document.frmlistings.DoWork[i].value + ",";
		}
		if(total=="")
		{
			alert("Please select checkbox first!");
			var selObj = document.getElementById('inner_menu');
			selObj.selectedIndex = 0;	
		}
		else
		{
			var confirmem = confirm("Are you sure you want to "+ menu + " selected property?");
			if(confirmem)
			{
				var len = total.length;
				total = total.substr(0,len-1);			
				//alert (total);
	
				xmlHttp=GetXmlHttpObject()
				if (xmlHttp==null) {
						alert ("Browser does not support HTTP Request")
						return
				}
				var url=baseURL+"ajax.php?type=DoInGroup&menu="+menu+"&postID="+total;
				//alert(url);
				xmlHttp.open("GET",url,false);
				xmlHttp.send(null);
				var result = xmlHttp.responseText;
				document.location.href = "my-listings/?return="+menu+"&listby="+current_user;
			}
		}			
	}
	return false;
}
function ValidEmailListing()
{
	var temp = true;	
	var txtfname = document.getElementById("txt_username").value;
	var txtemail = document.getElementById("txt_email_to").value;
	var txt_message = document.getElementById("txt_message").value;
	//Check First Name
	if(txtfname=="")
	{
		document.getElementById('error_username').innerHTML = 'Please enter your name.';
		temp = false;
	}
	else
	{
		if(!isAlphanumeric(txtfname))
		{
			document.getElementById('error_username').innerHTML = 'Invalid your name.';
			temp = false;		
		}
		else
		{
			document.getElementById('error_username').innerHTML = ' ';
		}
	}

	// Check Email
	if(!isnull(txtemail))
	{
		if(!isemail(txtemail))
		{
			document.getElementById('error_emailto').innerHTML = 'Invalid email address.';
			temp = false;
		}
		else
		{
			document.getElementById('error_emailto').innerHTML = ' ';
		}
	}
	else
	{
		document.getElementById('error_emailto').innerHTML = 'Please enter email address.';
		temp = false;
	}
	
	if(txt_message=="")
	{
		document.getElementById('error_message').innerHTML = 'Please enter your message.';
		temp = false;
	}
	else
	{
		document.getElementById('error_message').innerHTML = ' ';
	}
	
	//temp = false; // temporary
	if(temp == false)
	{	return false; }
	else { return true; }
}
function SetMenuItemsSingle(menu,current_user,property_id)
{
	if(menu!="")
	{		
		var confirmem = confirm("Are you sure you want to "+ menu + " property?");
		if(confirmem)
		{
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null) {
					alert ("Browser does not support HTTP Request")
					return
			}
			var url=baseURL+"ajax.php?type=DoInGroup&menu="+menu+"&postID="+property_id;
			//alert(url);
			xmlHttp.open("GET",url,false);
			xmlHttp.send(null);
			var result = xmlHttp.responseText;
			if(menu=="delete"){
				document.location.href = siteURL+"/my-listings/?return="+menu;
			}else{
				document.location.href = siteURL+"/edit-listing?post_id="+property_id+"&return_option="+menu;
			}
		}					
	}
	return false;
}
function SetMenuItemsSingleDelete(menu,current_user,property_id)
{
	if(menu!="")
	{		
		var confirmem = confirm("Are you sure you want to "+ menu + " property?");
		if(confirmem)
		{
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null) {
					alert ("Browser does not support HTTP Request")
					return
			}
			var url=baseURL+"ajax.php?type=DoInGroup&menu="+menu+"&postID="+property_id;
			//alert(url);
			xmlHttp.open("GET",url,false);
			xmlHttp.send(null);
			var result = xmlHttp.responseText;
			if(menu=="delete"){
				document.location.href = siteURL+"/my-listings/?return="+menu;
			}else{
				document.location.href = siteURL+"/edit-listing?post_id="+property_id+"&return_option="+menu;
			}
		}					
	}
	return false;
}

function selectAll(elemName,status)
{
	elem = document.getElementsByName(elemName);
	if(status=='1')
	{
		//alert('aaaaaa'+status);
		document.getElementById('chk_selectall').value = '0';
		for(i=0;i<elem.length;i++){
			elem[i].checked=status;			
		}	
	}	
	else
	{
		//alert('bbbbbbb'+status);
		document.getElementById('chk_selectall').value = '1';
		for(i=0;i<elem.length;i++){
			elem[i].checked=0;			
		}	
		
	}	
}

function SetSearchItems(menu){
	document.frm_search_result.submit();
}

function GUnloadme(viewid){
	document.getElementById("map_canvas"+viewid).style.display='none';
	//document.getElementById("printdiv").style.display='none';
}

