//
// ***
// * 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) {
		document.images.main_image.src = backupImage
	} else {
		document.images.main_image.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_description').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_description_tab').style.display = "inline";
		document.getElementById('pdp_description_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_description') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_description_tab').style.display = "none";
		document.getElementById('pdp_description_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_description_tab').style.display = "inline";
		document.getElementById('pdp_description_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_description_tab').style.display = "inline";
		document.getElementById('pdp_description_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_description_tab').style.display = "inline";
		document.getElementById('pdp_description_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_description_tab').style.display = "inline";
		document.getElementById('pdp_description_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";
	document.getElementById('video_display').style.display = "none";
	if (elementId == 'large_image_display') {
		document.getElementById('large_image_display').style.display = "inline";
		document.getElementById('pdp_large_image_tab').style.display = "none";
		document.getElementById('pdp_large_image_tab_current').style.display = "inline";
		document.getElementById('pdp_zoom_tab').style.display = "inline";
		document.getElementById('pdp_zoom_tab_current').style.display = "none";
		document.getElementById('pdp_video_tab').style.display = "inline";
		document.getElementById('pdp_video_tab_current').style.display = "none";	
		document.getElementById('pdp_buggy_walk_tab').style.display = "inline";
		document.getElementById('pdp_buggy_walk_tab_current').style.display = "none";		
		document.getElementById('pdp_cat_walk_tab').style.display = "inline";
		document.getElementById('pdp_cat_walk_tab_current').style.display = "none";				
	} else if (elementId == 'zoom_display') {
		document.getElementById('zoom_display').style.display = "inline";
		document.getElementById('pdp_large_image_tab').style.display = "inline";
		document.getElementById('pdp_large_image_tab_current').style.display = "none";
		document.getElementById('pdp_zoom_tab').style.display = "none";
		document.getElementById('pdp_zoom_tab_current').style.display = "inline";
		document.getElementById('pdp_video_tab').style.display = "inline";
		document.getElementById('pdp_video_tab_current').style.display = "none";
		document.getElementById('pdp_buggy_walk_tab').style.display = "inline";
		document.getElementById('pdp_buggy_walk_tab_current').style.display = "none";	
		document.getElementById('pdp_cat_walk_tab').style.display = "inline";
		document.getElementById('pdp_cat_walk_tab_current').style.display = "none";				
	} else if (elementId == 'video_display') {
		document.getElementById('video_display').style.display = "inline";
		document.getElementById('pdp_large_image_tab').style.display = "inline";
		document.getElementById('pdp_large_image_tab_current').style.display = "none";
		document.getElementById('pdp_zoom_tab').style.display = "inline";
		document.getElementById('pdp_zoom_tab_current').style.display = "none";
		document.getElementById('pdp_video_tab').style.display = "none";
		document.getElementById('pdp_video_tab_current').style.display = "inline";
		document.getElementById('pdp_buggy_walk_tab').style.display = "inline";
		document.getElementById('pdp_buggy_walk_tab_current').style.display = "none";	
		document.getElementById('pdp_cat_walk_tab').style.display = "inline";
		document.getElementById('pdp_cat_walk_tab_current').style.display = "none";			
	} else if (elementId == 'buggy_walk_display') {
		document.getElementById('video_display').style.display = "inline";	
		document.getElementById('pdp_large_image_tab').style.display = "inline";
		document.getElementById('pdp_large_image_tab_current').style.display = "none";
		document.getElementById('pdp_zoom_tab').style.display = "inline";
		document.getElementById('pdp_zoom_tab_current').style.display = "none";
		document.getElementById('pdp_video_tab').style.display = "inline";
		document.getElementById('pdp_video_tab_current').style.display = "none";	
		document.getElementById('pdp_buggy_walk_tab').style.display = "none";
		document.getElementById('pdp_buggy_walk_tab_current').style.display = "inline";	
		document.getElementById('pdp_cat_walk_tab').style.display = "inline";
		document.getElementById('pdp_cat_walk_tab_current').style.display = "none";	
	} else if (elementId == 'cat_walk_display') {
		document.getElementById('video_display').style.display = "inline";	
		document.getElementById('pdp_large_image_tab').style.display = "inline";
		document.getElementById('pdp_large_image_tab_current').style.display = "none";
		document.getElementById('pdp_zoom_tab').style.display = "inline";
		document.getElementById('pdp_zoom_tab_current').style.display = "none";
		document.getElementById('pdp_video_tab').style.display = "inline";
		document.getElementById('pdp_video_tab_current').style.display = "none";	
		document.getElementById('pdp_buggy_walk_tab').style.display = "inline";
		document.getElementById('pdp_buggy_walk_tab_current').style.display = "none";			
		document.getElementById('pdp_cat_walk_tab').style.display = "none";
		document.getElementById('pdp_cat_walk_tab_current').style.display = "inline";	
	}
}


