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_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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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];}
}


function openfriendwin()
{
	day = new Date();
	id = day.getTime();

	//var mainURL = escape(getmainURL());
	//var mainTitle = getmainTitle();
	var mainURL = escape(location.href);
	var mainTitle = get_title_tag();
	var url = "/scripts/friend.php?Page=" + mainURL + "&Title=" + mainTitle;
	//alert(url);
	window.open(url,'id', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600');
}

function get_title_tag()
{
	var t = document.getElementsByTagName('title')[0];
	if ( !!t.childNodes.length ) 
	{
		return t.firstChild.data;
	} 
	else if ( t.innerHTML ) 
	{
		return t.innerHTML;
	}
}

function contactus()
{
	day = new Date();
	id = day.getTime();

	//var mainURL = escape(getmainURL());
	//var mainTitle = getmainTitle();
	var mainURL = escape(location.href);
	var mainTitle = get_title_tag();
	var frame = getmainFrame();

	var url = "/scripts/form1.php?referrer=" + mainURL + "&title=" + mainTitle;
	//alert(url);
	top.window.frames[frame].location.href = url;
}

function feedback()
{
	day = new Date();
	id = day.getTime();

	//var mainURL = escape(getmainURL());
	//var mainTitle = getmainTitle();
	var mainURL = escape(location.href);
	var mainTitle = get_title_tag();
	//var frame = getmainFrame();

	var url = "/scripts/feedbackform.php?referrer=" + mainURL + "&title=" + mainTitle;
	//alert(url);
	//top.window.frames[frame].location.href = url;
	window.open(url,'id', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=600');
}



function selectval(Sel)
{
return Sel.options[Sel.selectedIndex].value;
}
function DoLogin(Form)
{
	if (Form.loginemail.value == "" ||
		Form.password.value == "")
	{
		outMessage = 'We are unable to proceed as the following\n';
		outMessage += "fields have not been completed correctly:\n";
		outMessage += "Email address and password (must be entered)";
	
		alert(outMessage);
		return false;
	}

		Form.ACTION.value = "login";
		//Form.action.value = "login";
	Form.submit();
	return true;

}

function validate_basket(Form)
{
Form.Submit.disabled = true;
var Element;
var elename;
var i;
var BadFields = "";
var outMessage = "";
var ccnumber = "";
var cctype = "";
var ccsecno = "";
var ccissueno = "";
var email = "";
var hire = "";
var trade = "";
var password1 = "";
var password2 = "";

for ( i = 0; i < Form.length; i++ )
{
	Element = Form.elements[i];

	if (Element.name == 'Hire')
	{
		hire = Element.value;
	}
	if (Element.name == 'Trade')
	{
		trade = Element.value;
	}
	if (Element.name == 'Card_Type')
	{
		cctype = Element.value;
	}
	if (Element.name == 'Card_Number')
	{
		ccnumber = Element.value;
	}
	if (Element.name == 'Issue_Number')
	{
		ccissueno = Element.value;
	}
	if (Element.name == 'Security_Code')
	{
		ccsecno = Element.value;
	}
	if (Element.name == 'Email')
	{
		email = Element.value;
	}
	if (Element.name == 'password1')
	{
		password1 = Element.value;
	}
	if (Element.name == 'password2')
	{
		password2 = Element.value;
	}
}
if (ccnumber == '' && hire == '' && trade == '' && password1 == '')
{
	for ( i = 0; i < Form.length; i++ )
  	{
		Element = Form.elements[i];
	
		if ( 
			 Element.name == 'Forename'    ||
			 Element.name == 'Surname' ||
			 Element.name == 'Contact' ||
			 Element.name == 'Email'  )
		{
			if ( Element.value == ""  ||
		 		Element.value == " "  )
				{
				if ( Element.name == 'Contact' )
				{
						BadFields += "- " + Element.name + " Phone No.\n";
				}
				else
				{
						BadFields += "- " + Element.name + "\n";
				}
		 	}
		}
	}
}
else
{
	for ( i = 0; i < Form.length; i++ )
	{
		Element = Form.elements[i];
	
		if ( 
			 Element.name == 'Forename'     ||
			 Element.name == 'Surname'     ||
			 Element.name == 'Contact'    ||
			 Element.name == 'Address1'   ||
			 Element.name == 'Town'		||
			 Element.name == 'PostalCode' ||
			 Element.name == 'Country'    ||
			 Element.name == 'Card_Type'    ||
			 Element.name == 'Card_Name'    ||
			 Element.name == 'Card_Expiremonth'    ||
			 Element.name == 'Card_Expireyear'    ||
			 Element.name == 'Security_Code'    ||
			 Element.name == 'Delivery_Instructions'    ||
			 Element.name == 'Delivery_Select'    ||
			 Element.name == 'How_heard'    ||
			 Element.name == 'Car'    ||
			 Element.name == 'Tyres'    ||
			 Element.name == 'Email'  )
		{
			if ( Element.value == ""  ||
		 		Element.value == " "  )
				{
				elename = Element.name;
				if ( elename == 'Address1' )
				{
					elename = "Address"
				}
				if ( elename == 'Contact' )
				{
					elename = "Contact Phone No."
				}
				if ( elename == 'Card_Startmonth' )
				{
					elename = "Valid from month"
				}
				if ( elename == 'Card_Startyear' )
				{
					elename = "Valid from year"
				}
				if ( elename == 'Card_Expiremonth' )
				{
					elename = "Valid to month"
				}
				if ( elename == 'Card_Expireyear' )
				{
					elename = "Valid to year"
				}
				if ( elename == 'Delivery_Select' )
				{
					elename = "Standard Delivery Instructions"
				}
				if ( elename == 'How_heard' )
				{
					elename = "How did you hear about us"
				}

				BadFields += "- " + elename + "\n";
			}
		}
	}
}
if ( BadFields )
{
	outMessage = 'We are unable to proceed as the following\n';
	outMessage += "required fields have not been completed:\n";
	outMessage += BadFields;

	alert(outMessage);
	Form.Submit.disabled = false;
	return false;
}
if (ccnumber != '')
{
	if (ccnumber.length > 19)
	{
		outMessage = 'We are unable to proceed as the following\n';
		outMessage += "fields have not been completed correctly:\n";
		outMessage += "Credit/ debit card number (must be up to 19 digits with no spaces)";
	
		alert(outMessage);
		Form.Submit.disabled = false;
		return false;

	}
}
if (ccsecno != '')
{
	if (ccsecno.length != 3 && ccsecno.length != 4) 
	{
		outMessage = 'We are unable to proceed as the following\n';
		outMessage += "fields have not been completed correctly:\n";
		outMessage += "Security Code (must be 3 or 4 digits)";
	
		alert(outMessage);
		Form.Submit.disabled = false;
		return false;

	}
}
email = email.toLowerCase();
if (!isEmailAddressValid(email))

{
	outMessage = 'We are unable to proceed as your email address:\n';
	outMessage += email + '\n';
	outMessage += "appears to be invalid.:\n";

	alert(outMessage);
	Form.Submit.disabled = false;

	return false;
}
if (password1 != '' || password2 != '' )
{
	if (password1.length < 6 || password2.length < 6)
	{
		outMessage = 'We are unable to proceed as the following\n';
		outMessage += "fields have not been completed correctly:\n";
		outMessage += "New password (must be 6 or more characters)";
	
		alert(outMessage);
		Form.Submit.disabled = false;
		return false;

	}
	if (password1 != password2)
	{
		outMessage = 'We are unable to proceed as the following\n';
		outMessage += "fields have not been completed correctly:\n";
		outMessage += "New password (must be the same as confirmation password)";
	
		alert(outMessage);
		Form.Submit.disabled = false;
		return false;

	}
}


Form.Submit.disabled = true;
Form.Back.disabled = true;
Form.Reset.disabled = true;
Form.submit();
return true;
}




// Ported from Recipe 3.9 in Secure Programming Cookbook for C and C++ by
// John Viega and Matt Messier (O'Reilly 2003)

var rfc822_specials = "()<>@,;L\\\"[]";

function isEmailAddressValid(str)
{
	
	var c, count, domain;
	var quot = '"';
	var backslash = "\\";

	for (c = 0;  c < str.length;  c++)
	{
		if (str.charAt(c) == ' ') continue;

		if (str.charAt(c) == quot &&
			(!c || str.charAt(c - 1) == "." || str.charCharAt(c - 1) == quot))
		{
			while (++c < str.length)
			{
				if (str.charAt(c) == quot) break;
				if (str.charAt(c) == backslash && (str.charAt(++c) == ' ')) continue;
				if (str.charCodeAt(c) <= 32 || str.charCodeAt(c) >= 127)
					return false;
			}
			if (c++ >= str.length) return false;
			if (str.charAt(c) == "@") break;
			if (str.charAt(c) != ".") return false;
			continue;
		}
		if (str.charAt(c) == "@") break;
		if (str.charCodeAt(c) <= 32 || str.charCodeAt(c) >= 127) return false;
		if (rfc822_specials.indexOf(str.charAt(c)) != -1) return false;
	}
	if (!c || str.charAt(c - 1) == ".") return false;

	if ((domain = ++c) >= str.length) return false;
	count = 0;
	do
	{
		if (str.charAt(c) == ' ') continue;

		if (str.charAt(c) == ".")
		{
			if (c == domain || str.charAt(c - 1) == ".") return false;
			count++;
		}
		if (str.charCodeAt(c) <= 32 || str.charCodeAt(c) >= 127) return false;
		if (rfc822_specials.indexOf(str.charAt(c)) != -1) return false;
	} while (++c < str.length);

	return (count >= 1 ? true : false);
}

function handleClick(num)
{
  var elevalue;
  var Element;
  var elename;
  var badfields;
  var delivfound = "N";
  var outMessage;
  var Form = document.myForm;
  var BadFields 
  var basket = document.myForm.securebasket.value;

  if ( num == 0 )
  {
	document.myForm.ACTION.value = "recalc";
	
  }
  else
  {
	if ( num == 1 )
	{

	

		document.myForm.target = "_top";
		document.myForm.action= basket;
		document.myForm.method= "get";
		document.myForm.ACTION.value = "mailorder";
		
	}
	else
	{
		if ( num == 10 )
		{

			for ( i = 0; i < Form.length; i++ )
			{
				Element = Form.elements[i];
				elename= Element.name
				elevalue= Element.value
				//alert(elename)
				//alert (elename.indexOf('-del=1'))
				if (elename.indexOf('-del') > -1 && 
					((elevalue > 0 && Element.checked) || 
					(elevalue == 'free')))
				{
					//alert(elename)
					//alert (elevalue)
					delivfound = "Y";
				}
			}
			if (delivfound == "N")
			{
				BadFields = " - Delivery Option\n";
			}
			if ( BadFields )
			{
				outMessage = 'We are unable to proceed as the following\n';
				outMessage += "required fields have not been completed:\n";
				outMessage += BadFields;
		
				alert(outMessage);
				return false;
			}
		
	
//			document.myForm.target = \"_top\";
//			document.myForm.action= \"$roofshop\";
			document.myForm.ACTION.value = "mailorder";
			
		}
		else
		{
			document.myForm.ACTION.value = "clear";
		}
		}
  }
  document.myForm.submit();

}
function disableEnterKey()
{
if (window.event.keyCode == 13) window.event.keyCode = 0;
}
function entsub(event,ourform) {
	if (event && event.which == 13)
	{
		return false;
	}
}
