/***********************************************
* Allow only numeric input.
************************************************/
function numericVal(obj)   {
  var tam = obj.value.length;
    var numeric = false;
    for(var i=0;i<tam;i++)  {
        caracter = obj.value.charCodeAt(i);
		if (caracter == 45 || caracter == 43) {
        	numeric = true;
		}
        else if((caracter >= 48 && caracter <= 57)) {
        	numeric = true;
		}
        else {
            obj.value=obj.value.substring(0,tam-1);
           	numericVal(obj);
       	}
    }
}

/***********************************************
* Layer hide / show.
************************************************/
function hideshow (id)	{
	var style = document.getElementById(id).style
	alert(style.display);
	if (style.display == "none")
		style.display = "";
	else
		style.display="none";
}

function show (id)	{
	var style = document.getElementById(id).style
		style.display = "";
}
function hide (id)	{
	var style = document.getElementById(id).style
		style.display = "none";
}
/***********************************************
* Check / Uncheck function for checkbox
************************************************/
function checkAll(){
	for (var i=0;i<document.forms[1].elements.length;i++)
	{
		var e=document.forms[1].elements[i];
		if ((e.name != 'checkall') && (e.type=='checkbox'))
		{
			e.checked=document.forms[1].checkall.checked;
		}
	}
}

/***********************************************
* Hide Enail from spam bots.
************************************************/
function emailCloak() {
	if (document.getElementById) {
		var alltags = document.all? document.all : document.getElementsByTagName("*");
		for (i=0; i < alltags.length; i++) {
		  if (alltags[i].className == "emailCloak") {
		  	var oldText = alltags[i].firstChild;
		  	var emailAddress = alltags[i].firstChild.nodeValue;
		  	var user = emailAddress.substring(0, emailAddress.indexOf("("));
		  	var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
		  	var newText = user+"@"+website;
		  	var a = document.createElement("a");
		  	a.href = "mailto:"+newText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			alltags[i].replaceChild(a,oldText);
		  }
		}
	}
}
window.onload = emailCloak;



/***********************************************
* POP-UP JS.
* onclick="NewWindow(this.href,'name','400','400','yes');return false"
************************************************/
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(mypage,myname,settings)
}

/***********************************************
* Property Enquiry Form Validation.
************************************************/
function enquiry_validation() {
	var valid = true;
	
	if(document.getElementById('enq_fullname').value == ""){
		alert('Kindly type your full name.');
		document.getElementById('enq_fullname').focus();
		valid = false;
	}
	else if(document.getElementById('enq_email').value == ""){
		alert('Kindly type your email address.');
		document.getElementById('enq_email').focus();
		valid = false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('enq_email').value))) {
		alert("A valid e-mail address is required.\nPlease amend and retry.");
		document.getElementById('enq_email').focus();
	    valid = false;
	}
	else if(document.getElementById('enq_phone').value == ""){
		alert('Kindly type your phone number.');
		document.getElementById('enq_phone').focus();
		valid = false;
	}
	else if(document.getElementById('enq_contact').value == ""){
		alert('Kindly select your preferred contact method.');
		document.getElementById('enq_contact').focus();
		valid = false;
	}
	else if(document.getElementById('enq_address1').value == ""){
		alert('Kindly type your address.');
		document.getElementById('enq_address1').focus();
		valid = false;
	}
	else if(document.getElementById('enq_message').value == ""){
		alert('Kindly select your message / comments.');
		document.getElementById('enq_message').focus();
		valid = false;
	}
	return valid;
}

/***********************************************
* Contact Form Validation.
************************************************/
function contact_validation() {
	var valid = true;
	
	if(document.getElementById('full_name').value == ""){
		alert('Kindly type your full name.');
		document.getElementById('full_name').focus();
		valid = false;
	}
	else if(document.getElementById('email').value == ""){
		alert('Kindly type your email address.');
		document.getElementById('email').focus();
		valid = false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))) {
		alert("A valid e-mail address is required.\nPlease amend and retry.");
		document.getElementById('email').focus();
	    valid = false;
	}
	else if(document.getElementById('code').value == ""){
		alert('Kindly type your area code.');
		document.getElementById('code').focus();
		valid = false;
	}
	else if(document.getElementById('phone').value == ""){
		alert('Kindly type your phone number.');
		document.getElementById('phone').focus();
		valid = false;
	}
	else if(document.getElementById('message').value == ""){
		alert('Kindly type your message or comments.');
		document.getElementById('message').focus();
		valid = false;
	}
	return valid;
}

