//var product page
debut="";
hp = "";
prd = "";
cat = ""

//var diagnostics code
diagCode = "";

// popup for the checkout pages
function popcheckout(URL)
{ 
	newWin = window.open(URL,"popup","width=748,height=369,top=10,left=10,resizable=0,toolbar=0,scrollbars=0,status=0,menubar=0");
}

var newWindow

function openPopup(url, popupWidth, popupHeight) {
	if (newWindow && !newWindow.closed)	{
		newWindow.close()
	}	
		
	var winl = (screen.width - popupWidth) / 2;
	var wint = (screen.height - popupHeight) / 2;
		
	newWindow = open(url, 'Biotherm', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
	newWindow.focus();
}

function openPopupPrint(url, popupWidth, popupHeight) {
	if(diagCode != '')
	{
		openPopup(url + '?catcode=' + diagCode, popupWidth, popupHeight);
	}
	else
	{
		openPopup(url, popupWidth, popupHeight);
	}
}



function AutoPost(oSelect)
{
	if (oSelect.options[oSelect.selectedIndex].value != '')
	{
		document.location = "index.aspx?StateID=" + oSelect.options[oSelect.selectedIndex].value;
	}
}

function AddToBag(SKU,RetailerSKU)
{
	var mf = GetMainFormName();

	var quantitySelect = GetElement("quantity_" + SKU,mf); 
	var quantity = quantitySelect.options[quantitySelect.selectedIndex].text; 
	
	if (location.search.indexOf('rtlid')!=-1)
		window.location = GetRetailerLocation(RetailerSKU,quantity);
	else
		window.location = '../checkout/Purchase_from_url.aspx?q=' + quantity + '&prdcode=' + SKU;
}

function AddToBag_men(SKU,RetailerSKU)
{
	var mf = GetMainFormName();

	var quantitySelect = GetElement("quantity_" + SKU,mf); 
	var quantity = quantitySelect.options[quantitySelect.selectedIndex].text; 
	
	if (location.search.indexOf('rtlid')!=-1)
		window.location = GetRetailerLocation(RetailerSKU,quantity);
	else
		window.location = '../../checkout_men/Purchase_from_url.aspx?q=' + quantity + '&prdcode=' + SKU;
}


function AddToBag_man(SKU)
{
	var mf = GetMainFormName();

	var quantitySelect = GetElement("quantity_" + SKU,mf); 
	var quantity = quantitySelect.options[quantitySelect.selectedIndex].text; 
	window.location = '../checkout_men/Purchase_from_url.aspx?q=' + quantity + '&prdcode=' + SKU;
}

function AddToBag_club(SKU)
{
	var mf = GetMainFormName();

	var quantitySelect = GetElement("quantity_" + SKU,mf); 
	var quantity = quantitySelect.options[quantitySelect.selectedIndex].text; 
	window.location = '/_us/_en/checkout/Purchase_from_url.aspx?q=' + quantity + '&prdcode=' + SKU;
}

function AddToBag_club_men(SKU)
{
	var mf = GetMainFormName();

	var quantitySelect = GetElement("quantity_" + SKU,mf); 
	var quantity = quantitySelect.options[quantitySelect.selectedIndex].text; 
	window.location = '../../../checkout_men/Purchase_from_url.aspx?q=' + quantity + '&prdcode=' + SKU;
}

function GetRetailerLocation(code,qty)
{
	//PJ: Please make sure that the correct macys url is in production everytime something on this page is changed.
	//Production url: externalurl = "http://www1.macys.com/bag/addto.ognc?AddToBagCall=External&Brand=Biotherm&";
	//Staging and other env externalurl = "http://www1.intmacys.fds.com/bag/addto.ognc?AddToBagCall=External&Brand=Biotherm&";
	//At this time the staging url is not working so setting the production url.
	externalurl = "http://www1.macys.com/bag/addto.ognc?AddToBagCall=External&Brand=Biotherm&";
	externalurl += "Upc=" + code + "&";
	externalurl += "Quantity="+ qty +"&";
	externalurl += "PartnerURL=" + urlEncode(document.location);
	externalurl += "&PseudoCat=ct-vb-sy-bi.index";
	return externalurl;
}

function poplog()
{
	//var winl = (screen.width - 400) / 2;
	//var wint = (screen.height - 450) / 2;
	openPopup("../club/popup_login_product.aspx", 430,450);
}	
	
review_width  = 520
review_height = 550;	

function openPopup_Review(url) {
	openPopup(url, review_width, review_height);
}
	
function poplog_review()
{
	openPopup("../club/popup_login_review.aspx", 430,450);
	//var winl = (screen.width - review_width) / 2;
	//var wint = (screen.height - review_height) / 2;
	//window.open("../club/popup_login_review.aspx",'popup_login',"width="+review_width+",height="+review_height+",top=" + wint + ",left=" + winl + ",resizable=0,toolbar=0,scrollbars=0,status=0,menubar=0");
}

function position_review()
{
//	window.resizeTo(review_width,review_height);	
//	var winl = (screen.width - review_width) / 2;
//	var wint = (screen.height - review_height) / 2;	
//	window.moveTo(winl,wint);
}

var myimages=new Array()

function MM_preloadImages() { 
for (i=0;i<MM_preloadImages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=MM_preloadImages.arguments[i]
}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null)
{
document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
}
}

