   // JavaScript Document


// Onload functions //
function getFuncs()
{	
	
	setTimeout('quoteshow()',1000);
	//initWhatsNew();
	setup();
	initExpCol();
}


// Element Position*******************************************************
//document.body.onresize=quoteShow();
var first=0;
var hide;
var diff;
window.onresize = quoteshow;
function quoteshow(e) {
e=e||window.event; //fudge browser
	getElPos("rightbor");
	diff = elPosX - 1130;
	if (diff < 0 && hide!=0)
	{
	document.getElementById("quotes").style.display="none";
	hide=0;
	}
	if (diff > 0 && hide!=1)
	{
	document.getElementById("quotes").style.display="inline";
	fadeIn();
	hide=1;		
	}
}
	
	

function getElPos(id){
el=document.getElementById(id);
elPosX = el.offsetLeft;
elPosY = el.offsetTop;
parentEl = el.offsetParent;

while (parentEl != null){
elPosX += parentEl.offsetLeft;
elPosY += parentEl.offsetTop;
parentEl = parentEl.offsetParent;
}
//alert ("Left pos = "+elPosX+"px\n\nTop pos = "+elPosY+"px"); // return totals
}

//Fade Code **********************************************************
var testObj;
function fadeIn() {
testObj = document.getElementById("quotes");
 for (i=0; i<10; i++) {
  setTimeout("setOpacity("+i+")",100*i);
 }
 var i = "";
 }
 
function fadeOut() {
testObj = document.getElementById("quotes");
 for (i=10; i>=0; i--) {
 setTimeout("setOpacity("+i+")", 1000-100*i); 
 }
 var i = "";
 }
function setOpacity(value) {
 testObj.style.opacity = value/10;
 testObj.style.filter = "alpha(opacity=" + value*10 + " )";
}



//  Element Position finished



// PopUp Script //
function setup() {
 if (!document.getElementsByTagName)
  return false;
 var links = 
  document.getElementsByTagName("a");
 for (var i=0; i < links.length; i++) {
  if (links[i].className =="popup") { 
     links[i].onclick = doboth;   	    
  }
 }
}


function doboth() {
this.className+=" done";
window.open(this.href,'','width=1000,height=700,scrollbars=yes,resizable=yes'); return false; 
 }
 
window.onload = setup


/*
//Fading Expander

speed=10
hideLast=1 // 0 = yes 1 = no: automatically hides the previously revealed content

function initExpCol(){ // create objects

count=0
numOfObj=0
tags=document.getElementById("content").getElementsByTagName("div");

while(tags[count]){
if(tags[count].id.indexOf("expdiv")!=-1){
numOfObj++
}
count++
}


for(var i=1;i<=numOfObj;i++){
window["my_object"+i]=new create("expdiv"+i)
document.getElementById("expander"+i).i=i

document.getElementById("expander"+i).onclick=function(){
window["my_object"+this.i].chk_status(this.i,'down')
}

}

// passing the divs number via the query string will automatically reveal the div when the page loads
if (location.search.length > 0){
preNum = unescape(location.search.substring(1))
window["my_object"+preNum].chk_status(preNum,'down')
}

}

lastNum=null

function create(id){ //define properties, pass id
this.id=id
this.num=this.id.replace(/[A-z]/g,"") // get number in id
this.element=document.getElementById(this.id)
this.height=this.element.offsetHeight
this.timer=null
this.running=0

this.chk_status=function(num,d){ // method & its properties, pass div number as argument

if(hideLast==1&&this.num!=lastNum&&lastNum!=null&&document.getElementById("expdiv"+lastNum).offsetHeight>0){
window["my_object"+lastNum].chk_status(lastNum,'up')
}

this.dir=d
if(this.dir=="up"){
document.getElementById("expander"+this.num).onclick=function(){
window["my_object"+num].chk_status(num,'down')
}
}
if(this.dir=="down"){
document.getElementById("expander"+this.num).onclick=function(){
window["my_object"+num].chk_status(num,'up')
}

}
this.running=1

this.step=speed

if("filters" in document.body && "alpha" in document.body.filters){this.opac=this.element.filters.alpha.opacity}
else{this.opac=this.element.style.opacity*100}

window["my_object"+num].animate('my_object'+num,num)

lastNum=this.num
}

this.animate=function(myobject,num){ // method & its properties, pass object name as argument
clearTimeout(this.timer)

if(this.dir=="down"){
this.element.style.display="block"
this.height+=this.step

this.opacStep=100/(this.element.scrollHeight/this.step)
this.opac=(this.opac+this.opacStep)*1

}
else{
this.height-=this.step
this.opacStep=100/(this.element.scrollHeight/this.step)

this.opac=(this.opac-this.opacStep)*1
}

this.stop=this.element.scrollHeight
this.timer=setTimeout(myobject+".animate('"+myobject+"','"+num+"')",50)

if(this.dir=="down"&&this.height>this.stop){
this.running=0
this.opac=100
clearTimeout(this.timer)
}

if(this.dir=="up"&&this.height<=speed){
this.height=0
this.running=0
this.opac=0
clearTimeout(this.timer)
this.element.style.display="none"
}

this.element.style.height=this.height

if("filters" in document.body && "alpha" in document.body.filters){this.element.filters.alpha.opacity=this.opac}
else{this.element.style.opacity=(this.opac/100)-0.01}

}
}
*/


