var urlAddress = "http://www.africanskyhomes.co.za";
var pageName = "africanskyhomes.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.province.value))
			//{
				//alert('Enter the property province, please!');
				//document.PostForm.province.focus();
				//return false;
			//}

			//if(isblank(document.PostForm.country.value))
			//{
			//	alert('Enter the property country, please!');
			//	document.PostForm.country.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 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 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);
}