// Eddie Traversa
// http://www.dhtmlnirvana.com/ 

// sniff for browser 

	ie	= (document.all && !window.opera);
	dom 	= (document.getElementById && !window.opera);
	opera 	= (window.opera);
	currentdiv = null;

// this will dynamically create an iframe 
// needs to be called at the onload event and target the id value of the layer we want to appear on top of active content
// it will track the layers position automatically and size and position the iframe automatically to fit the layer
function valpc(tf){
	if(!checkPostCode(tf.postcode.value)) {
		alert('Please enter a valid postcode');
		return false;
	}
	tf.postcode.value=checkPostCode(tf.postcode.value)
	return true;
	
}
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
  //alert(postCode);
  if (valid) {return postCode;} else return false;
}


function activecontentHider(id) {
	if (ie) {
		el = document.getElementById(id);
		ifrm = document.createElement("IFRAME");
		ifrm.setAttribute("id", "dummyFRM");
		ifrm.setAttribute("src", "#");
		ifrm.setAttribute("scroll", "no");
		ifrm.setAttribute("frameborder", "0");
		ifrm.style.setAttribute("position", "absolute");
		ifrm.style.setAttribute("visibility", "hidden");
		// better for IE5.5 to use old filter...
		ifrm.style.filter='Alpha(opacity=0)';
		ifrm.style.width = el.offsetWidth + "px";
		ifrm.style.height = el.offsetHeight + "px";
		ifrm.style.left = el.offsetLeft + "px";
		ifrm.style.top = el.offsetTop + "px";
		ifrm.style.zIndex = el.style.zIndex-1;
		document.body.appendChild(ifrm);
 }
}

// this hides elements 
// for opera we resize the flash movie back to original size
// arguments for the loadflash() function are id of layer, url of flash movie, width and height. 

function hideDiv(id){
if (ie) {
	document.getElementById(id).style.visibility = "hidden";
	//ifrm.style.visibility = "hidden";
 }
else if (dom) {
	document.getElementById(id).style.visibility="hidden";
 }
 else if (opera) {
	document.getElementById(id).style.visibility="hidden";
	loadFlash('flashLYR','matrix.swf',500,300);
 }
}

// this shows elements 
// for opera we resize the flash movie to a smaller size so as to allow the layer to show. 
// arguments for the loadflash() function are id of layer, url of flash movie, width and height. 

function showDiv(id){
if (currentdiv) mmDoHide;
currentdiv = id;
if (ie) {
	document.getElementById(id).style.visibility="visible";
	//ifrm.style.visibility = "visible";
}
else if (dom) {
	document.getElementById(id).style.visibility="visible";
}
else if (opera) {
	document.getElementById(id).style.visibility="visible";
	loadFlash('flashLYR','matrix.swf',500,161);
 }
}

// dynamically write in a flash movie to replace the one in the document body.  
// you should keep a normal object / embed tag in the document body in case javascript is turned off.  

function loadFlash(id,theurl,width,height) {
	document.getElementById(id).innerHTML ='<embed src="../'+ theurl + '" width="'+ width + '" height="'+ height + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" scale="exactfit" /><\/embed>';
}

function browsercheck() {
	//detect Netscape 4.7+
	if (navigator.appName=="Netscape"&&parseFloat(navigator.appVersion)<5)
		window.location = "browser.asp?browser=Netscape"	

	//Detect IE5.5+
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	if (version<5.5) //NON IE browser will return 0
		window.location = "browser.asp?browser=Internet Explorer"	
}


function MM_clearTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
}


function MM_startTimeout() {
	mmHideMenuTimer = null;
	mmStart = new Date();
	mmDHFlag = true;
	mmHideMenuTimer = setTimeout("mmDoHide()",1000);
}

