function loadfaqframe(page) {
    parent.faqframe.document.location = page
}

function showanswer(faq) {

hidebyclass('answer');
showitem(faq);
}

function hidebyclass(theClass) 
{
	var allPageTags = new Array(); 
	var allPageTags=document.getElementsByTagName("*");
	for (i=0; i<allPageTags.length; i++) 
	{
		if (allPageTags[i].className==theClass) 
		{
			allPageTags[i].style.display='none';
		}
	}
} 

function showbyclass(theClass) 
{
	var allPageTags = new Array(); 
	var allPageTags=document.getElementsByTagName("*");
	for (i=0; i<allPageTags.length; i++) 
	{
		if (allPageTags[i].className==theClass) 
		{
			allPageTags[i].style.display='inline';
		}
	}
} 

function showandhideitem(myvalue)
{

	if (myvalue == 5 )
	{
		hidebyclass('win');
		hidebyclass('lindom');
		hidebyclass('windom');
		showbyclass('lin');
		hideitem('domreg');
	}
	if (myvalue == 7 )
	{
		hidebyclass('win');
		hidebyclass('lin');
		hidebyclass('windom');
		showbyclass('lindom');
		showitem('domreg');
	}
	if (myvalue == 8 )
	{
		hidebyclass('lin');
		hidebyclass('lindom');
		hidebyclass('windom');
		showbyclass('win');
		hideitem('domreg');
	}
	if (myvalue == 10 )
	{
		hidebyclass('win');
		hidebyclass('lindom');
		hidebyclass('lin');
		showbyclass('windom');
		showitem('domreg');
	}
}

function showsingleitem(myitem)
{
	hidebyclass('box');
	showitem(myitem);
}

function showitem(myitem)
{
//	hidebyclass('box');
	mydiv = document.getElementById(myitem);
	mydiv.style.display='block';
}

function hideitem(myitem)
{
//	hidebyclass('box');
	mydiv = document.getElementById(myitem);
	mydiv.style.display='none';
}


function mymouseover()
{
 this.style.backgroundImage="url('./images/button5.gif')";
}

