function openwin(strUrl,intWidth,intHeight)
{

	intLeft = (window.screen.availWidth / 2) - (intWidth/2);
	intTop = (window.screen.availHeight / 2) - (intHeight/2); 
			
	ref = window.open(strUrl,"lookupWin","width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft + ",top=" + intTop + ",screenX=" + intLeft + ",screenY=" + intTop + ",toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes");
	ref.focus();
	ref.resizeTo(intWidth,intHeight);
	ref.moveTo(intLeft,intTop);
	ref.focus();
}

function IsEmpty(field){
	if(field.value!=""){
		return false;
	}
	return true;
}

function IsEmail(emailAddress) 
{
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,4}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

function IsPhoneNumber(field) {
	var valid = "0123456789- +"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if ((ok == "no")||((field.value.length<=4)&&(field.value.length>0))) {
			return false;
  	 	}
	return true;
}

function CheckEmail(field){
	if (IsEmpty(field)){
		alert ('Please include an email address!');
		return false;
	}
	
	if (!IsEmail(field.value)){
		alert ('Please check that the email address is valid');
		return false;
	}

	return true;
}

function CheckPhone(field){
	if (IsEmpty(field)){
		alert('Please include a phone number');
		return false;
	}
	
	if (!IsPhoneNumber(field)){
		alert('Please check that your phone number is valid');
		return false;
	}
	
	return true;
}

function IsValidDate(dayref,monthref,yearref){
		
	var day = dayref.value
	var month = new String(monthref.value);
	month = month.toLowerCase();
	var year = yearref.value;
	var isleap = "false";
				
	//Check that the startdate is a valid date		
	if (month=="apr" || month=="jun" || month=="sep" || month=="nov")
	{
		if (day>30) 
		{
			alert("You have entered an invalid start date! This month cannot have 31 days");
			dayref.focus();
			return false;
		}
	}
	else if (month=="feb") 
	{
		//Calculate whether the year is a leap year	
		if ((year%4) != 0 )
			isleap = "FALSE";
		else if ((year%400) == 0 )
			isleap = "TRUE";
		else if ((year%100) == 0 )
			isleap = "FALSE";
		else
			isleap = "TRUE";
								
		if (isleap == "FALSE")
		{
			if (day>28) 
			{
				alert("You have entered an invalid start date! February cannot have more than 28 days in this year.");
				dayref.focus();
				return false;
			}
		}
		else
		{
			if (day>29) 
			{
				alert("You have entered an invalid start date! February cannot have more than 29 days.");
				dayref.focus();
				return false;
			}
		}
	}
	
	return true;
}

function IsValidDateRange(fdayref,fmonthref,fyearref,tdayref,tmonthref,tyearref)
{
	fromdate = new Date(fyearref.value,GetMonthAsInt(fmonthref.value),fdayref.value);
	
	todate = new Date(tyearref.value,GetMonthAsInt(tmonthref.value),tdayref.value);
	if(fromdate > todate)
	{
		return false;
	}
	return true;
}

function GetMonthAsInt(month)
{
	//NOTE: the Date object requires the month as an integer between 0 - 11
	var imonth;
	switch(month)
	{
		case "jan":
			imonth=0
			break;
		case "feb":
			imonth=1
			break;
		case "mar":
			imonth=2
			break;
		case "apr":
			imonth=3
			break;
		case "may":
			imonth=4
			break;
		case "jun":
			imonth=5
			break;
		case "jul":
			imonth=6
			break;
		case "aug":
			imonth=7
			break;
		case "sep":
			imonth=8
			break;
		case "oct":
			imonth=9
			break;
		case "nov":
			imonth=10
			break;
		case "dec":
			imonth=11
			break;
	}
	return imonth;
}

function CheckIsLegalPassword(pw)
{
	var validchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-";
	var temp;
	
	for (var i=0; i<pw.length; i++) 
	{
		temp = "" + pw.substring(i, i+1);
	    if (validchars.indexOf(temp) == "-1") 
		{
			return false;	
	    }
	}
	return true;
}

function CheckIsNumeric(field)
{
	var validchars = "0123456789";
	var temp;
	
	for (var i=0; i<field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
	    if (validchars.indexOf(temp) == "-1") 
		{
			return false;	
	    }
	}
	return true;

}
function CheckIsDecimal(field)
{
	var validchars = "0123456789.";
	var temp;
	
	for (var i=0; i<field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
	    if (validchars.indexOf(temp) == "-1") 
		{
			return false;	
	    }
	}
	return true;

}

function CheckPostcode()
{	
	if (document.frmdiscounts.txtPostCode.value == "" || document.frmdiscounts.txtPostCode.value == "Enter your postcode")
	{
		alert("Please enter a valid postcode.")
		document.frmdiscounts.txtPostCode.focus();
		return false;
	}
	
	if (document.frmdiscounts.txtPostCode.value.length < 6 )
	{
		alert("The postcode you entered is not a valid postcode. Please enter your full postcode.")
		document.frmdiscounts.txtPostCode.focus();
		return false;
	}
	
	var space = " ";		
	var pcode = document.frmdiscounts.txtPostCode.value;		
	
	//trim it!
	 if ((pcode.substring(0,1) == ' ') || (pcode.substring(0,1) == '\n') || (pcode.substring(0,1) == '\r'))
	 {
	 	pcode = pcode.substring(1,pcode.length);
	 }		 	
	 if ((pcode.substring(pcode.length-1,pcode.length) == ' ') || (pcode.substring(pcode.length-1,pcode.length) == '\n') || (pcode.substring(pcode.length-1,pcode.length) == '\r'))
	 {
	 	pcode = pcode.substring(0,pcode.length-1);
	 }	
	
	if(pcode.indexOf(space) == "-1")
	{		
		alert("Please enter a space between the two parts of your postcode.");
		document.frmdiscounts.txtPostCode.focus();		
		return false;			 
	}
	
	return true;
}


/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu


function navigateTo(links)
{
	alert(links)
	window.location.href=links;
}