function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

function GetSeal()
{
 document.write("<script language=Javascript src=https://seal.verisign.com/getseal?host_name=www.biotherm-usa.com&size=S&use_flash=YES&use_transparent=YES&lang=en></script>") ;	
}

//Function to validate zipcode: Zip should have 5 numeric characters
function ValidateZip()
{	
	/*Check if the object exists before manipulating the values */
	if(document.all.divZipError!= null)
	{
		document.all.divZipError.style.display = "none";
			
		var mf = GetMainFormName();				
		var zipTextboxRef =  GetElementName("address_zip", mf);
		var zipTextbox = document.forms[mf].elements[zipTextboxRef];
		
		//If zip code is not entered, then let the webbox validation methods capture that error. 
		//This will enable the validation to work when "ship to billing" address checkbox is checked.
		if(zipTextbox.value.length == 0)
		{
			return true;
		}
		else
		{
			var allValid = true;
			
			var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/

			if (objRegExp.exec(zipTextbox.value) == null) allValid = false;
			
			if (!allValid) 
			{
				document.all.tblcellZip.style.color = "#FF0000";
				document.all.divZipError.style.display = "block";
				return false;
			}	
			else
			{
				validateDate();
				return true;
			}						
		}
	}
	else
	{
		return false;
	}
}

function SetZip(zipcode,ctrlname)
{
	alert(zipcode.value);
	var mf = GetMainFormName();
	if (mf==null) return;
	
	var ctrl = GetElementName(ctrlname,mf)
	if (ctrl!= null)
		document.forms[mf].elements[ctrl].value = zipcode.value;
}

function CheckZipCode(zipCtrl, errorMsgCtrl, tblCell)
{	
	var mf = GetMainFormName();
	
	var zipname = zipCtrl + ":" + "address_zip" ;	
	
	var zipCode = GetElement(zipname, mf);	
	
	var divZipError = document.getElementById(errorMsgCtrl);
		
	var tblcellZip = document.getElementById(tblCell);
		
	/*Check if the object exists before manipulating the values */
	if(divZipError!= null)
	{
		divZipError.style.display = "none";
				
		//If zip code is not entered, then let the webbox validation methods capture that error. 
		//This will enable the validation to work when "ship to billing" address checkbox is checked.
		if(zipCode != null && zipCode.value.length == 0)
		{
			return true;
		}
		else
		{
			var allValid = true;
			
			var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/

			if (objRegExp.exec(zipCode.value) == null) allValid = false;
			
			if (!allValid) 
			{
				if(tblcellZip != null) tblcellZip.style.color = "#FF0000";
				divZipError.style.display = "block";
				return false;
			}	
			else
			{
				return true;
			}						
		}
	}
	else
	{
		return false;
	}
}

function CheckNumeric(e) 
{ 
var key;var keychar; var reg; 
if(window.event) { // for IE, e.keyCode or window.event.keyCode can be used 
key = e.keyCode; 
} 
else if(e.which) { // netscape 
key = e.which; } 
else { // no event, so pass through 
return true; } 
if ( (key>47 && key<58) || (key==8) ){ return key; }else { return false;} 
} 

function validateDate()
{
	var mf = GetMainFormName();
	var monthTextboxName = GetElementName("birthmonth", mf);
	var dayTextboxName = GetElementName("birthday", mf);
	var yearTextboxName = GetElementName("birthyear", mf);
	
	/*Check if the object exists before manipulating the values */
	if(monthTextboxName != null && dayTextboxName != null && yearTextboxName != null)
	{	var monthTextbox =  document.forms[mf].elements[monthTextboxName];
		var dayTextbox	=  document.forms[mf].elements[dayTextboxName];
		var yearTextbox =  document.forms[mf].elements[yearTextboxName];
		
		/*Check if the object exists before manipulating the values */
		if(monthTextbox != null && dayTextbox != null && yearTextbox != null)
		{
			if (monthTextbox.value =='MM' && dayTextbox.value =='DD' && yearTextbox.value=='YYYY')
			{
				monthTextbox.value ='';
				dayTextbox.value ='';
				yearTextbox.value ='';
			}
		}
	}
}		

function Browser() {
  var ua, s, i;
  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;
  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

function ShowHideLayer(layerId){
		
	var layerObj = document.getElementById(layerId);
	if ( layerObj != null ){

		if ( layerObj.style.visibility == 'hidden' )
			layerObj.style.visibility = 'visible';
		else
			layerObj.style.visibility = 'hidden';
	}
}

