
	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;
	}

	//Shows/hides the right CONSUMER/PHYSICIAN panels
	function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v; }
	}

	//Calculates the SubTotal value on the Product Detail page based on the Variant/Price and Qty dropdowns
	function calculateSubTotal()
	 {		
		var mf = GetMainFormName();
		if (mf==null) return;	
		
		var quantitySelect = GetElement("QtyList",mf); 
		var quantity = quantitySelect.options[quantitySelect.selectedIndex].value; 
		var variantSelect = GetElement("VarList",mf); 
		var variant = variantSelect.options[variantSelect.selectedIndex].value; 
		var	val = variant.substring(variant.indexOf("#")+ 1,variant.length);
		var sku = variant.substring(0,variant.indexOf("#"));
		var subTotal = document.getElementById("SubTotal");
		
		if (val.indexOf("#") == -1)
		{
			var subTotalValue = (val * quantity);
		}
		else
		{
			val = variant.substring(variant.indexOf("#")+ 1,variant.lastIndexOf("#"));
			
			var subTotalValue = (val * quantity);
		}
		if (quantity != null && variant != null)
		{
			//Add the $ sign and 2 decimal points to the subTotal
			subTotal.innerHTML = '$ ' + subTotalValue.toFixed(2);
		}	
		
		setBackorderMessage(sku, 'boMessage');
	}
	
		
	// Used to set the back order message, if necessary.
function setBackorderMessage(sku, backorderMessageID)
{
	// Get a reference to the back order message object.
	var divBackorderMessage = document.getElementById(backorderMessageID);		
	hideControls();
	if (divBackorderMessage != null)
	{
		try
		{
			//get the back order information for the sku (if it exists)
			
			stock = eval('var'+sku);
			
			// if we get to this point, stock will hold a value:
			// <stock>#<backorder status>#<backorder date>
			// Seperate the values here.
			temp = stock.substring(stock.indexOf("#")+1,stock.length);
			isBackordered = temp.substring(0,temp.indexOf("#"));
			backorderedDate = temp.substring(temp.indexOf("#")+1,temp.length);
			stock = stock.substring(0,stock.indexOf("#"));
			
			// Only display the back order message if the stock is less than 1.
			if (stock<1)
			{
				// If the back order date is valid and the backorder status is <> 0, set the back/pre order message.
				if(backorderedDate != "" && isBackordered != 0)  // Has a valid backorder status and valid back order date.
				{
					divBackorderMessage.innerHTML = "This product will not be shipped until approximately " + backorderedDate + ". Your credit card will be charged when your order ships.";
				}
				else
				{
					if (isBackordered == 1) // Backorder
					{   //The following message is changed as per DT#1154-Backorder copy on product description page
						//divBackorderMessage.innerHTML = "This product is backordered and will ship separately from any other items you may have ordered." ;
						divBackorderMessage.innerHTML = "THIS ITEM IS CURRENTLY BEING PRE-SOLD FOR FUTURE DELIVERY. Order now to reserve your product. You will receive free standard shipping when your order ships in late April.";
					}
					else if (isBackordered == 2) // Preorder
					{
						divBackorderMessage.innerHTML = "This product will not be shipped until approximately " + backorderedDate + ". Your credit card will be charged when your order ships.";
					}
				}
			}
		}
		catch (er) 
		{
			// If the variable containing back/pre order information is not found, exit normally and reset the backorder message.
			divBackorderMessage.innerHTML = "" ;
		}
	}
	

}
	
