//function to check for valid email
function checkEmail(ctlName){
	var myString = new String(""+ctlName.value);
	var isvalid="yes";
	if ((myString.indexOf("@")<0) || (myString.charAt(0)==".") || (myString.charAt(0)=="@") || (myString.length<6) || (myString.indexOf(".")<0) || (myString.charAt(myString.indexOf("@")+1)==".") || (myString.charAt(myString.indexOf("@")-1)==".") || (myString.charAt(myString.length-1)==".") || (checkNumTimes(ctlName,"@")!=1) || (myString.charAt(myString.indexOf(".")+1)==".")){
		isvalid="no";
	}

	return isvalid;
	
}

//checks the number of occurences of strChar within value of intWhich
//used mainly for checking multiple "@" in email
function checkNumTimes(ctlName,strChar){
	var strValue2 = eval(ctlName.value);
	var noFound=0;
	for (var i=0; i<strValue2.length; i++){
		if(strValue2.charAt(i)==strChar){
			noFound++;
		}
	}
	return noFound;
}

function tellfriend()
{
	var currentURL = location.href;
	var theURL = "emailfriend.cfm?page="+currentURL;
	var features = "width=720,height=550,scrollbars=yes";
	window.open(theURL,'pop',features)
}

function validate_contactusform(hkform)
{
	if (hkform.contact_person.value=="") {
		window.alert("Please enter your name.");
		hkform.contact_person.focus();
		return false;
	}

	if (hkform.tel_no.value=="") {
		window.alert("Please enter telephone no.");
		hkform.tel_no.focus();
		return false;
	}
		
	if (hkform.enquiry.value=="") {
		window.alert("Please enter your enquiries.");
		hkform.enquiry.focus();
		return false;
	}			
	if (hkform.contact_email.value=="") {
		window.alert("Please enter your email address.");
		hkform.contact_email.focus();
		return false;
	}
	var sCont = document.hkform.contact_email;
	var sContVal = document.hkform.contact_email.value;

	var str=new String();
	str=sContVal;
	var span=new RegExp("[ ]","g");
	var rep=str.replace(span,"9");          

	if (sContVal.length != 0)
    {
    	if(sContVal == ''  || isNaN(rep) == false)
        {
		alert("Please enter email with the correct format.");
        sCont.focus();
        sCont.select();
        return false;
        }                         
                         
        var sAtSym    = sContVal.indexOf('@')
        var sAtSym2   = sContVal.lastIndexOf('@')
        var sPeriod   = sContVal.lastIndexOf('.')
        var sSpace    = sContVal.indexOf(' ')
        var sLength   = sContVal.length - 1   
          
        if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
    	{
        alert("Please enter email with the correct format.");
        sCont.focus();
        sCont.select();
        return false;
        }
    }
}

