//////////////////find DOM code///////////////
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {isID = 1; isDHTML = 1;}
else {
if (document.all) {isAll = 1; isDHTML = 1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
}}

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else { 
			if (isAll) {return (document.all[objectID].style); }
		else {
			if (isLayers) {return (document.layers[objectID]);}
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else { 
			if (isAll) {return (document.all[objectID]); }
		else {
			if (isLayers) {return (document.layers[objectID]);}
		};}
	}
}
///////////////////// end FindDOM ///////////////

function validate(item, type, notice, maxlen, evalString){ // negative for N/A, 0 for no limit but not blank, positive for maxlength
	valid = true;
	errormsg = notice;
	if(type == "String"){
		if(isBlank(item.value)){
			valid = false;
		}
	}
	if(type == "Number"){
		if(blank(item.value).length == 0 || isNaN(item.value)){
			valid = false;
		}
	}
	if(type == "Custom"){
		if(!eval(evalString)){
			valid = false;
		}
	}
	if(type == "Email"){
		if(isBlank(item.value) || !checkEmail(item.value)){
			valid = false;
		}
	}
	if(type == "TextArea"){
		if(isBlank(item.innerHTML))
			valid = false;
	}
	if(!valid){
		alert(errormsg);
		item.focus();
	}
	return valid;
}

function blank(aString){
	var str = String(aString);
	if (str.toLowerCase() == "undefined" || str.toLowerCase() == "null")
		return "";
	return str;
}

function checkNumeric(theInput)
{
	if(isNaN(theInput.value)&&theInput.value!="")
	{
		theInput.value = "";
		alert("Please enter a number");
		theInput.focus();
		return false;
	}
	return true;
}
function isBlank(item){
	temp1 = blank(item);
	temp1 = temp1.replace(/\s/g,"");
	if (temp1.length == 0)
		return true;
	return false;
}

function checkEmail(value){
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(value) && r2.test(value));
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function confirmSubmit(){
	var agree=confirm("Are you sure you wish to continue?");
	if (agree)
		return true ;
	else
		return false ;
}
function validateFields(){
		findDOM("txtAttention").value = findDOM("txtContactFirstName").value + " " + findDOM("txtContactSurname").value;
		findDOM("txtBillingCompany").value = findDOM("txtDeliveryBusiness").value;
		findDOM("txtBillingAddress").value = findDOM("txtDeliveryAddress").value;
		findDOM("txtBillingSuburb").value = findDOM("txtDeliveryCity").value;
		findDOM("selBillingState").value = findDOM("selDeliveryState").value;
		findDOM("txtBillingPostcode").value = findDOM("txtDeliveryPostcode").value;
		findDOM("txtBillingEmail").value = findDOM("txtContactEmail").value;
}

// AJAX Object Creator
function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}
