function set_sitelink(pagename)
{
	document.frmsitelink.pname.value=pagename+".html";
	document.frmsitelink.submit();
}
function check_login(frm)
{
	if(frm.username.value=="" || frm.password.value=="")
	{
		alert("Username & Password both are mandatory fields");
		return false;
	}
	return true;
}
function check_propertyfind(frm)
{
	if(frm.findpropertyid.value=="")
	{
		alert("Please enter Property ID");
		frm.findpropertyid.focus();	
		return false;	
	}
	else
	{
		frm.action="property_details.php?pid="+frm.findpropertyid.value;
		return true;
	}
	return true;
	alert("END");
}
function check_property(frm)
{	
	if(!check_listvalue(frm.duration,"duration"))	return false;
	if(!check_listvalue_none(frm.paidby,"Paid by"))	return false;
	if(!blankval(frm.property_name))	return false;
	if(!check_listvalue_zero(frm.housetype,"housetype"))	return false;
	if(!check_listvalue(frm.ptown,"town"))	return false;
	//if(!check_listvalue_zero(frm.bedrooms,"Bedrooms"))	return false;
	//if(!check_listvalue_zero(frm.bathrooms,"Bathrooms"))	return false;
	//if(!check_listvalue_zero(frm.sleeps,"Sleeps"))	return false;
	if(!blankval(frm.squarefoot))	return false;
	if(!blankval(frm.rent))	return false;
	
	//if(!check_photo(frm.elements("photo[]"))) return false;
	if(!blankval(frm.paddress))	return false;
	if(!blankval(frm.psuburb))	return false;
	if(!blankval(frm.pcity))	return false;
	if(frm.psuburb.value==frm.paddress.value)
	{
		alert("Property 'Address' and 'Cross Street' must not be the same");
		frm.paddress.focus();
		return false;
	}
	if(!check_listvalue_zero(frm.usastate,"USA State"))	return false;
	if(!blankval(frm.pzipcode))	return false;
	if(!check_photo_one(frm.elements("photo[]"))) return false;
	//if(!check_photo_ext(frm.elements("property_flp[]"))) return false;
	//if(!blanktitlevirtual(frm.elements("virtual_tour[]"),frm.elements("virtual_title[]"))) return false;
	
return true;
}
function check_renew(frm)
{	
	if(!check_listvalue(frm.duration,"duration"))	return false;
	if(!check_listvalue_none(frm.paidby,"Paid by"))	return false;
}
function check_signupform(frm)
{	
	if(frm.signup_mode.value!="free")
	{
		if(!check_listvalue(frm.duration,"duration"))	return false;
		if(frm.paidby)
		{
			if(frm.paidby.value=="none")
			{
				alert("Please select payment type");
				return false;
			}
		}
	}
	if(!blankval(frm.username))	return false;
	if(!blankval(frm.password))	return false;
	if(!blankval(frm.cpassword)) return false;
	if(!blankval(frm.name))	return false;
	if(!blankval(frm.city))	return false;
	
	if(frm.usastate.value==0)
	{
		alert("Please select USA state");
		return false;
	}
	if(!blankval(frm.zipcode))	return false;
	if(!emailval(frm.email))	return false;
	if(!confirm_password(frm.password,frm.cpassword))	return false;
	if(frm.username.value.indexOf(" ")!= -1 || frm.username.value.indexOf("&")!= -1)
	{
		alert("Space, & or special characters are not allowed in Username");
		frm.username.value="";
		frm.username.focus();
		return false;	
	}
	if(frm.signup_type.value=="c")
	{
		if(frm.usastate.options[frm.usastate.selectedIndex].value=="")
		{
			alert("Please select State");
			frm.usastate.focus();
			return false;
		}
	}
//	frm.usastatename.value=frm.usastate[frm.usastate.selectedIndex].text;
	return true;
}

