var urlAddress = "http://searchproperty.co.za";
var pageName = "searchproperty.co.za";
function addToFavorites() { 
	if (window.external) { 
	window.external.AddFavorite(urlAddress,pageName) 
	} 
	else { 
	alert("Sorry! Your browser doesn't support this function."); 
	} 
}

		function CheckSearch() {

			if(isblank(document.f1.what.value))
			{
				window.alert('Enter the search criteria, please!');
				document.f1.what.focus();
				return false;
			}

		}

		function CheckFriend() {

			if(isblank(document.sfriend.f1.value))
			{
				window.alert('Enter your email address!');
				document.sfriend.f1.focus();
				return false;
			}

			if(isblank(document.sfriend.f2.value))
			{
				window.alert('Enter your friend email address!');
				document.sfriend.f2.focus();
				return false;
			}

		}

		function CheckLogin() {

			if(isblank(document.lform.us.value))
			{
				window.alert('Enter your username, please!');
				document.lform.us.focus();
				return false;
			}

			if(isblank(document.lform.ps.value))
			{
				window.alert('Enter your password, please!');
				document.lform.ps.focus();
				return false;
			}

		}

		function CheckForgot() {

			if(isblank(document.ForgotForm.u2.value))
			{
				window.alert('Enter your username, please!');
				document.ForgotForm.u2.focus();
				return false;
			}
		}

		function CheckRegister() {

			if(isblank(document.RegForm.NewUsername.value))
			{
				window.alert('Enter your username, please!');
				document.RegForm.NewUsername.focus();
				return false;
			}

			if(isblank(document.RegForm.p1.value))
			{
				window.alert('Enter your password, please!');
				document.RegForm.p1.focus();
				return false;
			}

			if(isblank(document.RegForm.p2.value))
			{
				window.alert('Confirm your password, please!');
				document.RegForm.p2.focus();
				return false;
			}

			if(document.RegForm.p1.value != "" && document.RegForm.p2.value != "" && document.RegForm.p1.value != document.RegForm.p2.value)
			{
				window.alert('Enter and confirm your password again!');
				document.RegForm.p1.value="";
				document.RegForm.p2.value="";
				document.RegForm.p1.focus();
				return false;
			}

			if(isblank(document.RegForm.FirstName.value))
			{
				window.alert('Enter your First Name, please!');
				document.RegForm.FirstName.focus();
				return false;
			}

			if(isblank(document.RegForm.LastName.value))
			{
				window.alert('Enter your Last Name, please!');
				document.RegForm.LastName.focus();
				return false;
			}

			if(isblank(document.RegForm.phone.value))
			{
				window.alert('Enter your Phone, please!');
				document.RegForm.phone.focus();
				return false;
			}

			if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.RegForm.email.value))
			{
				return true;
			}
			
			alert("Invalid E-mail Address! Please re-enter.");
			document.RegForm.email.focus();
			return false;
			

		}

		function CheckProfile() {

			if(isblank(document.RegForm.p1.value))
			{
				window.alert('Enter your password, please!');
				document.RegForm.p1.focus();
				return false;
			}

			if(isblank(document.RegForm.p2.value))
			{
				window.alert('Confirm your password, please!');
				document.RegForm.p2.focus();
				return false;
			}

			if(document.RegForm.p1.value != "" && document.RegForm.p2.value != "" && document.RegForm.p1.value != document.RegForm.p2.value)
			{
				window.alert('Enter and confirm your password again!');
				document.RegForm.p1.value="";
				document.RegForm.p2.value="";
				document.RegForm.p1.focus();
				return false;
			}

			if(isblank(document.RegForm.FirstName.value))
			{
				window.alert('Enter your First Name, please!');
				document.RegForm.FirstName.focus();
				return false;
			}

			if(isblank(document.RegForm.LastName.value))
			{
				window.alert('Enter your Last Name, please!');
				document.RegForm.LastName.focus();
				return false;
			}

			if(isblank(document.RegForm.phone.value))
			{
				window.alert('Enter your Phone, please!');
				document.RegForm.phone.focus();
				return false;
			}

			if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.RegForm.email.value))
			{
				return true;
			}
			
			alert("Invalid E-mail Address! Please re-enter.");
			document.RegForm.email.focus();
			return false;

		}

		function CheckOffer() {
	
			if(isblank(document.PostForm.SelectCategory.value))
			{
				alert('Select the category in which your offer will appear!');
				document.PostForm.SelectCategory.focus();
				return false;
			}
			
			if(isblank(document.PostForm.city.value))
			{
				alert('Enter the property city, please!');
				document.PostForm.city.focus();
				return false;
			}		

			if(isblank(document.PostForm.ShortDesc.value))
			{
				alert('Enter the property short description, please!');
				document.PostForm.ShortDesc.focus();
				return false;
			}

			
			if(isblank(document.PostForm.Price.value))
			{
				alert('Enter the property price, please!');
				document.PostForm.Price.focus();
				return false;
			}

			if(isblank(document.PostForm.PropertyType.value))
			{
				alert('Select the property type, please!');
				document.PostForm.PropertyType.focus();
				return false;
			}

			if(isblank(document.PostForm.rooms.value))
			{
				alert('Enter the number of bedrooms, please!');
				document.PostForm.rooms.focus();
				return false;
			}

			if(isblank(document.PostForm.bathrooms.value))
			{
				alert('Enter the number of bathrooms, please!');
				document.PostForm.bathrooms.focus();
				return false;
			}

		}
		
		//Function to open new pop up window with variable width and height
		function openNew(img_nm,w,h,nm)
		{
		
			var myfeatures="directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h+",left=0,top=0";
		
			if(nm == "")
				nm="new";
		
			var newImg=open(img_nm,nm,myfeatures);
			newImg.focus();
		}
		//Function to open new pop up window only for Pamphlets
		function openNew1(img_nm,w,h,nm)
		{
		
			var myfeatures="directories=no,location=no,menubar=yes,status=yes,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h+",left=0,top=0";
		
			if(nm == "")
				nm="new";
		
			var newImg=open(img_nm,nm,myfeatures);
			newImg.focus();
		}
		//Function to open new pop up window with fixed size
		function openWin(win_nm,nm)
		{
			var h=screen.height;
			h=h-80;
		
			var myfeatures="directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=680,height="+h+",left=0,top=0";
		
			if(nm == "")
				nm="new";
		
			var newImg=window.open(win_nm,nm,myfeatures);
			newImg.focus();
		}
		