function loadVideo(videoSource, type) {
	blankMediaDisplay('large_image_display');
	blankMediaDisplay('zoom_display');
	if (type == 'youtube') {
		var videoString = '<div style="width:100%;"><object width="374" height="306"><param name="movie" value="http://www.youtube.com/'+videoSource+'&hl=en&fs=1&ap=%2526fmt%3D22&autoplay=1" type="application/x-shockwave-flash" width="374" height="306" allowfullscreen="true" wmode="transparent" /><embed src="http://www.youtube.com/'+videoSource+'&hl=en&fs=1&ap=&fmt=22&autoplay=1" type="application/x-shockwave-flash" width="374" height="306" wmode="transparent" allowfullscreen="true" /></object></div><div style="width:99%;"><a href="http://www.youtube.com/user/Kiddicare">Kiddcare on youtube</a><br/><a href="wcsstore/ConsumerDirect/images/video/install_flash_player.exe">No video? Download Flash player here</a><br/><br/><span style="font-size:80%;"><u><strong>Important Information</strong></u><br/>This video is a guide to the product, please read the product item page for full information to establish what is included within the price of your purchase.<br/></span></div>';	
	} else {
		var videoString = '<div style="width:100%;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="374" height="320" id="video" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="'+videoSource+'.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><parameter name="wmode" value="transparent" /><embed src="'+videoSource+'.swf" quality="high" bgcolor="#ffffff" width="374" height="320" wmode="transparent" name="Kiddicare video" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="//www.macromedia.com/go/getflashplayer" allowFullScreen="true" /></object></div><div style="width:99%;"><a href="wcsstore/ConsumerDirect/images/video/install_flash_player.exe">No video? Download Flash player here</a><br/><br/></div>';
	}
	document.getElementById('video_display').innerHTML = videoString;
	document.getElementById('video_display').style.display = 'block';
}

function showLargeImage(imageSource, imageAlt) {
	blankMediaDisplay('video_display');
	blankMediaDisplay('zoom_display');
	document.getElementById('large_image_display').innerHTML = '<img src="'+imageSource+'" alt="'+imageAlt+'" name="main_image" />';
	document.getElementById('large_image_display').style.display = 'block';	
}

function loadZoom(zoomSource) {
	blankMediaDisplay('large_image_display');
	blankMediaDisplay('video_display');
	blankMediaDisplay('zoom_display');
	document.getElementById('zoom_display').innerHTML = '<object id="fsiviewer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" width="350px" height="400px" wmode="transparent"><param name="movie" value="http://62.128.130.204:8180/erez3/fsi3/fsi.swf?showcase_server=http://62.128.130.204:8180/erez3&showcase_dir=' + zoomSource + '/&cfg=showcase_presets/plain&showcase_Align=bottom&plugins=resize,clockprogress&Skin=plain"><param name="menu" value="FALSE" /><param name="wmode" value="transparent" /><embed src="http://62.128.130.204:8180/erez3/fsi3/fsi.swf?showcase_server=http://62.128.130.204:8180/erez3&showcase_dir=' + zoomSource + '/&cfg=showcase_presets/plain&showcase_Align=bottom&plugins=resize,clockprogress&Skin=plain" width="350px" height="400px" name="fsiviewer" menu="false" wmode="transparent" pluginspage="//www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"/></object>';
	document.getElementById('zoom_display').style.display = 'block'
}

function loadZoomImages() {
	blankMediaDisplay('large_image_display');
	blankMediaDisplay('video_display');
	document.getElementById('zoom_display').style.display = 'block';
}

function blankMediaDisplay(mediaElement) {
	if (mediaElement == 'large_image_display' || mediaElement == 'zoom_images_display') {
		document.getElementById(mediaElement).style.display = 'none';	
	} else {
		document.getElementById(mediaElement).innerHTML = '';
		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">&pound;'+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>&pound;" + multibuyA_price + "</strong> each."; 	
		}
		if (multibuyB_amount != '0') {
			document.getElementById("multiB").innerHTML = "Buy " + multibuyB_amount + " " + productName + " for <strong>&pound;" + 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">There are currently ' +stockLevelString+ ' available 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">There are currently '+stockLevelString+' available 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>';
				}
			}
		}
	}
}