// Script for FAQ div reveal //
//*************************************************************************************
// Script for FAQ div reveal //
speed=15
hideLast=1 // 0 = no 1 = yes: automatically hides the previously revealed content

function initExpCol(){

count=0
numOfObj=0
tags=document.getElementsByTagName("DIV")

while(tags[count]){
if(tags[count].id.indexOf("expdiv")!= -1){
numOfObj++
}
count++
}

for(var i=1;i<=numOfObj;i++){
window["my_object"+i]=new create("expdiv"+i)
document.getElementById("expander"+i).i=i

document.getElementById("expander"+i).onclick=function(){
window["my_object"+this.i].chk_status(this.i,'down')
}

}

// passing the divs number via the query string will automatically reveal the div when the page loads
if (location.search.length > 0){
preNum = unescape(location.search.substring(1))
window["my_object"+preNum].chk_status(preNum,'down')
}

}

lastNum=null

function create(id){ //define properties, pass id
this.id=id;
this.num=this.id.replace(/[A-z]/g,"");
this.element=document.getElementById(this.id);
this.height=this.element.offsetHeight;
this.timer=null;
this.running=0;

this.chk_status=function(num,d){

if(hideLast==1&&this.num!=lastNum&&lastNum!=null&&document.getElementById("expdiv"+lastNum).offsetHeight>0){
window["my_object"+lastNum].chk_status(lastNum,'up')
}

this.dir=d
if(this.dir=="up"){
document.getElementById("expander"+this.num).onclick=function(){
window["my_object"+num].chk_status(num,'down')
}
}
if(this.dir=="down"){
document.getElementById("expander"+this.num).onclick=function(){
window["my_object"+num].chk_status(num,'up')
}

}
this.running=1

this.step=speed
window["my_object"+num].animate('my_object'+num,num)

lastNum=this.num
}

this.animate=function(myobject,num){
clearTimeout(this.timer)
if(this.dir=="down"){
this.element.style.display="block"
this.height+=this.step
}
else{
this.height-=this.step
}

this.stop=this.element.scrollHeight

this.timer=setTimeout(myobject+".animate('"+myobject+"','"+num+"')",50)

if(this.dir=="down"&&this.height>this.stop){
this.running=0
clearTimeout(this.timer)
this.height=this.stop
}

if(this.dir=="up"&&this.height<=speed){
this.height=0
this.running=0
clearTimeout(this.timer)
this.element.style.display="none"
}

this.element.style.height=this.height

}

}


//********************************************************************************************


// Form Validation //
//################################################################# 
//Edit these variables to suit 
//################################################################# 
//Build up the required fields array 
//################################################################# 
var validfields = new Array(); 
validfields[0] = "firstname";
validfields[1] = "taxinterest";
validfields[2] = "surname"; 
validfields[3] = "email"; 
validfields[4] = "prefphone"; 
validfields[5] = "tcagree";
  
//################################################################# 
//what type of field is it 
//choices are 
//txt = textbox or textarea 
//radio = radio group 
//chkbx = checkbox 
//dropbox = select > option 
//################################################################# 
var fieldtype = new Array(); 
fieldtype[0] = "txt"; 
fieldtype[1] = "dropbox"; 
fieldtype[2] = "txt"; 
fieldtype[3] = "txt"; 
fieldtype[4] = "txt"; 
fieldtype[5] = "chkbx"; 
/*fieldtype[6] = "txt"; 
fieldtype[7] = "txt";
fieldtype[8] = "txt";
fieldtype[9] = "chkbx";
//fieldtype[10] = "chkbx";
*/
  
//################################################################# 
//whats allowed in the field  
  
//na = not applicable use for non txt validation 
//asc = a-z A-Z 0-9 _ and space
//aschyp = a-z A-Z 0-9_and space_and hyphen
//textonly = a-z A-Z - no spaces 
//email = valid email address 
//num = 0-9 and spaces 
//numonly = 0-9 no spaces 
//dateUK = date in the format dd/mm/yyyy 
//dateUS = date in the format mm/dd/yyyy
//zipUK = Letters and Numbers only in UK approved combinations
  
