function popWin(page,name,w,h)
{
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = ((screen.height) ? (screen.height-h)/2 : 0) - 50;
	var showLocation='no';
	
	if(name=='_cart')
		showLocation='yes';
		
  var w = window.open(page,name,'scrollbars=yes,toolbar=no,statusbar=1,location='+showLocation+',width='+w+',height='+h+',resizable=yes'+',top='+TopPosition+',left='+LeftPosition);
}

function popWinToolbar(page,name,w,h)
{
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = ((screen.height) ? (screen.height-h)/2 : 0) - 50;
	var showLocation='no';
	
	if(name=='_cart')
		showLocation='yes';
		
  var w = window.open(page,name,'menubar=1,scrollbars=yes,toolbar=yes,statusbar=1,location='+showLocation+',width='+w+',height='+h+',resizable=yes'+',top='+TopPosition+',left='+LeftPosition);
}

function popWinNoToolbar(page,name,w,h)
{
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = ((screen.height) ? (screen.height-h)/2 : 0) - 50;
	
		
  var w = window.open(page,name,'menubar=0,scrollbars=yes,toolbar=no,statusbar=0,location=no,width='+w+',height='+h+',resizable=no'+',top='+TopPosition+',left='+LeftPosition);
}

function refreshParentWin()
{
	if(window.opener){
		//window.opener.location.href = window.opener.location.href;
		window.opener.location.reload();
	}
}

function showSpecialOffer(obj)			
{	
	var curtop = findPosY(obj);				
	var e = document.getElementById('specialOffer');				
	e.style.display="block";
	e.style.top=(curtop+15)+'px';
	e.style.left='5px';					
}

function hideSpecialOffer()			
{				
	var e = document.getElementById('specialOffer');				
	e.style.display="none";							
}	

function findPosX(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 findPosY(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;
}

var selectedShippingPrices = new Array();

function reCalcTotals(currShipSelection, row){
	var oOrder = document.getElementById("order_total");
	var orderTotal 	=	parseFloat(oOrder.value);
	var oShip = document.getElementById("ship_total");
	var shipTotal 	=	parseFloat(oShip.value);				
	var prevShipSelection = parseFloat(selectedShippingPrices[row]);
	
	selectedShippingPrices[row] = currShipSelection;
	shipTotal += (currShipSelection-prevShipSelection);
	orderTotal += (currShipSelection-prevShipSelection);		
	
	oShip.value=shipTotal;
	oOrder.value=orderTotal;

	document.getElementById("order_total_display").innerHTML=formatCurrency(orderTotal);
	document.getElementById("ship_total_display").innerHTML=formatCurrency(shipTotal);
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function populateBillingInfo(frm, bChecked){	
	if(bChecked)
	{
		document.getElementById("billToFirstName").value=document.getElementById("shipToFirstName").value;
		document.getElementById("billToLastName").value=document.getElementById("shipToLastName").value
		document.getElementById("billToAddress.address1").value=document.getElementById("shipToAddress.address1").value;  
		document.getElementById("billToAddress.address2").value=document.getElementById("shipToAddress.address2").value;  
		document.getElementById("billToAddress.zip5").value=document.getElementById("shipToAddress.zip5").value;    
		document.getElementById("billToAddress.state").value=document.getElementById("shipToAddress.state").value;      
		document.getElementById("billToAddress.city").value=document.getElementById("shipToAddress.city").value;    		   
	}
	else
	{
		document.getElementById("billToFirstName").value="";
		document.getElementById("billToLastName").value="";  
		document.getElementById("billToAddress.address1").value="";  
		document.getElementById("billToAddress.address2").value="";  
		document.getElementById("billToAddress.zip5").value="";    
		document.getElementById("billToAddress.state").value="";      
		document.getElementById("billToAddress.city").value="";    		   		
	}
	           		           	           
}

function populateShippingInfo(frm, bChecked){	
	if(bChecked)
	{
		document.getElementById("shipToFirstName").value=document.getElementById("billToFirstName").value;
		document.getElementById("shipToLastName").value=document.getElementById("billToLastName").value
		document.getElementById("shipToAddress.address1").value=document.getElementById("billToAddress.address1").value;  
		document.getElementById("shipToAddress.address2").value=document.getElementById("billToAddress.address2").value;  
		document.getElementById("shipToAddress.zip5").value=document.getElementById("billToAddress.zip5").value;    
		document.getElementById("shipToAddress.state").value=document.getElementById("billToAddress.state").value;      
		document.getElementById("shipToAddress.city").value=document.getElementById("billToAddress.city").value;    		   
	}
	else
	{
		document.getElementById("billToFirstName").value="";
		document.getElementById("billToLastName").value="";  
		document.getElementById("billToAddress.address1").value="";  
		document.getElementById("billToAddress.address2").value="";  
		document.getElementById("billToAddress.zip5").value="";    
		document.getElementById("billToAddress.state").value="";      
		document.getElementById("billToAddress.city").value="";    		   		
	}
	           		           	           
}

function showWaitMsg(){
	document.getElementById("submit").style.display='none';
	document.getElementById("loading").style.display='block';
		
}

function showButtonWaitMsg(btn){
	btn.style.display='none';
	document.getElementById("loading").style.display='block';
		
}

function hideWaitMsg(){
	document.getElementById("submit").style.display='block';
	document.getElementById("loading").style.display='none';	
}

function hideButtonWaitMsg(btn){
	btn.style.display='block';
	document.getElementById("loading").style.display='none';	
}

function replaceDivAjax(targetUrl, target){
	
	var xmlHttp;
	try {    // Firefox, Opera 8.0+, Safari    
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {    
	  	// Internet Explorer    
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			target.innerHTML = xmlHttp.responseText;
	  }
	};
	xmlHttp.open("POST", targetUrl, true);
	xmlHttp.send(null);

}

function ajaxCallWithMethod(targetUrl){
	
	var xmlHttp;
	try {    // Firefox, Opera 8.0+, Safari    
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {    
	  	// Internet Explorer    
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
	  }
	};
	xmlHttp.open('POST', targetUrl, true);
	xmlHttp.send(null);

}

function showProcessing(box) {
	box.innerHTML = "Processing...";
}