/***********************************************
* Tell a Friend Form Validation.
************************************************/
function tell_friend_validation() {
	var valid = true;
	
	if(document.getElementById('your_name').value == ""){
		alert('Kindly type your full name.');
		document.getElementById('your_name').focus();
		valid = false;
	}
	else if(document.getElementById('your_email').value == ""){
		alert('Kindly type your email address.');
		document.getElementById('your_email').focus();
		valid = false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('your_email').value))) {
		alert("A valid e-mail address is required.\nPlease amend and retry.");
		document.getElementById('your_email').focus();
	    valid = false;
	}
	else if(document.getElementById('friend_name').value == ""){
		alert('Kindly type your friend name.');
		document.getElementById('friend_name').focus();
		valid = false;
	}
	else if(document.getElementById('friend_email').value == ""){
		alert('Kindly type your friend email address.');
		document.getElementById('friend_email').focus();
		valid = false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('friend_email').value))) {
		alert("A valid e-mail address is required.\nPlease amend and retry.");
		document.getElementById('friend_email').focus();
	    valid = false;
	}

	return valid;
}

/***********************************************
* Newsletter Form Validation.
************************************************/
function validate_newsletter()
{
	var valid = true;
	
	if(document.getElementById('nl_name').value == ""){
		alert('Kindly type your full name.');
		document.getElementById('nl_name').focus();
		valid = false;
	}
	else if(document.getElementById('nl_email').value == ""){
		alert('Kindly type your email address.');
		document.getElementById('nl_email').focus();
		valid = false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('nl_email').value))) {
		alert("A valid e-mail address is required.\nPlease amend and retry.");
		document.getElementById('nl_email').focus();
	    valid = false;
	}
	return valid;
}

/***********************************************
* Search price combo fill-up.
************************************************/

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

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


function prp_price()
{
	var primary = document.frm_search.iwant.selectedIndex;

	if ((primary == null) || (primary == 0)) 
	{
		removeAllOptions();
		addOption(document.frm_search.price_min, "Select","");
		addOption(document.frm_search.price_max, "Select","");
	}
	
	if (primary == 1) {
		removeAllOptions();
	  	// Min price combo
		addOption(document.frm_search.price_min, "Select","");
		addOption(document.frm_search.price_min, "200,000","200000");
		addOption(document.frm_search.price_min, "300,000","300000");
		addOption(document.frm_search.price_min, "400,000","400000");
		addOption(document.frm_search.price_min, "500,000","500000");
		addOption(document.frm_search.price_min, "1 Million","1000000");
		addOption(document.frm_search.price_min, "2 Million","2000000");
		addOption(document.frm_search.price_min, "3 Million","3000000");
		addOption(document.frm_search.price_min, "4 Million","4000000");
		addOption(document.frm_search.price_min, "5 Million","5000000");
		addOption(document.frm_search.price_min, "6 Million","6000000");
        // Max price combo
		addOption(document.frm_search.price_max, "Select","");
        addOption(document.frm_search.price_max, "200,000","200000");
		addOption(document.frm_search.price_max, "300,000","300000");
		addOption(document.frm_search.price_max, "400,000","400000");
		addOption(document.frm_search.price_max, "500,000","500000");
		addOption(document.frm_search.price_max, "1 Million","1000000");
		addOption(document.frm_search.price_max, "2 Million","2000000");
		addOption(document.frm_search.price_max, "3 Million","3000000");
		addOption(document.frm_search.price_max, "4 Million","4000000");
		addOption(document.frm_search.price_max, "5 Million","5000000");
		addOption(document.frm_search.price_max, "6 Million","6000000");
		addOption(document.frm_search.price_max, "> 6 Million","19900000");
	}
	
	if (primary == 2) {
		removeAllOptions();
	  	// Min price combo
		addOption(document.frm_search.price_min, "Select","");
		addOption(document.frm_search.price_min, "30,000","30000");
		addOption(document.frm_search.price_min, "40,000","40000");
		addOption(document.frm_search.price_min, "50,000","50000");
		addOption(document.frm_search.price_min, "70,000","70000");
		addOption(document.frm_search.price_min, "80,000","80000");
		addOption(document.frm_search.price_min, "100,000","100000");
		addOption(document.frm_search.price_min, "200,000","200000");
		addOption(document.frm_search.price_min, "300,000","300000");
		addOption(document.frm_search.price_min, "400,000","400000");
		addOption(document.frm_search.price_min, "500,000","500000");

        // Max price combo
        addOption(document.frm_search.price_max, "Select","");
       	addOption(document.frm_search.price_max, "30,000","30000");
		addOption(document.frm_search.price_max, "40,000","40000");
		addOption(document.frm_search.price_max, "50,000","50000");
		addOption(document.frm_search.price_max, "70,000","70000");
		addOption(document.frm_search.price_max, "80,000","80000");
		addOption(document.frm_search.price_max, "100,000","100000");
		addOption(document.frm_search.price_max, "200,000","200000");
		addOption(document.frm_search.price_max, "300,000","300000");
		addOption(document.frm_search.price_max, "400,000","400000");
		addOption(document.frm_search.price_max, "500,000","500000");
	}
	
	
 	//document.frm_search.price_min.options[0].selected = true;
}