﻿// TWJScript File
//All Common Javascript functions


/*
//prevent right click on site
var message="Right click is disabled - L&C Ltd";

 

///////////////////////////////////

function clickIE4(){

if (event.button==2){

alert(message);

return false;

}

}

 

function clickNS4(e){

if (document.layers||document.getElementById&&!document.all){

if (e.which==2||e.which==3){

alert(message);

return false;

}

}

}

 

if (document.layers){

document.captureEvents(Event.MOUSEDOWN);

document.onmousedown=clickNS4;

}

else if (document.all&&!document.getElementById){

document.onmousedown=clickIE4;

}

 

document.oncontextmenu=new Function("alert(message);return false")
*/

//prevents user hitting back space and moving back a page if no control is selected
  function cancelBack()
    {
        if ((event.keyCode == 8 || 
           (event.keyCode == 37 && event.altKey) || 
           (event.keyCode == 39 && event.altKey))
            && 
           (event.srcElement.form == null || event.srcElement.isTextEdit == false)
          )
        {
            event.cancelBubble = true;
            event.returnValue = false;
        }
    }

//used wizard 2 for mortgage product decision popups
function openNewWindow(newPageURL)
{
    window.open(newPageURL, "_blank","height=600px width=770px " +
        "resizable=no scrollbars=no menubar=no location=no status=no left=100 top=100");
}


//used pn wizard 1 and qual 1
function CalcLTVProp()
{
	
	if (document.form1.txtLoanReq.value == "")//> Number(form.txtPrice.value))
	{
	//do nothing
	//alert("nothing fired prop")
	}
	else
	//calculate it
	{
	//	alert("calc fired prop")
	var Result = (Number(document.form1.txtLoanReq.value) / Number(document.form1.txtPropertyValue.value)) * 100
	 Result = Math.round(Result*100)/100 //2dp

	  document.form1.txtLTV.value = Result
	 
	 }
	 	
}

function CalcLTVLoan()
{

	
	if (document.form1.txtPropertyValue.value == "")//> Number(form.txtPrice.value))
	{
	//do nothing
	//alert("nothing fired loan")
	}
	else
	//calculate it
	{
		//alert("calc fired loan")
	var Result = (Number(document.form1.txtLoanReq.value) / Number(document.form1.txtPropertyValue.value)) * 100
	 Result = Math.round(Result*100)/100 //2dp

	  document.form1.txtLTV.value = Result
	 	 
	}
		
}

function CalcRepayAmount()
{

	
	if (document.form1.txtLoanReq.value == "")//> Number(form.txtPrice.value))
	{
	//do nothing
	//alert("nothing fired loan")
	}
	else
	//calculate it
	{
		//alert("calc fired loan")
	var Result = (Number(document.form1.txtLoanReq.value) - Number(document.form1.txtInterestOnlyAmount.value))
	
	  if (Result < 0)
	 {
	 var response = "The interest only amount cannot exceed the loan amount"
	 alert(response)
	 document.form1.txtInterestOnlyAmount.value = ""
	 document.form1.txtRepaymentAmount.value = ""
	
	 }
	 else
	 {
	  document.form1.txtRepaymentAmount.value = Result
	 }
	 
	 
	}
	
	
	
}

function getParam(strParam) {
   //alert(strParam)
                        var iStart, iEnd, iLen;

                        var strValue = "";

                        var strURL = window.location.href + "&";

                      // alert(strURL)

                        iStart = strURL.toLowerCase().indexOf("&" + strParam + "=");

                        if (iStart < 0) {

                                    iStart = strURL.toLowerCase().indexOf("?" + strParam + "=");
// alert(iStart)
                        }

                        if (iStart > -1) {

                                    iStart += strParam.length + 2;

                                    strURL = strURL.substr(iStart);

                                    iEnd = strURL.toLowerCase().indexOf("&");

                                    if (iEnd > 0) {

                                                strValue = strURL.substr(0, iEnd);

                                    }

                        }

                      
 //alert(strValue)
                        return strValue;

}
            
           
function ShowAltText(img, e){

//set alt text
var alt = img;
var help = document.getElementById('help')

//Get image position

var top = 0, left = 0; 
  if (!e) { e = window.event; } 
  var myTarget = e.currentTarget; 
  if (!myTarget) { 
   myTarget = e.srcElement; 
  } 
  else if (myTarget == "undefined") { 
   myTarget = e.srcElement; 
  } 
  while(myTarget!= document.body) { 
     top += myTarget.offsetTop; 
     left += myTarget.offsetLeft; 
     myTarget = myTarget.offsetParent; 
  } 
  
  
 // populate div 
 help.innerHTML = alt;
 
 left = left + 40
 top = top 
 //move div
help.style.position = "absolute";
help.style.left = left + "px";
 help.style.top = top + "px";
 help.style.display = "inline";
 setTimeout("hidediv()",7000)		
}

function hidediv(){
document.getElementById('help').style.display = "none";
}


