var popupTimeout;
var searchTimeout;
//var serverpath = "http://10.0.0.1:81/lwmv2/";
//var securepath = "http://10.0.0.1:81/lwmv2/";
var serverpath = "http://www.livewiremedia.com/";
var securepath = "https://www.livewiremedia.com/";

/*general functions starts here*/
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function Right(obj)
{
	var curRight = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curRight += obj.offsetRight
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curRight += obj.x;
	return curRight;
}
function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	curtop += obj.y;
	return curtop;
}
function emailcheck(emailID) 
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(emailID))
	{		
		return false;					
	}
	else
	{
		return true;
	}	
}
function onlyDigits(e,obj)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) 
	{
		keynum = e.keyCode;
	}else if(e.which) 
	{
		keynum = e.which;
	}		
	if(keynum==8 || e.charCode==0)
	{
		return true;
	}
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;	
	return numcheck.test(keychar);
}
function onlyDecimals(e,obj)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) 
	{
		keynum = e.keyCode;
	}else if(e.which) 
	{
		keynum = e.which;
	}		
	if(keynum==8 || e.charCode==0 || keynum==46)
	{
		if(keynum==46)
		{
			txtVal=obj.value;
			var arr=txtVal.split(".");//checking for number of dots
			if(arr.length!=1)
			{
				return false;//if dots is more return false
			}
		}
		return true;
	}
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;	
	return numcheck.test(keychar);
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function txtFocusIn(objname,text,className)
{	
	obj = document.getElementById(objname);		
	if(obj.value == text)
	{
		obj.value="";	
		obj.className = className;
	}	
}
function txtFocusOut(objname,text,className)
{
	obj = document.getElementById(objname);
	if(obj.value == "")
	{
		obj.value = text;
		obj.className = className;		
	}
}
function showValidation(obj,div,msg)
{
	var obj = document.getElementById(obj);
	var div = document.getElementById(div);
	div.innerHTML = msg;
	div.style.display="block";
	div.style.top=Top(obj)+0+"px";
	div.style.left=Left(obj)+100+"px";
}
function getleftNavHeight()
{
	/* if(document.getElementById("divRightRelatedProd"))
	{
		var maxHeight;
		if(document.getElementById("centerContainer").clientHeight>document.getElementById("leftContainer").clientHeight)
		{
			maxHeight = document.getElementById("centerContainer").clientHeight;
		}
		else
		{
			maxHeight = document.getElementById("leftContainer").clientHeight;
		}
		
		if(document.getElementById("rightContainer").clientHeight<=maxHeight)
		{					
			document.getElementById("divRightRelatedProd").style.height = maxHeight - Top(document.getElementById("divRightRelatedProd")) + 130 + "px";
		}
		// else
		// {
			// if(document.getElementById("divProducts"))
			// {
				// document.getElementById("divRightRelatedProd").style.height = document.getElementById("divProducts").clientHeight + "px";
			// }			
		// }
	}
	//alert(document.getElementById("wrapper").clientHeight); */
	
}
function showShortDesc()
{
	document.getElementById("divShortDesc").style.display = "block";
}
function getShortDesc(obj,header,desc,url)
{
	document.getElementById("divShortDesc").style.display = "block";
	document.getElementById("divShortDesc").style.top = Top(obj)+12+"px";
	document.getElementById("divShortDesc").style.left = Left(obj)+"px";
	document.getElementById("divShortDescH1").innerHTML = header.replace(/%6/g,"'").replace(/%7#/g," ");
	document.getElementById("divShortDescP").innerHTML = desc.replace(/%6/g,"'").replace(/%7#/g," ");
	$("#divShortDescA").attr("href",url);
}
function hideShortDesc()
{
	document.getElementById("divShortDesc").style.display = "none";
}
var featuredProdTimer;
var featProdPlayIndex=1;
function displayprod(count)
{
	$(".divHomeFlashContent").css("display","none");
	$("#divHomeFlashContent_"+count).fadeIn(1000);
	var featuredCount = document.getElementById("HFFeaturedCount").value;
	if(featProdPlayIndex==featuredCount)
	{
		featProdPlayIndex=1;
	}
	else
	{
		featProdPlayIndex=featProdPlayIndex+1;
	}
}
function playFeaturedProd(count)
{
	if(featuredProdTimer)
	{
		clearInterval(featuredProdTimer);
	}
	displayprod(featProdPlayIndex);
	featuredProdTimer=setInterval(function(){displayprod(featProdPlayIndex)},6000);
}
function pauseFeaturedProd()
{
	if(featuredProdTimer)
		clearInterval(featuredProdTimer);	
}
function goToProducts(page)
{
	window.location.href= page;
}
function changeTab(tabName)
{
	var prevURL="";
	if(document.getElementById("HFPrevURL").value!="")
	{
		prevURL = "&"+document.getElementById("HFPrevURL").value
	}
	window.location.href="?"+tabName+prevURL;
	scroll(0,0);
	
}

function showProducts(pageNo)
{	
	window.location.href= serverpath+"product"+"?p="+pageNo;
}
function showProdSubjects(subject,pageNo)
{
	window.location.href= serverpath+subject+"?p="+pageNo;
}
function search(type)
{	
	clearInterval(searchTimeout);
	var qryStr = "?t="+type;
	if(type==1)
	{
		var grade = document.getElementById("ddlLeftGrdLvl").value;
		var subject = document.getElementById("ddlLeftSubject").value;
		var media = document.getElementById("ddlLeftMediaType").value;
		qryStr = qryStr+"&g="+grade+"&s="+subject+"&m="+media;
		window.location.href= serverpath+"search"+qryStr;
	}	
	else
	{
		var key = document.getElementById("txtSearch").value;
		if(key!="Type in subject, grade level, keyword, etc")
		{
			qryStr = qryStr+"&key="+key;
		}		
		window.location.href= serverpath+"search"+qryStr;
		var xmlHttp;		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		url="ajax_search.php?v="+key;
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				
			}		
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);		
	}		
}
function searchedProduct(page,productName)
{
	var key = document.getElementById("txtSearch").value;
	productName = productName.replace(/%6/g,"'").replace(/%7#/g," ");
	var xmlHttp;		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	url="ajax_search.php?v="+key+"&c="+productName;
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			window.location.href= serverpath+page;
		}		
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function searchProducts(searchType,grade,subject,media,searchTxt,pageNo)
{
	if(searchTxt=="Type in subject, grade level, keyword, etc")
	{
		searchTxt = "";
	}
	var qryStr = "?t="+searchType;
	if(searchType==1)
	{		
		qryStr = qryStr+"&g="+grade+"&s="+subject+"&m="+media;
	}
	else
	{
		var key = searchTxt;
		qryStr = qryStr+"&key="+key;
	}
	qryStr = qryStr+"&p="+pageNo;
	window.location.href= serverpath+"search"+qryStr;
}
function checkSearchClicked(e,obj)
{
	var e=window.event?event:e;	
	var srcElement=window.event?e.srcElement.id:e.target.id;
	if(e.keyCode==13)
	{		
		if(srcElement=="txtSearch")
		{			
			search(2);
		}		
	}
	else
	{
		/* if(obj.value.replace(/ /g,"")!="" && obj.value.replace(/ /g,"").length>=4)
		{
			var xmlHttp;
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			}
			url="ajax_dynamicsearch.php?param="+escape(obj.value);
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange=function()
			{
				if (xmlHttp.readyState==4)
				{
					var respText=xmlHttp.responseText;
					// if(respText.replace(/ /g,"")!="")
					// {
						// clearInterval(searchTimeout);
						// searchTimeout = setInterval(function(){showdynamicSearch(respText);}, 1200);
					// }
					// else
					// {
						// clearInterval(searchTimeout);
						// searchTimeout = setInterval(function(){hidedynamicSearch();}, 1200);
					// }
					document.getElementById("divSearchContainer").style.display="block";
					document.getElementById("divSearchContainer").innerHTML=respText;	
				}	
				else
				{
					document.getElementById("divSearchContainer").style.display="block";
					document.getElementById("divSearchContainer").innerHTML= "<img src='images/ajax-loader.gif' border='0' style='float:left;margin:10px 0px 10px 60px;width:100px;height:100px;'  />";
					clearInterval(searchTimeout);
				}			
			}			
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);	
		}
		else
		{			
			clearInterval(searchTimeout);
			document.getElementById("divSearchContainer").style.display="none";	
		} */
	}
}
function showdynamicSearch(respText)
{	
	document.getElementById("divSearchContainer").style.display="block";
	document.getElementById("divSearchContainer").innerHTML=respText;	
}
function hidedynamicSearch()
{
	document.getElementById("divSearchContainer").style.display="none";	
}
function addToCart(type,seriesCount,bundleCount)
{
	$(".msgAddCart").css("display", "none");
	var orgType = type;
	var params="";
	var prodCount  = 0;
	if(type==1)//series
	{
		if(document.getElementById("txtSeriesQty").value>0)
		{
			if(document.getElementById("HFMainProduct").value==1)
			{
				var productId =document.getElementById("HFProductId").value;
			}
			else
			{
				var productId =document.getElementById("HFProductSeries").value;
			}
			params = "&p1="+productId+"&q1="+document.getElementById("txtSeriesQty").value;
			prodCount = prodCount + 1;
		}
	}
	else if(type==2)//bundle
	{
		if(document.getElementById("txtBundleQty").value>0)
		{
			params = "&p1="+document.getElementById("HFBundleId_"+bundleCount).value+"&q1="+document.getElementById("txtBundleQty").value;
			prodCount = prodCount + 1;
		}
	}
	else if(type==3)//individual products
	{		
		if(document.getElementById("txtProductQty_"+seriesCount).value>0)
		{
			params = "&p1="+document.getElementById("HFProductId_"+seriesCount).value+"&q1="+document.getElementById("txtProductQty_"+seriesCount).value;
			prodCount = prodCount + 1;
		}
	}
	else//product
	{
		type=3;
		if(document.getElementById("txtProductQty").value>0)
		{
			params = "&p1="+document.getElementById("HFProductId").value+"&q1="+document.getElementById("txtProductQty").value+"&c=1";
			prodCount = prodCount + 1;
		}
	}
	if(prodCount>0)
	{
		var xmlHttp;		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		url="ajax_addtocart.php?t="+type+""+params;
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4)
			{
				document.getElementById("txtCartQty").innerHTML = xmlHttp.responseText;				
				popupTimeout = setInterval(hideMessageDiv, 2000);
				if(xmlHttp.responseText=="Empty")
				{
					document.getElementById("divCookieAlert").style.display = "inline";
				}
				else
				{
					document.getElementById("divAlertMessage").style.display = "inline";
				}
			}		
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else
	{
		alert("Please enter the quantity");
	}
}
function hideMessageDiv()
{
	clearInterval(popupTimeout);
	document.getElementById("divAlertMessage").style.display = "none";
	document.getElementById("divCookieAlert").style.display = "none";
}
function updateCart()
{
	document.forms[0].action="shopping_cartDB.php";
	document.forms[0].submit();		
}
function setCountry(type)
{
	if(document.getElementById("ddl"+type+"State").value>50)
	{
		document.getElementById("ddl"+type+"Country").value = 2;
	}
	else
	{
		document.getElementById("ddl"+type+"Country").value = 1;
	}
}
function resetStates(type)
{
	document.getElementById("ddl"+type+"State").value = 0;
}
function confirmShipping(checkoutOption)
{
	$(".errtextbox").attr("class", "textbox");
	$(".errdropdown").attr("class", "dropdown");
	document.getElementById("txtShipAddress1").className = "textarea";
	document.getElementById("ErrMsg").innerHTML = "";
	var errMsg=0;
	if(document.getElementById("txtShipFirstName").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipFirstName").className = "errtextbox";
		document.getElementById("txtShipFirstName").focus();
		errMsg=1;
	}	
	if(document.getElementById("txtShipLastName").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipLastName").className = "errtextbox";		
		if(errMsg==0)
		{
			document.getElementById("txtShipLastName").focus();
		}
		errMsg=1;
	}		
	if(document.getElementById("txtShipAddress1").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipAddress1").className = "errtextarea";		
		if(errMsg==0)
		{
			document.getElementById("txtShipAddress1").focus();
		}
		errMsg=1;
	}	
	if(document.getElementById("txtShipCity").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipCity").className = "errtextbox";
		if(errMsg==0)
		{
			document.getElementById("txtShipCity").focus();
		}
		errMsg=1;
	}
	if(document.getElementById("txtShipZipCode").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipZipCode").className = "errtextbox";
		if(errMsg==0)
		{
			document.getElementById("txtShipZipCode").focus();
		}
		errMsg=1;
	}	
	if(document.getElementById("ddlShipState").value==0)
	{
		document.getElementById("ddlShipState").className = "errdropdown";
		if(errMsg==0)
		{
			document.getElementById("ddlShipState").focus();
		}
		errMsg=1;
	}	
	if(document.getElementById("txtShipPhone").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipPhone").className = "errtextbox";
		if(errMsg==0)
		{
			document.getElementById("txtShipPhone").focus();
		}
		errMsg=1;
	}
	
	if(document.getElementById("txtShipEmail").value.replace(/ /g,"")=="")
	{
		document.getElementById("txtShipEmail").className = "errtextbox";
		if(errMsg==0)
		{
			document.getElementById("txtShipEmail").focus();
		}
		errMsg=1;
	}
	else if(!emailcheck(document.getElementById("txtShipEmail").value))
	{
		document.getElementById("txtShipEmail").className = "errtextbox";
		if(errMsg==0)
		{
			document.getElementById("txtShipEmail").focus();
		}
		errMsg=1;
	}		
	if(errMsg==0)
	{		
		document.getElementById("HFStateName").value = document.getElementById("ddlShipState").options[document.getElementById("ddlShipState").selectedIndex].text;
		document.getElementById("HFCountryName").value = document.getElementById("ddlShipCountry").options[document.getElementById("ddlShipCountry").selectedIndex].text;
		document.forms[0].action= securepath+"confirm_shippingDB.php?o="+checkoutOption;
		document.forms[0].submit();
	}
	else
	{
		document.getElementById("ErrMsg").innerHTML = "The fields in red are mandatory fields.";
	}
}
function applyCoupon()
{
	document.getElementById("HFCouponCode").value = "";
	document.getElementById("HFCouponValue").value = 0;
	document.getElementById("HFCouponType").value = 0;
	document.getElementById("HFDiscountValue").value = 0;
	document.getElementById("discountErrMsg").innerHTML = "";
	document.getElementById("spanDiscount").innerHTML = "";
	document.getElementById("discountUL").style.display = "none";
	var coupon = document.getElementById("txtCoupon").value;
	var total = document.getElementById("HFProductTotal").value;
	if(coupon.replace(/ /g,""))
	{		
		var xmlHttp;		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		url="ajax_applydiscount.php?c="+coupon+"&t="+total;
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4)
			{
				str = xmlHttp.responseText
				str = str.split(",")
				var discount = parseFloat(str[0]);
				if(discount>=0)
				{					
					document.getElementById("HFCouponCode").value = coupon;
					document.getElementById("HFCouponValue").value = str[1];
					document.getElementById("HFCouponType").value = str[3];
					document.getElementById("HFDiscountValue").value = discount;					
					document.getElementById("discountUL").style.display = "block";
					document.getElementById("discountVal").innerHTML = addCommas(discount.toFixed(2));
					document.getElementById("spanDiscount").innerHTML = str[2];
					var discTotal = parseFloat(total-discount);
					if(discTotal<0)
					{
						discTotal = 0;
					}
					document.getElementById("Total").innerHTML = addCommas(discTotal.toFixed(2));
					document.getElementById("HFTotal").value = discTotal;
				}
				else
				{
					document.getElementById("discountErrMsg").innerHTML = str[0];					
					document.getElementById("discountUL").style.display = "none";
					document.getElementById("Total").innerHTML = addCommas(parseFloat(total).toFixed(2));
					document.getElementById("HFTotal").value = total;
				}			
			}		
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else
	{
		document.getElementById("Total").innerHTML = addCommas(parseFloat(total).toFixed(2));
		alert('Please enter the Promotional Code.')
	}
}

function disableBillTxt()
{
	document.getElementById("txtBillFirstName").disabled = true;
	document.getElementById("txtBillFirstName").style.background = "#FFFFFF";
	document.getElementById("txtBillLastName").disabled = true;
	document.getElementById("txtBillLastName").style.background = "#FFFFFF";
	document.getElementById("txtSchool").disabled = true;
	document.getElementById("txtSchool").style.background = "#FFFFFF";
	document.getElementById("txtBillAddress1").disabled = true;
	document.getElementById("txtBillAddress1").style.background = "#FFFFFF";
	document.getElementById("txtBillCity").disabled = true;
	document.getElementById("txtBillCity").style.background = "#FFFFFF";
	document.getElementById("ddlBillState").disabled = true;
	document.getElementById("ddlBillCountry").disabled = true;
	document.getElementById("txtBillZipCode").disabled = true;
	document.getElementById("txtBillZipCode").style.background = "#FFFFFF";
	document.getElementById("txtBillPhone").disabled = true;
	document.getElementById("txtBillPhone").style.background = "#FFFFFF";
	document.getElementById("txtBillEmail").disabled = true;
	document.getElementById("txtBillEmail").style.background = "#FFFFFF";

	document.getElementById("txtBillFirstName").value= document.getElementById("HFShipFirstName").value;
	document.getElementById("txtBillLastName").value= document.getElementById("HFShipLastName").value;
	document.getElementById("txtSchool").value= document.getElementById("HFShipSchool").value;
	document.getElementById("txtBillAddress1").value= document.getElementById("HFShipAddress").value;
	document.getElementById("txtBillCity").value= document.getElementById("HFShipCity").value;	
	document.getElementById("ddlBillState").value= document.getElementById("HFShipState").value;
	document.getElementById("ddlBillCountry").value= document.getElementById("HFShipCountry").value;
	document.getElementById("txtBillZipCode").value= document.getElementById("HFShipZipcode").value;
	document.getElementById("txtBillPhone").value= document.getElementById("HFShipPhone").value;
	document.getElementById("txtBillEmail").value= document.getElementById("HFShipEmail").value;
	
}
function radOtherBilling()
{
	document.getElementById("txtBillFirstName").value= "";
	document.getElementById("txtBillLastName").value= "";
	document.getElementById("txtSchool").value= "";
	document.getElementById("txtBillAddress1").value= "";
	document.getElementById("txtBillCity").value= "";	
	document.getElementById("ddlBillState").value= 0;
	document.getElementById("ddlBillCountry").value= 0;
	document.getElementById("txtBillZipCode").value= "";
	document.getElementById("txtBillPhone").value= "";
	document.getElementById("txtBillEmail").value= "";
	
	document.getElementById("txtBillFirstName").disabled = false;
	document.getElementById("txtBillLastName").disabled = false;
	document.getElementById("txtSchool").disabled = false;
	document.getElementById("txtBillAddress1").disabled = false;
	document.getElementById("txtBillCity").disabled = false;
	document.getElementById("ddlBillState").disabled = false;
	document.getElementById("ddlBillCountry").disabled = false;
	document.getElementById("txtBillZipCode").disabled = false;
	document.getElementById("txtBillPhone").disabled = false;
	document.getElementById("txtBillEmail").disabled = false;	
}
function confirmBilling()
{
	var errMsg=0;
	$(".errdropdown").attr("class", "dropdown");
	if(!document.forms[0].radShip[0].checked)
	{
		$(".errtextbox").attr("class", "textbox");
		document.getElementById("txtBillAddress1").className = "textarea";
		document.getElementById("ErrMsg").innerHTML = "";		
		if(document.getElementById("txtBillFirstName").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillFirstName").className = "errtextbox";
			document.getElementById("txtBillFirstName").focus();
			errMsg=1;
		}
		if(document.getElementById("txtBillLastName").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillLastName").className = "errtextbox";		
			if(errMsg==0)
			{
				document.getElementById("txtBillLastName").focus();
			}
			errMsg=1;
		}
		if(document.getElementById("txtBillAddress1").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillAddress1").className = "errtextarea";		
			if(errMsg==0)
			{
				document.getElementById("txtBillAddress1").focus();
			}
			errMsg=1;
		}	
		if(document.getElementById("txtBillCity").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillCity").className = "errtextbox";
			if(errMsg==0)
			{
				document.getElementById("txtBillCity").focus();
			}
			errMsg=1;
		}
		if(document.getElementById("txtBillZipCode").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillZipCode").className = "errtextbox";
			if(errMsg==0)
			{
				document.getElementById("txtBillZipCode").focus();
			}
			errMsg=1;
		}		
		if(document.getElementById("ddlBillState").value=="0")
		{
			document.getElementById("ddlBillState").className = "errdropdown";
			if(errMsg==0)
			{
				document.getElementById("ddlBillState").focus();
			}
			errMsg=1;
		}				
		if(document.getElementById("txtBillPhone").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillPhone").className = "errtextbox";
			if(errMsg==0)
			{
				document.getElementById("txtBillPhone").focus();
			}
			errMsg=1;
		}		
		if(document.getElementById("txtBillEmail").value.replace(/ /g,"")=="")
		{
			document.getElementById("txtBillEmail").className = "errtextbox";
			if(errMsg==0)
			{
				document.getElementById("txtBillEmail").focus();
			}
			errMsg=1;
		}
		else if(!emailcheck(document.getElementById("txtBillEmail").value))
		{
			document.getElementById("txtBillEmail").className = "errtextbox";
			if(errMsg==0)
			{
				document.getElementById("txtBillEmail").focus();
			}
			errMsg=1;
		}		
	}	
	if(errMsg==0)
	{		
		document.getElementById("HFStateName").value = document.getElementById("ddlBillState").options[document.getElementById("ddlBillState").selectedIndex].text;
		document.getElementById("HFCountryName").value = document.getElementById("ddlBillCountry").options[document.getElementById("ddlBillCountry").selectedIndex].text;
		document.forms[0].action= securepath+"confirm_billingDB.php";   
		document.forms[0].submit();
	}
	else
	{
		document.getElementById("ErrMsg").innerHTML = "The fields in red are mandatory fields.";
	}
}

function checkCard()
{
	document.getElementById("txtCardNum").value="";
	document.getElementById("txtCVVNum").value="";
	document.getElementById("txt4DBCNum").value="";
	if(document.getElementById("ddlCardType").value==3)
	{
		document.getElementById("LI_CVVNum").style.display = "none";
		document.getElementById("LI_4DBCNum").style.display = "block";
		$("#txtCardNum").attr("maxlength", "15");
	}
	else
	{
		document.getElementById("LI_CVVNum").style.display = "block";
		document.getElementById("LI_4DBCNum").style.display = "none";
		$("#txtCardNum").attr("maxlength", "16");
	}	
}
function confirmPayment()
{	
	
	
		document.getElementById("overlay").style.height = document.getElementById("mainContainer").clientHeight+210+"px";
		document.getElementById("overlay").style.display= "block";
		document.getElementById("divProcessing").style.display= "block";
		document.forms[0].action = securepath+"payment_confirmDB.php";
		document.forms[0].submit();
	
}
function showCCV()
{
	scroll(0,0)
	document.getElementById("overlay").style.height = document.getElementById("mainContainer").clientHeight+210+"px";
	document.getElementById("overlay").style.display= "block";
	document.getElementById("divCCVNum").style.display= "block";
}
function hideCCV()
{
	document.getElementById("overlay").style.display= "none";
	document.getElementById("divCCVNum").style.display= "none";
}
function printOrder()
{
    var width=500;
    var height=300;
    if (screen) 
    {
        width = parseInt(screen.width)-15;
        height = parseInt(screen.height)-90;
    }
    window.open('printorder_page.php?p='+document.getElementById("HFOrderId").value,'Order','scrollbars=yes,resizable=yes,menu=yes,width='+width+',height='+height+',top=0,left=0');
}
function printCart()
{
    var width=500;
    var height=300;
    if (screen) 
    {
        width = parseInt(screen.width)-15;
        height = parseInt(screen.height)-90;
    }
    window.open('print_cart.php','Cart','scrollbars=yes,resizable=yes,menu=yes,width='+width+',height='+height+',top=0,left=0');
}
function cartCheckout()
{
	document.forms[0].action = securepath+"confirm_shipping.php";
	document.forms[0].submit();
}

function getOrderDetails(orderId)
{		
	var xmlHttp;		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	url="ajax_getOrderDet.php?p="+orderId;
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			if(xmlHttp.responseText!="")
			{
				document.getElementById("divOrderDetails").innerHTML = xmlHttp.responseText;
			}
			else
			{
				document.getElementById("divOrderDetails").innerHTML = "<div style='float:left;margin-top:20px;'>Sorry, This order id does not exist!</div>";
			}
		}		
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function sendOrder()
{
	if(document.getElementById("filePrintOut").value!="")
	{
		fileName = document.getElementById("filePrintOut").value
		var pathLength = fileName.length;
		var lastDot = fileName.lastIndexOf(".");
		var fileType = fileName.substring(lastDot,pathLength);
		if(fileType != ".pdf" && fileType != ".PDF" && fileType != ".doc" && fileType != ".DOC" && fileType != ".docx" && fileType != ".DOCX" && fileType != ".xls" && fileType != ".XLS" && fileType != ".xlsx" && fileType != ".XLSX" && fileType != ".jpg" && fileType != ".JPG" && fileType != ".JPEG" && fileType != ".jpeg" && fileType != ".rtf" && fileType != ".RTF" && fileType != ".gif" && fileType != ".GIF" && fileType != ".png" && fileType != ".PNG" && fileType != ".bmp" && fileType != ".BMP" && fileType != ".tif" && fileType != ".TIF") 
		{
			alert("Only .pdf, .doc, .xls, .docx, .xlsx, .jpg, .rtf, .gif, .png, .bmp, .tif  formats allowed");
		}
		else
		{
			document.forms[0].action = "payment_orderDB.php";
			document.forms[0].submit();
		}		
	}
	else
	{
		alert("Please attach the Purchase order.");
	}	
}

function showVideo(id)
{
	scroll(0,0);
	var xmlHttp;		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	url="ajax_videoclip.php?p="+id;
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			document.getElementById("overlay").style.height = document.getElementById("mainContainer").clientHeight+210+"px";
			document.getElementById("overlay").style.display= "block";
			document.getElementById("divVideoContainer").innerHTML = xmlHttp.responseText;
			document.getElementById("divVideoContainer").style.display= "block";
		}		
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}
function hideVideo()
{
	document.getElementById("overlay").style.display= "none";
	document.getElementById("divVideoContainer").style.display= "none";
	document.getElementById("divVideoContainer").innerHTML = "";
}
function choosePO(type)
{	
	if(document.getElementById("HFOrderType").value!=type)
	$(".divPODesc").slideUp();

	if(type==1)
	{
		$("#divChooseOrder_1").slideDown();		
	}
	else if(type==2)
	{
		$("#divChooseOrder_2").slideDown();
		document.getElementById("ULAttachOrder").style.display="none";
		document.getElementById("txtOrderId").value = "";
		document.getElementById("divOrderDetails").innerHTML = "";
	}
	document.getElementById("HFOrderType").value=type;
}
function removeFromCart(id)
{
	if(confirm("Are you sure you want to remove this product from cart?"))
	{
		document.forms[0].action = "shopping_cartDB.php?id="+id;
		document.forms[0].submit();
	}
}
function sendmail()
{
	var errMsg;
	errMsg = "";
	var focuscontrol;
	focuscontrol="";
	var name = document.getElementById('Txtfname').value.replace(/ /g,"");
	if(name=="")
	{
		focuscontrol='Txtfname';
		errMsg = "Please enter the first name.";
	}
	var lname = document.getElementById('Txtlname').value.replace(/ /g,"");
	if(lname=="")
	{
		if (focuscontrol=="")
		{
		focuscontrol='Txtlname';
		}
		errMsg = errMsg+"\nPlease enter the last name.";
	}
	var Email = document.getElementById('Txtemail').value;
	if(Email=="")	
	{
		if (focuscontrol=="")
		{
		focuscontrol='Txtemail';
		}
		errMsg = errMsg+"\nPlease enter your Email address";
	}
	else
	{
		if(!emailcheck(Email))
		{
		if (focuscontrol=="")
		{
		focuscontrol='Txtemail';
		}
		errMsg = errMsg+"\nPlease enter a valid Email address";
		}
	}
	if(document.getElementById('txtcomments').value.replace(/ /g,"")=="" || document.getElementById('txtcomments').value=="Type your question or comment here.")
	{
		if (focuscontrol=="")
		{
		focuscontrol='txtcomments';
		}
		errMsg = errMsg+"\nPlease enter the Question or Comments.";
	}
	if(errMsg!="")
	{
		alert(errMsg)
		if (focuscontrol!="")
			{
				document.getElementById(focuscontrol).focus();
			}
	}
	else
	{
		document.getElementById("HFstate").value=document.getElementById("ddlState").options[document.getElementById("ddlState").selectedIndex].text;
		document.forms[0].action="contactDB.php"
		document.forms[0].submit();
	}
}
function showPrevVideos(pageNo)
{	
	window.location.href= "previewvideos.php"+"?p="+pageNo;
}
function printOrder(orderId)
{
    var width=500;
    var height=300;
    if (screen) 
    {
        width = parseInt(screen.width)-15;
        height = parseInt(screen.height)-90;
    }
    window.open('order_print.php?param='+orderId,'Order','scrollbars=yes,resizable=yes,menu=yes,width='+width+',height='+height+',top=0,left=0');
}
function openTeachingGuideAcc(objName)
{
	$(".divTeachingGuides div").slideUp();
	$("#"+objName+" div").slideDown();
}

function editShoppingCart()
{
	if(document.getElementById("HFDiscountCoupon").value!="")
	{
		alert("Note: You have added a coupon code to this order. After you edit the order or shipping details, you will need to use the coupon code again during checkout.")
	}
	window.location.href=serverpath+'shopping_cart.php'
}
function editShippingDetails()
{
	if(document.getElementById("HFDiscountCoupon").value!="")
	{
		alert("Note: You have added a coupon code to this order. After you edit the order or shipping details, you will need to use the coupon code again during checkout.")
	}	
	window.location.href='confirm_shipping.php?opt='+document.getElementById("HFCheckoutOption").value;
}
