// JavaScript Document
<!--

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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 MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var newWindow = window.open(theURL,winName,features);
  newWindow.focus();
}

function valForm2(formNum){
	formVar = document.forms['form' + formNum]

	if (formVar.option_1_value.value == "0"){		
		alert("Please Select A Size")
		return false				
	}	
	else if (formVar.option_2_value.value == "0"){
			alert("Please Select A Colour")
			return false
	} 
	else
	{
		formVar.submit()
	}
}

function valForm(formNum){
	formVar = document.forms['form' + formNum]

	if (formVar.option_1_value.value == "0"){
		alert("Please Select A Size")
		return false
	}else{
		formVar.submit()
	}

}

var form = "";
var submitted = false;
var error = false;
var error_message = "";

function check_input(field_name, field_size, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_radio(field_name, message) {
  var isChecked = false;

  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var radio = form.elements[field_name];

    for (var i=0; i<radio.length; i++) {
      if (radio[i].checked == true) {
        isChecked = true;
        break;
      }
    }

    if (isChecked == false) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_select(field_name, field_default, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == field_default) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_password(field_name_1, field_name_2, field_size, message_1, message_2) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password = form.elements[field_name_1].value;
    var confirmation = form.elements[field_name_2].value;

    if (password == '' || password.length < field_size) {
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    } else if (password != confirmation) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    }
  }
}

function check_password_new(field_name_1, field_name_2, field_name_3, field_size, message_1, message_2, message_3) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password_current = form.elements[field_name_1].value;
    var password_new = form.elements[field_name_2].value;
    var password_confirmation = form.elements[field_name_3].value;

    if (password_current == '' || password_current.length < field_size) {
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    } else if (password_new == '' || password_new.length < field_size) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    } else if (password_new != password_confirmation) {
      error_message = error_message + "* " + message_3 + "\n";
      error = true;
    }
  }
}

function check_form(form_name) {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_radio("gender", "Please select your Gender.");

  check_input("firstname", 2, "Your First Name must contain a minimum of 2 characters.");
  check_input("lastname", 2, "Your Last Name must contain a minimum of 2 characters.");

  //check_input("dob", 10, "Your Date of Birth must be in this format: DD/MM/YYYY (eg 21/05/1970)");

  check_input("email_address", 6, "Your E-Mail Address must contain a minimum of 6 characters.");
  
  check_password("email_address", "confirm_email_address", 5, "Your Password must contain a minimum of 5 characters.", "The Email Confirmation must match your Email Address.");
  
  check_input("street_address", 5, "Your Street Address must contain a minimum of 5 characters.");
  check_input("postcode", 4, "Your Postcode/Zip must contain a minimum of 4 characters.");
  check_input("city", 3, "Your City must contain a minimum of 3 characters.");

  check_input("state", 2, "Your County/Region must contain a minimum of 2 characters.");
  check_select("country", "", "You must select a country from the Countries pull down menu.");
  check_input("telephone", 3, "Your Telephone Number must contain a minimum of 3 characters.");
  check_password("password", "confirmation", 5, "Your Password must contain a minimum of 5 characters.", "The Password Confirmation must match your Password.");
  check_password_new("password_current", "password_new", "password_confirmation", 5, "Your Password must contain a minimum of 5 characters.", "Your new Password must contain a minimum of 5 characters.", "The Password Confirmation must match your new Password.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function check_change_password(form_name) {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";
  check_input("password",5,"Please enter your current password.");
  check_password("newpassword", "confirm", 5, "Your New Password must contain a minimum of 5 characters.", "The Password Confirmation must match your Password.");
 // check_password_new("password_current", "password_new", "password_confirmation", 5, "Your Password must contain a minimum of 5 characters.", "Your new Password must contain a minimum of 5 characters.", "The Password Confirmation must match your new Password.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}


function check_change_email(form_name) {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_password("email", "confirm", 6, "Your Email must contain a minimum of 6 characters.", "The Email Confirmation must match your Email.");
 // check_password_new("password_current", "password_new", "password_confirmation", 5, "Your Password must contain a minimum of 5 characters.", "Your new Password must contain a minimum of 5 characters.", "The Password Confirmation must match your new Password.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function log_out()
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('Are you sure you want to log out?'))
	{
		return true;
	}
	else
	{
		ht[0].style.filter = "";
		return false;
	}
}

function empty_basket()
{	
	if (confirm('Are you sure you want to empty your basket?'))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function InitialiseNavigation() 
{ 
	if (arguments.length != 0) 
	throw new Error("function InitializeNavigation() incorrectly called"); 
	HideNav(); 
	document.getElementById("navurls").style.display = "block"; 
	return; 
}

function ShowNavigtion() 
{ 
      if (arguments.length != 0) 
        throw new Error("function ShowNavigation() incorrectly called"); 
      document.getElementById('openNav').style.display="block"; 
      document.getElementById('closedNav').style.display="none"; 
      document.getElementById('nav').style.display="block"; 
      return; 
}

function HideNav() 
{ 
     if (arguments.length != 0) 
     throw new Error("function HideNav() incorrectly called"); 
      document.getElementById('openNav').style.display="none"; 
      document.getElementById('closedNav').style.display="block"; 
      document.getElementById('nav').style.display="none"; 
      return; 
}

function ExpandDisp(id) 
{ 
      if (arguments.length != 1) 
      throw new Error("function ExpandDisp() incorrectly called"); 
      document.getElementById(id).style.display = ((document.getElementById(id).style.display == "none") ? "block" : "none"); 
      return; 
}
function write_flash(flash, width, height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'" style="z-index: 0;">');
	document.write('<param name="movie" value="'+flash+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+flash+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent" style="z-index: 0;"></embed>');
	document.write('</object>');
} //end function write_header()

//--> 