function mmDoHide() {
	hideDiv(currentdiv);
	currentdiv = null;
}

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 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_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function showdetails(branch) {
	if (branch == 'Hampshire') {
		MM_setTextOfLayer('Layer1','','BOX-IT Head Office: Hampshire');
		MM_setTextOfLayer('Layer2','','BOX-IT, Winnall Down, Fair Lane, Winchester, Hants SO21 1HF');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01962 830200');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01962 830300');
		MM_setTextOfLayer('Layer5','','<b>Website:</b> <a href="http:/www.boxit.co.uk">www.boxit.co.uk</a>');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxit.co.uk">sales@boxit.co.uk</a>');
	}

	if (branch == 'South East') {
		MM_setTextOfLayer('Layer1','','BOX-IT South East');
		MM_setTextOfLayer('Layer2','','Oad Street, Borden, Sittingbourne, Kent ME9 8JP');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01795 841010');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01795 844734');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:enquiries@boxit-se.co.uk">enquiries@boxit-se.co.uk</a>');
	}

	if (branch == 'Wales & Severn') {
		MM_setTextOfLayer('Layer1','','BOX-IT Wales &amp; Severn');
		MM_setTextOfLayer('Layer2','','The Sawmills, Glanusk Park, Crickhowell, Powys NP8 1LP');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01873 811803');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01873 812383');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:webmaster@boxit-wales.co.uk">webmaster@boxit-wales.co.uk</a>');
	}

	if (branch == 'East') {
		MM_setTextOfLayer('Layer1','','BOX-IT East');
		MM_setTextOfLayer('Layer2','','Shardelows Office, New England Lane, Cowlinge, Newmarket, Suffolk CB8 9HP');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01638 500986');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01638 500987');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxit-east.co.uk">sales@boxit-east.co.uk</a>');
	}

	if (branch == 'South Midlands') {
		MM_setTextOfLayer('Layer1','','BOX-IT South Midlands');
		MM_setTextOfLayer('Layer2','','Cottage Farm Buildings, Hartwell Road, Roade,<br> Northamptonshire NN7 2NU');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01604 861912');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01604 861909');
		MM_setTextOfLayer('Layer5','','<b>Website:</b> <a href="http://www.boxit-southmidlands.co.uk" target="_blank">www.boxit-southmidlands.co.uk</a>');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxit-southmidlands.co.uk">sales@boxit-southmidlands.co.uk</a>');
	}

	if (branch == 'Central') {
		MM_setTextOfLayer('Layer1','','BOX-IT Central');
		MM_setTextOfLayer('Layer2','','Squab Hall, Bishops Tachbrook, Leamington Spa, Warwickshire <br>CV33 9QB');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01926 332244');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01926 882283');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:enquiries@boxit-central.co.uk">enquiries@boxit-central.co.uk</a>');
	}

	if (branch == 'West Midlands') {
		MM_setTextOfLayer('Layer1','','BOX-IT West Midlands');
		MM_setTextOfLayer('Layer2','','The Hyde, Upton upon Severn, Worcestershire WR8 0SE');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01684 592915');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01684 594863');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:a.perrins@boxit-westmidlands.co.uk">a.perrins@boxit-westmidlands.co.uk</a>');
	}

	if (branch == 'North Midlands') {
		MM_setTextOfLayer('Layer1','','BOX-IT North Midlands');
		MM_setTextOfLayer('Layer2','','Rolleston Park, Tutbury, Burton-on-Trent, <br>Staffordshire DE13 9HQ');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01283 815748');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01283 521416');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxit-nm.co.uk">sales@boxit-nm.co.uk</a>');
	}

	if (branch == 'North West') {
		MM_setTextOfLayer('Layer1','','BOX-IT North West');
		MM_setTextOfLayer('Layer2','','Smithy Lane, Mouldsworth, Chester, Cheshire CH3 8AR');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01928 740707 ');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01928 740594');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:enquiries@boxit-northwest.co.uk">enquiries@boxit-northwest.co.uk</a>');
	}

	if (branch == 'Humberside') {
		MM_setTextOfLayer('Layer1','','BOX-IT Humberside');
		MM_setTextOfLayer('Layer2','','Cave Road, Brough, East Yorkshire HU15 1HH');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01482 667116');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01482 667436');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:info@boxit-humberside.co.uk">info@boxit-humberside.co.uk</a>');
	}

	if (branch == 'Yorkshire') {
		MM_setTextOfLayer('Layer1','','BOX-IT Yorkshire');
		MM_setTextOfLayer('Layer2','','Mill Road, Off Bradford Road, Dewsbury, W Yorkshire WF13 2HR');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01924 465323');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01924 502662');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxit-yorkshire.co.uk">sales@boxit-yorkshire.co.uk</a>');
	}

	if (branch == 'Newcastle') {
		MM_setTextOfLayer('Layer1','','BOX-IT North');
		MM_setTextOfLayer('Layer2','','West Newham, Millbourne, Newcastle-upon-Tyne NE20 0DJ');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01661 881770');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01661 881382');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:enquiries@boxit-north.co.uk">enquiries@boxit-north.co.uk</a>');
	}

	if (branch == 'Scotland') {
		MM_setTextOfLayer('Layer1','','BOX-IT Scotland');
		MM_setTextOfLayer('Layer2','','Spittalrigg, Haddington, East Lothian EH41 3SU');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>01620 829700');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>01620 826533');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxitscotland.co.uk">sales@boxitscotland.co.uk</a>');
	}

	if (branch == 'NI') {
		MM_setTextOfLayer('Layer1','','BOX-IT Ireland');
		MM_setTextOfLayer('Layer2','','46 Megargy Road, Co Londonderry, BT45 5HP');
		MM_setTextOfLayer('Layer3','','<b>Telephone: </b>02879 633298');
		MM_setTextOfLayer('Layer4','','<b>Fax: </b>02879 633001');
		MM_setTextOfLayer('Layer5','','');
		MM_setTextOfLayer('Layer6','','<b>Email:</b> <a href="mailto:sales@boxitireland.com">sales@boxitireland.com</a>');
	}

}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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];}
}

