// JavaScript Document
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.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 submit_cus_reg(form)
{
	if(validate_cus_reg(form) == true)
	{
		form.submit();
	}
}

function validate_cus_reg(form)
{
	var return_value = false;
	
	var name_ok = false;
	var pw_ok = true;
	if(form.user_id.value > 0)
	{
		if(form.contact_name.value == "")
		{
			alert("Please enter your contact name");
			form.contact_name.focus();
		}
		else
		{
			name_ok = true;
		}
		
		if(form.password.value.length < 8)
		{
			pw_ok = false;
			alert("Please enter a password of at least 8 characters")
			form.password.focus();
		}
		else if(form.password.value != form.conf_pw.value)
		{
			pw_ok = false;
			alert("Your passwords do not match")
			form.password.focus();
		}
	}
	else
	{
		if(form.first_name.value == "")
		{
			alert("Please enter your first name");
			form.first_name.focus();
		}
		else if(form.last_name.value == "")
		{
			alert("Please enter your last name");
			form.last_name.focus();
		}
		else
		{
			name_ok = true;
		}
	}

	if(pw_ok == true)
	{
		if(name_ok == false)
		{
			//alert("Please enter your name");
			if(form.user_id.value > 0)
			{
				form.contact_name.focus();
			}
			else
			{
				form.first_name.focus();
			}
		}
		else if(form.company_name.value == "")
		{
			alert("Please enter your company name");
			form.company_name.focus();
		}
		else if(form.addr1.value == "")
		{
			alert("Please enter your address");
			form.addr1.focus();
		}
		else if(form.country.value == "0")
		{
			alert("Please select a country");
			form.country.focus();
		}
		else if(form.postcode.value == "")
		{
			alert("Please enter your post/zip code");
			form.postcode.focus();
		}
		else if(is_email(form.email.value) == false)
		{
			alert("Please enter a valid email address");
			form.email.focus();
		}
		else if(form.bus_type.value == "0")
		{
			alert("Please select a business type");
			form.bus_type.focus();
		}
		else if((form.bus_type.value == "SDT" || form.bus_type.value == "X") && form.extra_info.value == "")
		{
			alert("Please enter more information");
			form.extra_info.focus();
		}
		else
		{
			return_value = true;
		}
	}
	
	return return_value;
}

function is_email(str)
{
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp)
  {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function open_window(url)
{
	var features = "height=600,width=970,left=50,top=50,menubar=no,location=no,resizable=no,scrollbars=yes,status=no,toolbar=no";
	
	var new_win = window.open(url,"popup",features);
}
function open_window2(url)
{
	var features2 = "height=600,width=600,left=50,top=50,menubar=no,location=no,resizable=no,scrollbars=yes,status=no,toolbar=no";
	
	var new_win2 = window.open(url,"enquiry",features2);
}