if(!document.getElementById)
{
	if(document.all)
	{
		accessObj = function()
		{
			if(typeof document.all[arguments[0]]!="undefined")
				return document.all[arguments[0]];
			else
				return null;
		}
	}
	else if(document.layers)
	{
		accessObj = function()
		{
			if(typeof document[arguments[0]]!="undefined")
				return document[arguments[0]];
			else
				return null;
		}
	}
}
else
{
	accessObj = function()
	{
		return document.getElementById(arguments[0]);
	}
}

function isNull(val)
{
	return (val == null);
}

function openDiv(name)
{
	var obj = accessObj(name);
	if (!isNull(obj))
		obj.style.display = "block";
}

function closeDiv(name)
{
	var obj = accessObj(name);
	if (!isNull(obj))
		obj.style.display = "none";
}

function checkformOther(check, ref)
{
	if (check == "other...")
	{
		accessObj(ref).value="";
	}
}

function validateJob(forms)
{
	var fail = false;	

	if(!checkEmpty(forms.company))
	{
		fail = true;
	}

	if (fail == true)
	{
		alert("Some mandatory fields have been left blank. These have been marked in red for you to check before re-submitting the form.")
		return false;
	}
	else
	{
		return true;
	}
}

function validate(form_id, frm_id)
{
	var fail = false;

	forms = accessObj(form_id);

	if(!checkEmpty(forms.name, frm_id))
	{
		fail = true
	}

	if(!checkEmpty(forms.email, frm_id))
	{
		fail = true;
	}

	if(!checkEmpty(forms.phone, frm_id))
	{
		fail = true;
	}

	if (fail == true)
	{
		alert("Some mandatory fields have been left blank. These have been marked in red for you to check before re-submitting the form.");		
	}
	else
	{
		captcha_popup("form-quote-"+frm_id);
	}
}

function validate_open_account()
{
	var fail = false;
	forms = accessObj("form-open-account");

	if(!checkEmpty(forms.name, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.company, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.address, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.phone, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.referee1, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.referee2, ""))
	{
		fail = true;
	}

	if (fail == true)
	{
		alert("Some mandatory fields have been left blank. These have been marked in red for you to check before re-submitting the form.");		
	}
	else
	{
		captcha_popup("form-open-account");
	}
}

function validate_send_me()
{
	var fail = false;
	forms = accessObj("form-send-me");

	if(!checkEmpty(forms.name, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.address, ""))
	{
		fail = true;
	}
	
	if(!checkEmpty(forms.postcode, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.email, ""))
	{
		fail = true;
	}

	if (fail == true)
	{
		alert("Some mandatory fields have been left blank. These have been marked in red for you to check before re-submitting the form.");		
	}
	else
	{
		captcha_popup("form-send-me");
	}
}

function validate_new_instructions()
{
	var fail = false;
	forms = accessObj("form-new-instructions");

	if(!checkEmpty(forms.company, ""))
	{
		fail = true;
	}

	if (fail == true)
	{
		alert("Some mandatory fields have been left blank. These have been marked in red for you to check before re-submitting the form.");		
	}
	else
	{
		captcha_popup("form-new-instructions");
	}
}

function validate_offer()
{
	var fail = false;
	forms = accessObj("form-offer");

	if(!checkEmpty(forms.name, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.address, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.email, ""))
	{
		fail = true;
	}

	if(!checkEmpty(forms.phone, ""))
	{
		fail = true;
	}

	if (fail == true)
	{
		alert("Some mandatory fields have been left blank. These have been marked in red for you to check before re-submitting the form.");		
	}
	else
	{
		captcha_popup("form-offer");
	}

	return !fail;
}

var frm_type = "";

function captcha_popup(frm_id)
{
	var obj = accessObj("captchapopup");
	obj.style.display = "block";
	frm_type = frm_id;
}

function check_captcha(script)
{
	var obj = accessObj("captcha_code");
	var captcha = obj.value;

	var xmlHttpReq = false;
	var code = captcha;
	var self = this;

	self.xmlHttpReq = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	self.xmlHttpReq.open('POST', script, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4)
		{
			if(self.xmlHttpReq.responseText == "passed")
			{
				var obj = accessObj(frm_type);
				obj.captcha.value = captcha;
				obj.submit();
			}
		}
	}
	self.xmlHttpReq.send("test="+captcha);
}

function checkEmpty(fld, frm_id)
{
	if (fld.value.length == 0)
	{
		var checkThis = fld.name + "label"+frm_id;
		var obj = accessObj(checkThis);
		obj.style.color = "#d81813";
		return false;	
	}
	else
	{
		var checkThis = fld.name + "label"+frm_id;
		var obj = accessObj(checkThis);
		obj.style.color = "#000";
		return true;
	}
}

function swap(these)
{
		var obj = accessObj(these);
		var obj2 = accessObj(these+"_roll");
		obj.style.display = "none";
		obj2.style.display = "";
}

function swapback(these)
{
		var obj = accessObj(these);
		var obj2 = accessObj(these+"_roll");
		obj.style.display = "";
		obj2.style.display = "none";
}

function show_more_form(button_holder, form_holder)
{
	closeDiv(button_holder);
	openDiv(form_holder);
	closeDiv("printing-form-details");
}
