// JavaScript Document

function ftrim(str) 
{ 
	    var ResultStr = "";       
        Temp=str.split(/\s/);        
        for(i = 0; i < Temp.length; i++)       
            ResultStr +=Temp[i];       
        return ResultStr;
} 

function checknumberformat(str){
	if (str.length==4)
		str = str + " ";
	else if (str.length==8)
		str = str + " ";	
	return str;
}


function formatmonumber(num){
	num = ftrim(num);
	var p1 = num.substring(0,4);
	var p2 = num.substring(4,7);	
	var p3 = num.substring(7,10);
	var newnum = p1 + " " + p2 + " " + p3;
	return newnum;
}

 

function isnumberic(num){                                                                                                       
  num = ftrim(num);
  for(i=0;i<num.length;i++){                                                                                                       
  	char=num.charAt(i);                                                                                                       
  	if(!('0'<=char&&char<='9')){                                                                                                 
      return false;                                                                                                       
  	}                                                                                                       
  }   
  return true;                                                                                                       
 }

function isEmail(str){ 
	var myReg = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/; 
	if(myReg.test(str)) 
		return true; 
	return false; 
}


function checkform(){
		
		if (document.getElementById("LoanAmount").value == ""){
			alert("Please type in the Loan Amount!");
			document.getElementById("LoanAmount").style.background = "#FCC"; 
			return false;
		}
		if (ftrim(document.getElementById("LoanAmount").value)<1000) {
			alert("Minimum loan amount is $1,000. Please borrow more.");
			document.getElementById("LoanAmount").style.background = "#FCC";
			return false;
		} 
		if (document.getElementById("Purpose").value == "-Select-"){
			alert("Please select Purpose!");
			document.getElementById("Purpose").style.background = "#FCC"; 
			return false;
		}
		if (document.getElementById("I/weOwn").value != "Motor Vehicle" && document.getElementById("I/weOwn").value != "Real Estate" && document.getElementById("I/weOwn").value != "Motor Vehicle & Real Estate") {
			alert("Please select asset/s that you or the other applicant own.");
			document.getElementById("I/weOwn").style.background = "#FCC";
			return false;
		} 
		
		if (document.getElementById("CreditHistory").value == "-Select-"){
			alert("Please select your credit history.");		
			document.getElementById("CreditHistory").style.background = "#FCC";
			return false;
		} 
		if (document.getElementById("WkIncome").value == ""){
			alert("Please type in your Weekly Income.");	
			document.getElementById("WkIncome").style.background = "#FCC";
			return false;
		} 
		if (document.getElementById("Purpose").value=="Personal"){
			if (ftrim(document.getElementById("WkIncome").value)<500){
				alert("Minimum total weekly income after tax MUST be at least $500 per week. If your income is below the requirement, a joint application with a person who has sufficient income maybe a good option.");	
				document.getElementById("WkIncome").style.background = "#FCC";
				return false;
			}
		}else if (document.getElementById("Purpose").value=="Business"){
			if (ftrim(document.getElementById("WkIncome").value)<300){
				alert("Minimum total weekly income after tax MUST be at least $300 per week. If your income is below the requirement, a joint application with a person who has sufficient income maybe a good option.");	
				document.getElementById("WkIncome").style.background = "#FCC";
				return false;
			}
		}
		if (document.getElementById("FullName").value == ""){
			alert("Please type in your Full Name.");	
			document.getElementById("FullName").style.background = "#FCC";
			return false;
		} 
		if (document.getElementById("MobNumber").value == ""){
			alert("Please type in your mobile phone for us to promptly contact you.");	
			document.getElementById("MobNumber").style.background = "#FCC";
			return false;
		}
		if (document.getElementById("Email").value == ""){
			alert("Please enter your email for us to promptly contact you. If you don't have an email address, please click on 'Apply Now' on the left of the navigate bar to complete full application form.");	
			document.getElementById("Email").style.background = "#FCC";
			return false;
		}
		if (document.getElementById("State").value == "-Select-"){
			alert("Please select the State that you live in.");	
			document.getElementById("State").style.background = "#FCC";
			return false;
		}
		/*if ((document.getElementById("State").value == "NSW"||document.getElementById("State").value == "ACT")&&document.getElementById("PPurpose").checked == false){
			document.getElementById("PPurpose").className = "field-error";
			alert('NSW/ACT applicants can only apply for Premium Loans (INTENDED for Business/investment use)"Tick Box". If this loan is INTENDED for personal/household/residential property use, we are afraid we cannot assist you at the moment.');	
			return false;
		}*/
		document.getElementById("sendfrom").value = window.location.href;
			return true;
	}	
//google code
function googlecode(){
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	try {
		var pageTracker = _gat._getTracker("UA-10616712-1");
		pageTracker._trackPageview();
	} catch(err) {}	
}

//own selection change
function ownchange(){
	document.getElementById("vmortgage").style.display = "none";
	document.getElementById("vproperty").style.display = "none";
	if (document.getElementById("I/weOwn").value == "Real Estate"){
		document.getElementById("vproperty").style.display = "inline";
		document.getElementById("vmortgage").style.display = "none";
	} else if (document.getElementById("I/weOwn").value == "Motor Vehicle"){
		document.getElementById("vproperty").style.display = "none";
		document.getElementById("vmortgage").style.display = "inline";	
	}else if (document.getElementById("I/weOwn").value == "Motor Vehicle & Real Estate"){
		document.getElementById("vproperty").style.display = "inline";
		document.getElementById("vmortgage").style.display = "inline";	
	}
	
}