function isblank(s)
{
	for(var i=0; i < s.length; i++)
	{
		var c=s.charAt(i);

		if((c != " ") && (c != "\n") && (c != "\t"))
			return false;
	}
	return true;
}

function checkbuyers()
{
			
			if(isblank(document.buyers.suburb.value))
			{
				alert('Enter the Suburb, please!');
				document.buyers.suburb.focus();
				return false;
			}
			if(isblank(document.buyers.city.value))
			{
				alert('Enter the property city, please!');
				document.buyers.city.focus();
				return false;
			}	

			
			if(isblank(document.buyers.Price.value))
			{
				alert('Enter the maximum property price, please!');
				document.buyers.Price.focus();
				return false;
			}

			if(isblank(document.buyers.PropertyType.value))
			{
				alert('Select the property type, please!');
				document.buyers.PropertyType.focus();
				return false;
			}	
			
			if(isblank(document.buyers.FirstName.value))
			{
				window.alert('Enter your First Name, please!');
				document.buyers.FirstName.focus();
				return false;
			}

			if(isblank(document.buyers.LastName.value))
			{
				window.alert('Enter your Last Name, please!');
				document.buyers.LastName.focus();
				return false;
			}
		
//for phone validation which takes only digit
		
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
		
function isInteger(s)
       {   var i;
           for (i = 0; i < s.length; i++)
           {   
               var c = s.charAt(i);
               if (((c < "0") || (c > "9"))) return false;
           }
           return true;
       }

function stripCharsInBag(s, bag)
	   {   var i;
	       var returnString = "";
	       
	        for (i = 0; i < s.length; i++)
	       {   
	         
	           var c = s.charAt(i);
	           if (bag.indexOf(c) == -1) returnString += c;
	       }
	       return returnString;
	   }
	
function checkInternationalPhone(strPhone)
{
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s));
}
			 
			var Phone=document.buyers.Phone;
	
			if((Phone.value==null)||(Phone.value==""))
			{
			alert("Please Enter your Phone Number");
			Phone.focus();
			return false;
			}
	
			if (checkInternationalPhone(Phone.value)==false)
			{
			alert("Please Enter only Digit");
			Phone.value="";
			Phone.focus();
			return false;
		    }