function DisplayCCLastFourDigit()
{
	divCCLastFourDigitMessage = document.getElementById('CCLastFourDigitMessage');	
	var mf = GetMainFormName();
	if (mf==null) return;

	var paymentChoice = GetElement("paymentChoice",mf); 
	if (paymentChoice != null)
	{
		var choice = paymentChoice.options[paymentChoice.selectedIndex].value; 
	}
	if 	(divCCLastFourDigitMessage != null)
	{
		try
		{
			var ccLastFourValue
			ccLastFourValue = eval('CCFourDigit');
			temp = ccLastFourValue.substring(ccLastFourValue.indexOf("#")+1,ccLastFourValue.length);
			cctype = temp.substring(0,temp.indexOf("#"));
			ccLastFourDigit = temp.substring(temp.indexOf("#")+1,temp.length);
			piType = ccLastFourValue.substring(0,ccLastFourValue.indexOf("#"));
			
			if(piType == choice && piType == 1)
			{
				if (ccLastFourDigit != null || ccLastFourDigit!= "")
				{
					divCCLastFourDigitMessage.innerHTML = "<SPAN class=VdrkGrey11_R>Credit Card Number:</span><span style=padding-left:65px></span> XXXXXXXXXXXX" + ccLastFourDigit;
				}	
			} 
			else
			{
				divCCLastFourDigitMessage.innerHTML ="";
			}
		}
		catch(er)
		{
			divCCLastFourDigitMessage.innerHTML = "" ;
		}
    }

}	
	function hideControls()
	{
		var mf = GetMainFormName();
		if (mf==null) return;
		var variantSelect = GetElement("VarList",mf); 
		var variant = variantSelect.options[0].value; 	
		if (variant == "")
		{
			//hide the add to bag button , add to regimen, subtotal section if the item is out of stock
			// firefox was not supporting hiding with one <tr> tag.
			document.getElementById("hideSection1").style.display = "none";
			document.getElementById("hideSection2").style.display = "none";	
			document.getElementById("hideSection3").style.display = "none";	
		}
	}
	
	
	
	//Displays or hides a given DIV element...it does this based on the current visibility status of the DIV
	function showHideItem(myItem)
	{
		//This is the ID of the DIV item to display or hide
		var myItem = document.getElementById(myItem);

		if (myItem.style.display != "none") 
		{
			//Item is currently displayed, so hide it
			myItem.style.display = "none";
		
		}
		else 
		{
			//Item is currently hidden, so display it
			myItem.style.display = "block";
		}
	}

	//Prints a page
	function printPage()
	{
		var agt = navigator.userAgent.toLowerCase();
		
		if (window.print) 
		{
			setTimeout('window.print();', 333);
		}
		else if (agt.indexOf("mac") != -1) 
		{
			alert("Press 'Cmd+p' on your keyboard to print article.");
		}
		else 
		{
			alert("Press 'Ctrl+p' on your keyboard to print article.")
		}
	}
	var newWindow
	//Open a pop-up window
	function openPopup(url, popupWidth, popupHeight) 
	{
		var newWindow;
		
		if (newWindow && !newWindow.closed)	
		{
			newWindow.close();
		}	
			
		var winl = (screen.width - popupWidth) / 2;
		var wint = (screen.height - popupHeight) / 2;
			
		newWindow = open(url, 'LRP', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
		newWindow.focus();
	}
	
	function openLargePopup(url, popupWidth, popupHeight) {
	if (newWindow && !newWindow.closed)	{
		newWindow.close()
	}	
		
	var winl = (screen.width - popupWidth) / 2;
	var wint = (screen.height - popupHeight) / 2;
		
	newWindow = open(url, 'LRP', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
	newWindow.focus();
}
	
	
	//Function to clear the MM, DD and YYYY textboxes if nothing is entered by user at the time of checkout
	//Also validates that correct format is entered for MM, DD and YYYY.
	function validateDate(errorMsgCtrl)
	{
		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 ='';
				}
				else
				{
					//Validate the MM, DD, YYYY values entered
					var month = monthTextbox.value;
					var day = dayTextbox.value;
					var year = yearTextbox.value;
					var objMonthDayRegExp = /(^\d{2}$)/;
					var objYearRegExp = /(^\d{4}$)/;					
					
					if (objMonthDayRegExp.exec(month) == null || objMonthDayRegExp.exec(day) == null || objYearRegExp.exec(year) == null) 
					{	
						var divDateError = document.getElementById(errorMsgCtrl);
						/*Check if the object exists before manipulating the values */
						if(divDateError != null)
						{
							//Display Birthdate error
							divDateError.style.display = "block";
							return(false);
						}
						else
						{
							//Correct format - Hide any errors
							divZipError.style.display = "none";
							return(true);
						}
					}
				 }
			}
		}
	}		

	//Function to validate zipcode: Zip should have 5 numeric characters
	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 goPhysicianSearch(FieldName)
	{	
		var mf = GetMainFormName();		
		if (mf==null) return;
		
		var searchItems = FieldName.split(',');
		var searchQuery = "";
		for(i=0;i<searchItems.length;i++)
		{
			var searchVal = document.forms[mf].elements[searchItems[i]].value;
			if(searchVal != "")
			{
				searchVal = searchVal.toLowerCase();
				searchQuery += searchItems[i] + "=" + searchVal + "&";
			}
		}

		document.forms[mf].action="index.aspx?" + searchQuery;
		document.forms[mf].submit();
	}	
	
	function goPhysicianReset()
	{	
		var mf = GetMainFormName();		
		if (mf==null) return;
		
		document.forms[mf].action="index.aspx";
		document.forms[mf].submit();
	}
	function GetProductCode()
	{
		var strValue;
		// Begin: Try to get Variant ID from form dropdown.
		// Developer Comment: The Variant ID must be stored in the user's Favorites list, in order for the product to display properly in the Favorites list. 
		var mf = GetMainFormName();
		if (mf != null)
		{
			var sel = GetElementName("VarList", mf);
			if (sel != null)
			{
				if (document.forms[mf].elements[sel].value != null)
				{
					strValue = document.forms[mf].elements[sel].value;
				}
			}
		}
		return strValue;
	}

	function poplog(){
		var prd = GetProductCode();
		openPopup("/_us/_en/Consumer/club/add_favorite_from_popup.aspx?prdcode=" + prd, 350,350);
		//openPopup("../club/add_favorite_from_popup.aspx?prdcode=" + prd, 350,350);
		//window.location = "../club/add_favorite_from_popup.aspx?prdcode=" + prd;
	}
	

	
	function favDelete(prd)
	{
		openPopup("del_favorite_popup.aspx?prdcode=" + prd, 350,350);
		//window.location = "del_favorite_popup.aspx?prdcode=" + prd;
	}
	
	function insertFlash(movie, quality, width, height, bgcolor, menu, version, title)
	{
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+version+",0,0,0' width='"+width+"' height='"+height+"' title='"+title+"'>");
	document.write("<param name='movie' value='"+movie+"' />");
	document.write("<param name='quality' value='"+quality+"' />");
	document.write("<param name='menu' value='"+menu+"' />");
	document.write("<param name='bgcolor' value='#"+bgcolor+"' />");;
	document.write("<param name='wmode' value='opaque'>");

	document.write("<embed src='"+movie+"' wmode='opaque' quality='"+quality+"' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' menu='"+menu+"' bgcolor='#"+bgcolor+"' width='"+width+"' height='"+height+"'></embed>");
	document.write("</object>");
	}
	
	var PhysicianID="";
	var PhysicianName="";
	function PhysicianProfile(id,physName){
		PhysicianID = id;
		PhysicianName = physName;  
	}
	
	function sampleChoiceVal() 
				{

			var mf = GetMainFormName();		
			if (mf==null) return;
			
			var SampleChoice = GetElement("SampleChoice",mf); 
			var quantityAndTopic = SampleChoice.options[SampleChoice.selectedIndex].value; 
			var topic = quantityAndTopic.substring(quantityAndTopic.indexOf("#")+ 1,quantityAndTopic.length)
			var boxes = document.getElementById("Boxes");
			var packets = document.getElementById("Packets");
			var mixMatch = document.getElementById("Mixmatch");
			
			
			var _f = document.forms[0];
	
			for (i=0;i<_f.elements.length;i++)
			{

				if (_f.elements[i].id.indexOf("SampleChoice") == -1)
				{
					
					var chk = _f.elements[i];
				
					//chk.checked = false;
					if (_f.elements[i].id.indexOf(topic) != -1)
					  {				
					
						if (topic.indexOf("Packets") != -1)
						{
							if (boxes != null)
							{
								document.getElementById("Boxes").style.display = "none";
							}
							if (mixMatch != null)
							{
								document.getElementById("Mixmatch").style.display = "none";
							}
							
							if (packets != null)
							{
								document.getElementById("Packets").style.display = "";
							}
						}
						else if(topic.indexOf("Boxes") != -1)
						{
							if (packets != null)
							{
								document.getElementById("Packets").style.display = "none";
							}
							if (mixMatch != null)
							{
								document.getElementById("Mixmatch").style.display = "none";
							}
							if (boxes != null)
							{
								document.getElementById("Boxes").style.display = "";
							}
						}
						else if (topic.indexOf("Mix") != -1)
						{
							if (packets != null)
							{
								document.getElementById("Packets").style.display = "none";
							}
							if (boxes != null)
							{
								document.getElementById("Boxes").style.display = "none";
							}
							if (mixMatch != null)
							{
								document.getElementById("Mixmatch").style.display = "";
							}
						}

					}


				}

			}			
			
		}

	function sampleVerifyForm()
	{
	
			var mf = GetMainFormName();		
			if (mf==null) return;
			
			var SampleChoice = GetElement("SampleChoice",mf); 
			var quantityAndTopic = SampleChoice.options[SampleChoice.selectedIndex].value; 
			var topic = quantityAndTopic.substring(quantityAndTopic.indexOf("#")+ 1,quantityAndTopic.length)
			var boxes = document.getElementById("Boxes");
			var packets = document.getElementById("Packets");
			var mixMatch = document.getElementById("Mixmatch");
			var flagBox = false;
			var flagPackets = false;			
			
			var _f = document.forms[0];
	
			//We allow physician to select either Boxes or Packettes only if it's not the Mix and Match section
			/*if(topic.indexOf("Mix") != 0)
			{
				for (i=0;i<_f.elements.length;i++)
				{

					if (_f.elements[i].id.indexOf("Boxes") == -1)
					{
						
						var chk = _f.elements[i];
					
						if(chk.checked)
						{
							flagBox = true;
							alert("Box-"+_f.elements[i].id);
						}
					}
					
					if (_f.elements[i].id.indexOf("Packets") == -1)
					{
						
						var chk = _f.elements[i];
					
						if(chk.checked)
						{
							flagPackets = true;
							alert("Packet-"+_f.elements[i].id);
						}
					}			
					
					if (flagBox && flagPackets)
					{
						alert ("You can only select Boxes or Packets");
						return false;
					}
					
				}	
			}*/
	
	
	} 

















