﻿function checkoptions(someform) {
	if (typeof(someform.optionname)=='object') {
		if (someform.myoption.selectedIndex==0) {
			alert('Please select a ' + someform.optionname.value);
			return false;
		} else {
			return true;
		}		
	} else {
		return true;
	}
}

function showhide(someid) {
	if (document.getElementById(someid).style.display=='') {
		document.getElementById(someid).style.display='none';
	} else {
		document.getElementById(someid).style.display='';
	}
}

function openLiveZoom (productcode)
{
	liveZoomWin=window.open('/content/zoom/zoom2.asp?pid='+productcode,'liveZoomWindow','width=450,height=600,location=no,toolbars=no,scrollbars=no,resize=no,status=yes');
	liveZoomWin.focus();
}

function openzoom(imageurl) {
	window.open(imageurl,'Zoom','width=620,height=420,scrollbars=yes');
}

function ecsearchgroup(thegroupid) {
	if (document.getElementById(thegroupid).style.display=='none') {
		document.getElementById(thegroupid).style.display='';
		document.getElementById(thegroupid+'_img').src='/images/arrow_down.gif';	
	} else {
		document.getElementById(thegroupid).style.display='none';
		document.getElementById(thegroupid+'_img').src='/images/arrow_in.gif';
	}
	var cookiename=thegroupid
	var cookievalue=(document.getElementById(thegroupid).style.display=='');
	document.cookie=cookiename+"="+cookievalue;

}

function toggleid(theid) {
	if (document.getElementById(theid).style.display=='none') {
		document.getElementById(theid).style.display='';
	} else {
		document.getElementById(theid).style.display='none';
	}
}


function popup(url, width, height)
{
	newwindow=window.open(url,'name','height='+height+',width='+width+',scrollbars=yes,resizable=yes');
	if (window.focus) {newwindow.focus()}
}

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your browser is incompatible with this site!!");
	}
}

var searchReq = getXmlHttpRequestObject();

function searchSuggest() {
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		var str = escape(document.getElementById('txtSearch').value);
		searchReq.open("GET", '/searchSuggest.asp?search=' + str, true);
		searchReq.onreadystatechange = handleSearchSuggest; 
		searchReq.send(null);
	}		
}

//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';
		var str = searchReq.responseText.split("\n");
		for(i=0; i < str.length - 1; i++) {
			//Build our element string.  This is cleaner using the DOM, but
			//IE doesn't support dynamically added attributes.
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			ss.innerHTML += suggest;
		}
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}

//Click function
function setSearch(value) {
	document.getElementById('txtSearch').value = value;
	document.getElementById('search_suggest').innerHTML = '';
}

//Open Popup windows in the screen centre
function popwin(url,width,height) {
var iHalfResWidth;
var iHalfResHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iHalfResWidth = (window.screen.width/2) - ((width/2) + 10);
//half the screen height minus half the new window height (plus title and status bars).
iHalfResHeight = (window.screen.height/2) - ((height/2) + 50);
//Open the window.
var win2 = window.open(url,"PWC","status=no,height="+height+",width="+width+",resizable=no,left=" + iHalfResWidth + ",top=" + iHalfResHeight + ",screenX=" + iHalfResWidth + ",screenY=" + iHalfResHeight + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
if (window.focus) {win2.focus()}
}

//Image Refresh
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}