var popupWin = null;
function openWindow(url) {
	popupWin = window.open(url,'Name', 'top=0,left=0,resizable=no,width=575,height=400,scrollbars=yes,menubar=no');
	popupWin.focus();
	popupWin.moveTo(200,200);
}

/* Extra stuff to enable nav hovers in lame IE */
sfHover = function() {
	var sfEls = document.getElementById("topNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() { this.className+=" sfhover";	selectHide(); }
		sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); selectShow(); }
	}
	
	if ( document.getElementById("chartPopContainer") ) {
		var sfEls = document.getElementById("chartPopContainer").getElementsByTagName("DIV")
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() { this.className+=" sfhover";	document.getElementById("tablePopContainer").style.visibility= "hidden"; selectHide(); }
			sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); document.getElementById("tablePopContainer").style.visibility= "visible"; selectShow(); }
		}		
	}

	if ( document.getElementById("tablePopContainer") ) {
		var sfEls = document.getElementById("tablePopContainer").getElementsByTagName("DIV")
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() { this.className+=" sfhover";	selectHide(); }
			sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); selectShow(); }
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function selectHide(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "hidden"; }
}

function selectShow(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "visible"; }
}       	

function showDiv(o, sDiv){
	$("#frm-portion").show();
	$(sDiv).show();        		
}

function closeDiv(sDiv){
	$(sDiv).slideToggle("up");
	if (sDiv == "#submit-a-question"){
		// if form elements were hidden by the submit button, show them before closing
		$("#temp-div").html("");
	}
}

function toggleImg(o){
	var s = $(o).attr("src");
	if (s.indexOf("-hover.gif") > 0){
		$(o).attr("src", s.replace("-hover.gif", ".gif"));
	}else{
		$(o).attr("src", s.replace(".gif", "-hover.gif"));
	}
}

function submitQuestion(){

	var lastname = $("#lastname").val();
	var firstname = $("#firstname").val();
	var email = $("#email").val();
	var question = $("#question").val();
	var product = $("h1").length == 0  ? $("title").text() : $("h1").html();

	product = product.replace(/<([^>]+)>/ig, '');


	if (email != "") {
		$.post(
			"index_backend.asp", 
			{ "cmd":1,"lastname":lastname, "firstname":firstname, "email":email, "product":product, "question":question },
			function(data){
				$("#frm-portion").hide();
				$("#temp-div").html(data).show();
				setTimeout("closeDiv('#submit-a-question')", 3000);
			}
		);
	} else {
		alert("Please enter your email address.");
	}

}

function submitDemo(){

	var name = $("#name-demo").val();
	var email = $("#email-demo").val();
	var organization = $("#organization-demo").val();
	var phone = $("#phone-demo").val();
	var product = $("h1").length == 0  ? $("title").text() : $("h1").html();

	product = product.replace(/<([^>]+)>/ig, '');


	if (name != "" && email != "" && organization != "" && phone != "") {
		if (check_Email(document.getElementById("email-demo"))){
			if (checkPhone(phone)){
				$.post(
					"index_backend.asp", 
					{ "cmd":3, "name":name, "email":email, "product":product, "organization":organization, "phone":phone },
					function(data){
						$("#frm-portion-demo").hide();
						$("#temp-div-demo").html(data).show();
						setTimeout("closeDiv('#request-demo')", 3000);
					}
				);
			}else{
				alert("Phone number is invalid.");
			}
		}
	} else {
		alert("All fields are required.");
	}
}

function ChangeSelect(iVal) { document.selector.selVal.value=iVal; }

function checkPhone(str){
	
	var oReg = /^([()-.+ EeXxTt]*[0-9]){10,}[()-.+ EeXxTt]*$/;
	
	if(str.match(oReg))
		return true;
	else
		return false;

}
