// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitDoc(formName,pconf) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		var conf = true;
		var gateway = findObj(formName).elements["gateway"];
		var mcc ="";
		if (gateway != undefined)
		{
			mcc = gateway.value;
		}
		if (formName == "gateway" && pconf == undefined)
		{
			conf = confirm("Please confirm that you would like to proceed with this order.");
		}
		if (conf)
		{
			findObj(formName).submit(); 
		}
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}

function checkenquiryData()
{
	var badfields = "";
	
	var cb = document.getElementById("interested_in_brochure");
	var cbi = document.getElementById("interested_in_invitations");
	
	if(cb)
	{
		if (cb.checked == true)
		{
			if (document.form.postcode.value=="")
			{
				badfields = "Your postal code\n" + badfields;
			}
			if (document.form.town.value=="")
			{
				badfields = "Your town\n" + badfields;
			}
			if (document.form.add1.value=="")
			{
				badfields = "First line of your address\n" + badfields;
			}
		}
	}
	if (document.form.email.value==""){
		badfields = "Your email address\n" + badfields;
		document.form.email.focus();
	}
	if (document.form.firstname.value==""){
		badfields = "Your first name\n" + badfields;
		document.form.firstname.focus();
	}
	if (SelectVal("how_heard") == "")
	{
		badfields = badfields  + "How did you hear about us?\n";
	}

	if (badfields != "")
	{
		alert ("Please enter the following details:\n" +  badfields)
		return false;
	}
}

function sendFreeSample()
{
	var badfields = "";
	
	var cbi = document.getElementById("interested_in_invitations");
	
	if (document.form.firstname.value==""){
		badfields += "Your first name\n";
		document.form.firstname.focus();
	}
	
	var rad_val = "";
	for (var i=0; i < document.form.design.length; i++)
	{
		if (document.form.design[i].checked)
		{
			rad_val = document.form.design[i].value;
		}
	}
	
	if (rad_val == ""){
		badfields += "Your design\n";
	}
	if (document.form.email.value==""){
		badfields += "Your email address\n";
		document.form.email.focus();
	}
	if (document.form.email2.value==""){
		badfields += "Confirm your email address\n";
		document.form.email2.focus();
	}
	if (document.form.email.value != "" && document.form.email2.value != "" && document.form.email.value != document.form.email2.value){
		badfields += "Email addresses don't match\n";
		document.form.email.focus();
	}
	if (document.form.telephone.value=="")
	{
		badfields += "Your telephone number\n";
		document.form.telephone.focus();
	}
	if (SelectVal("how_heard") == "")
	{
		badfields += "How did you hear about us?\n";
	}

	if (badfields != "")
	{
		alert ("Please enter the following details:\n" +  badfields)
		return false;
	}
}

function SelectVal(selname)
{
	var sel = document.getElementById(selname);
	var val = "" + sel.options[sel.selectedIndex].value;
	return val;
}

function enable_name_check()
{
	var ele;
	var val;
	var submit;
	
	ele = document.getElementById("name_check_input");
	submit = document.getElementById("name_check_submit");
	
	if(ele)
	{
		val = ele.value;
		
		if(val != "")
		{
			//alert(val);
			submit.href = "/images/general/name_check_result.gif";
		}
		else
		{
			submit.href = "/images/general/please.jpg";
		}
	}
}

function handleEnter(inField, e) 
{
	var charCode;

	if(e && e.which)
	{
		charCode = e.which;
	}
	else if(window.event)
	{
		e = window.event;
		charCode = e.keyCode;
	}

	//if enter key pressed
	if(charCode == 13) 
	{
		//alert("Enter was pressed on " + inField.id);
		
		try {
			enable_name_check();
			document.getElementById('name_check_submit').click() 
		}
		catch(e) {
			//alert('cant');
		}
	}
}