//--Trim Whitespace from String
function trimStr(str)
{
    while(str.charAt(0) == (" ") )	
    {
	    str = str.substring(1);	
    }
    while(str.charAt(str.length-1) == " " )
    {
	    str = str.substring(0,str.length-1);	
    }	
    return str;
}

function checkemailaddress(inputbox){

var teststring 
teststring = inputbox.toString()

if(inputbox == ""){
	return 1002
}

if(teststring.length <= 6){
	return 1002
}

var illegalchrs = new Array("*","£","$","!")
var counter
	
for(counter=0;counter<=illegalchrs.length;counter++){
	if(teststring.indexOf(illegalchrs[counter]) != -1){
		return 1002
	}
}

var atpositionback = teststring.lastIndexOf("@")
var dotpositionback = teststring.lastIndexOf(".")
var atpositionfront = teststring.indexOf("@")

if(atpositionback == -1){
	return 1002
}

if(dotpositionback == -1){
	return 1002
}

if(atpositionfront != atpositionback){
	return 1002
}

if(atpositionback > dotpositionback){
	return 1002
}

return 0
}

function CheckContactBarTop(WebsiteArea){

if (document.ContactBar.ContactBarName.value == "" || document.ContactBar.ContactBarName.value == " "){
	alert ("Please give us your name");
	document.ContactBar.ContactBarName.focus();
	return false;
}
if (document.ContactBar.ContactBarEmail.value == "" || document.ContactBar.ContactBarEmail.value == " "){
	alert("Please give us an Email address");
	document.ContactBar.ContactBarEmail.focus();
	return false;
}
if(checkemailaddress(document.ContactBar.ContactBarEmail.value)!=0){
	alert("Please give us a valid Email address");
	document.ContactBar.ContactBarEmail.focus();
	return false;
}
if ((document.ContactBar.ContactBarTelephone.value == "") || (document.ContactBar.ContactBarTelephone.value == " ")){
	alert("Please give us at least one telephone number");
	document.ContactBar.ContactBarTelephone.focus();
	return false;
}
if (document.ContactBar.ContactBarDay.value == 0){
	alert("Please give a preferred day");
	document.ContactBar.ContactBarDay.focus();
	return false;
}
if (document.ContactBar.ContactBarTime.value == 0){
	alert("Please give a preferred time");
	document.ContactBar.ContactBarTime.focus();
	return false;
}
if (document.ContactBar.ContactBarComments.value == "Your comments:"){
	document.ContactBar.ContactBarComments.value = "";
}
document.ContactBar.submit();
return true
}

function CheckContactBar(WebsiteArea){

if (document.ContactBar.ContactBarName.value == "" || document.ContactBar.ContactBarName.value == " "){
	alert ("Please give us your name");
	document.ContactBar.ContactBarName.focus();
	return false;
}
if (document.ContactBar.ContactBarEmail.value == "" || document.ContactBar.ContactBarEmail.value == " "){
	alert("Please give us an Email address");
	document.ContactBar.ContactBarEmail.focus();
	return false;
}
if(checkemailaddress(document.ContactBar.ContactBarEmail.value)!=0){
	alert("Please give us a valid Email address");
	document.ContactBar.ContactBarEmail.focus();
	return false;
}
if (document.ContactBar.ContactBarDay.value == 0){
	alert("Please give a preferred day");
	document.ContactBar.ContactBarDay.focus();
	return false;
}
if (document.ContactBar.ContactBarTime.value == 0){
	alert("Please give a preferred time");
	document.ContactBar.ContactBarTime.focus();
	return false;
}
if ((document.ContactBar.ContactBarTelephone.value == "" || document.ContactBar.ContactBarMobile.value == " ") && (document.ContactBar.ContactBarMobile.value == "" || document.ContactBar.ContactBarTelephone.value == " ")){
	alert("Please give us at least one telephone number");
	document.ContactBar.ContactBarTelephone.focus();
	return false;
}
}

