/*
	Display Image Function
	----------------------
	
	Main images are saved in these locations:
		Thumbnail: 	/images/products/thumbnails/[productNumber].jpg
		Detail:		/images/products/details/[productNumber].jpg
	
	Alternate (zoomed) images are saved in these locations:
		Thumbnail: 	/images/zoom/thumbnails/[productNumber].jpg
		Detail:		/images/zoom/details/[productNumber].jpg

	imageVersion: 	'A' indicates a request for the main image
					'B' indicates a request for the zoomed image
	
*/
function displayImage(productNumber, imageVersion) {
	var output;
	
	output =  '<img src="/images/';
	if (imageVersion == 'A') {
		output += 'products/';
	} else if (imageVersion == 'B') {
		output += 'zoom/';
	}
	
	output += "details/" 
	output += productNumber;
	output += '.jpg" alt="Large photograph of product" />';
	
	if (document.getElementById("primary-image")) {
		document.getElementById("primary-image").innerHTML = output;
	}
}

/*
	hideDiv function
	Takes an id of an element and sets 
	the style display property to "none"
	
*/
function hideElement(id) {
	var theElement = document.getElementById(id);
	if (null!=theElement) {
		theElement.style.display = "none";
	}
}

/*
	hideDiv function
	Takes an name of an element and sets 
	the style display property to "none"
	
*/
function hideElementByName(name) {
	var theElement = document.getElementsByName(name);
	for(var i=0;i<theElement.length;i++){
		if (null!=theElement[i]) {
			theElement[i].style.display = "none";
		}
	}
}



/*
	hidePlaceOrderButton Function
*/
function hidePlaceOrderButton() {
	hideElement('page-top-navigation');
	hideElement('page-navigation');
	var waitMsg;
	var waitMsgDiv = document.getElementById('processing-message');
	if (null!=waitMsgDiv) {
		waitMsg = waitMsgDiv.innerHTML.substr(4, (waitMsgDiv.innerHTML.length-7));
		waitMsgDiv.innerHTML = waitMsg;
	}
	return true;
}

/*
	validateSearchInput Function
*/
function validateSearchInput(searchForm) {
	if (searchForm.searchTerm.value == "Search product name / number") {
		searchForm.searchTerm.value = "";
		searchForm.searchTerm.focus();
		return false; 
	} else {
		return true;
	}
}

var needVersion = 6; // todo: verify minimum flash version compatible
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
var dhtmlUrl = "http://s7ondemand4.scene7.com/s7viewers/dhtml/basicZoomTemplate.html?image=Signet/";
var flashUrl = "http://s7ondemand4.scene7.com/s7ondemand/zoom/flasht_zoom.jsp?company=Signet&config=zoom&zoomwidth=400&zoomheight=450&sku=";
var localUrl = "/webstore/zoom.do?config=zoom&sku=";

if (plugin) {
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i) {
		if (isNaN(parseInt(words[i])))
		continue;
		var pluginVersion = words[i]; 
	}
	var flashCanPlay = pluginVersion >= needVersion;
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\>\n'); //PJD: Stop IE4.5 Mac thinking we're starting a new scriptblock by splitting the tag
	document.write('on error resume next \n');
	document.write('flashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & needVersion)))\n');
	document.write('</SCR' + 'IPT\>\n');
}

/*
	Show Scene7 Zoom Window
*/
function openS7ZoomWindow(sku) {
	var properties = 'left=10,top=10,width=480,height=520,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes';
	var url = "";
	if (flashCanPlay) {
		url = flashUrl + sku;
	} else {
		url = dhtmlUrl + sku;
	}
	window.open(url,'',properties);
	return false;
}

/*
	Show Scene7 Zoom Window
*/
function openLocalS7ZoomWindow(sku, config) {
	var properties = 'left=10,top=10,width=480,height=520,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes';
	var url = "";
	if (flashCanPlay) {
		url = localUrl + sku + "&zoomConfig=" + config + "&useFlash=true";
	} else {
		url = dhtmlUrl + sku;	
	}
	window.open(url,'',properties);
	cmCreateElementTag(sku, 'Product View Tools - Zoom');
	return false;
}


/*
	showHide nav function
*/
function showHide(showContainerId, hideContainerId) {
	var showContainer = document.getElementById(showContainerId);
	var hideContainer = document.getElementById(hideContainerId);
	if (null!=showContainer && null!=hideContainer) {
		showContainer.style.display = "block";
		hideContainer.style.display = "none";
		return false;
	}
}

/*

*/
function forceValCustomOption(form) {
	form.secretvalentinemsgindx[3].checked = true;
}

function setValInputFieldFocus(form) {
	form.customValentineMsg.focus();
}


/*

	Show a scene 7 spin window

*/


function openLocalS7SpinWindow(sku){
	var properties = 'left=10,top=10,width=480,height=520,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes';
	var url="http://s7ondemand4.scene7.com/s7/spin/flash_spin.jsp?company=Signet&sku=spinset" + sku + "&config=Scene7SharedAssets/SpinSet-MM1&locale=en";
	window.open(url,'',properties);
	cmCreateElementTag(sku, 'Product View Tools - 360 View');
	return false;
}
