﻿<!--
function Submitlogin()
{
	document.login.submit();
}
function Submitconsultant()
{
	document.consultant.submit();
}
function Submitformtoemail()
{
	document.formtoemail.submit();
}

function chkempty(passedVal)
{
	var i;
	var checkok=0;

	if (passedVal=="")
	{	return false;	}
	else
	{
	for(i=0; i<passedVal.length; i++) { 
    if(passedVal.charAt(i) !=" ")
		{ checkok=1	}
	}
	if (checkok!=1)
		{ return false; }
	return true;
	}
}

function validEmail(ename)
{
	invalidChars = " ~`!#$%^&*()+=|\{}[];:'<>,?/";

	if (ename == "" ) { return false; }
	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if ( ename.indexOf(badChar,0) > -1)
		{	return false;
		}
	}
	atSign = ename.indexOf("@",1);
	if (atSign == -1 )
	{	return false;
	}
	if (ename.indexOf("@",atSign+1) != -1 )
	{	return false;
	}
	dotSign = ename.indexOf(".",atSign);
	if (dotSign == -1)
	{	return false;
	}
	if (dotSign+3 > ename.length)
	{	return false;
	}
	return true;
}

function validChar(ename)
{
	invalidChars = " ~`!#$%^&*()+=|\{}[];:'<>,?/-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (ename == "" ) { return false; }
	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if ( ename.indexOf(badChar,0) > -1)
		{	return false;
		}
	}
	return true;
}

function dataCheck_login(Form)
{
	var err_Mesg = "";

	if (!chkempty(document.all("txtName").value))
	{	err_Mesg = err_Mesg + "*Login empty\n"; }
	if (!chkempty(document.all("txtPassword").value))
	{	err_Mesg = err_Mesg + "*Password empty\n"; }

	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	Submitlogin();
		return true;
	}
}

function dataCheck_consultant(Form)
{
	var err_Mesg = "";

	if (!chkempty(document.all("present_monthly").value))
	{	err_Mesg = err_Mesg + "*Present Monthly empty\n"; }
	else {
		if (parseInt(document.all("present_monthly").value) != parseFloat(document.all("present_monthly").value))
		{	err_Mesg = err_Mesg + "*Present Monthly not integer\n"; }
	}
	if (!chkempty(document.all("age_now").value))
	{	err_Mesg = err_Mesg + "*Age Now empty\n"; }
	else {
		if (parseInt(document.all("age_now").value) != parseFloat(document.all("age_now").value))
		{	err_Mesg = err_Mesg + "*Age Now not integer\n"; }
	}
	if (!chkempty(document.all("retirement_age").value))
	{	err_Mesg = err_Mesg + "*Retirement Age empty\n"; }
	else {
		if (parseInt(document.all("retirement_age").value) != parseFloat(document.all("retirement_age").value))
		{	err_Mesg = err_Mesg + "*Retirement Age not integer\n"; }
	}
	if ((document.all("retirement_age").value - document.all("age_now").value) < 1)
	{	err_Mesg = err_Mesg + "*Retirement Age should larger than Age Now"; }
	if (!chkempty(document.all("growth").value))
	{	err_Mesg = err_Mesg + "*Growth empty\n"; }
	else {
		if (parseInt(document.all("growth").value) != parseFloat(document.all("growth").value))
		{	err_Mesg = err_Mesg + "*Growth not integer\n"; }
	}
	if (!chkempty(document.all("saving").value))
	{	err_Mesg = err_Mesg + "*Saving empty\n"; }
	else {
		if (parseInt(document.all("saving").value) != parseFloat(document.all("saving").value))
		{	err_Mesg = err_Mesg + "*Saving not integer\n"; }
	}
	if (!chkempty(document.all("inflation").value))
	{	err_Mesg = err_Mesg + "*Inflation empty\n"; }
	else {
		if (parseInt(document.all("inflation").value) != parseFloat(document.all("inflation").value))
		{	err_Mesg = err_Mesg + "*Inflation not integer\n"; }
	}

	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	
	    Submitconsultant();
		return true;
	}
}
function dataCheck_Contactus(Form)
{
	var err_Mesg = "";
    if (!(document.all("check_Y").checked)&!(document.all("check_N").checked))
    {   err_Mesg = err_Mesg + "*Are you our existing client? \n";}
	if (!chkempty(document.all("sender_name").value))
	{	err_Mesg = err_Mesg + "*Name empty\n"; }
	if (!chkempty(document.all("dayTel").value))
	{	err_Mesg = err_Mesg + "*Telephone no.(day) empty\n"; }
	
	if (!validEmail(document.all("sender_email").value))
	{	err_Mesg = err_Mesg + "*Invalid E-mail Address\n";}
	
	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	Submitformtoemail();
		return true;
	}
}


