var ie4, ie5, ie55, ns3, ns4, ns6, mz1
isIE = isMz = ie4 = ie5 = ie55 = ns3 = ns4 = ns6 = mz1 = false
var navigatorName = navigator.userAgent
var navigatorVersion = parseInt(navigator.appVersion)

if (navigatorName.indexOf("Gecko") != -1 && navigatorVersion >= 1) {
	mz1 = true
	isMz = true;
} else if (navigatorName.indexOf("MSIE") != -1) {
	isIE = true;
	if (document.getElementById) {
		ie5 = true
		if (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 6") != -1) {
			ie55 = true
		}
	} else {
		ie4 = true
	}
} else if (navigatorName.indexOf("Mozilla") != -1) {
	isMz = true;
	if (document.getElementById) {
		ns6 = true
	} else if (document.layers) {
		ns4 = true
	} else if (document.images) {
		ns3 = true
	}
}
//alert("navigatorName = " + navigatorName + "\n" + "navigatorVersion = " + navigatorVersion)
//alert("ie4 = " + ie4 + "\nie5 = " + ie5 + "\nins4 = " + ns4 + "\nns6 = " + ns6 + "\nmz1 = " + mz1)

function checkForm(thisFormObj) {
//	alert('thisFormObj.elements.length = ' + thisFormObj.elements.length)
	var errorArray = new Array()
	for (cf = 0; cf < thisFormObj.length; cf ++) {
//		alert("thisFormObj.elements[" + cf + "].style.name/ compulsary = " + thisFormObj.elements[cf].name + " " + thisFormObj.elements[cf].style.compulsary)
		if (thisFormObj.elements[cf].style.compulsary == 'true') {
			if (thisFormObj.elements[cf].value == "") {
				errorArray[errorArray.length] = thisFormObj.elements[cf].style.friendlyName + " is empty."
			} else if (thisFormObj.elements[cf].style.required != null) {
				if (thisFormObj.elements[cf].value.indexOf(thisFormObj.elements[cf].style.required) == -1) {
					errorArray[errorArray.length] = thisFormObj.elements[cf].style.friendlyName + " is not in the right format."
				}
			}
		}
		if (thisFormObj.elements[cf].style.maxChar > 0) { // length of the form exceeds the number of characters allowed
			if (thisFormObj.elements[cf].value.length > thisFormObj.elements[cf].style.maxChar) {
				errorArray[errorArray.length] = thisFormObj.elements[cf].style.friendlyName + " is too long (" + thisFormObj.elements[cf].style.maxChar + " characters allowed, you have " + thisFormObj.elements[cf].value.length + ")"
			}
		}
	}
	if (errorArray.length > 0) {
		var errorMessage = "I can't process the form like that!\n"
		errorMessage += "Please check the form for the following information:\n"
		for (cf = 0; cf < errorArray.length; cf ++) {
			errorMessage += "- " + errorArray[cf] + "\n"
		}
		alert(errorMessage)
		return false
	} else {
//		alert("returning true")
		return true
	}
}

function returnObjectById(thisID) {
	if (document.getElementById) {
		return(document.getElementById(thisID))
	} else if (document.all){
		return(document.all.item(thisID))
	} else {
		alert("uh-oh... no support for your browser!\nPlease email admin@bandspace.co.uk and tell us what you're using!")
		return false
	}
}

function sendMail(thisExt, thisDomain, thisName) {
	var mailWindow = window.open("mailto:" + thisName + "@" + thisDomain + "." + thisExt, "_blank")
}

function sendmail2(thisDomain, thisName) { // as used in discussionboard
	var mailWindow = window.open("mailto:" + thisName + "@" + thisDomain, "_blank")
}

function checkEmail(thisEmail) {

	if (thisEmail == "") {
		return "missing";
	} else if (thisEmail.indexOf(" ") != -1 || thisEmail.indexOf("\\") != -1 || thisEmail.indexOf("*") != -1 || thisEmail.indexOf("@") == -1 || thisEmail.indexOf(".") == -1 || thisEmail.indexOf(".") >= thisEmail.length - 2 || (thisEmail.indexOf("@") > thisEmail.indexOf(".") && thisEmail.indexOf(".", thisEmail.indexOf("@")) == -1)   || thisEmail.indexOf("@") + 1 == thisEmail.indexOf(".") || thisEmail.indexOf("@") == 0 || thisEmail.substr(thisEmail.length - 1, 1) == "." || thisEmail.substr(thisEmail.length - 2, 1) == ".") {
		// if illigal characters (3) or (no @) or (no .) or (. 1 or less chars from end) or (. before the @ while no . behind the @) or (. right next to @) or (nothing before @) or (last char = . or last char minus 1 = .)
		return "invalid";
	} else {
		return true;
	};
};

function positionContent(thisObjectName) {
	var positionObject = returnObjectById(thisObjectName);

	positionObject.style.visibility = "hidden";

	var docWidth = getDocWidth();
	var docHeight = getDocHeight();
	var objectWidth = getObjectWidth(positionObject);
	var objectHeight = getObjectHeight(positionObject);

	positionObject.style.left = ((docWidth - objectWidth) / 2)  +"px";
	positionObject.style.top = ((docHeight - objectHeight) / 2) + "px";
	
	showContent(thisObjectName);
};

function showContent(thisObjectName) {
	returnObjectById(thisObjectName).style.visibility = "visible";
}

function getDocWidth() {
	if (self.innerHeight) {// all except Explorer
		return self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		return document.body.clientWidth;
	}
}
function getDocHeight() {
		
	if (self.innerHeight) {// all except Explorer
		return self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		return document.body.clientHeight;
	}
}

function getObjectWidth(thisObject) {
	if (self.innerWidth) {// all except Explorer
		return thisObject.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return thisObject.clientWidth;
	} else if (document.body) { // other Explorers
		return thisObject.clientWidth;
	}
}

function getObjectHeight(thisObject) {
	if (self.innerHeight) {// all except Explorer
		return thisObject.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return thisObject.clientHeight;
	} else if (document.body) { // other Explorers
		return thisObject.clientHeight;
	}
}

function checkNo(thisEvent) {
	var echar = thisEvent.keyCode
	if ( (echar > 31) && (echar != 32) && (echar < 48) || (echar > 57) ) {
		return false
	}
	else { 
		return true
	}
}