// JavaScript Document
window.onload = function(e) {
  var cookie = readCookie("fontSize");
  var title = cookie ? cookie : getPreferredSize();
  setFontSize(title);
  browsercheck();

	var anchors = document.getElementsByTagName("a");
	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var n = anchors[i]; 
	    
		if (n.href==window.location&&n.parentNode.parentNode.parentNode.id=="nav"){
			//alert(n.href);
			n.parentNode.className+=n.parentNode.className?' current':'current';
			//alert(n.parentNode.className);
		}
	}

if (document.all&&document.getElementById) {
	navRoot = document.getElementById("nav").childNodes[0];
	for (i=0; i<navRoot.childNodes.length; i++) {
	node = navRoot.childNodes[i];
	if (node.nodeName=="LI") {
	node.onmouseover=function() {
	this.className+=" over";
	  }
	  node.onmouseout=function() {
	  this.className=this.className.replace(" over", "");
	   }
	   }
	  }
  }
}

function validate(theform) {
	msg = "";
	
	if (theform.name.value=="") { msg = msg + " - Name\n"; }
	if (theform.company.value=="") { msg = msg + " - Company\n"; }
	if (theform.address4.value=="") { msg = msg + " - County\n"; }
	if (theform.tel.value=="") { msg = msg + " - Tel\n"; }
	if (theform.email.value=="") { msg = msg + " - Email\n"; }
	if (msg!="") {
		msg = "The following fields are required:\n\n" + msg + "\n\nPlease complete and try again";
		alert (msg);
		return false;
	}
	return true;
}

function browsercheck() {
	var browserName=navigator.appName; 
	var browserVer=parseInt(navigator.appVersion); 
}

function printit() {
	window.print();  
}

function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}

function setCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function getPreferredSize() {
  return ('12');
}


var min=10;
var max=18;

function setFontSize(s) {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      p[i].style.fontSize = s+"px"
   }
  setCookie('fontSize', s, 365);
}


function increaseFontSize() {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
  setCookie('fontSize', s, 365);
}

function decreaseFontSize() {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
  setCookie('fontSize', s, 365);
}

function P7_swapClass(){ //v1.4 by PVII
 var i,x,tB,j=0,tA=new Array(),arg=P7_swapClass.arguments;
 if(document.getElementsByTagName){for(i=4;i<arg.length;i++){tB=document.getElementsByTagName(arg[i]);
  for(x=0;x<tB.length;x++){tA[j]=tB[x];j++;}}for(i=0;i<tA.length;i++){
  if(tA[i].className){if(tA[i].id==arg[1]){if(arg[0]==1){
  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}else{tA[i].className=arg[2];}
  }else if(arg[0]==1 && arg[1]=='none'){if(tA[i].className==arg[2] || tA[i].className==arg[3]){
  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}
  }else if(tA[i].className==arg[2]){tA[i].className=arg[3];}}}}
}


function showregion(region) {
	if(region=='national'){
		setClassName('instructions', 'hidden');
	} else {
		setClassName('instructions', 'shown');
	}
	P7_swapClass(1,region,'row','hidden','div');
}
function showcs(cs) {
	P7_swapClass(1,'cs'+cs,'row','hidden','ul');
}
function P7_colH2(){ //v2.1.0 by PVII-www.projectseven.com
 var i,oh,h=0,tg,el,np,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
 for(i=1;i<dA.length;i+=2){dA[i+1].style.paddingBottom='';}for(i=1;i<dA.length;i+=2){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=1;i<dA.length;i+=2){oh=dA[i].offsetHeight;
 if(oh<h){np=h-oh;if(!an&&dA[0]==1){P7_eqA2(dA[i+1].id,0,np);}else{
 dA[i+1].style.paddingBottom=np+"px";}}}document.p7eqa=1;
 document.p7eqth=document.body.offsetHeight;
 document.p7eqtw=document.body.offsetWidth;}
}
function P7_eqT2(){ //v2.1.0 by PVII-www.projectseven.com
 if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){P7_colH2();}
}
function P7_equalCols2(){ //v2.1.0 by PVII-www.projectseven.com
 var c,e,el;if(document.getElementById){document.p7eqc=new Array();
 document.p7eqc[0]=arguments[0];for(i=1;i<arguments.length;i+=2){el=null;
 c=document.getElementById(arguments[i]);if(c){e=c.getElementsByTagName(arguments[i+1]);
 if(e){el=e[e.length-1];if(!el.id){el.id="p7eq"+i;}}}if(c&&el){
 document.p7eqc[document.p7eqc.length]=c;document.p7eqc[document.p7eqc.length]=el}}
 setInterval("P7_eqT2()",10);}
}
function P7_eqA2(el,p,pt){ //v2.1.0 by PVII-www.projectseven.com
 var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
 g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
 setTimeout("P7_eqA2('"+el+"',"+np+","+pt+")",sp);}
}