function dataCheck_formtoemail(Form)
{
	var err_Mesg = "";
	if (!chkempty(Form.sender_name.value))
	{	err_Mesg = err_Mesg + "*Name empty\n"; }
	if (!validEmail(Form.sender_email.value))
	{	err_Mesg = err_Mesg + "*Invalid E-mail Address\n";}
	
	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	Submitformtoemail();
		return true;
	}
}
function dataCheck_forgetPass(Form)
{
	var err_Mesg = "";

	if (!chkempty(document.all("txb_Account").value))
	{	err_Mesg = err_Mesg + "*Login Name empty\n"; }
	if (!chkempty(document.all("txb_ID").value))
	{	err_Mesg = err_Mesg + "*Email Address empty\n";}
	
	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	Submitformtoemail();
		return true;
	}
}




function dataCheck_valuation(Form)
{
	var err_Mesg = "";

	if (!chkempty(Form.sender_name.value))
	{	err_Mesg = err_Mesg + "*Name empty\n"; }
	if (!validEmail(Form.sender_email.value))
	{	err_Mesg = err_Mesg + "*Invalid E-mail Address\n"; }
	
	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	Submitformtoemail();
		return true;
	}
}
var newWindow = null;
	function NewWindowP(strHref, Height, Width){
		newWindow = window.open(strHref);
	}
	
function MaxWindow(strHref){
		newWindow = window.open(strHref);
	}
		
function Golan(oldlan,newlan)
{
    var strURL = window.document.location.toString();
	strURL = strURL.replace('/'+oldlan+'/', '/'+newlan+'/');
	window.location = strURL;
}





function trim_space(bstr)
{
	astr = new String(bstr);
	if (astr==null||astr=="")
		return "";

	var s = -1;
	var e = astr.length - 1;

	if (e < s) return '';
		for (var i=0; i < astr.length; i++)
		{
			if ((astr.charAt(i) != " ") && (astr.charAt(i) != '\t'))
			{
				s = i; break;
			}
		}
	if (s != -1)
	{
		for (var i = astr.length - 1; i >= 0; i--)
		{
			if ((astr.charAt(i) != " ") && (astr.charAt(i) != '\t'))
			{
				e = i; break;
			}
		}
	}
	else
	{
		return "";
	}
	return astr.substring(s,(e+1));
}

function is_integer(in_value)
{
  var temp_integer = String(trim_space(in_value))
  var re = /[^0-9]/g
  
  if (re.test(temp_integer))
    return false;       //number is not an integer
  else
    return true;
}

function is_number(in_value)
{
  var temp_num = String(trim_space(in_value))
  var re = /[^0-9.]/g
  
	
  if (re.test(temp_num))
      return false;       //number not valid
  else
	{
		var temp_pt = temp_num.indexOf(".")
		if (temp_pt >= 0)
		{
			if (temp_num.indexOf(".",temp_pt + 1) >= 0)
		        return false;       //number not valid
			else
				return true;
  	}
	  else
		{
	    return true         //number valid
		}
  }
}

function is_null(in_value)
{
    var temp_value = trim_space(String(in_value))
    
    if (temp_value.length==0)
        return true;
    else
        return false;
}

function digit_corr(in_value,digit,dec)
{
	if (is_number(in_value))
	{
		var temp = String(in_value)
		
		if (temp.indexOf(".") >= 0)
		{
			if (temp.indexOf(".") > digit || (temp.length - 1 - temp.indexOf(".")) > dec)
				return false;
		  else
		    return true;
		}
		else
		{
			if (temp.length > digit)
				return false;
			else
			  return true;
		}
	}
	else
	  return false;
}

function value_in_range(in_value,low,up)
{
	if (in_value < low || in_value > up)
    return false;
	else
		return true;
}

function SetRadio(radioOn, radioOff, focusTxt, blurTxt)
{
	radioOn.checked = true;
	radioOff.checked = false;
	blurTxt.value = '';
}

function RadioChanged(radioOn, focusTxt) {
	focusTxt.focus();
}