function bgcolour()
{
document.getElementById("mainbody").style.backgroundColor="white";
//document.bgColor = 'white';
}

		/* VALIDATION START */
		
		//Connection + Line + Hardware
		var onceTotal = parseFloat("0.00");
		var monthlyTotal = parseFloat("0.00");
		
		var Connection = parseFloat("0.00");
		var Line = parseFloat("0.00");
		var Hardware = parseFloat("0.00");
		
		function setPrice(frm) {
			//Clear Previous Totals
			onceTotal = parseFloat("0.00");
			monthlyTotal = parseFloat("0.00");
						
			id = -1;
			for (i=0;i<frm.Connection.length;i++) {
				if (frm.Connection[i].checked == true) {
					id = i;
				}
			}
			if (id != -1) {
				//frm.ConnectionID.value = id;
				frm.ConnectionID.value = frm.Connection[id].id;
				Connection = parseFloat(frm.Connection[id].value);
			} else {
				Connection = parseFloat("0.00");
			}
			
			id = -1;
			for (i=0;i<frm.Hardware.length;i++) {
				if (frm.Hardware[i].checked == true) {
					id = i;
				}
			}
			if (id != -1) {
				//frm.HardwareID.value = id;
				frm.HardwareID.value = frm.Hardware[id].id;
				Hardware = parseFloat(frm.Hardware[id].value);
			} else {
				Hardware = parseFloat("0.00");
			}
			
			onceTotal = parseFloat(Connection) + parseFloat(Hardware) + parseFloat(Line);
			
			id = -1;
			for (i=0;i<frm.Line.length;i++) {
				if (frm.Line[i].checked == true) {
					id = i;
				}
			}
			if (id != -1) {
				//frm.LineID.value = id;
				frm.LineID.value = frm.Line[id].id;
				Line = parseFloat(frm.Line[id].value);
			} else {
				Line = parseFloat("0.00");
			}
			
			monthlyTotal = parseFloat(Line);
			
			//Set Total Values
			setTotals(frm);
		}
		
		function setTotals(frm) {
			frm.InitalTotal.value = '£ ' + getTotal('once');
			frm.MonthlyTotal.value = '£ ' + getTotal('monthly');
		}
		
		function getTotal(freq) {
			if (freq == "once") {
				Total = onceTotal;
			} else if (freq == "monthly") {
				Total = monthlyTotal;
			}
			return DA2(Total, 2);
		}
		
		
		function validate(frm)
		{
			//Check connection
			id = -1;
			for (i=0;i<frm.Connection.length;i++) {
				if (frm.Connection[i].checked == true) {
					id = i;
				}
			}
			if (id == -1) return setFocus(frm.Connection[0], "Please choose a connection type");
			
			//Check line
			id = -1;
			for (i=0;i<frm.Line.length;i++) {
				if (frm.Line[i].checked == true) {
					id = i;
				}
			}
			if (id == -1) return setFocus(frm.Line[0], "Please choose a connection speed");
			
			//Check hardware
			id = -1;
			for (i=0;i<frm.Hardware.length;i++) {
				if (frm.Hardware[i].checked == true) {
					id = i;
				}
			}
			if (id == -1) return setFocus(frm.Hardware[0], "Please choose a hardware option");
			
			if(frm.EndUserTitle.value == "") return setFocus(frm.EndUserTitle, "Please select a title");
			if(frm.EndUserFirstName.value == "") return setFocus(frm.EndUserFirstName, "Please enter the first name");
			if(frm.EndUserLastName.value == "") return setFocus(frm.EndUserLastName, "Please enter the last name");
			if(frm.EndUserPremisesName.value == "" && frm.EndUserPremisesNumber.value == "") return setFocus(frm.EndUserPremisesNumber, "Please enter the house/building name or number");
			if(frm.EndUserPremisesStreet.value == "") return setFocus(frm.EndUserPremisesStreet, "Please enter the street");
			if(frm.EndUserPremisesPostTown.value == "") return setFocus(frm.EndUserPremisesPostTown, "Please enter the post town");
			if(frm.EndUserPremisesPostCode.value == "") return setFocus(frm.EndUserPremisesPostCode, "Please enter the post code");
			if(frm.EndUserContactPhone.value == "") return setFocus(frm.EndUserContactPhone, "Please enter the contact telephone number");
			//These values must be last...
			frm.EndUserContactPhone.value = frm.EndUserContactPhone.value.replace(/ /g, '');
			if(frm.EndUserPremisesPostCode.disabled = true) frm.EndUserPremisesPostCode.disabled = false;
			//Disable submit button after clicked to prevent duplicate submissions
			frm.submit.disabled = true;
			return true;

		}

		function switchCheckbox(checkbox)
		{
			if (checkbox.checked) {
				checkbox.checked = false;
			}
		}

		function setFocus(f, message)
		{
			if( message != "")
			{
				alert(message);
			}
			f.focus();
			return false;
		}
		

		Number.prototype.toFixxed = function(f) {
			f = parseInt(f/1 || 0)
			if (f<0 || f>20) // next line was throw ...
				alert("The number of fractional digits is out of range")
			if (isNaN(this)) return "NaN"
				var s = this<0 ? "-" : "", x = Math.abs(this)
			if (x>Math.pow(10,21)) return s + x.toString()
				var m = Math.round(x*Math.pow(10,f)).toString()
			if (!f) return s + m
				while (m.length<=f) m = "0" + m
			return s + m.substring(0,m.length-f)+"."+m.substring(m.length-f)
		}
		
		function DA2(X, M) {
			return (new Number(X)).toFixxed(M)
		}
		
		/* VALIDATION END */
		
//		A few cookie functions

function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}
function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setcookie(name,value,duration){
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
document.cookie=cookiestring;
if(!getcookie(name)){
return false;
}
else{
return true;
}
}
	
window.onload=function() //page must load before you can refer to html elements
{
	var inputs = document.getElementsByTagName("*");
//	var inputs = document.getElementsByClass("menubutton");
	
	for(var i = 0, len = inputs.length; i < len; i++)
	{
		if(inputs[i].className == "menubutton" || inputs[i].className == "menubutton2") 
		{
			inputs[i].onmouseover = someFunc;
			inputs[i].onmouseout = anotherFunc;
		}
	}
};

function someFunc()
{
//	this.style.backgroundColor = "blue"; 
  this.style.backgroundImage="url('./images/button5.gif')";

	//'this' refers to the element that was moused over
}

function anotherFunc()
{
//	this.style.backgroundColor = "";
  this.style.backgroundImage="url('./images/button4.gif')";

	//'this' refers to the element that was moused out
}


function openwin(myurl)
 {
 newWindow = open(myurl,'' ,'');
}