function blankval(obj)
{
	if(obj.value=="")
	{
		alert("Fields with blue color are required");
		obj.focus();
		return false;
	}
	return true;
}
function blanktitlevirtual(obj1,obj2)
{
	if(obj1,obj2)
	{
		if(obj1.value!="")
		{
			if(obj2.value=="")
			{
				alert("If you want to add virtual tour then must be add virtual tour's title");
				obj2.focus();
				return false;
			}
		//	return true;
		}
		return true;
	}
	return true;
}
function blank_title_virtualmore(obj1,obj2)
{
	len=obj1.length;
	for(i=0;i<len;i++)
	{
		if(obj1[i].value!="")
		{
			if(obj2[i].value=="")
			{
				alert("If you want to add virtual tour then must be add virtual tour's title");
				obj2[i].focus();
				return false;
			}
	}
	//	return true;
	}
	return true;
}
function check_virtual_tour(frm)
{	
	if(!blank_title_virtualmore(frm.elements("virtual_tour[]"),frm.elements("virtual_title[]"))) return false;
	return true;
}
function emailval(obj)
{
	var em=obj.value;
	atspos=em.lastIndexOf('@');
	dtspos=em.indexOf('.',atspos);
	if(atspos < 0 || dtspos < 0)
	{
		alert("Enter Valid E-mail Address");
		obj.focus();
		return false;
	}
	return true;
}
function confirm_password(mobj,cobj)
{
	if(mobj.value!=cobj.value)
	{
		alert("Your password does not match with the confirm password. \n\n Please retype your password.")
		mobj.value="";
		cobj.value="";
		mobj.focus();
		return false;
	}
	return true;
}
function submit_loginsignup_form(val)
{
	document.frmloginsignup_setting.signup_type.value = val;
	document.frmloginsignup_setting.submit();
}
function submit_editproperty_form(val)
{
	document.frmedit_property.action.value = val;
	document.frmedit_property.submit();
}
//Check valicity for forgetpassword form
function check_validity(frm)
{
	if(frm.username.value == "" && frm.emailaddress.value == "")
	{
		if(!blankval(frm.username))
			return false;
	}
	else if(frm.emailaddress.value != "")	
	{
		if(!emailval(frm.emailaddress))	return false;
	}
}
function open_index_photo(path,width,height)
{
	scr="No";
	//alert(path);
	if(width>780 || height>600)
		scr="Yes";
		
	wnd=window.open(path,"","munubar=0,statusbar=0,resizable=yes,scrollbars="+scr+",width="+(width+27)+",height="+(height+15)+",top=0,left=0");
}
function confirm_delete(pid,photoid,flag)
{
	if(confirm("Are you sure! You want to delete this file?"))
	{
		location.replace('photo_galery_db.php?delete=1&pid='+pid+'&photoid='+photoid+'&photoflag='+flag);
	}
}
function confirm_delete_saved(sid)
{
	if(confirm("Are you sure! You want to delete this profile?"))
	{
		location.replace('search_result_db.php?delsid='+sid);
	}
}
function selecte_listbox_value(obj,val)
{
	
	for(i=0;i<obj.length;i++)
	{
		
		if(obj[i].value==val)
		{	
			obj.selectedIndex=i;	
			break;
		}	
	}
}
function selecte_radio_value(obj,val)
{
	for(i=0;i<obj.length;i++)
	{
		if(obj[i].value==val)
		{
			obj[i].checked=true;
			break;
		}	
	}
}
function zeroval(obj)
{
	if(obj.value==0)
	{
		alert("You can not enter 0 value");
		obj.focus();
		return false;
	}
	return true;
}
function open_newwindow(path,wdth,hght)
{
	//alert(path);
	wnd=window.open(path,"","munubar=0,statusbar=0,resizable=yes,scrollbars=yes,width="+(wdth+20)+",height="+(hght+15)+",top=0,left=0"); 
}
function check_listvalue(obj,msg)
{
	if(obj)
	{
		if(obj.value=="")
		{
			alert("Please select "+msg);
			obj.focus();
			return false;
		}
		return true;
	}
	return true;
}
function check_listvalue_zero(obj,msg)
{
	if(obj)
	{
		if(obj.value==0)
		{
			alert("Please select "+msg);
			obj.focus();
			return false;
		}
		return true;
	}
	return true;
}
function check_listvalue_none(obj,msg)
{
	if(obj)
	{
		if(obj.value=="none")
		{
			alert("Please select "+msg);
			obj.focus();
			return false;
		}
		return true;
	}
	return true;
}
function open_photo(path,width,height)
{
	scr="No";
	if(width>780 || height>600)
		scr="Yes";
		
	wnd=window.open(path,"","munubar=0,statusbar=0,resizable=yes,scrollbars="+scr+",width="+(width+27)+",height="+(height+15)+",top=0,left=0");
}
function check_photo(objphoto)
{	
	if(objphoto)
	{
	photoflag=false;
	for(i=0;i<objphoto.length;i++)
	{
		if(objphoto[i].value!="")
		{  
			photoflag=true;
			pos=objphoto[i].value.lastIndexOf(".");
			len=objphoto[i].value.length;
			ext=objphoto[i].value.substring(pos+1,len);
			if(ext!="gif" && ext!="jpg" && ext!="jpeg" && ext!="jpe" && ext!="png" && ext!="bmp")
			{
				alert("Sorry! You can't upload ."+ext+" file. \n\n Only gif, jpg, jpeg, jpe, png and bmp files are allowed.");
				return false;
			}
		}
	}
	if(!photoflag)
	{	
		alert("You have to upload atleast one photo");
		return false;
	}
	return true;
 }
	return true;
}
function bookmarkus(path,name)
{
	if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4))
	{
    	window.external.AddFavorite(path,name);
	}
	else
	{
		alert("First push OK and then hit CTRL+D to add a bookmark to this site");
		return false;
	}
}
function checknum(ty)
{
	key=window.event.keyCode;
	if(key < 48 || key > 57)
	{
		/*if(key < 48 || key > 57) 
		{
			return true;
		}*/
		alert("Enter Only Number");
		return false;
	}		
	return true;
}
function checknum_only(ty)
{
	key=window.event.keyCode;
	//alert(key);
	if(key < 48 || key > 57)
	{
		alert("Enter Only Number");
		return false;
	}		
	return true;
}
function check_contactus(frm)
{
	if(!blankval(frm.yourname))	return false;
	if(!emailval(frm.emailaddress))	return false;
	if(!blankval(frm.subject)) return false;
	if(!blankval(frm.message)) return false;
}
function setsubject()
{
	selregard = frmemail.yourregard;
	selectedindex = selregard.selectedIndex;
	selval=selregard[selectedindex].text;
	frmemail.subject.value = selval;
}
function set_sitelink(pagename)
{
	document.frmsitelink.pname.value=pagename+".html";
	document.frmsitelink.submit();
}
function mapview_c(city,address,zip)
{
	window.open("http://www.mapquest.com/maps/map.adp?searchtype=address&country=US&addtohistory=&searchtab=home&address="+address+"&city="+city+"&state=OR&zipcode="+zip,"","munubar=0,statusbar=0,resizable=yes,scrollbars=yes,width=670,height=550,top=0,left=0");
}
function mapview_v(city,zip)
{
	// First of all search type city,state,country is availble or not
	//window.open("http://www.mapquest.com/maps/map.adp?formtype=mapcity&searchtype=address&country=US&addtohistory=&city=Eugene&state=OR&zipcode=97403");
	window.open("http://www.mapquest.com/maps/map.adp?city="+city+"&state=OR&zip="+zip+"&country=us&zoom=5","","munubar=0,statusbar=0,resizable=yes,scrollbars=yes,width=670,height=550,top=0,left=0");
}
// chech validation for tell a friend form field
function check_email(frm)
{
	if(!blankval(frm.yname))
		return false;
			
	if(!emailval(frm.yemailadd))
		return false;
		
	if(!emailval(frm.femail))
		return false;
}
function check_photo_one(objphoto)
{	
	if(objphoto)
	{
		photoflag=false;
		if(objphoto.value!="")
		{  
			photoflag=true;
			pos=objphoto.value.lastIndexOf(".");
			len=objphoto.value.length;
			ext=objphoto.value.substring(pos+1,len);
			if(ext!="gif" && ext!="jpg" && ext!="jpeg" && ext!="jpe" && ext!="png" && ext!="bmp")
			{
				alert("Sorry! You can't upload ."+ext+" file. \n\n Only gif, jpg, jpeg, jpe, png and bmp files are allowed.");
				return false;
			}
			
		}
		/*else
		{
			alert("You have to upload atleast one photo");
			return false;
		}*/
		return true;
	}
	return true;
 }
 
