﻿// JScript File
function loadXMLDoc(url) {


      // branch for native XMLHttpRequest object
      if (window.XMLHttpRequest) {
          req = new XMLHttpRequest();

          req.onreadystatechange = processEmailChange;
          req.open("GET", url, true);
          req.send(null);
      // branch for IE/Windows ActiveX version
      } else if (window.ActiveXObject) {
          isIE = true;
          req = new ActiveXObject("Microsoft.XMLHTTP");
          if (req) {
              req.onreadystatechange = processEmailChange;
              req.open("GET", url, true);
              req.send();
          }
      }
  }
  
  function processEmailChange() {
  var styleObject = getStyleObject('thealert');

      if (req.readyState == 4) {  
          if (req.status == 200) {
          
                 if (req.responseText == "false") {
                 styleObject.display = 'block'
                 }else {
                  styleObject.display = 'none'
                  }
                
          } else {
            
          }
      }
  }
  
  function checkEmail(form) {
  loadXMLDoc('js/emailLookup.asp?domain='+ document.forms[0].email.value);
  }
  
  function hideAll()
{
   changeObjectVisibility("theAlert","hidden");

}
  
  function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get the object's stylesheet
    var styleObject = getStyleObject(objectId);

    // then if we find a stylesheet, set its visibility
    // as requested
    //
    if (styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
}


//// panel 1 functions
function getPercent(form) { 
aVal = document.forms[0].propertyvalue.value
aVal = aVal.replace(/,/g,"");

if  (document.forms[0].percent.value != "") {
    mort = aVal/100 * document.forms[0].percent.value
    document.forms[0].mortgageAmount.value = Math.round(mort)
    }
}

function checkmort(form) {
   switch (document.forms[0].mType[document.forms[0].mType.selectedIndex].value)
{  
  case "Re-mortgage":
        changeObjectVisibility("PnlPropFound","hidden");
		changeObjectVisibility("PnlFTB","hidden"); 
  break
  
  case "Purchase":
        changeObjectVisibility("PnlPropFound","visible");
		changeObjectVisibility("PnlFTB","visible"); 
  break
  
  case "Buy-to-let":
        changeObjectVisibility("PnlPropFound","visible");
		changeObjectVisibility("PnlFTB","hidden"); 
  break
  
  case "Commercial":
        changeObjectVisibility("PnlPropFound","visible");
		changeObjectVisibility("PnlFTB","hidden"); 
  break
  
  case "International":
        changeObjectVisibility("PnlPropFound","visible");
		changeObjectVisibility("PnlFTB","hidden"); 
  break
  
  }
};

function checkMvalues(){
var styleObject = getStyleObject('PnlnoticePrice');
styleObject.display = 'none'

var mortval = document.forms[0].mortgageAmount.value
var propval = document.forms[0].propertyvalue.value

mortval = mortval.replace(/,/g,"");
propval = propval.replace(/,/g,"");


	if (parseInt(mortval) > parseInt(propval)) {
	styleObject.display = 'block'
	}else {
	styleObject.display = 'none'
	}
	if  (mortval  != "" && propval != "") {
	theval = mortval / propval *100
	if (isNaN(theval)) {
	}else {
	document.forms[0].percent.value = theval
	}
}
}


function check90Value(mortamount,propamount){
var styleObject = getStyleObject('Pnlnotice90');
styleObject.display = 'none'

var styleObject2 = getStyleObject('introText');
var styleObject3 = getStyleObject('percenttxt');

for (i=0;i<=6;i++){
if (eval("document.forms[0].credStatus_"+i).checked) {
          
           percentval = parseInt(parseInt(mortamount) / propamount *100)
               if (percentval>89) {
             //  document.getElementById('introText').innerHTML = "Usually you can only borrow up to 90% of your property value if you have recent credit issues. We have changed the loan amount to 90% which is £"+ parseInt(propamount/100 * 90)+ " for you, however to reject this suggestion simply return to section (1)";
                    styleObject.display = 'block';
                    styleObject3.display='block'
                 }
           }
    }
}


function CustomValidator_ClientValidateTick(validators,thediv) {
var styleObject = getStyleObject(thediv);

var arrValidators = validators.split(",");
var lastIndex = validators.length - 1;
var bolthisValid = true

 var lastValIndex = Page_Validators.length - 1;
        for (i=0; i<=lastValIndex; i++) {
           for (c=0; c<=lastIndex; c++) {
                if(Page_Validators[i].id == arrValidators[c]) {

                        if (Page_Validators[i].isvalid == false || Page_Validators[i].isvalid == undefined ) {
                           bolthisValid =false
                           }
                 }
            }
               
        }

   if (bolthisValid == true) {
           styleObject.border = '2px green solid'
   } else {
        styleObject.border = '2px red solid'
   }
};

