

function changeImage(id, image) {
	document.getElementById(id).src = root + "img/gnav/" + image;
	//document.getElementById(id).src =  image;
}


// DHTML dropdown menu functions;
function Browser() {
	var ua, s, i;
	this.version = 0;
	this.ok = false;
	
	ua = ua=navigator.userAgent.toLowerCase();
	
	this.isOpera = ua.indexOf('opera') != -1;
	this.isKonq = ua.indexOf('konqueror') != -1;
	this.isIE = ua.indexOf('msie') != -1;
	if (this.isIE) this.version = parseFloat(ua.substr(ua.indexOf('msie') + 4));
	this.isAol = ua.indexOf('aol') != -1;
	this.isNav = ua.indexOf('netscape6/') != -1;
	if (this.isNav) this.version = parseFloat(ua.substr(ua.indexOf('netscape6/') + 10));
	this.isGecko = ua.indexOf('gecko') != -1;
	if (this.isGecko){
		this.isNav = true;
		this.version = 6.1;
	}
	this.isFirefox = ua.indexOf("firefox") != -1;

	this.isSafari = ua.indexOf("safari") != -1;
	
	this.isMac = ua.indexOf('mac') != -1;
	this.isWin = ua.indexOf('win') != -1;
	this.isLin = !(this.bMac || this.bWin);
	
	this.isMacIE = this.isIE && this.isMac;
	
	this.ok = 	(this.isIE && this.isWin && this.version >= 4) || 
				(this.isIE && this.isMac && this.version >= 5) || 
				(this.isNavigator && this.version >= 5) || 
				(this.isGecko) || 
				(this.Safari);
	//alert(this.ok);
}

var browser = new Browser();
function IsEmpty(val) {
	for (i=0; i<val.length; i++) { 
		if (val.charAt(i) != ' ') return false
	}
	return true
}

function IsValidEmail(val) {
	var iLen = val.length;
	if 	((iLen < 6) || (val.indexOf('@') < 1) || ((val.charAt(iLen - 3) != '.') && (val.charAt(iLen - 4) != '.')) ) return false
	return true
}

function formVal(){
	var msg = "";
	var typeList = "text,password,select-one";
	curForm = document.getElementById("form");
	for (var i=0; i<curForm.elements.length; i++){
		tag = curForm.elements[i];
		if (typeList.indexOf(tag.type) >= 0 && tag.getAttribute('required') == 1 && tag.value == "") {
			msg = msg + "<li>" + tag.title + " </li>";
		};
		if (tag.name.indexOf("email") >= 0  && tag.value.length != 0) {
			flag = IsValidEmail(tag.value);
			if (!flag) {
				msg = msg + "<li>" +  tag.title + " is invalid</li>";
			}
		};
		if (tag.type == "password" && tag.value.length > 0  && tag.value.length < 4) {
			msg = msg + "<li>" + "Password is too short</li>";
		}
		if (tag.name == "password2" && tag.value != "" && tag.value != curForm.password.value)
			msg = msg + "<li>" + "Password confirmation</li>";
	};
	
	document.getElementById('err').innerHTML = "";
	if (msg != "") {
		document.getElementById('err').innerHTML = "The following fields are required: <ul>" + msg + "</ul>";
		window.scrollTo(0,10);
		return false;
	} else {
		return true;
	}
}


function sideNav () {
	evt = window.event;
	if (browser.isIE) {
		obj = window.event.srcElement;
	} else  {
		obj = event.currentTarget;
	}
	targetObj = obj.parentNode.firstChild;
	obj.onmouseover = function () {
		targetObj.className = "img-on";
		
	}
	obj.onmouseout = function () {
		targetObj.className = "img";
	}
	
	/*
	if (evt.type == "mouseover") {
		obj.parentNode.firstChild.className = "img-on";
	} else {
		obj.parentNode.firstChild.className = "img";
	}
	*/
}

function sideNavOver(obj){
	//alert(obj.parentNode.parentNode.firstChild.firstChild.tagName);
	//alert(obj.parentNode.parentNode.childNodes[1].tagName);
	/*
	if (!browser.isFirefox) {
		obj.parentNode.parentNode.firstChild.className = "img-on";
	} else {
		obj.parentNode.parentNode.childNodes[1].className = "img-on"; 
	}
	*/
	if (browser.isFirefox) {
		obj.parentNode.parentNode.childNodes[1].className = "img-on";
	} else {
		obj.parentNode.parentNode.firstChild.className = "img-on";
	}
	
}
function sideNavOut(obj) {
	if (!browser.isFirefox) {
		obj.parentNode.parentNode.firstChild.className = "img";
	} else {
		obj.parentNode.parentNode.childNodes[1].className = "img"; 
	}
}


