// Stuff for menus

// Menu colours

asMenuColors=['#6182B7','#6182B7','#6182B7','#6182B7','#4e9ec1','#7FB87C','#a287c7','#c07575','#bf804e','#C289BA'];
asMenuColorsOff=['#A3AAB7','#A3AAB7','#A3AAB7','#A3AAB7','#818CA1','#818CA1','#818CA1','#818CA1','#818CA1','#A3AAB7'];

// Turn on a menu (pass menu number)

function vMenuOn(iMenu)
{
	vShowPop(iMenu);

	// highlight menu and display popup
	document.getElementById('menuitem'+iMenu).style.backgroundColor=asMenuColors[iMenu];
	
	iMenuOn=iMenu;	// define which menu is now on
}

// Turn off a menu

function vMenuOff()
{
	vHidePop();
	document.getElementById('menuitem'+iMenuOn).style.backgroundColor=asMenuColorsOff[iMenuOn];
}

// Turn on a popup (pass menu number)

function vShowPop(iPop)
{
	if (typeof iHideAbs!="undefined")
	{
		window.clearTimeout(iHideAbs);
	}
	vHidePopAbsolute();

	// Make pop up visible
	document.getElementById('Lpop'+iPop).style.visibility='visible';
	document.getElementById('Lpop'+iPop+'s').style.visibility='visible';

	iPopOn=iPop;		// define which popup is now on
}

// Turn off a popup

function vHidePop()
{
	iHideAbs=window.setTimeout('vHidePopAbsolute()',750);
}

// Internal function

function vHidePopAbsolute()
{
	// First make sure there is a menu displayed
	if (typeof iPopOn!="undefined")
	{
		document.getElementById('Lpop'+iPopOn).style.visibility='hidden';
		document.getElementById('Lpop'+iPopOn+'s').style.visibility='hidden';
		iPopOn=void 0;	// Clear pop display
	}
	iHideAbs=void 0; // Clear timeout handle
}

// Highlight a popup item (pass menu number and popup number)

function vPopOn(iMenu,iPop)
{
	// highlight menu and display popup
	document.getElementById('menu'+iMenu+'item'+iPop).style.backgroundColor=asMenuColors[iMenu];
	
	iMenuItemOn=iMenu;	// define which menu is now on
	iMenuPopOn=iPop;	// define which menu is now on
}

// Un highlight a popup item

function vPopOff()
{
	document.getElementById('menu'+iMenuItemOn+'item'+iMenuPopOn).style.backgroundColor=asMenuColorsOff[iMenuItemOn];
}

//
//
//

// Stuff for switching style sheets

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			// Only disable alternate style sheets - base stylesheets should never be disabled
			if(a.getAttribute("rel").indexOf("alt") != -1)
			{
      	a.disabled = true;
			}
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		// only return if alternate stylesheet is active
    if(a.getAttribute("rel").indexOf("alt") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

//
//
//

// Print function

function PrintPage()
{
	window.print();
}

function myFocus(myName,myColor)
{
	eval("document.Form1."+myName+".style.border='1px solid #000000'");
	eval("document.Form1."+myName+".style.backgroundColor='#eeeeee'");
}
function myBlur(myName,myColor)
{
	eval("document.Form1."+myName+".style.border='1px solid #626262'");
	eval("document.Form1."+myName+".style.backgroundColor='#ffffff'");
}

function vCheckDomain(sDom)
{
	if(isblank(sDom))
	{
		alert('You must enter a domain name to check');
		return false;
	}
	else
	{
		return true;
	}
}

function isblank(s) {
  for(var i=0;i<s.length;i++) {
    var c=s.charAt(i);
    if((c!=' ') && (c!='\\n') && (c!='\\t')) return false;
  }
  return true;
}

function verifyADSLCheck(f)
{
	AlertText="";
	if(isblank(document.Form1.Tel.value))
	{
		AlertText=AlertText+"You must enter your telephone number!\n";
	}

	if(AlertText!="")
	{
		alert(AlertText);
		return false;
	}
	return true;
}

function verifyEnquiry(f)
{
	AlertText="";
	if(document.Form1.Title[0].selected)
	{
		AlertText=AlertText+"You must select your title\n";
	}
	if(isblank(document.Form1.FirstName.value))
	{
		AlertText=AlertText+"You must enter your first name\n";
	}
	if(isblank(document.Form1.LastName.value))
	{
		AlertText=AlertText+"You must enter your last name\n";
	}
	if(isblank(document.Form1.Email.value))
	{
		AlertText=AlertText+"You must enter your e-mail address\n";
	}
	if(isblank(document.Form1.Telephone.value))
	{
		AlertText=AlertText+"You must enter your telephone number\n";
	}
	if(isblank(document.Form1.Company.value))
	{
		AlertText=AlertText+"You must enter the Company name\n";
	}
	if(isblank(document.Form1.Position.value))
	{
		AlertText=AlertText+"You must enter your position\n";
	}
	if(isblank(document.Form1.Address1.value))
	{
		AlertText=AlertText+"You must enter the first line of the company address\n";
	}
	if(isblank(document.Form1.Postcode.value))
	{
		AlertText=AlertText+"You must enter the company postcode\n";
	}

	if(AlertText!="")
	{
		alert(AlertText);
		return false;
	}
	return true;
}