function ChangeTimeContactBar(){
if (document.ContactBar.ContactBarDay.value == 6){
	document.ContactBar.ContactBarTime.length = 0;
	document.ContactBar.ContactBarTime.options[0]= new Option("-Time-","0");
	document.ContactBar.ContactBarTime.options[1]= new Option("10:00 - 11:00","10:00 - 11:00");
	document.ContactBar.ContactBarTime.options[2]= new Option("11:00 - 12:00","11:00 - 12:00");
	document.ContactBar.ContactBarTime.options[3]= new Option("12:00 - 13:00","12:00 - 13:00");
	document.ContactBar.ContactBarTime.options[4]= new Option("13:00 - 14:00","13:00 - 14:00");
	document.ContactBar.ContactBarTime.options[5]= new Option("14:00 - 15:00","14:00 - 15:00");
	document.ContactBar.ContactBarTime.options[6]= new Option("15:00 - 16:00","15:00 - 16:00");
}else{
	document.ContactBar.ContactBarTime.length = 0;
	document.ContactBar.ContactBarTime.options[0]= new Option("-Time-","0");
	document.ContactBar.ContactBarTime.options[1]= new Option("09:00 - 10:00","09:00 - 10:00");
	document.ContactBar.ContactBarTime.options[2]= new Option("10:00 - 11:00","10:00 - 11:00");
	document.ContactBar.ContactBarTime.options[3]= new Option("11:00 - 12:00","11:00 - 12:00");
	document.ContactBar.ContactBarTime.options[4]= new Option("12:00 - 13:00","12:00 - 13:00");
	document.ContactBar.ContactBarTime.options[5]= new Option("13:00 - 14:00","13:00 - 14:00");
	document.ContactBar.ContactBarTime.options[6]= new Option("14:00 - 15:00","14:00 - 15:00");
	document.ContactBar.ContactBarTime.options[7]= new Option("15:00 - 16:00","15:00 - 16:00");
	document.ContactBar.ContactBarTime.options[8]= new Option("16:00 - 17:00","16:00 - 17:00");
	document.ContactBar.ContactBarTime.options[9]= new Option("17:00 - 18:00","17:00 - 18:00");
	document.ContactBar.ContactBarTime.options[10]= new Option("18:00 - 19:00","18:00 - 19:00");
	document.ContactBar.ContactBarTime.options[11]= new Option("19:00 - 20:00","19:00 - 20:00");
}
}

function CheckNewsSearch(){
if (document.NewsSearch.NewsSearchArg.value == "" || document.NewsSearch.NewsSearchArg.value == " "){
	alert ("Please enter something to search for");
	document.NewsSearch.NewsSearchArg.focus();
	return false
}
}

function SubmitNewsSearch(){
document.NewsSearch.submit();
}

function articleWin(url)
{		
    artWin = window.open(url,"article","height=650, width=850, toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no");
    artWin.focus(); 	
}

function showHideSelectControls(action,x,y,width,height)
{  
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  
  var myOffset = 0;
  if(myWidth>770){
  	myOffset = Math.round(((myWidth-770)/2)-.1);
  } else {
  	myOffset = 0;
  }
  
  x=x+myOffset;
  
  var right=x+width-1;
  var bottom=y+height-1;

  var selectControls=document.getElementsByTagName("select");
  for (var i=0; i<selectControls.length; i++)
  { if (action=='hide')
    { var sx=selectControls[i].offsetLeft;
      var sy=selectControls[i].offsetTop;

      // sx and sy are relative to parent. Compute absolute values
      var parent=selectControls[i].offsetParent;
      do {
        sx += parent.offsetLeft;
        sy += parent.offsetTop;
      } while ( parent = parent.offsetParent );

      var sRight=sx+selectControls[i].offsetWidth-1;
      var sBottom=sy+selectControls[i].offsetHeight-1;

      if (bottom >= sy
          && (x >= sx && x <= sRight
              ||
              right >= sx && right <= sRight))
        selectControls[i].style.visibility='hidden';
    }
    else selectControls[i].style.visibility='visible';
  } 
}
<!--
function showmenu(elmnt)
{
if (elmnt == "aboutus") {
	showHideSelectControls('hide',665,130,200,175)
	}
document.getElementById(elmnt).style.visibility="visible";
}

function hidemenu(elmnt)
{
if (elmnt == "aboutus") {
	showHideSelectControls('show',665,130,200,175)
	}
document.getElementById(elmnt).style.visibility="hidden";
}

function openWin(target)
{		
    newWin = window.open(target,"newwin","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes");
    newWin.focus(); 	
}