//**************************************************
// check the 'What will my repayments be' form (home)
//**************************************************
function dataCheck_Mortgage(Form,lan)
{
    var err_Mesg = "";
	if (!chkempty(document.all("txtPropertyPrice").value))
	{	err_Mesg = err_Mesg + "*Property Value empty\n";}
	else {
	    if(!(is_number(document.all("txtPropertyPrice").value))){
	    err_Mesg = err_Mesg + "*The property value you provided is invalid. Please re-enter.\n";
	    }else{
	        if (!(is_integer(document.all("txtPropertyPrice").value))){
	        err_Mesg = err_Mesg + "*Please limit your input for the property value to a whole number.\n";
	        }else{
		        if (parseInt(document.all("txtPropertyPrice").value)<100000 || parseInt(document.all("txtPropertyPrice").value)>999999999)
		        {	err_Mesg = err_Mesg + "*Please enter the property value within the range from HK$100,000 to HK$999,999,999.\n"; }
		    }
		}
	}
	
	if (!chkempty(document.all("txtPeriodYear").value))
	{	err_Mesg = err_Mesg + "*Loan Period empty\n"; }
	else {
	    if(!(is_number(document.all("txtPeriodYear").value))){
	    err_Mesg = err_Mesg + "*The Loan Period value you Loan Period is invalid. Please re-enter.\n";
	    }else{
	        if (!(is_integer(document.all("txtPeriodYear").value))){
	        err_Mesg = err_Mesg + "*Please limit your input for the Loan Period value to a whole number.\n";
	        }else{
	            if (parseInt(document.all("txtPeriodYear").value)<5 || parseInt(document.all("txtPeriodYear").value)>30)
		        {	err_Mesg = err_Mesg + "*Please enter the Loan Period within the range from 5 to 30 Years.\n"; }
	
	        }
	    }
	}
	
	if (!chkempty(document.all("txtInterest").value))
	{	err_Mesg = err_Mesg + "*Interest Rate empty\n"; }
	else {
	    if (!(is_number(document.all("txtInterest").value))){
   	    err_Mesg = err_Mesg + "*The Interest Rate value you Interest Rate is invalid. Please re-enter.\n";
	    }else{
		    if (document.all("txtInterest").value<0.001 || document.all("txtInterest").value>99.999)
		    {	err_Mesg = err_Mesg + "*Please enter the Interest Rate within the range from 0.001% to 99.999%.\n"; }
	    }
	}	
	if((!chkempty(document.all("loanRatio").value)) && (!chkempty(document.all("loan").value))){
	    err_Mesg = err_Mesg + "*Loan Ratio or Loan Amount empty\n"; 
	}else{
	    if(document.all("loanAmtBy")(1).checked){	
	        if (!chkempty(document.all("loanRatio").value))
	        {	err_Mesg = err_Mesg + "*Loan Ratio empty\n"; }
	        else {
	            if (!(is_number(document.all("loanRatio").value))){
   	            err_Mesg = err_Mesg + "*The Loan Ratio value you Loan Ratio is invalid. Please re-enter.\n";
	            }else{
		            if (parseInt(document.all("loanRatio").value)<1 || parseInt(document.all("loanRatio").value)>95)
		            {	err_Mesg = err_Mesg + "*Please enter the Loan Ratio within the range from 1% to 95%.\n"; }
	            }
	        }
	    }	
	    if(document.all("loanAmtBy")(0).checked){	
	        if (!chkempty(document.all("loan").value))
	        {	err_Mesg = err_Mesg + "*Loan Amount  empty\n"; }
	        else {
	            if (!(is_number(document.all("loan").value))){
   	            err_Mesg = err_Mesg + "*The Loan Amount value you Loan Amount is invalid. Please re-enter.\n";
	            }else{
	                if (!(is_integer(document.all("loan").value))){
	                err_Mesg = err_Mesg + "*Please limit your input for the  Loan Amount value to a whole number.\n";
	                }else{
		                if (parseInt(document.all("loan").value)<50000 || (parseInt(document.all("loan").value)>Math.floor(document.all("txtPropertyPrice").value*0.9)))
		                {	err_Mesg = err_Mesg + "*Please enter the Loan Amount  within the range from HK$50,000 to HK$"+Math.floor(document.all("txtPropertyPrice").value*0.9)+".\n"; }
	                }
	            }
	        }
	    }
	}		
	
	if (err_Mesg!="")
	{	err_Mesg = "<<Error found>>\n\n" + err_Mesg;
		alert(err_Mesg);
		return false;
	}
	else
	{	
	    Submitconsultant();
		return true;
	}
}



 function cgcolor(a,i){
   if(i==1)
   { a.style.backgroundColor='#FFFFFF';}
   if(i==0)
   { a.style.backgroundColor=''; }
   if(i==2)
    { a.style.backgroundColor='#F8D1D1'; }
   if(i==3)
    { a.style.backgroundColor='#FF3300'; 

	  }
  }
  


//-->
function popUp(purl,pname,pwidth,pheight) {
		
		if (purl != ""){
				if (newWindow && !newWindow.closed)
			newWindow.close();
			var win = window.open(purl, pname, 'top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no,width=' + pwidth + ',height=' + pheight + '', true);
		}
}

function changeSrc(imgName, imgSrc)
{
   document[imgName].src = imgSrc;
}

