var popWin = "";
// * FORECOLOUR POPUP WINDOW
function popwindow(pageaddress){

var w = 480, h = 340;

if (document.all) {

   w = document.body.clientWidth;
   h = document.body.clientHeight;
}
else if (document.layers) {
   w = window.innerWidth;
   h = window.innerHeight;
}

var popW = 275, popH = 200;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;

if (popWin != ""){popWin.close()}
popWin = window.open(""+pageaddress+"","window","toolbar=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + popW + ",height="+popH+",top="+topPos+",left="+leftPos)
window.opener = self;

}

if (document.images)
{
	house5On=new Image;
	house5On.src="../images/house_on.gif";
	house5Off=new Image;
	house5Off.src="../images/house_off.gif";
	
	mail5On=new Image;
	mail5On.src="../images/mail_on.gif";
	mail5Off=new Image;
	mail5Off.src="../images/mail_off.gif";
	
	home5On=new Image;
	home5On.src="../images/home_on.jpg";
	home5Off=new Image;
	home5Off.src="../images/home_off.jpg";
	
	about5On=new Image;
	about5On.src="../images/about_on.jpg";
	about5Off=new Image;
	about5Off.src="../images/about_off.jpg";
	
	solbus5On=new Image;
	solbus5On.src="../images/solbus_on.jpg";
	solbus5Off=new Image;
	solbus5Off.src="../images/solbus_off.jpg";
	
	solhome5On=new Image;
	solhome5On.src="../images/solhome_on.jpg";
	solhome5Off=new Image;
	solhome5Off.src="../images/solhome_off.jpg";
	
	human5On=new Image;
	human5On.src="../images/human_on.jpg";
	human5Off=new Image;
	human5Off.src="../images/human_off.jpg";
	
	products5On=new Image;
	products5On.src="../images/products_on.jpg";
	products5Off=new Image;
	products5Off.src="../images/products_off.jpg";
	
	links5On=new Image;
	links5On.src="../images/links_on.jpg";
	links5Off=new Image;
	links5Off.src="../images/links_off.jpg";
	
	contact5On=new Image;
	contact5On.src="../images/contact_on.jpg";
	contact5Off=new Image;
	contact5Off.src="../images/contact_off.jpg";
	
	terms5On=new Image;
	terms5On.src="../images/terms_on.jpg";
	terms5Off=new Image;
	terms5Off.src="../images/terms_off.jpg";
}

function on(pic)
{
if (document.images)
	{
	document.images[pic].src=eval(pic + "On.src");
	}
}

function off(pic)
{
if (document.images)
	{
	document.images[pic].src=eval(pic + "Off.src");
	}
}

function emailCheck (element) 
{
	emailStr=element;
	
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	var matchArray=emailStr.match(emailPat)
	
	if (matchArray==null) {
		return false
	}
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}


//  End -->

function ShowTR(id)
{
	if(document.getElementById(id).style.display == 'none')
		document.getElementById(id).style.display = 'block';
	else
		document.getElementById(id).style.display = 'none';
}

function checkphone(input)
{
	var returnval = false;
	
	var re = new RegExp('^([0-9]{5}[0-9]{6})$');
	if (input.match(re)) {
		returnval = true;
	}
	return returnval;
}

function checkdate(input)
{
	var returnval = false;
	
	var re = new RegExp('(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checkcurrency(input)
{
	var returnval = false;
	
	var re = new RegExp('^\\d+\\.\\d\\d$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checknumber(input)
{
	var returnval = false;
	
	var re = new RegExp('^[0-9]\\d*$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checksortcode(input)
{
	var returnval = false;
	
	var re = new RegExp('^([0-9]{2})$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checktime(input)
{
	var returnval = false;
	
	var re = new RegExp('^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checkccard(input, nl)
{
	var returnval = false;
	
	var re = new RegExp('^([0-9]{'+nl+'})$');
	if (input.match(re)) {
		returnval = true;
	}	
	return returnval;
}

function checkrequired(which) 	
{
	var pass=true;

	if (document.images) 
	{
		for (i=0;i<which.length;i++)
		{
			var tempobj=which.elements[i];
			//if (tempobj.name.substring(0,8)=="required") 
			
			if (tempobj.required == "1")
			{
			if ( (tempobj.type=="checkbox" && tempobj.checked==false) || ((tempobj.type=="text"||tempobj.type=="password"||tempobj.type=="textarea")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) 
				{
					pass = false;
					break;
				}
				else
				{
					if (tempobj.isdate == "1")
					{
						if (checkdate(tempobj.value) == false)
						{
							pass = false;
							break;
						}
					}
					if (tempobj.istime == "1")
					{
						if (checktime(tempobj.value) == false)
						{
							pass = false;
							break;
						}
					}
					if (tempobj.iscurrency == "1")
					{
						if (checkcurrency(tempobj.value) == false)
						{
							pass = false;
							break;
						}
					}
					if (tempobj.isnumber == "1")
					{
						if (checknumber(tempobj.value) == false)
						{
							pass = false;
							break;
						}
						if (tempobj.lnum)
						{
							if (parseFloat(tempobj.value) < parseFloat(tempobj.lnum))
							{
								pass = false;
								break;
							}
						}
						if (tempobj.unum)
						{
							if (parseFloat(tempobj.value) > parseFloat(tempobj.unum))
							{
								pass = false;
								break;
							}
						}
					}
					if (tempobj.isemail == "1")
					{
						if(emailCheck(tempobj.value) == false)
						{
							pass = false;
							break;
						}
					}
					if (tempobj.isphone == "1")
					{
						if(checkphone(tempobj.value) == false)
						{
							pass = false;
							break;
						}
					}
					if (tempobj.issortcode == "1")
					{
						if(checksortcode(tempobj.value) == false)
						{
							pass = false;
							break;
						}
					}
					if (tempobj.isccard == "1")
					{
						if (tempobj.value.length >= 13)
						{
							if(checkccard(tempobj.value, tempobj.value.length) == false)
							{
								pass = false;
								break;
							}
						}
						else
						{
							pass = false;
							break;
						}
					}
					if (tempobj.tomatch)
					{
						if(tempobj.value != document.getElementById(tempobj.tomatch).value)
						{
							
							pass = false;
							alert ("Please make sure the " + tempobj.name.toUpperCase() + " field matches the " + tempobj.tomatch.toUpperCase() + " field.");
							tempobj.focus;
							return false;
						}
					}
				}
			}
		}
	}
	
	if (!pass) 
	{
		if(tempobj.ct)
		{
			alert(tempobj.ct);
		}
		else
		{
			//shortFieldName=tempobj.name.substring(8,30).toUpperCase();
			shortFieldName=tempobj.name.toUpperCase();
			alert("Please make sure the "+shortFieldName+" field was properly completed.");
		}
		
		if (tempobj.disabled != true)
			tempobj.focus();
			
		return false;
	}
	else
	{
		return true;
		//SUBMIT FORM HERE	
	}
}
//  End -->

function CheckCover(ctrl, ctrl2)
{
	var ct = document.getElementById(ctrl);
	
	if (ct.selectedIndex==1)
	{
		document.getElementById('ACC_' + ctrl2).selectedIndex = 1;
		document.getElementById('SUM_' + ctrl2).value = "0";
		document.getElementById('SUM_' + ctrl2).disabled = true;
		document.getElementById('ACC_' + ctrl2).disabled = true;
		if(ctrl2 == 'BUILDINGS')
			document.getElementById('SUM_' + ctrl2).required = '1';
		else
		{
			document.getElementById('SUM_' + ctrl2).required = '0';
			if(document.getElementById('ADD_PUBLIC_LIABILITY'))
				document.getElementById('ADD_PUBLIC_LIABILITY').disabled = true;
		}
	}
	else
	{
		document.getElementById('ACC_' + ctrl2).disabled = false;
		document.getElementById('SUM_' + ctrl2).disabled = false;
		document.getElementById('SUM_' + ctrl2).required = '1';
		
		if(ctrl2 == 'CONTENT' && document.getElementById('ADD_PUBLIC_LIABILITY'))
		{
			document.getElementById('ADD_PUBLIC_LIABILITY').disabled = false;
		}
	}
}

 /*   if (COVER_CONTENTS_COVERREQ.selectedIndex==1) {
      COVER_CONTENTS_ACCDAMAGE.selectedIndex=1;
      COVER_CONTENTS_ACCDAMAGE.disabled=true;
    COVER_PUBLICLI_REQ.selectedIndex=0;
    COVER_PUBLICLI_REQ.disabled=true;
    COVER_CONTENTS_SUM_INSURED.value="0";
    } else {
      COVER_CONTENTS_ACCDAMAGE.disabled=false;
    COVER_PUBLICLI_REQ.disabled=false;
    }
	
    if (COVER_BUILDINGS_COVERREQ.selectedIndex==1) {  // No buildings
      COVER_BUILDINGS_ACCDAMAGE.selectedIndex=1;
      COVER_BUILDINGS_ACCDAMAGE.disabled=true;
    COVER_PROPERTYLI_REQ.selectedIndex=0;
    COVER_PROPERTYLI_REQ.disabled=true;
    COVER_BUILDINGS_SUM_INSURED.value="0";
    } else { 
      COVER_BUILDINGS_ACCDAMAGE.disabled=false;
    COVER_PROPERTYLI_REQ.disabled=false;
    if (COVER_PROPERTYLI_REQ.selectedIndex==0) {
      COVER_PROPERTYLI_REQ.selectedIndex=1;
    }*/