function doValidation() {
CustomValidator_ClientValidateTick('RequiredFieldValidator17','CoverAmount')
CustomValidator_ClientValidateTick('RequiredFieldValidator16,RangeValidator8','yrsCover')
CustomValidator_ClientValidateTick('RequiredFieldValidator19','tick37');
CustomValidator_ClientValidateTick('RequiredFieldValidator15','tobacco');
CustomValidator_ClientValidateTick('RequiredFieldValidator7','tick6')
CustomValidator_ClientValidateTick('RequiredFieldValidator1,RequiredFieldValidator31','firstname')
CustomValidator_ClientValidateTick('RequiredFieldValidator8,RequiredFieldValidator26','lastname')
CustomValidator_ClientValidateTick('RequiredFieldValidator32','occupation')
CustomValidator_ClientValidateTick('RequiredFieldValidator9,RangeValidator1,RequiredFieldValidator6','dobDay')
CustomValidator_ClientValidateTick('RequiredFieldValidator10,RangeValidator2,RequiredFieldValidator21','dobMonth')
CustomValidator_ClientValidateTick('RequiredFieldValidator11,RangeValidator3,RequiredFieldValidator24','dobYear')
CustomValidator_ClientValidateTick('RequiredFieldValidator14','address');
CustomValidator_ClientValidateTick('RequiredFieldValidator19','manAddress1');
CustomValidator_ClientValidateTick('RequiredFieldValidator20','manAddress2')
CustomValidator_ClientValidateTick('RequiredFieldValidator21','manAddress3')
CustomValidator_ClientValidateTick('RequiredFieldValidator22','manAddress4')
CustomValidator_ClientValidateTick('RequiredFieldValidator5,RegularExpressionValidator2','email')
CustomValidator_ClientValidateTick('RequiredFieldValidator12,RegularExpressionValidator29','hometel')
CustomValidator_ClientValidateTick('RequiredFieldValidator13,RegularExpressionValidator33','evetel')
CustomValidator_ClientValidateTick('RequiredFieldValidator3,RequiredFieldValidator33','JointLIFirstName')
CustomValidator_ClientValidateTick('RequiredFieldValidator4,RequiredFieldValidator34','JointLILastName')
CustomValidator_ClientValidateTick('RequiredFieldValidator21','JointLIOccupation')
CustomValidator_ClientValidateTick('RequiredFieldValidator28,RangeValidator4,RequiredFieldValidator35','JointLIDOBDay')
CustomValidator_ClientValidateTick('RequiredFieldValidator29,RangeValidator5,RequiredFieldValidator36','JointLIDOBMonth')
CustomValidator_ClientValidateTick('RequiredFieldValidator30,RangeValidator6,RequiredFieldValidator37','JointLIDOBYear')
CustomValidator_ClientValidateTick('RequiredFieldValidator23','JoinLItobacco');
 
}

function Panel1() {
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('botnav2', '', true, '', '', false, false))
doValidation()
}

function Panel2() {
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('Button1', '', true, '', '', false, false))
doValidation()
}


function postingPPC() {
    alert('asdas')
};

var expdate = new Date();
expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 365));
 
function createBreadcrumbArray() {

        var arrFieldNames=new Array();
        
        	arrFieldNames[0]='Cover amount';		
			arrFieldNames[1]='Cover length';
			arrFieldNames[2]='Debt reduction';
			arrFieldNames[3]='Smoker';
			arrFieldNames[4]='Critical illness';		
			
			arrFieldNames[5]='Title';
			arrFieldNames[6]='First name';
			arrFieldNames[7]='Last name';
			arrFieldNames[8]='Date of birth';
			arrFieldNames[9]='Email';
			arrFieldNames[10]='Day tel';
			arrFieldNames[11]='Eve tel';
			arrFieldNames[12]='Occupation';
			arrFieldNames[13]='Newsletter';
			
			arrFieldNames[14]='Partners name';
			arrFieldNames[15]='Partners occupation';
			arrFieldNames[16]='Partners DOB';
			arrFieldNames[17]='Partners smoker?';
			 
	       setCookieArray("fieldresults","blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank^blank")
	       	
	       	
	       setCookieArray("fieldnames", "Cover amount^Cover length^Debt reduction^Smoker^Critical illness^Title^First name^Last name^Date of birth^Email^Day tel^Eve tel^Occupation^Newsletter^Partners name^Partners occupation^Partners DOB^Partners smoker?");

}