//end of phone validation 			

			if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.buyers.Email.value))
			{
				return true;
			}
			
			alert("Invalid E-mail Address! Please re-enter.");
			document.buyers.Email.focus();
			return false;

}

function test(obj,prov,ct)
{
	removeAllOptions(obj.city);
	removeAllOptions(obj.suburb);
	if(prov!=''){
	var pval = prov;
	}else{
	var pval = obj.province.value; 
	}
var selcity;
var parr_length = eval('city'+pval).length;
	addOption(obj.city,"", "Please Select","");
for(var ml=0 ; ml < parr_length ; ml++){
	addOption(obj.city,eval('valcity'+pval+'['+ml+']'), eval('city'+pval+'['+ml+']'));
	if(ct==eval('valcity'+pval+'['+ml+']')){
		selcity = ml+1;
	}
}
obj.city.selectedIndex = selcity;
}

function test2(obj,selpro,selcity,selsub)
{

	removeAllOptions(obj.suburb);
	var selsuburb;
	var pval1 = obj.province.value; 
	var pval2 = obj.city.value; 
	addOption(obj.suburb,"","Please Select","");
var parr_length = eval('suburb'+pval1+pval2).length;

for(var ml=0 ; ml < parr_length ; ml++){
	addOption(obj.suburb,eval('valsuburb'+pval1+pval2+'['+ml+']'), eval('suburb'+pval1+pval2+'['+ml+']'));
	if(selsub==eval('valsuburb'+pval1+pval2+'['+ml+']')){
		selsuburb = ml+1;
	}
}
obj.suburb.selectedIndex = selsuburb;
}

////////////////// 

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}
function Checkdigit() {
if(!isNumber(document.valuation_form.commision.value)){
alert('Please Enter Digit only.');
document.valuation_form.commision.focus();
return false;}
else{
window.print();
}
}
function isNumber(s) {
	//if(s.match(/^\d{0,10,.}$/) && s <= 2147483647)
	if(s == parseFloat(s) || s == "")	
		return true;
	else
		return false ;
}
function validate()
{
document.multi_list_form.selling_agent.value = 100 - parseFloat(document.multi_list_form.listing_agent.value);
}
function print_page()
{
print();
}
function multivalid()
{
if(isblank(document.multi_list_form.estateagency.value) && isblank(document.multi_list_form.ilggroup.value)){
window.alert('Select Either Estate Agent or ILG , please!');
document.multi_list_form.estateagency.focus();
return false;	
}
	
}
function ilgdel(ilg,opt){
	if(confirm("Are you sure you want to remove this from MiniListing?")){
		return true;
	}else{
		return false;
	}
}

function CheckSellers()
{
if(isblank(document.seller_form.sel_name.value)){
window.alert('Enter your Name, please!');
document.seller_form.sel_name.focus();
return false;	
}
if(isblank(document.seller_form.sel_tel_home.value)){
window.alert('Enter your Telephone Number, please!');
document.seller_form.sel_tel_home.focus();
return false;	
}

}
function CheckFixtures()
{
if(isblank(document.fixtures_form.incl_bc.value)){
window.alert('Enter Bathroom cabinets INCL., please!');
document.fixtures_form.incl_bc.focus();
return false;	
}
}
