/**
* @author Cristian Ciobanu
*/
sfHover = function() {
	if (document.getElementById("nav") != null) {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function openWindow(URL,width,height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 50,top = 50');");
	return false;
}

function swapPIC(id, source) {
	document.getElementById(id).src = source;
	return false;
}

function checkMail() {
	var name = document.getElementById('name_ml').value;
	var mail = document.getElementById('email_ml').value;

	var str = "";
	if (name.length < 1) str = str + "Please enter your name!\n";
	if (mail.length > 0){
		var countMe = 0
		var theCharacter = ""
		for (var x = 0; x < mail.length; x++)	{
			theCharacter = mail.charAt(x)
			if (theCharacter == "@")	{
				countMe++
			}
		}
		if (countMe != 1) str = str + "Your e-mail is not valid! Please enter a valid email address!\n";
	}
	else {
		str = str + "Please enter your e-mail!\n";
	}
	if (str.length == 0){
		return true;
	}
	else {
		alert(str);
		return false;
	}
}

function IsNumeric(sText, accept) {
	var ValidChars = accept;
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function validateQty(frm, qty) {
	var myFrm = document.getElementById(frm);
	var myQty = document.getElementById(qty).value;
	if (!IsNumeric(myQty, '0123456789') || myQty.length == 0) {
		alert('Please enter a valid quantity!')
	}
	else {
		myFrm.submit();
	}
}

function validate_Qty1(idElem) {
	var elem = document.getElementById(idElem);
	if (!IsNumeric(elem.value, '0123456789')) {
		elem.focus();elem.select();
		alert('Please enter a valid quantity!');
	}
}

function validate_Qty2() {
	var x = document.getElementById('frmFast');
	for (var i=0;i<x.length;i++) {
		var val = x.elements[i].id;
		if (val.substr(4,1) == 's' && IsNumeric(x.elements[i].value, '0123456789') && x.elements[i].value < 10 && x.elements[i].value != '') {
			x.elements[i].focus();x.elements[i].select();
			alert('Student Edition - minimum 10 per grade/subject!');
			return false;
		}
	}
	return true;
}

function ask_switch() {
	var agree=confirm("Switching locations will clear any existing items from your shopping cart.");
	if (agree) {
		return true;
	} else {
		return false;
	}
}