// JavaScript Document
var validation="";
var form_ok=true;
var bg_error="#FF00FF";
var bg_ok="#CCCCCC";

function P7_autoLayers() { //v1.4 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(var u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(var j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}
function P7_MultiClass2() { //v1.0 by PVII
 var args=P7_MultiClass2.arguments;if(document.getElementById){
  for(var i=0;i<args.length;i+=2){if(document.getElementById(args[i])!=null){
  if(document.p7setdown){for(var k=0;k<p7dco.length-1;k+=2){
  if(args[i]==p7dco[k]){args[i+1]=p7dco[k+1];break;}}}
  document.getElementById(args[i]).className=args[i+1];}}}
}
function P7_hideDiv(evt) { //v1.3 by PVII
 var b,relT,mT=false; 
 if(document.layers){b=evt.target;if(b.p7aHide){
  b.visibility="hidden";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;
  while(b!=null){if(b.tagName=="DIV" && b.p7ahD){mT=true;break;}b=b.parentElement;}
  if(!b.contains(event.toElement)){b.style.visibility="hidden";}
 }else if(document.getElementById){b=evt.currentTarget;relT=evt.relatedTarget;
  while(relT!=null){if(b==relT){mT=true;break;}
  relT=relT.parentNode;}if(!mT){b.style.visibility="hidden";}}
}

function P7_autoHide() { //v1.3 by PVII
 var i,g,args=P7_autoHide.arguments;
 for(i=0;i<args.length;i++){if((g=MM_findObj(args[i]))!=null){
  g.p7aHide=true;if(document.layers){
  g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideDiv;g.p7ahD=true;}}
}

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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function setColor(el, bg) {
  if (el.style) el.style.backgroundColor = bg;
}

function checkFields() {
    if (document.contactform.name.value=='') {
        validation += "Please enter your name\n";
		setColor(document.contactform.name, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.contactform.name, bg_ok);
	}
    if ((document.contactform.email.value.indexOf('@')==-1) || (document.contactform.email.value.indexOf('.')==-1) || (document.contactform.email.value.indexOf('.') == document.contactform.email.value.length - 1)) {
        validation += "Please enter a valid email address\n";
		setColor(document.contactform.email, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.contactform.email, bg_ok);
	}
	if (document.contactform.query.value=='') {
        validation += "Please enter your query\n";
		setColor(document.contactform.query, bg_error);
		form_ok = false;
    }
    else {
	    setColor(document.contactform.query, bg_ok);
	}
    if (validation != "") {
	  rc=alert(validation);
	  validation="";
	}
	else {
      document.contactform.submit();
	}
}

function checkCableOrderFields() {
    if (document.cableorderform.name.value=='') {
        validation += "Please enter your name\n";
		setColor(document.cableorderform.name, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.cableorderform.name, bg_ok);
	}
    if (document.cableorderform.address1.value=='') {
        validation += "Please enter the address to be connected\n";
		setColor(document.cableorderform.address1, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.cableorderform.address1, bg_ok);
	}
    if ((document.cableorderform.email.value.indexOf('@')==-1) || (document.cableorderform.email.value.indexOf('.')==-1) || (document.cableorderform.email.value.indexOf('.') == document.cableorderform.email.value.length - 1)) {
        validation += "Please enter a valid email address\n";
		setColor(document.cableorderform.email, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.cableorderform.email, bg_ok);
	}
    if (document.cableorderform.telephone.value=='') {
        validation += "Please enter your contact telephone number\n";
		setColor(document.cableorderform.telephone, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.cableorderform.telephone, bg_ok);
	}
    if (validation != "") {
	  rc=alert(validation);
	  validation="";
	}
	else {
      document.cableorderform.submit();
	}
}


function checkApplication1() {
    
	if (document.applicationform1.givenname.value=='') {
        validation += "Please enter your given name\n";
		setColor(document.applicationform1.givenname, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform1.givenname, bg_ok);
	}
	if (document.applicationform1.surname.value=='') {
        validation += "Please enter your surname\n";
		setColor(document.applicationform1.surname, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform1.surname, bg_ok);
	}
	if (document.applicationform1.address1.value=='') {
        validation += "Please enter your address\n";
		setColor(document.applicationform1.address1, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform1.address1, bg_ok);
	}
	if (document.applicationform1.postcode.value=='') {
        validation += "Please enter your postcode\n";
		setColor(document.applicationform1.postcode, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform1.postcode, bg_ok);
	}
	if (document.applicationform1.telephone.value=='') {
        validation += "Please enter your telephone number\n";
		setColor(document.applicationform1.telephone, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform1.telephone, bg_ok);
	}
	if (validation != "") {
	  rc=alert(validation);
	  validation="";
	}
	else {
	  document.applicationform1.submit();
	}
}

function checkApplication2() {
    
	if (document.applicationform2.billingaddress1.value=='') {
        validation += "Please enter your billing address\n";
		setColor(document.applicationform2.billingaddress1, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform2.billingaddress1, bg_ok);
	}
	if (document.applicationform2.billingpostcode.value=='') {
        validation += "Please enter your billing postcode\n";
		setColor(document.applicationform2.billingpostcode, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform2.billingpostcode, bg_ok);
	}
	if (validation != "") {
	  rc=alert(validation);
	  validation="";
	}
	else {
	  document.applicationform2.submit();
	}
}

function checkApplication3() {
    
	if (document.applicationform3.pref_emailaddr.value=='') {
        validation += "Please enter your preferred email address(username)\n";
		setColor(document.applicationform3.pref_emailaddr, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.pref_emailaddr, bg_ok);
	}
	if (document.applicationform3.password.value=='') {
        validation += "Please enter your preferred password\n";
		setColor(document.applicationform3.password, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.password, bg_ok);
	}
	if (document.applicationform3.password.value.length < 6) {
        validation += "Your password must be at least 6 characters\n";
		setColor(document.applicationform3.password, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.password, bg_ok);
	}
	if (document.applicationform3.hintquestion.value=='') {
        validation += "Please enter a hint question\n";
		setColor(document.applicationform3.hintquestion, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.hintquestion, bg_ok);
	}
	if (document.applicationform3.hintanswer.value=='') {
        validation += "Please enter a hint answer\n";
		setColor(document.applicationform3.hintanswer, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.hintanswer, bg_ok);
	}
	if ((document.applicationform3.emailaddr2.value!='') && (document.applicationform3.password2.value.length < 6)) {
        validation += "The 2nd email address password must be at least 6 characters\n";
		setColor(document.applicationform3.password2, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.password2, bg_ok);
	}
	if ((document.applicationform3.emailaddr3.value!='') && (document.applicationform3.password3.value.length < 6)) {
        validation += "The 3rd email address password must be at least 6 characters\n";
		setColor(document.applicationform3.password3, bg_error);
		form_ok = false;
    }
	else {
	    setColor(document.applicationform3.password3, bg_ok);
	}
	if (validation != "") {
	  rc=alert(validation);
	  validation="";
	}
	else {
	  document.applicationform3.submit();
	}
}

function checkApplication7() {
    
	if (document.applicationform7.agreetoterms.checked==false) {
        validation += "You must agree to the Terms & Conditions before continuing\n";
		form_ok = false;
    }
	if (validation != "") {
	  rc=alert(validation);
	  validation="";
	}
	else {
	  document.applicationform7.submit();
	}
}

function checkNewsFields() {
	form_ok = true;
	cms_validation = "";
	if (document.frmCMSNews.txtNewsTitle.value=='') {
        cms_validation += "Please enter the news title\n";
		form_ok = false;
    }
	if (document.frmCMSNews.txtNewsSummary.value=='') {
        cms_validation += "Please enter the news summary\n";
		form_ok = false;
    }
	if (document.frmCMSNews.txtNewsBody.value=='') {
        cms_validation += "Please enter the news body\n";
		form_ok = false;
    }
	if (form_ok == false) {
	  if (cms_validation != "") {
	    rc=alert(cms_validation);
	    cms_validation="";
	  }
	}
	else {
	  frmCMSNews.submit();
	}
}

function stripInvalid (s, invalid)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not space or underscore, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (invalid.indexOf(c) == -1) returnString += c;
		
    }

    return returnString;
}

function checkInvoiceField(obj) {
    var i;
    for (i = 0; i < obj.value.length; i++)
    {   
      // Check that current character is valid.
      var c = obj.value.charAt(i);
        
      if (((c >= "a") && (c <= "z")) || ((c >= "0") && (c <= "9")) || ((c >= "A") && (c <= "Z"))) {
        // char is good    
      }
      else {
        rc=alert('Invalid character detected (' + c + ' is invalid).\nPlease use alphanumeric or underscore characters with no spaces only');
        obj.focus();
        obj.select();
        return (false);
      }
    }
    return (true);
}

function checkTextField(obj) {
    var i;
    for (i = 0; i < obj.value.length; i++)
    {   
      // Check that current character is valid.
      var c = obj.value.charAt(i);
        
      if (((c >= "a") && (c <= "z")) || ((c >= "0") && (c <= "9")) || ((c >= "A") && (c <= "Z")) || (c == ".") || (c == "-") || (c == "_") || (c == " ") || (c == "@")) {
        // char is good    
      }
      else {
        rc=alert('Invalid character detected (' + c + ' is invalid).\nPlease use a combination of alphanumeric, full stops, hyphens or underscores only');
        obj.focus();
        obj.select();
        return (false);
      }
    }
    return (true);
}

function checkBannerFields() {
	form_ok = true;
	cms_validation = "";
    if (document.frmCMSBanner.txtNewsTitle.value=='') {
        cms_validation += "Please enter the banner title\n";
		form_ok = false;
    }
	if ((document.frmCMSBanner.txtLinkURL.value=='') && (document.frmCMSBanner.txtNewsBody.value=='')) {
        cms_validation += "Please enter a Link URL or banner body\n";
		form_ok = false;
    }
	if ((!document.frmCMSBanner.txtLinkURL.value=='') && (!document.frmCMSBanner.txtNewsBody.value=='')) {
        cms_validation += "You cannot enter a Link URL AND banner body\n";
		form_ok = false;
    }
	if (form_ok == false) {
	  if (cms_validation != "") {
	    rc=alert(cms_validation);
	    cms_validation="";
	  }
	}
	else {
	  frmCMSBanner.submit();
	}
	
}

function checkPaymentFields() {
    var invoicenum;
	var buyvalidation="";
    var buyform_ok = true;
    var bg_error="#DB0066";
    var bg_ok="#CCCCCC";

	invoicenum = stripInvalid(document.paymentform.mtid.value, " _");
    
    document.paymentform.mtid.value = invoicenum;
	
	if (document.paymentform.userid.value=='') {
        buyvalidation += "Please enter your user id\n";
    	setColor(document.paymentform.userid, bg_error);
		buyform_ok = false;
    }
	else {
	  if (!checkTextField(document.paymentform.userid)) {
        buyvalidation += "Please enter your user id\n";
    	setColor(document.paymentform.userid, bg_error);
		buyform_ok = false;
      }
	  else {
	    setColor(document.paymentform.userid, bg_ok);
	  }
	}
	if (document.paymentform.mtid.value=='') {
        buyvalidation += "Please enter the invoice number\n";
		setColor(document.paymentform.mtid, bg_error);
		buyform_ok = false;
    }
	else {
	  if (!checkInvoiceField(document.paymentform.mtid)) {
        buyvalidation += "Please enter the invoice number\n";
		setColor(document.paymentform.mtid, bg_error);
		buyform_ok = false;
      }
	  else {
	    setColor(document.paymentform.mtid, bg_ok);
	  }
	}
	if (document.paymentform.name.value=='') {
        buyvalidation += "Please enter your name\n";
		setColor(document.paymentform.name, bg_error);
		buyform_ok = false;
    }
	else {
	  if (!checkTextField(document.paymentform.name)) {
        buyvalidation += "Please enter your name\n";
		setColor(document.paymentform.name, bg_error);
		buyform_ok = false;
      }
	  else {
	    setColor(document.paymentform.name, bg_ok);
	  }
	}
	if ((document.paymentform.email.value.indexOf('@')==-1) || (document.paymentform.email.value.indexOf('.')==-1) || (
	      document.paymentform.email.value.indexOf('.') == document.paymentform.email.value.length - 1)) {
	      buyvalidation += "Please enter a valid email address\n";
		  setColor(document.paymentform.email, bg_error);
		  buyform_ok = false;
		}
	else {
	  if (!checkTextField(document.paymentform.email)) {
        buyvalidation += "Please enter a valid email address\n";
		setColor(document.paymentform.email, bg_error);
		buyform_ok = false;
      }
	  else {
	    setColor(document.paymentform.email, bg_ok);
	  }
	}
	if (document.paymentform.amt.value=='') {
        buyvalidation += "Please enter the invoice amount\n";
		setColor(document.paymentform.amt, bg_error);
		buyform_ok = false;
    }
	else {
	  if (!checkTextField(document.paymentform.amt)) {
        buyvalidation += "Please enter the invoice amount\n";
		setColor(document.paymentform.amt, bg_error);
		buyform_ok = false;
      }
	  else {
	    setColor(document.paymentform.amt, bg_ok);
	  }
	}
	if (!buyform_ok) {
	  rc=alert(buyvalidation);
	   buyvalidation='';
	}
	else {
	  document.paymentform.name.value += ' (' + document.paymentform.userid.value + ')';
	  document.paymentform.submit();
	}
}
function flipImage(imgname,imgsrc) {
    document.images[imgname].src=imgsrc;
}

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_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];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function startPrint(where){
var is_mac=(navigator.platform.indexOf("ac") != -1);
(document.all &&  is_mac)?
alert("Select  \"Print\" from the menu") : where? where.window.print() :
window.print();
}

