﻿// JScript File
function initFields() {
    if (!document.getElementsByTagName){ return; }
    var allfields = document.getElementsByTagName("input");

    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
    thisfunction = ''
        var field = allfields[i];

        if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password") ) {
           // var oldonload  =  field.onfocus;
           var oDiv = document.getElementById(field.id);
           // alert(oDiv)
           //addEvent(oDiv,'Focus',function() {setvalidationsvis();this.onFocus='';})

          field.onblur = function () {setvalidationsvis();removePrompt();}
       // field.onfocus = function () {setvalidationsvis()}
        }  
    }
   
}

function clearfield(thedefault,thefield) {
    if (thefield.value == thedefault) {
    thefield.value = ''
    }
}


function setvalidationsvis() {
    //changeObjectVisibility('instructions', 'visible')
}

function promptText(thetxt) {


var s = document.getElementById('prompttxt')
    s.innerHTML = thetxt + "<br>"
    setvalidationsvis();
     ///bits to set the alert as required
       var styleObject = getStyleObject('PnlnoticePrice');
     //  styleObject.display = 'none'
}

function removePrompt() {
ptext = document.getElementById('prompttxt')
ptext.innerHTML = '';
}

function custVal_firstname(source,args) {

    fsValid = true
    var myRegxp = /^[A-Za-zÀ-ÖØ-öø-ÿ '\-\.]{2,35}$/;

    if (myRegxp.test(args.Value) == false) {
        fsValid = false
    }

    if (args.Value == '' || args.Value == 'first name' || fsValid == false) {

            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }

        args.IsValid = fsValid 
};





function custVal_surname(source,args) {



 fsValid = true
    var myRegxp = /^[A-Za-zÀ-ÖØ-öø-ÿ '\-\.]{2,35}$/;

    if (myRegxp.test(args.Value) == false) {
        fsValid = false
    }

    if (args.Value == '' || args.Value == 'surname' || fsValid == false) {

            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_bothnames(source,args) {
var fnameval = document.getElementById('CustomValidator1')
var snameval = document.getElementById('CustomValidator22')

    if (fnameval.isvalid && snameval.isvalid) {
        args.IsValid = true
    } else {
    
    args.IsValid = false
    
    }
};


function custVal_dealends(source,args) {

var sendsmonth = document.getElementById('RequiredFieldValidator45')
var sendsyear = document.getElementById('RequiredFieldValidator46')

 if (sendsmonth.isvalid && sendsyear.isvalid) {
        args.IsValid = true
    } else {
    
    args.IsValid = false
    
    }
    
    
};



function custVal_dob(source,args) {
var fdobday = document.getElementById('RequiredFieldValidator4')
var sdobmonth = document.getElementById('RequiredFieldValidator5')
var sdobyear = document.getElementById('RequiredFieldValidator6')

 if (fdobday.isvalid && sdobmonth.isvalid && sdobyear.isvalid) {
        args.IsValid = true
    } else {
    
    args.IsValid = false
    
    }
    
    
};

function custVal_streetcity(source,args) {
var fstreet = document.getElementById('CustomValidator3')
var fcity = document.getElementById('CustomValidator4')

 if (fstreet.isvalid && fcity.isvalid) {
        args.IsValid = true
    } else {
    
    args.IsValid = false
    
    }
    
    
};


function custVal_phone(source,args) {
var f1 = document.getElementById('CustomValidator5')
var f2 = document.getElementById('CustomValidator6')

 if (f1.isvalid && f2.isvalid) {
        args.IsValid = true
    } else {
    
    args.IsValid = false
    
    }
    
    
};

function custVal_INT_postcode(source,args) {
 fsValid = true

    
    if (args.Value == '' || args.Value == 'postcode') {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}



function custVal_postcode(source,args) {
 fsValid = true

  var myRegxp = /^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/;


var postcode = args.Value


    if (myRegxp.test(postcode.toUpperCase()) == false) {
        fsValid = false
   }
    
    
    if (args.Value == '' || args.Value == 'postcode') {
            fsValid = false
           
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}


function custVal_street(source,args) {
 fsValid = true

    if (args.Value == '' || args.Value == 'house no & street') {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_city(source,args) {
 fsValid = true

    if (args.Value == '' || args.Value == 'city') {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_daytime_phone(source,args) {
 fsValid = true
var myRegxp = /^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?\d{5}\)?\s?\d{5})|(\(?\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/;

//var myRegxp = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;




   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }
  
  
  var myRegxp2 = /0{5,}|1{5,}|2{5,}|3{5,}|4{5,}|5{5,}|6{5,}|7{5,}|8{5,}|9{5,}/;
  
    if (myRegxp2.test(args.Value) == true) {
        fsValid = false
  }

    if (args.Value == '' || args.Value == 'daytime' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_INT_daytime_phone(source,args) {
 fsValid = true
//var myRegxp = /^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?\d{5}\)?\s?\d{5})|(\(?\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/;

var myRegxp = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;




   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }
  
  
  var myRegxp2 = /0{5,}|1{5,}|2{5,}|3{5,}|4{5,}|5{5,}|6{5,}|7{5,}|8{5,}|9{5,}/;
  
    if (myRegxp2.test(args.Value) == true) {
        fsValid = false
  }

    if (args.Value == '' || args.Value == 'daytime' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_evening_phone(source,args) {
 fsValid = true
    var myRegxp = /^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?\d{5}\)?\s?\d{5})|(\(?\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/;
    
   // var myRegxp = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;

   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }
  
    
  var myRegxp2 = /0{5,}|1{5,}|2{5,}|3{5,}|4{5,}|5{5,}|6{5,}|7{5,}|8{5,}|9{5,}/;
  
    if (myRegxp2.test(args.Value) == true) {
        fsValid = false
  }
  

    if (args.Value == '' || args.Value == 'evening' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_INT_evening_phone(source,args) {
 fsValid = true
   // var myRegxp = /^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?\d{5}\)?\s?\d{5})|(\(?\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/;
    
    var myRegxp = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;

   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }
  
    
  var myRegxp2 = /0{5,}|1{5,}|2{5,}|3{5,}|4{5,}|5{5,}|6{5,}|7{5,}|8{5,}|9{5,}/;
  
    if (myRegxp2.test(args.Value) == true) {
        fsValid = false
  }
  

    if (args.Value == '' || args.Value == 'evening' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}


function custVal_daytime_phoneb(source,args) {
 fsValid = true
    var myRegxp = /^[0-9\s\(\)\+\-]+$/;

   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }

    if (args.Value == '' || args.Value == 'daytime' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_evening_phoneb(source,args) {
 fsValid = true
    var myRegxp = /^[0-9\s\(\)\+\-]+$/;

   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }

    if (args.Value == '' || args.Value == 'evening' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_email(source,args) {
 fsValid = true
    var myRegxp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

   if (myRegxp.test(args.Value) == false) {
        fsValid = false
  }

    if (args.Value == '' || args.Value == 'you@here.co.uk' || fsValid == false) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_propertyvalue(source,args) {

var thisval = args.Value


thisval = thisval.replace(',','')
thisval = thisval.replace('.','')
thisval = thisval.replace(' ','')

    fsValid = true
  var myRegxp = /^[-+]?\d*$/;

    if (myRegxp.test(thisval) == false) {
        fsValid = false
    }

    if (args.Value == '' || args.Value == 'amount(£)' || fsValid == false || thisval < 25000 || thisval > 10000000) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
          // document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }

        args.IsValid = fsValid 

}

function custVal_mortgageAmount(source,args) {

var thisval = args.Value


thisval = thisval.replace(',','')
thisval = thisval.replace('.','')
thisval = thisval.replace(' ','')


    fsValid = true
  var myRegxp = /^[-+]?\d*$/;

    if (myRegxp.test(thisval) == false) {
        fsValid = false
    }

    if (args.Value == '' || args.Value == 'amount(£)' || fsValid == false || thisval < 25000 || thisval > 10000000) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
         //  document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }

        args.IsValid = fsValid 

}

function custVal_currlender(source,args) {
 fsValid = true

    if (args.Value == '' ) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_currrate(source,args) {
 fsValid = true

    if (args.Value == '' || parseInt(args.Value) < 1 || parseInt(args.Value) > 12 ) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }
        
        args.IsValid = fsValid 
  
}

function custVal_familyincome(source,args) {

    fsValid = true
  var myRegxp = /^[-+]?\d*$/;

    if (myRegxp.test(args.Value) == false) {
        fsValid = false
    }

    if (args.Value == '' || args.Value == 'amount(£)' || fsValid == false ) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }

        args.IsValid = fsValid 

}

function custVal_invdebt(source,args) {

    fsValid = true
  var myRegxp = /^[-+]?\d*$/;

    if (myRegxp.test(args.Value) == false) {
        fsValid = false
    }

    if (args.Value == ''  || fsValid == false ) {
            fsValid = false
           } else {
            fsValid = true
        }
        
        if (fsValid == true) {
          document.getElementById(source.controltovalidate).style.border =  '1px solid #7F9DB9';
           document.getElementById(source.controltovalidate).style.padding =  '1px';
        }
        else {
   document.getElementById(source.controltovalidate).style.border = '2px red solid'
        }

        args.IsValid = fsValid 

}