function CheckForm(){
if (document.newsletterForm.foreNames.value == "" || document.newsletterForm.foreNames.value == " "){
	alert ("Please give us your Forenames")
	document.newsletterForm.foreNames.focus();
	return false
}
if (document.newsletterForm.surName.value == "" || document.newsletterForm.surName.value == " "){
	alert ("Please give us your Surname")
	document.newsletterForm.surName.focus();
	return false
}
if (document.newsletterForm.eMail.value == "" || document.newsletterForm.eMail.value == " "){
	alert ("Please give us your Email Address")
	document.newsletterForm.eMail.focus();
	return false
}
 if(checkemailaddress(document.newsletterForm.eMail.value)!=0){
	 alert("Please give us a valid Email address");
	 document.newsletterForm.eMail.focus();
	 return false;
 }
if (document.newsletterForm.eMail.value != document.newsletterForm.ConfirmEmail.value){
	alert ("Sorry, your email address confirmation does not match the email address given, please re-enter")
	document.newsletterForm.eMail.focus();
	return false
}

document.newsletterForm.submit();
return true
}

function checkBCform(){
	
if(document.formBC.ForeName.value=="" || document.formBC.ForeName.value==" "){
	alert("Please give us your Fore Name");
	document.formBC.ForeName.focus();
	return false;
	}
if(document.formBC.Surname.value=="" || document.formBC.Surname.value==" "){
	alert("Please give us your Surname");
	document.formBC.Surname.focus();
	return false;
	}
if(document.formBC.Telephone.value=="" || document.formBC.Telephone.value==" "){
	alert("Please give us your Daytime Telephone number");
	document.formBC.Telephone.focus();
	return false;
	}	
	
document.formBC.submit();
return true;
}

function CheckContactUs(){

if (document.ContactBar.ContactBarName.value == "" || document.ContactBar.ContactBarName.value == " "){
	alert ("Please give us your name");
	document.ContactBar.ContactBarName.focus();
	return false;
}
if (document.ContactBar.ContactBarEmail.value == "" || document.ContactBar.ContactBarEmail.value == " "){
	alert("Please give us an Email address");
	document.ContactBar.ContactBarEmail.focus();
	return false;
}
if(checkemailaddress(document.ContactBar.ContactBarEmail.value)!=0){
	alert("Please give us a valid Email address");
	document.ContactBar.ContactBarEmail.focus();
	return false;
}
if ((document.ContactBar.ContactBarTelephone.value == "") || (document.ContactBar.ContactBarTelephone.value == " ")){
	alert("Please give us at least one telephone number");
	document.ContactBar.ContactBarTelephone.focus();
	return false;
}
if (document.ContactBar.ContactBarDay.value == 0){
	alert("Please give a preferred day");
	document.ContactBar.ContactBarDay.focus();
	return false;
}
if (document.ContactBar.ContactBarTime.value == 0){
	alert("Please give a preferred time");
	document.ContactBar.ContactBarTime.focus();
	return false;
}
document.ContactBar.submit();
return true
}

//--Legal Enquiry Form

function setLegalfocus(){
    //document.getElementById('footer_navigation').style.verticalAlign="baseline";
	document.legalenquiryForm.foreNames.focus();	
}	