function check_photo_ext(objphoto)
{	
 if(objphoto)
	 {
		if(objphoto.value!="")
		{
			pos=objphoto.value.lastIndexOf(".");
			len=objphoto.value.length;
			ext=objphoto.value.substring(pos+1,len);
			if(ext!="gif" && ext!="jpg" && ext!="jpeg" && ext!="jpe" && ext!="png" && ext!="bmp")
			{
				alert("Sorry! You can't upload ."+ext+" file. \n\n Only gif, jpg, jpeg, jpe, png and bmp files are allowed.");
				return false;
			}
		return true;
		}
		return true;
	}
return true;
}
function check_newsletter(frm)
{
	var flagsub = false;
	var frmobj = frm.elements;
	
	if(!frmobj["sub"][0].checked && !frmobj["sub"][1].checked)
	{
		alert("Please select option for news letter");
		return false;
	}
	if(frmobj.emailaddress.value == "you@yourdomain.com" || frmobj.emailaddress.value == "")
	{
		alert("Please enter your email address");
		return false;
	}
	else
	{
		if(!emailval(frm.emailaddress))
			return false;
	}
	if(frmobj["sub"][0].checked)
	{
		var URL = "newsletter.php?sub=0&emailaddress=" + frmobj.emailaddress.value;
	}
	else if(frmobj["sub"][1].checked)
	{
		var URL = "newsletter.php?sub=1&emailaddress=" + frmobj.emailaddress.value;
	}
	wnd=window.open(URL,"","munubar=0,statusbar=0,resizable=no,scrollbars=no,width=350,height=100,top=0,left=0");
}

// CHECKBOX SELECTION TO PRINT SEARCH RESULT
function checkall_click()
	{
		var frm=document.frmpropprint;
		if(frm.elements["cboxpropid[]"])
		{	
			if(frm.elements["cboxpropid[]"].length)
			{
				for(i=0;i<frm.elements["cboxpropid[]"].length;i++)
				{
					frm.elements["cboxpropid[]"][i].checked=frm.checkall.checked;
				}
			}
			else
			{
				frm.elements["cboxpropid[]"].checked=frm.checkall.checked;
			}
		}
	}
function checkprop()
{
	var frm=document.frmpropprint;
	
	if(frm.elements["cboxpropid[]"].length)
	{	
		for(i=0;i<frm.elements["cboxpropid[]"].length;i++)
		{
			if(frm.elements["cboxpropid[]"][i].checked==true)return true;
		}
		alert("No property selected to print");
		return false;
	}
	else if(frm.elements["cboxpropid[]"].checked==true)return true;
	else
	{
		alert("No property selected to print");
		return false;
	}
}