//################################################################# 
var fieldallow = new Array(); 
fieldallow[0] = "textonly"; 
fieldallow[1] = "na"; 
fieldallow[2] = "aschyp"; 
fieldallow[3] = "email"; 
fieldallow[4] = "num"; 
fieldallow[5] = "na";

//################################################################# 
//set this to the same value as the name of your form 
//################################################################# 
var formname = "subscribe"; 
  
//################################################################# 
//Background colors 
//bcol = should be the set the same as the page color 
//bcolerr = if you want to change the background color when an error appears 
//then set this to whatever color you wish 
//################################################################# 
var bcol = "white"; 
var bcolerr ="#FF9"; 
  
//################################################################# 
//Text colors 
//tcol = should be the set the same as the bcol (makes the text invisible) 
//tcolerr = change the error text color (makes it visible) 
//################################################################# 
var tcol= "white"; 
var tcolerr = "#800020"; 
  


//################################################################# 
//What can this do for me then? 
//Not only can you validate all of the common form elements such as 
//radio buttons - checkboxes - select boxes etc 
//you can also validate the data that is entered into the form 
//check for valid email syntax 
//have text boxes that can only have numbers and spaces 
//or just just alpha-numeric 
//validate that dates are entered in the format UK (dd/mm/yyyy) US (mm/dd/yyyy) 
//It's dead easy to set up  
  
//you must have errX style for each error message 
//#err0{color:white;font-weight:bold;} 
//#err1{color:white;font-weight:bold;} 
//#err2{color:white;font-weight:bold;} 
//#err3{color:white;font-weight:bold;} 
  
//the error text can be enclosed in a div (opera didn't seem to like span) 
//or you can give the ID to a table cell as most of the demo is. 
  
//set up the few variables below and thats about all there is to it 
  
