// ****************************************
// *  Generic functions, DOM check, etc.
// *
// ****************************************

var isNS7 = 0;
var isNS9 = 0;
var isFF2 = 0;
var isSafari = 0;
var isIE = 0;
var isOpera9 = 0;
var isUnknown = 0;

var nav_agent;
var nav_browser;
var nav_version;

function checkBrowser() {
	nav_agent = navigator.userAgent;
	nav_browser = navigator.appName;
	nav_version = navigator.appVersion;

	// assign browser variables
	isNS7 = (nav_browser == "Netscape" && nav_agent.indexOf("Netscape/7") + 1)? 1: 0;
	isNS9 = (nav_browser == "Netscape" && nav_agent.indexOf("Navigator/9") + 1)? 1: 0;
	isFF2 = (nav_browser == "Netscape" && nav_agent.indexOf("Firefox/2") + 1)? 1: 0;
	isSafari = (nav_browser == "Netscape" && nav_agent.indexOf("Safari") + 1)? 1: 0;
	isIE = (nav_browser == "Microsoft Internet Explorer" && nav_agent.indexOf("Opera") < 0)? 1: 0;
	isOpera9 = (nav_browser == "Opera" && nav_agent.indexOf("Opera/9") + 1)? 1: 0;

	isUnknown = (!isNS7 && !isNS9  && !isFF2 && !isSafari && !isIE && !isOpera9)? 1: 0;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		// add a function to the onLoad event
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) { oldonload(); }
			func();
		}
	}
}

function openWin(url, height, width) {
	var today = new Date();
	var secs = today.getSeconds();

	window.open(url, "win" + secs,
	"toolbar=no, location=yes, directories=no, status=no, menubar=yes, scrollbars=no, resizable=yes, copyhistory=yes, width=" + width + ", height=" + height + " ");
}

function openWebPage(url, height, width) {
	var today = new Date();
	var secs = today.getSeconds();

	window.open(url, "win" + secs,
	"toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width=" + width + ", height=" + height + " ");
}

function getPageNum() {
	var page = " " + this.location.href + " ";
	var end = page.lastIndexOf(".htm");
	var pageNum = page.substring(end - 1, end);

	if (pageNum == "x" || pageNum == "." || pageNum == "") {
		pageNum = "0";
	}

	return pageNum;
}

function getSampleType() {
	var sampleType = "";
	var page = " " + this.location.href + " ";
	var begin = page.lastIndexOf("/");
	var end = page.lastIndexOf(".htm");
	var sample = page.substring(begin + 1, end);
	
	if (sample.substring(0, 3) == "img") {
		sampleType = "img";
	} else if (sample.substring(0, 4) == "logo") {
		sampleType = "logo";
	} else if (sample.substring(0, 3) == "web") {
		sampleType = "web";
	}

	return sampleType;
}

function getSampleImg() {
	var sampleType = getSampleType();
	var pageNum = getPageNum();	
	var arrayNum = parseInt(getPageNum()) - 1;	
	var extension = eval(getSampleType() + 'TypeArray[' + arrayNum + ']')
	var sampleImg = sampleType + pageNum + extension;
	
	return sampleImg;
}


// ****************************************
// *  Custom functions
// *
// ****************************************

function verifyForm(f){
	msg="";

	if (!f.email.value){
		msg+="\n Please complete the E-mail Address field.";
	} else {
		if (!checkEmail(f.email.value))
			msg+="\n Please enter a proper E-mail address (i.e. joe@abc.com).";
	}
	if (!f.subject.value){
		msg+="\n Please complete the Subject field.";
	}
	if (!f.comments.value){
		msg+="\n Please complete the Comments field.";
	}
	if (msg){
		alert(msg);
		return false;
	}	else{
		return true;
	}
}

function checkEmail(e){
	// verify that the e-mail address has at least this format xx@xx.xx
	i=e.indexOf('@',0)
	j=e.indexOf('.',i)
	if ((i < 2) || (j < 5) || (e.length < 7))
		return false;
	if (((j-i) < 3) || ((e.length - j) < 3))
		return false;
	return true;
}



addLoadEvent(checkBrowser);

// the following event listeners ar eused with the auto-centering function
//window.onresize = new Function("location.assign(location.href);");
//addLoadEvent(repositionDivs);