function storefieldresult(theid,thetype,theitem) {

document.getElementById('breadcrumb').style.display = 'block'
    var theresult
        if (thetype == "text") {
            theresult = callBreadcrumbText(theitem)
        }
        
        if (thetype == "radio") {
       
            theresult = callBreadcrumbRadio(theitem)
            
        }
        
        if (thetype == "select") {
            theresult = callBreadcrumbSelect(theitem)
        }
        
         if (thetype == "check") {
            theresult = callBreadcrumbCheck(theitem)
        }
        
    resultsArray = getCookieArray('fieldresults')
    resultsArray[theid] = theresult;
    
       var ArString = ""
      for (i=0;i<resultsArray.length;i++) {
        result = resultsArray[i];  
        ArString = ArString + result +"^";
      }
        setCookieArray("fieldresults",ArString)
      
      writeResultsString();
}

function writeResultsString() {

     var ArrayResults = new getCookieArray("fieldresults");
     var ArrayFieldNames = new getCookieArray("fieldnames");
     
    document.getElementById('breadcrumb').innerHTML = ""
    
       for (i=0;i<ArrayFieldNames.length;i++) {
            if (ArrayResults[i] != "" && ArrayResults[i] != undefined && ArrayResults[i] != "blank") {
             document.getElementById('breadcrumb').innerHTML = document.getElementById('breadcrumb').innerHTML + "<span class='crumblabel'>"+ArrayFieldNames[i] + ":</span> "+ArrayResults[i]+" " ;
             }
        }
};

function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
                if (dcookie.substring(cbegin, vbegin) == cname) { 

                var vend = dcookie.indexOf (";", vbegin);
                        if (vend == -1) vend = clen;
                return unescape(dcookie.substring(vbegin, vend));
              
                }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
                if (cbegin == 0) break;
        }
return null;
}

function setCookieArray(name,str){
    document.cookie = name + "=" + escape (str) + 
"; path=/";
}

function getCookieArray(name){
    cookieStr = getCookie(name)
    arrCookie = cookieStr.split("^")
    return arrCookie
}


function callBreadcrumbText(theitem) {
if (theitem.id == 'dobYear') {
    return  document.form1.dobDay.value + '/'+document.form1.dobMonth.value +'/'+ theitem.value;
}

if (theitem.id == 'JointLIDOBYear') {
    return  document.form1.JointLIDOBDay.value + '/'+document.form1.JointLIDOBMonth.value +'/'+ theitem.value;
}

 if (theitem.value != undefined) {     
     return theitem.value
 }
}

function callBreadcrumbCheck(theitem) {

    if (theitem.checked) {
        return 'yes'
    } else {
        return 'no'
    }
}



function callBreadcrumbRadio(radioObj) {
radioObj = eval('document.forms[0].'+radioObj)

	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			if(radioObj[i].value == '1') {
			    return 'yes'
			    } 
			    if(radioObj[i].value == '0') {
			    return 'no'
			    } 
			}else {
		//return	radioObj[i].value;
			}
		}

	return "";
}

function callBreadcrumbSelect(theitem) {
var myCredStatus = new Array()
myCredStatus[0] = "CCJs"
myCredStatus[1] = "Defaults"
myCredStatus[2] = "Mortgage arrears"
myCredStatus[3] = "Repossession pending"
myCredStatus[4] = "Previously turned down"
myCredStatus[5] = "No proof of income"
myCredStatus[6] = "Late or missed payment on loans and credit cards"

var strResult = ""
    for (i=0;i<6;i++) {
        if (eval('document.forms[0].credStatus_'+i+'.checked')){
            strResult = strResult +", " + myCredStatus[i]
        }
    }
    return strResult
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function


function cleanMortAmount(field) {
var amount
amount = field.value
    if (amount < 20000) {
        field.value = amount* 1000
    }
}

function numeralsOnly(currv, evt, decimal) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) {
        return false;
    }
    if (charCode == 46) {  
        if (decimal == 0) { 
            return false;
        } else {
         if (currv.indexOf(".") != -1) {
             return false;
         }
     }
 } else if (currv.indexOf(".") != -1) {   
     var s = currv.substring(currv.indexOf("."));
  if (s.length > decimal) {
   return false;
  }
 }
    return true;
}