//################################################################# 
  
  
function validform(){ 
var err=1; 
var etext=""; 
var i=0; 
        //reset the styles to white 
        while (i != validfields.length ){ 
        eval("document.getElementById('err"+i+"').style.backgroundColor='"+bcol+"';"); 
        eval("document.getElementById('err"+i+"').style.color='"+tcol+"';"); 
        i++; 
        } 
  
    //check the required fields from array 
    var i=0; 
    while (i != validfields.length ){ 
    whatfield = "";     
    //################################################################# 
    //text - textarea 
    if(fieldtype[i] == "txt"){ 
    whatfield = eval("document."+formname+"."+validfields[i]+".value");
	} 
    //#################################################################         
    //radio 
    if(fieldtype[i] == "radio"){ 
    radcount = eval("document."+formname+"."+validfields[i]+".length"); 
        for (var a = 0; a < radcount; a++){ 
            if (eval("document."+formname+"."+validfields[i]+"["+a+"].checked")){ 
            whatfield = "OK"; 
            } 
        } 
    } 
    //################################################################# 
    //checkbox 
    if(fieldtype[i] == "chkbx"){     
        if (eval("document."+formname+"."+validfields[i]+".checked")){ 
        whatfield = "OK"; 
        }     
    } 
    //################################################################# 
    //Select 
    if(fieldtype[i] == "dropbox"){         
        radstr = "document."+formname+"."+validfields[i]; 
        rs2 = eval(radstr+".options["+radstr+".selectedIndex].value");         
        whatfield = rs2;     
    }     
  
  
     
//################################################################# 
// 
// Check Data  
// 
//################################################################# 
  
  
//#################################################################     
//email address 
    if (fieldallow[i] == "email" && whatfield != ""){ 
        var re=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i; 
        if (!re.test(whatfield)) { 
        whatfield=""; 
        } 
    } 
//END email address 
//################################################################# 
  
  
//################################################################# 
//a-z A-Z _0-9_and space 
    if (fieldallow[i] == "asc" && whatfield != ""){
		var re = /^[\w ]+$/;  
        if (!re.test(whatfield)) {    
        whatfield=""; 
        } 
    } 
//END a-z A-Z _0-9_and space 
//#################################################################

//################################################################# 
//a-z A-Z _0-9_ and space_and hyphen 
    if (fieldallow[i] == "aschyp" && whatfield != ""){ 
        var re = /^[\w -]+$/;  
        if (!re.test(whatfield)) {    
        whatfield=""; 
        } 
    } 
//END a-z A-Z _ and space_and hyphen
//#################################################################


  
  
//################################################################# 
//a-z A-Z ONLY 
    if (fieldallow[i] == "textonly" && whatfield != ""){ 
        var re = /^[a-zA-Z]+$/;  
        if (!re.test(whatfield)) {    
        whatfield=""; 
        } 
    } 
//END a-z A-Z ONLY 
//################################################################# 
  

//################################################################# 
//a-z A-Z plus_space_plus hyphen ONLY 
    if (fieldallow[i] == "textonlyhyp" && whatfield != ""){ 
        var re = /^[a-zA-Z -]+$/;  
        if (!re.test(whatfield)) {   
        whatfield=""; 
        } 
    } 
//END a-z A-Z plus_space_plus hyphen ONLY 
//################################################################# 
    
  
//################################################################# 
//0-9 and space 
    if (fieldallow[i] == "num" && whatfield != ""){ 
        var re = /^[0-9 ]+$/;  
        if (!re.test(whatfield)) {; 
       whatfield=""; 
        } 
    } 
//END 0-9 and space 
//################################################################# 
/*
//################################################################# 
//0-9 and space for altphone (ie. not required) 
    if (fieldallow[i] == "numalt")
		{
		if (whatfield == ""){return true
			
			}
		else {
	   var re = /^[0-9 ]+$/;  
        if (!re.test(whatfield)) {; 
       whatfield=""; 
        } 
		}
    } 
//END 0-9 and space 
//################################################################# 
*/     
//################################################################# 
//0-9 
    if (fieldallow[i] == "numonly" && whatfield != ""){ 
        var re = /^[0-9]+$/;  
        if (!re.test(whatfield)) {; 
       whatfield=""; 
        } 
    } 
//END 0-9 
//################################################################# 

/*
//Convert 1st Letter to Uppercase
function upperCase(word)
{
	var first = word;
	first1 = first.substring(0,1);
	rest = first.substring(2,first.length);
	first1.toUpperCase();
	first = first1+rest;
	return first;
}
*/	
     
//################################################################# 
//Date UK and US date formats 
    if (fieldallow[i] == "dateUK" && whatfield != "" || fieldallow[i] == "dateUS" && whatfield != ""){ 
        var re = /^\d{2}\/\d{2}\/\d{4}$/;  
        var isitok=0; 
            if (re.test(whatfield)) { 
                var bits = whatfield.split("/"); 
                isitok = (bits.length == 3); // should be three components 
              if (isitok) 
               { 
                    if(fieldallow[i] == "dateUK"){ 
                     day = parseInt(bits[0],10); 
                      month = parseInt(bits[1],10); 
                     } 
                  
                     if(fieldallow[i] == "dateUS"){                     
                     day = parseInt(bits[1],10); 
                      month = parseInt(bits[0],10);                     
                     } 
                  
                 var year = parseInt(bits[2]); 
                 isitok = !isNaN(month) && (month > 0) && (month < 13) && !isNaN(day) && (day > 0) && (day < 32) && !isNaN(year) && (bits[2].length == 4); 
           } 
        } 
  
            if(!isitok || !re.test(whatfield)){ 
            whatfield="";   
           }
	}
	
//EndDate UK and US date formats 
//################################################################# 
	
//################################################################# 
// UK Post Code format checker
if (fieldallow[i] == "zipUK" && whatfield !=""){
	testPostCode();
}



//################################################################# 

	
//################################################################# 
// 
// End Check Data  
// 
//################################################################# 
  
  
//################################################################# 
//if the required fields are empty reveal the warning message 
        if(whatfield == "" ){ 
        eval("document.getElementById('err"+i+"').style.backgroundColor='"+bcolerr+"';"); 
        eval("document.getElementById('err"+i+"').style.color='"+tcolerr+"';"); 
        err=0; 
        } 
//################################################################# 
//continue count     
    i++; 
     
} 
  
//################################################################# 
//do not submit the form if there are errors 
//REQUIRED 
if (err==0){ return false;} 
//################################################################# 
  
//################################################################# 
//remove this line on a real form or if you want an alert change  
//return false to return true 
//OPTIONAL 
//if (err==1){alert('If this was real the data provided would now be sent to the host server for processing and a suitable acknowledgement returned to you');return true;} 
//################################################################# 
} 
  
//END OF SCRIPT 
//################################################################# 


// UK Post Code Checker
/*

if (checkPostCode (myPostCode)) {
    alert ("Postcode has a valid format")
  } 
  else {alert ("Postcode has invalid format")};
*/

	
	
function testPostCode() {
	
	var myPostCode = document.getElementById("postcode").value;
    if (checkPostCode (myPostCode)) {
    document.getElementById('postcode').value = checkPostCode (myPostCode)
   } 
  else {whatfield=""}
 }


function checkPostCode(toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

//End UK Post Code Checker
//################################################################# 



