//
// ***
// * This javascript library contains the javascript functions used on the
// * product detail pages
// ***
//

var busy = false;

/*************** Product media display functions *****************/

// function to display the large image of the product
function displayLargeImage(filename) {
	large_image = window.open('','movie','width=370, height=500');
	large_image.document.writeln("<html><title></title><body><div align='center'>");
	large_image.document.writeln("<img src='"+filename+"'/>");
	large_image.document.writeln("<br/><br/><a href='#' onClick='window.close()'><strong>Close</strong></a></div></body></html>");
	large_image.document.close();
}


// function to display the print view of the product
function openPrintWindow(url) {
	print_popup = window.open(url,'','width=640,height=750,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}


// function to display the zoom image of the product
function openZoomWindow(url) {
	print_popup = window.open(url,'','width=495,height=520,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}


// function to display the text a friend page
function openTextAFriendWindow(url){
	print_popup = window.open(url,'','width=515,height=480,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}
  
    
// function to display the email a friend page
function openEmailAFriendWindow(url){
	print_popup = window.open(url,'','width=515,height=670,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}   

// function to display the video of the product
function openVideoWindow(url) {
	print_popup = window.open(url,'','width=870,height=690,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}


// function to switch the product detail large image for a large image alternative
// backupImage is a fall back image if the product does not have a large
function displayLargeAltImage(largeAltImage, backupImage) {
	if (largeAltImage.length < 26) {
		$(".main_image").attr("src", backupImage);
	} else {
		$(".main_image").attr("src", largeAltImage); 
	}
}


// function to switch between tabs on the product detal page
// there was a clever function for doing this by switching the src attribute
// on the tab images - IE7 didn't like it.
function showTab(elementId) {
	document.getElementById('product_page_similar_products').style.display = "none";
	document.getElementById('product_page_reviews').style.display = "none";
	document.getElementById('product_page_bundles').style.display = "none";
	document.getElementById('product_page_delivery').style.display = "none";
	document.getElementById('product_page_service_comments').style.display = "none";
	document.getElementById('product_page_faq').style.display = "none";
	document.getElementById(elementId).style.display = "inline";	
	if (elementId == 'product_page_reviews') {
		document.getElementById('pdp_reviews_tab').style.display = "none";
		document.getElementById('pdp_reviews_tab_current').style.display = "inline";
		document.getElementById('pdp_similar_products_tab').style.display = "inline";
		document.getElementById('pdp_similar_products_tab_current').style.display = "none";
		document.getElementById('pdp_bundles_tab').style.display = "inline";
		document.getElementById('pdp_bundles_tab_current').style.display = "none";	
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";	
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";		
	} else if (elementId == 'product_page_similar_products') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_similar_products_tab').style.display = "none";
		document.getElementById('pdp_similar_products_tab_current').style.display = "inline";
		document.getElementById('pdp_bundles_tab').style.display = "inline";
		document.getElementById('pdp_bundles_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";			
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	}else if (elementId == 'product_page_bundles') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_similar_products_tab').style.display = "inline";
		document.getElementById('pdp_similar_products_tab_current').style.display = "none";
		document.getElementById('pdp_bundles_tab').style.display = "none";
		document.getElementById('pdp_bundles_tab_current').style.display = "inline";	
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";			
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	} else if (elementId == 'product_page_delivery') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_similar_products_tab').style.display = "inline";
		document.getElementById('pdp_similar_products_tab_current').style.display = "none";
		document.getElementById('pdp_bundles_tab').style.display = "inline";
		document.getElementById('pdp_bundles_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "none";
		document.getElementById('pdp_delivery_tab_current').style.display = "inline";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";	
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	} else if (elementId == 'product_page_service_comments') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_similar_products_tab').style.display = "inline";
		document.getElementById('pdp_similar_products_tab_current').style.display = "none";
		document.getElementById('pdp_bundles_tab').style.display = "inline";
		document.getElementById('pdp_bundles_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "none";
		document.getElementById('pdp_service_comments_tab_current').style.display = "inline";	
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	} else {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_similar_products_tab').style.display = "inline";
		document.getElementById('pdp_similar_products_tab_current').style.display = "none";
		document.getElementById('pdp_bundles_tab').style.display = "inline";
		document.getElementById('pdp_bundles_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";	
		document.getElementById('pdp_faq_tab').style.display = "none";
		document.getElementById('pdp_faq_tab_current').style.display = "inline";	
	}
}


function showMediaTab(elementId) {
	document.getElementById('large_image_display').style.display = "none";
	document.getElementById('zoom_display').style.display = "none";
}


function showLargeImage(imageSource, imageAlt) {
	blankMediaDisplay('zoom_display');
	document.getElementById('zoom_display').style.display = 'block';	
	document.getElementById('zoom_display').innerHTML = '<img src="'+imageSource+'" alt="'+imageAlt+'" name="main_image" />';	
}


function loadZoomImages() {
	blankMediaDisplay('zoom_display');
	document.getElementById('zoom_display').style.display = 'block';
}


function blankMediaDisplay(mediaElement) {
	document.getElementById(mediaElement).style.display = 'none';	
}


/***************** ieupdate functions *********************/
theObjects = document.getElementsByTagName("object"); 
for (var i = 0; i < theObjects.length; i++) { 
	theObjects[i].outerHTML = theObjects[i].outerHTML; 
}


/***************** dynamic kit functions - unused *****************/
var configurationId = "";
var componentsSelected = 0;

function AddKit2ShopCart(form) {
	if (componentsSelected > 1) {
		if (!busy) {
    		busy = true;    	
	        form.action="DynamicKitConfigurationAdd";
        	form.configurationId.value = configurationId;
    	    if(form.forRegistry && form.forRegistry.value){
	        	form.externalId.value=form.forRegistry.value;
        	}
    	    form.submit();
		}
	} else {
		alert("you need two or more elements to make a package!");
	}
    return false;
}


function CompositeClicked(itemId, price) {
	if (document.getElementById(itemId + '_itemId').checked) {
		if (configurationId.length == 0) {
			configurationId = itemId;
		} else {
			configurationId = configurationId + '_' + itemId;
		}
		document.getElementById(itemId + '_quantity').disabled = false;
		document.getElementById(itemId + '_price').disabled = false;
		componentsSelected++;
	} else {
		if (configurationId.length != 0) {
			document.getElementById(itemId + '_quantity').value = true;
			document.getElementById(itemId + '_price').value = true;
			if (configurationId.indexOf(itemId) != -1) {
				configurationId = configurationId.replace(itemId, "");
				configurationId = configurationId.replace("__", "_");
				if (configurationId.charAt(0) == "_") {
					configurationId = configurationId.substring(1,configurationId.length);
				}
				if (configurationId.charAt(configurationId.length-1) == "_") {
					configurationId = configurationId.substring(0,(configurationId.length-1));
				}
			}
		}
		componentsSelected--;
	}
	alert(configurationId);
}


/******************** Tripp Trapp function ******************/
// Javascript library file for the TrippTrapp highchair
function openStokke() {
	var windowOpenUrl = 'http://www.stokke.com/layouts/siibs/movie.aspx?LANG=en&Q=high&MIME=flash&RETURNSUCCESS=http://'+document.domain+'/wcsstore/ConsumerDirect/static/TrippTrappSuccess.html';
	window.open(windowOpenUrl,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=800,height=635');
}


function returnStokkeSuccess() {
	document.getElementById('additional_conditions_reminder').style.display = 'none'; 
	document.getElementById('additional_conditions_buy_button_holder').style.display = 'block';
	document.getElementById('tripp_trapp_details').style.display = 'none';
}


/***************** PreOrder Popup functions ******************/
var dialog = null;

// function to display the pre order popup
function showPreOrderPopup(event, shippingDate) {
	if (dialog == null) {
		var body = document.getElementsByTagName("body")[0];
		dialog = document.createElement("div");
		dialog.id = "preorderPopup";
		
		var text1 = "This product is available as a "; 		
		var text2 = "pre-order";
		var text3 = ". This means that we do not currently have the item in stock but we are expecting it shortly. You can place an order for this product now and it will be shipped on ";
		
		var textContent1 = document.createElement("p");
		textContent1.appendChild(document.createTextNode(text1));		
		dialog.appendChild(textContent1);
		
		var textContent2 = document.createElement("p");
		textContent2.className = "strong";
		textContent2.appendChild(document.createTextNode(text2));		
		dialog.appendChild(textContent2);
		
		var textContent3 = document.createElement("p");
		textContent3.appendChild(document.createTextNode(text3));		
		dialog.appendChild(textContent3);
		
		var textContent4 = document.createElement("p");
		textContent4.className = "strong";
		textContent4.appendChild(document.createTextNode(shippingDate));		
		dialog.appendChild(textContent4);			
		body.appendChild(dialog);	
		
		var scrollPosition = getScrollingPosition();			
		var viewPortSize = getViewportSize();		
		if ((event.clientY + 10) > (viewPortSize[1])) {
			var newHeight = event.clientY - ((event.clientY + 10) - viewPortSize[1])
			dialog.style.top = scrollPosition[1] + newHeight + "px";
			dialog.style.left = event.clientX + scrollPosition[0] - 195 + "px";
		} else {	
			dialog.style.top = event.clientY + scrollPosition[1] + 15 + "px";		
			dialog.style.left = event.clientX + scrollPosition[0] - 195 + "px";
		}
		dialog.style.visibility = "visible";	
	}
}

// function to make the preorder popup visible
function makeVisible() {
	if (dialog != null) {
		dialog.style.visibility = "visible";
	}
}


// function to hide the preorder popup
function hidePreOrderPopup() {
	if (dialog != null) {
		dialog.style.visibility = "hidden";
		dialog = null;
	}
}

// function to get the window's scoll position on the current page
function getScrollingPosition() {
	var position = [0, 0];
	if (typeof window.pageYOffset != 'undefined') {
		position = [window.pageXOffset, window.pageYOffset];
	} else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
		position = [document.documentElement.scrollLeft, document.documentElement.scrollTop];
	} else if (typeof document.body.scrollTop != 'undefined') {
		position = [document.body.scrollLeft, document.body.scrollTop];
	}
	return position;
}


// function to get the window size (viewport size)
function getViewportSize() {
	var size = [0, 0];
	if (typeof window.innerWidth != 'undefined') {
		size = [window.innerWidth, window.innerHeight];
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
	} else {
		size = [document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight];
	}
	return size;
}



/***************** WhenBackInStock functions *******************/
var request = null;

function createRequest(){
	try {
		request = new XMLHttpRequest();
	}catch(trymicrosoft){
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(othermicrosoft){
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(failed){
				request = null;
			}
		}
	}
	if(request == null){
		alert("Error creating request object"); 
	}
}


// function for submitting the request and receiving the response
function registerBackInStockEmail() {
	if ((document.getElementById("toName").value == null) || (document.getElementById("toName").value == "")){
    	alert("Please Enter your Name");
		document.getElementById("toName").focus()
		return false;
	}
	if ((document.getElementById("toEmail").value==null)||(document.getElementById("toEmail").value=="")){
		alert("Please Enter your Email Address")
		document.getElementById("toEmail").focus()
		return false;
	}
	if (echeck(document.getElementById("toEmail").value)==false){
		document.getElementById("toEmail").value=""
		document.getElementById("toEmail").focus()
		return false;
	}
	var name = document.getElementById("toName").value;
	var email = document.getElementById("toEmail").value;
	var catentry_id = document.getElementById("catentryId").value;
	ValidateForm(document.getElementById("toEmail"));
	if(!busy){
		busy = true;
		createRequest();
		var product = document.getElementById("product").value;
		if(product == "true"){
			catentry_id = pr_page_id;
		}
		var url = "RegisterInterestOutOfStockCmd?dummey=" + escape(Math.random()) + "&name=" + escape(name) + "&email=" + escape(email) +"&product="+product+"&catentryId="+escape(catentry_id);
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	}
}


function updatePage(){
	if(request.readyState == 4){
    	var message = request.responseText;
		document.getElementById("formContent").style.display="none";
		if(message == "success"){
			document.getElementById("customerMessage").innerHTML = "<p style=\"padding: 45px 0 45px 0\"><span style=\"color: black; padding: 35px 0 0 40px; font-size: 100%;\">You will receive an email when back in stock.</span></p>";
		}else{
			document.getElementById("customerMessage").innerHTML = "<p style=\"padding: 45px 20px 45px 20px; text-align:center; color: black;\"><span style=\" font-size: 100%;\">We have been unable to process your request due to technical issues.</span></p>";
		}
		busy = false;
	}
}
  
  
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("Invalid E-mail Address")
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Invalid E-mail Address")
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail Address")
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail Address")
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail Address")
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail Address")
		return false
	}		
	if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail Address")
		return false
	}
	return true					
}


function ValidateForm(emailID){
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
}

 
function hideEmailBackInStock(){
      document.getElementById("emailBackInStock").style.display="none";
}


function showEmailBackInStock(){
     document.getElementById("whenBackInStockWindow").style.display="block";
}
 
  
var dialog = null;

// function to display the pre order popup
function showBackInStockPopup(event) {
	if (dialog == null) {
		var body = document.getElementsByTagName("body")[0];
		dialog = document.createElement("div");
		dialog.id = "preorderPopup";		
		var text1 = "This product is currently out of stock. Click the button, enter your details and we will contact you via email when this product is back in stock."; 						
		var textContent1 = document.createElement("p");
		textContent1.appendChild(document.createTextNode(text1));		
		dialog.appendChild(textContent1);
		body.appendChild(dialog);	
		
		var scrollPosition = getScrollingPosition();			
		var viewPortSize = getViewportSize();		
		if ((event.clientY + 10) > (viewPortSize[1])) {
			var newHeight = event.clientY - ((event.clientY + 10) - viewPortSize[1])
			dialog.style.top = scrollPosition[1] + newHeight + "px";
			dialog.style.left = event.clientX + scrollPosition[0] - 195 + "px";
		} else {	
			dialog.style.top = event.clientY + scrollPosition[1] + 15 + "px";		
			dialog.style.left = event.clientX + scrollPosition[0] - 195 + "px";
		}
		dialog.style.visibility = "visible";	
	}
}


// function to make the preorder popup visible
function makeVisible() {
	if (dialog != null) {
		dialog.style.visibility = "visible";
	}
}


// function to hide the preorder popup
function hideEmailBackInStockPopup() {
	if (dialog != null) {
		dialog.style.visibility = "hidden";
		dialog = null;
	}
}


// function to get the window's scoll position on the current page
function getScrollingPosition() {
	var position = [0, 0];
	if (typeof window.pageYOffset != 'undefined') {
		position = [window.pageXOffset, window.pageYOffset];
	} else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
		position = [document.documentElement.scrollLeft, document.documentElement.scrollTop];
	} else if (typeof document.body.scrollTop != 'undefined') {
		position = [document.body.scrollLeft, document.body.scrollTop];
	}
	return position;
}


// function to get the window size (viewport size)
function getViewportSize() {
	var size = [0, 0];
	if (typeof window.innerWidth != 'undefined') {
		size = [window.innerWidth, window.innerHeight];
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
	} else {
		size = [document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight];
	}
	return size;
}


/****************** ItemSelectDisplay functions *******************/
function ChangeItem(form, productName) {
	if (form.def_attributes.options[form.def_attributes.selectedIndex].value != 0) {
		var optionSelectedString = form.def_attributes.options[form.def_attributes.selectedIndex].value;
		var imageString = optionSelectedString.substring((optionSelectedString.indexOf('#img#')+5),optionSelectedString.indexOf('#stk#'));
		var stockLevelString = optionSelectedString.substring((optionSelectedString.indexOf('#stk#')+5),optionSelectedString.indexOf('#pri#'));
		var priceString = optionSelectedString.substring((optionSelectedString.indexOf('#pri#')+5),optionSelectedString.indexOf('#pre#'));
		var preorderString = optionSelectedString.substring((optionSelectedString.indexOf('#pre#')+5),optionSelectedString.indexOf('#buy#'));
		var buyable = optionSelectedString.substring((optionSelectedString.indexOf('#buy#')+5),optionSelectedString.indexOf('#maa#'));
		var multibuyA_amount = optionSelectedString.substring((optionSelectedString.indexOf('#maa#')+5),optionSelectedString.indexOf('#map#'));
		var multibuyA_price = optionSelectedString.substring((optionSelectedString.indexOf('#map#')+5),optionSelectedString.indexOf('#mba#'));		
		var multibuyB_amount = optionSelectedString.substring((optionSelectedString.indexOf('#mba#')+5),optionSelectedString.indexOf('#mbp#'));		
		var multibuyB_price = optionSelectedString.substring((optionSelectedString.indexOf('#mbp#')+5),optionSelectedString.indexOf('#dat#'));		
		var availabilityDate = optionSelectedString.substring((optionSelectedString.indexOf('#dat#')+5),optionSelectedString.length);
		form.catEntryId.value = optionSelectedString.substring(0,optionSelectedString.indexOf('#img#'));
		document.getElementById("catentryId").value = optionSelectedString.substring(0,optionSelectedString.indexOf('#img#'));
		document.getElementById("product").value = 'false';
		showLargeImage(imageString, productName); 
		document.getElementById("price").innerHTML = '<span class="offerprice">'+priceString+'</span>';
		if (stockLevelString < 1) {
			buyable = '0';
		}
		if (buyable == '0') {
			document.buy_button1.src = "/wcsstore/ConsumerDirect/en_US/images/blank.gif";
			document.buy_button1.width = 0;
			document.buy_button1.height = 0;
		} else {
			if ((buyable == '1') && (preorderString == 'true')) {
				document.buy_button1.width = 74;
				document.buy_button1.height = 28;	
				document.buy_button1.setAttribute('src','/wcsstore/ConsumerDirect/images/pd/pdp_bt_pre_order_only.gif');
				document.buy_button1.setAttribute('id','buy_button_one');	
				document.buy_button1.setAttribute('preorder','true');
			} else {
				document.buy_button1.setAttribute('src', '/wcsstore/ConsumerDirect/images/pd-button-add-to-basket.gif');
                document.buy_button1.setAttribute('preorder','false');
				document.buy_button1.width = 97;
				document.buy_button1.height = 28;	
			}
		}	
		if (multibuyA_amount != '0') {
			document.getElementById("multiA").innerHTML = "Buy " + multibuyA_amount + " " + productName + " for <strong>" + multibuyA_price + "</strong> each."; 	
		}
		if (multibuyB_amount != '0') {
			document.getElementById("multiB").innerHTML = "Buy " + multibuyB_amount + " " + productName + " for <strong>" + multibuyB_price + "</strong> each.<br/>";		
		}
		if (multibuyA_amount == '0' && multibuyB_amount == '0') {
			document.getElementById("multiA").innerHTML = "There are no multi-buy savings for this product.";
			document.getElementById("multiB").innerHTML = "";
		}
		if (stockLevelString == '0') {
			document.getElementById("stocklevel").innerHTML = '<p class="shipping_date">Out of Stock <img id="outOfStockExplaination" align="absmiddle" onClick="openOutOfStockOverlay()" src="/wcsstore/ConsumerDirect/images/speaker-icon-green.gif" /></p>'; 
			document.getElementById("open_email_when_in_stock").style.display="block";
			initOutOfStockExtras();
		} else {                                              
			if (preorderString == 'true') {
			    document.getElementById("open_email_when_in_stock").style.display="none";
			    document.getElementById("whenBackInStockWindow").style.display="none";
				var availabilityDate = optionSelectedString.substring((optionSelectedString.indexOf('#dat#')+5),optionSelectedString.length); 
				document.getElementById("stocklevel").innerHTML = '<p class="shipping_date">Shipping Date:&nbsp;&nbsp;&nbsp;'+availabilityDate+'<span class="feature_preorder_stock_level">&nbsp;&nbsp;&nbsp;('+ stockLevelString + ' expected)</span> <img id="preorderExplaination" class="preorderItemExplaination" align="absmiddle" onClick="openPreOrderOverlay()" src="/wcsstore/ConsumerDirect/images/speaker-icon-green.gif" alt="Pre-Order Explaination"/></p>';		
        var preOrderTip = $('div .poCondition', '#preOrderItemConditionTip');
			  preOrderTip.html('<strong>This product is available as a pre-order. This means that we do not currently have the item in stock but we are expecting it shortly. You can place an order for this product now and it will be shipped on '+availabilityDate+'</strong>');
				initPreOrderExtras();
			  } else {
				if (stockLevelString != 'direct delivery') {
					if (stockLevelString > 50) {
				    	document.getElementById("open_email_when_in_stock").style.display="none";
			      		document.getElementById("whenBackInStockWindow").style.display="none";
						document.getElementById("stocklevel").innerHTML = '<p class="stock_blue_bg">'+stockLevelString+ ' in stock <img class="slItemExplaination" align="absmiddle" onClick="openStockLevelOverlay()" src="/wcsstore/ConsumerDirect/images/speaker-icon-green.gif" /></p>';	
						initStockLevelExtras();
					} else {
					  	document.getElementById("open_email_when_in_stock").style.display="none";
			      		document.getElementById("whenBackInStockWindow").style.display="none";
						document.getElementById("stocklevel").innerHTML = '<p class="stock_red_bg">'+stockLevelString+' in stock <img class="slItemExplaination" align="absmiddle" onClick="openStockLevelOverlay()" src="/wcsstore/ConsumerDirect/images/speaker-icon-green.gif" /></p>';		
					  	initStockLevelExtras();						
					}
				} else {
				    document.getElementById("open_email_when_in_stock").style.display="none";
			    	document.getElementById("whenBackInStockWindow").style.display="none";
					document.getElementById("stocklevel").innerHTML = '<p class="stock_blue_bg">'+ stockLevelString + '</p>';
				}
			}
		}
	}
}


/****************** Dutailier Wood/Fabric functions *******************/
var woodSwatchSelectedId;
var fabricSwatchSelectedId;

function setWood(form, catEntryId, productCatEntryId, image, name, swatchId) {
	if (woodSwatchSelectedId != null) {
		document.getElementById(woodSwatchSelectedId).className = "dutalier_displaybox dutalier_not_selected";
	}
	woodSwatchSelectedId = swatchId;
	document.getElementById(woodSwatchSelectedId).className = "dutalier_displaybox dutalier_selected";
	document.getElementById('dutailier_wood_swatch').innerHTML = '<div class="dutailier_img"><img src="http://' + document.domain + '' + image + '"/></div><div class="dutailier_name">' + name + '<br/><a class="pointer" onclick="showTabbedProductOverlay(\'product_page_dutailier_options\', false)"><br/>>Change wood</a></div><div style="clear:both;"></div>';
	form.catEntryId_1.value = catEntryId;
	form.catEntProd_1.value = productCatEntryId;
}

function setFabric(form, catEntryId, productCatEntryId, image, name, swatchId) {
	if (fabricSwatchSelectedId != null) {
		document.getElementById(fabricSwatchSelectedId).className = "dutalier_displaybox dutalier_not_selected";
	}
	fabricSwatchSelectedId = swatchId;
	document.getElementById(fabricSwatchSelectedId).className = "dutalier_displaybox dutalier_selected";
	document.getElementById('dutailier_fabric_swatch').innerHTML = '<div class="dutailier_img"><img src="http://' + document.domain + '' + image + '"/></div><div class="dutailier_name">' + name + '<br/><a class="pointer" onclick="showTabbedProductOverlay(\'product_page_dutailier_options\', false)"><br/>>Change fabric</a></div><div style="clear:both;"></div>';
	form.catEntryId_2.value = catEntryId;
	form.catEntProd_2.value = productCatEntryId;
}


$(document).ready(function(){	
	$('div .accessories_and_crosssells').css("display","block");
	jQuery('.first-and-second-carousel').jcarousel();	
	$("div#static-zoom").mouseenter(function(event) {
		$("div#magic-zoom").css({'display':'block'});
		$(this).css({'display':'none'});				
	});
	$("div#magic-zoom").mouseleave(function(event) {
		$("div#static-zoom").css({'display':'block'});
		$(this).css({'display':'none'});		
	});
	
	$("div#zoom_display .zoom_thumb").click(function(event) {
		$("div#zoom_display .main_image").attr("src", $(this).attr("rev"));
	});
});


/******************* GetSatisfaction product topic list *******************/
var getSatProductTopics;

$(document).ready(function(){  
	getSatProductTopics = new Array()		
	$.getJSON("http://api.getsatisfaction.com/companies/kiddicare/topics.json?user_defined_code=" + pr_page_id + "&sort=recently_active&limit=5&callback=?",   
		function(data){
			populateProductGetSatTopics(data);
	}); 
	if (getSatProductTopics == null || getSatProductTopics.length<5) {
		$.getJSON("http://api.getsatisfaction.com/companies/kiddicare/products/kiddicare_top_faq_s/topics.json?sort=recently_active&limit=5&callback=?",   
			function(data){
				populateProductGetSatTopics(data);
		});
	} 
	setTimeout('testForAndDisplayProductGetSatTopics()',1000);
}); 

function testForAndDisplayProductGetSatTopics() {
	if (getSatProductTopics != null && getSatProductTopics.length>0) {
		displayProductGetSatTopics();
	}
}

function populateProductGetSatTopics(JSONProductObject) {
	var i=0;
	while (i<JSONProductObject.data.length && getSatProductTopics.length<5) {
		topicObject = new Object();
		topicObject.link = JSONProductObject.data[i].at_sfn;
		topicObject.link = topicObject.link.replace("getsatisfaction.com","community.kiddicare.com");
		topicObject.question = JSONProductObject.data[i].subject;
		getSatProductTopics[getSatProductTopics.length] = topicObject;
		i++;
	}
}

function displayProductGetSatTopics() {
	var topicListString = "";
	for (var i=0; i<getSatProductTopics.length; i++) {
		topicListString += "<li><a href=\"" + getSatProductTopics[i].link + "\" target=\"_blank\">" + getSatProductTopics[i].question + "</a></li>";				
	}
	document.getElementById('pdp_gsfn_list_widget_topics').innerHTML = topicListString;
}

