//init variables
var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;

//check DOM Model
if(document.getElementById){
	isID = 1; isDHTML = 1;
}
if(document.all){
	isAll = 1; isDHTML = 1;
}
browserVersion = parseInt(navigator.appVersion);
if((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)){
	isLayers = 1; isDHTML = 1;
}

//function to tell the existing DOM model
function whatDOM(){
	return(navigator.appName + ' ' + navigator.appVersion + String.fromCharCode(10) + isDHTML.toString(10) + isID.toString(10) + isAll.toString(10) + isLayers.toString(10));
}

//function to return an object or object style
function findDOM(objectID, withStyle){
	if(withStyle){
		if(isID)
			return(document.getElementById(objectID).style);
		if(isAll)
			return(document.all[objectID].style);
		if(isLayers)
			return(document.layers[objectID]);
	}else{
		if(isID)
			return(document.getElementById(objectID));
		if(isAll)
			return(document.all[objectID]);
		if(isLayers)
			return(document.layers[objectID]);
	}
}

//function to identify an object
function whoAmI(objectID){
	domStyle = findDOM(objectID, 1);
	dom = findDOM(objectID, 0);
	
	if(domStyle.pixelTop != null){
		alert('pos=' + domStyle.position + ' top=' + domStyle.pixelTop);
	}else{
		alert('pos=' + domStyle.position + ' top=' + domStyle.top);
	}
	alert(dom.id);
}


//opens a new instance of browser
function openWindow(contentURL, windowName, windowLeft, windowTop, windowWidth, windowHeight) {
	dim = "left=" + windowLeft + "px, top=" + windowTop + "px, height=" + windowHeight + "px, width=" + windowWidth + "px, scrollbars=1, resizable=1";
	newWindow = window.open(contentURL, windowName, dim);
	newWindow.focus();
	return(newWindow);
}

//close an instance of the browser
function closeWindow(newWindow) {
	if (newWindow != null) {
		newWindow.close();
		newWindow = null;
	}
}

//removes leading and trailing spaces in a string
function trim(str) {
	re = /^\s+|\s+$/gi;
	return(str.replace(re, ""));
}

//check if the string is an email address
function checkEmail(email) {
	re = /^[\w\-]+(?:\.[\w\-]+)*@[\w\-]+(?:\.[\w\-]+)*\.[a-z]{2,}$/;
	e = email.match(re);
	if (e == null) return(0);
	if (email != e) return(0);
	return(1);
}

function checkTextBox(control_name, field_name) {
	var txt = findDOM(control_name, 0);
	if (trim(txt.value) == "") {
		txt.value = "";
		txt.focus();
		alert ("Please enter the " + field_name + "!");
		return(0);
	}
	return(1);
}

function checkEmailTextBox(control_name, field_name) {
	var txt = findDOM(control_name, 0);
	if (trim(txt.value) == "") {
		txt.value = "";
		txt.focus();
		alert ("Please enter the " + field_name + "!");
		return(0);
	}
	if (!checkEmail(txt.value)) {
		txt.focus();
		alert ("The " + field_name + " value is incorrect!");
		return(0);
	}
	return(1);
}