function CheckLegalForm(){
	
boolValid = true;
strFieldList = "Please correct the following errors on this form:\n\n";

// validate forenames
if (trimStr(document.legalenquiryForm.foreNames.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Forenames\n";
	boolValid = false;
	document.legalenquiryForm.foreNames.focus();
}
// validate surname
if (trimStr(document.legalenquiryForm.surName.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Surname\n";
    if (boolValid == true){
	    document.legalenquiryForm.surName.focus();
		boolValid = false;
	}
}
// validate address line 1
if (trimStr(document.legalenquiryForm.Address1.value) == ""){
    strFieldList = strFieldList + "-  Please give us at least one line of your Address\n";
    if (boolValid == true){ 
        document.legalenquiryForm.Address1.focus();	
		boolValid = false;
	}
}
// validate town
if (trimStr(document.legalenquiryForm.Town.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Address Town/City\n";
    if (boolValid == true){ 
        document.legalenquiryForm.Town.focus();	
		boolValid = false;
	}
}
// validate post code
if (trimStr(document.legalenquiryForm.postCode.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Postal Code\n";
    if (boolValid == true){ 
        document.legalenquiryForm.postCode.focus();	
		boolValid = false;
	}
}
// validate telephone number
if (trimStr(document.legalenquiryForm.tel.value) == ""){
     strFieldList = strFieldList + "-  Please give us your Telephone Number\n";
     if (boolValid == true){ 
         document.legalenquiryForm.tel.focus();	
	      boolValid = false;
    }
}

// validate email address
if (trimStr(document.legalenquiryForm.eMail.value) == ""){
        strFieldList = strFieldList + "-  Please give us an Email address\n";
        if (boolValid == true){ 
            document.legalenquiryForm.eMail.focus();	
		    boolValid = false;
	    }
}

// validate email address format
if(checkemailaddress(document.legalenquiryForm.eMail.value)!=0){
        strFieldList = strFieldList + "-  Please give us a valid Email address\n";
        if (boolValid == true){ 
            document.legalenquiryForm.eMail.focus();	
		    boolValid = false;
	    }
}

// validate DOB
if (document.legalenquiryForm.dobDate.value == "" || document.legalenquiryForm.dobMonth.value == "" || document.legalenquiryForm.dobYear.value == ""  ){
        strFieldList = strFieldList + "-  Please give us your Date of Birth\n";
        if (boolValid == true){ 
            document.legalenquiryForm.dobDate.focus();	
		    boolValid = false;
	    }
}

// Validate Summary
if (trimStr(document.legalenquiryForm.summary.value) == ""){
        strFieldList = strFieldList + "-  Please give us a Summary of your Illness\n";
        if (boolValid == true){ 
            document.legalenquiryForm.summary.focus();	
		    boolValid = false;
	    }
}

// Validate Diagnosed by a Specialist
if (!document.legalenquiryForm.specialist[0].checked && !document.legalenquiryForm.specialist[1].checked){
        strFieldList = strFieldList + "-  Please indicate whether you have been Diagnosed by a Specialist\n";
        if (boolValid == true){ 
            document.legalenquiryForm.summary.focus();	
		    boolValid = false;
	    }
}

// validate Diagnosis Year
if (document.legalenquiryForm.specialist[0].checked && document.legalenquiryForm.diagnosisYear.value == ""){
        strFieldList = strFieldList + "-  Please give us the Year of your Diagnosis\n";
        if (boolValid == true){ 
            document.legalenquiryForm.diagnosisYear.focus();	
		    boolValid = false;
	    }
}

// validate work history
if (trimStr(document.legalenquiryForm.workHistory.value) == ""){
        strFieldList = strFieldList + "-  Please give us details of your Work History\n";
        if (boolValid == true){ 
            document.legalenquiryForm.workHistory.focus();	
		    boolValid = false;
	    }
}


if (document.legalenquiryForm.agreeTandC.checked != true){
    strFieldList = strFieldList + "-  Please acknowledge that you have read and agree to our Terms of Use\n";
    if (boolValid == true){ 
	    boolValid = false;
	}
}
if (boolValid == false){
    alert(strFieldList);
	return false;
	}
	
document.legalenquiryForm.submit();	
return true
}

//--Date Arrays
var endday=new Array("31","28","31","30","31","30","31","31","30","31","30","31");
var enddayleap=new Array("31","29","31","30","31","30","31","31","30","31","30","31");
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

//--Liability Enquiry Form

function setliabilityfocus(){
    document.getElementById('footer_navigation').style.verticalAlign="baseline";	
    document.liabilityenquiryForm.foreNames.focus();
}	

function CheckLiabilityForm(){
	
boolValid = true;
strFieldList = "Please correct the following errors on this form:\n\n";

// validate forenames
if (trimStr(document.liabilityenquiryForm.foreNames.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Forenames\n";
	boolValid = false;
	document.liabilityenquiryForm.foreNames.focus();
}
// validate surname
if (trimStr(document.liabilityenquiryForm.surName.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Surname\n";
    if (boolValid == true){
	    document.liabilityenquiryForm.surName.focus();
		boolValid = false;
	}
}
// validate address line 1
if (trimStr(document.liabilityenquiryForm.Address1.value) == ""){
    strFieldList = strFieldList + "-  Please give us at least one line of your Address\n";
    if (boolValid == true){ 
        document.liabilityenquiryForm.Address1.focus();	
		boolValid = false;
	}
}
// validate town
if (trimStr(document.liabilityenquiryForm.Town.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Address Town/City\n";
    if (boolValid == true){ 
        document.liabilityenquiryForm.Town.focus();	
		boolValid = false;
	}
}
// validate post code
if (trimStr(document.liabilityenquiryForm.postCode.value) == ""){
    strFieldList = strFieldList + "-  Please give us your Postal Code\n";
    if (boolValid == true){ 
        document.liabilityenquiryForm.postCode.focus();	
		boolValid = false;
	}
}
// validate telephone number
if (trimStr(document.liabilityenquiryForm.tel.value) == ""){
     strFieldList = strFieldList + "-  Please give us your Telephone Number\n";
     if (boolValid == true){ 
         document.liabilityenquiryForm.tel.focus();	
	      boolValid = false;
    }
}

// validate email address
if (trimStr(document.liabilityenquiryForm.eMail.value) == ""){
        strFieldList = strFieldList + "-  Please give us an Email address\n";
        if (boolValid == true){ 
            document.liabilityenquiryForm.eMail.focus();	
		    boolValid = false;
	    }
}

// validate email address format
//if(checkemailaddress(document.liabilityenquiryForm.eMail.value)!=0){
//        strFieldList = strFieldList + "-  Please give us a valid Email address\n";
//        if (boolValid == true){ 
//            document.liabilityenquiryForm.eMail.focus();	
//		    boolValid = false;
//	    }
//}

// validate work history
if (trimStr(document.liabilityenquiryForm.productDetails.value) == ""){
        strFieldList = strFieldList + "-  Please give us Details of Products\n";
        if (boolValid == true){ 
            document.liabilityenquiryForm.productDetails.focus();	
		    boolValid = false;
	    }
}


if (document.liabilityenquiryForm.agreeTandC.checked != true){
    strFieldList = strFieldList + "-  Please acknowledge that you have read and agree to our Terms of Use\n";
    if (boolValid == true){ 
	    boolValid = false;
	}
}
if (boolValid == false){
    alert(strFieldList);
	return false;
	}
	
document.liabilityenquiryForm.submit();	
return true
}

// PPI Validation

function setPPIfocus(){
    document.ppiForm.foreNames.focus();
}	

function CheckPPIForm(){
	
boolValid = true;
strFieldList = "Please correct the following errors on this form:\n\n";

// validate forenames
if (document.ppiForm.foreNames.value == "" || document.ppiForm.foreNames.value == " "){
    strFieldList = strFieldList + "-  Missing Forenames\n";
	boolValid = false;
	document.ppiForm.foreNames.focus();
}
// validate surname
if (document.ppiForm.surName.value == "" || document.ppiForm.surName.value == " "){
    strFieldList = strFieldList + "-  Missing Surname\n";
    if (boolValid == true){
	    document.ppiForm.surName.focus();
		boolValid = false;
	}
}
// validate address line 1
if (document.ppiForm.Address1.value == "" || document.ppiForm.Address1.value == " "){
    strFieldList = strFieldList + "-  Please give us at least one line of your Address\n";
    if (boolValid == true){ 
        document.ppiForm.Address1.focus();	
		boolValid = false;
	}
}
// validate town
if (document.ppiForm.Town.value == "" || document.ppiForm.Town.value == " "){
    strFieldList = strFieldList + "-  Please give us your Address Town/City\n";
    if (boolValid == true){ 
        document.ppiForm.Town.focus();	
		boolValid = false;
	}
}
// validate post code
if (document.ppiForm.postCode.value == "" || document.ppiForm.postCode.value == " "){
    strFieldList = strFieldList + "-  Please give us your Postal Code\n";
    if (boolValid == true){ 
        document.ppiForm.postCode.focus();	
		boolValid = false;
	}
}
// validate telephone number
if (document.ppiForm.tel.value == "" || document.ppiForm.tel.value == " ") {
     strFieldList = strFieldList + "-  Please give us a telephone number on which we may contact you\n";
     if (boolValid == true){ 
         document.ppiForm.tel.focus();	
	      boolValid = false;
    }
}
// validate email address for web queries only
if (document.ppiForm.eMail.value == "" && document.ppiForm.eMail.value == " "){
        strFieldList = strFieldList + "-  Please give us an Email address\n";
        if (boolValid == true){ 
            document.ppiForm.eMail.focus();	
		    boolValid = false;
	    }
}
if(checkemailaddress(document.ppiForm.eMail.value)!=0){
        strFieldList = strFieldList + "-  Please give us a valid Email address\n";
        if (boolValid == true){ 
            document.ppiForm.eMail.focus();	
		    boolValid = false;
	    }
}

if (document.ppiForm.agreeTandC.checked != true){
    strFieldList = strFieldList + "-  Please acknowledge that you have read and agree to our Terms of Use\n";
    if (boolValid == true){ 
	    boolValid = false;
	}
}
if (boolValid == false){
    alert(strFieldList);
	return false;
	}
	
document.ppiForm.submit();	
return true
}

function reAlign(){
    document.getElementById('footer_navigation').style.verticalAlign="baseline";	
}