function checkcontact(){
	document.getElementById("namecheck1").style.display = "none"; 
	document.getElementById("contactcheck1").style.display = "none";
	
	if (document.getElementById("name").value == ""){
			document.getElementById("namecheck1").style.display = "inline"; 
			document.getElementById("name").style.background = "#FCC";
			return false;
		}else if (document.getElementById("Mobile").value == ""&&document.getElementById("Email2").value == ""){
			document.getElementById("Mobile").style.background = "#FCC";
			document.getElementById("Email2").style.background = "#FCC";
			document.getElementById("contactcheck1").style.display = "inline";	
			return false;
		}else 
			return true;
}

//the js code in the original page
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



//replace first letter with capital letter
function replaceReg(str){ 
	str = str.toLowerCase();
	var reg = /\b(\w)|\s(\w)/g;
	return str.replace(reg,function(m){return m.toUpperCase()})
}

//background gray------
function G(id){
    return document.getElementById(id);
};
function GC(t){
   return document.createElement(t);
};
String.prototype.trim = function(){
          return this.replace(/(^\s*)|(\s*$)/g, '');
};
function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
} 
 


function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 60;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}

function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
}


function setcover() {
   popCoverDiv();  
   //document.body.style.overflow = "hidden";
}

function cancelcover(){
   //document.body.style.overflow = '';
	G("cover_div").style.display = 'none';
};

//---------

function popupmessage(){
	document.write(" ");
		
}


function openfeedbackform(){
	var url=window.location.href;
	url = url.replace("http://","")
	url = url.replace("/","|")
	window.open('http://www.mycashfinance.com.au/feedback.php?sendfrom=FastLoanToday.com.au&sendfromaddress='+url,'','height=540,width=480,top=0,left=0,location=no,menubar=no,resizable=no,scrollbar=no,statue=no,toolbar=no,true')	
}



function purposechange(){
	if (document.getElementById("Purpose").value=="Personal"){
		var selection = document.getElementById("State");
		if (selection.value=="NSW"||selection.value=="ACT"){ 	 
			document.getElementById("statehint").style.display="";
			document.getElementById("statehint").innerHTML= '<div align="left" style="font-size:11px; padding:26px 5px 10px 10px; ">Personal purpose loans are not available in <b>'+selection.value+'</b>, only loans mainly for business purpose are available. <a href="http://www.mycashfinance.com.au/nsw-law-change.html" target="blank">Know More</a></div><div align="left" style="padding-left:10px"><b>Apply for a business loan?</b></div><div align="center" style="padding-top:3px width:100%"><input type="button" value="YES" id="Yesbtn" style="background-color:#F90; cursor:pointer; width:43px; border:0" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button"style="background-color:#F90; cursor:pointer; width:43px;border:0" id="Nobtn" value="NO"></div> ';
			document.getElementById("Yesbtn").onclick=function(){
				document.getElementById("Purpose").value="Business";
				document.getElementById("statehint").style.display="none";						
			}
			
			document.getElementById("Nobtn").onclick=function(){
				document.getElementById("statehint").innerHTML= '<div align="right" style="height:16px;  padding: 25px 8px 0px 2px;"><img id="imgbtn" src="Pic/hint_close.png" width="16" height="16" style="cursor:pointer" /></div><div align="left" style="font-size:11px; padding:5px 5px 5px 20px">Unfortunately we cannot help you at the moment. However in the future if you need funds for business purpose we are happy to help.</div>';						
				document.getElementById("imgbtn").onclick=function(){
					document.getElementById('statehint').style.display='none';
				}
			}
		document.getElementById("Purpose").value="-Select-"	
		}
	}
}

//for new selector

function option_show(sltid){
	var obj=document.getElementById(sltid+"_options");	
	obj.style.display=''
}

function option_hide(sltid){
	var obj=document.getElementById(sltid+"_options");	
	obj.style.display='none'
}

function option_click(content,sltid){
	document.getElementById(sltid).value=content
	document.getElementById(sltid).style.background ="#FFF"
	option_hide(sltid)
	purposechange()
}


function option_select(sltid){
	var obj=document.getElementById(sltid+"_options");
	if (obj.style.display=='')	
		option_hide(sltid)
	else if (obj.style.display=='none')	
		option_show(sltid)			
}


window.document.onmousedown=function(){
	var e = arguments[0] || window.event;
   	var eventSource = e.srcElement||e.target; 
	if (document.getElementById("Purpose_options").style.display==""){
		
		var str=eventSource.id
		if ((str.indexOf("Purpose"))==-1){
			document.getElementById("Purpose_options").style.display="none"	
		}
	}
	if (document.getElementById("I/weOwn_options").style.display==""){
		
		var str=eventSource.id
		if ((str.indexOf("I/weOwn"))==-1){
			document.getElementById("I/weOwn_options").style.display="none"	
		}
	}
	if (document.getElementById("CreditHistory_options").style.display==""){
		
		var str=eventSource.id
		if ((str.indexOf("CreditHistory"))==-1){
			document.getElementById("CreditHistory_options").style.display="none"	
		}
	}
}
	
