/*-------------------------------------------*\
Common Functions for the site
\*-------------------------------------------*/
var select = 0;

function popWindow(theURL,winName,features) {
  var newWin
  newWin = window.open(theURL,winName,features);
  newWin.focus();
}
function IsIE() {
	return (navigator.appName == "Microsoft Internet Explorer")
}
function openCalendar(prefixValue) {
	var Xpos = 200;
	var Ypos = 300;
	// set the prefix on the calling page so that the child window knows which calendar dropdown controls to update.
	prefix = prefixValue;
	popWindow('/CmsApp/Scripts/calendar.htm','termsWindow','scrollbars=no,resizable=no,width=181,height=155,left=' + Xpos + ',top=' + Ypos); //width=175, height=125
}
function isValidDate(source, arguments) {
	var y, m, d;
	// retrieve the values from the three dropdown controls (date, month, year).
	d = document.forms[0].elements[source.dateControlID].value;
	m = document.forms[0].elements[source.monthControlID].value - 1;	// m = 0..11
	y = document.forms[0].elements[source.yearControlID].value;
	
	// check for a valid date.
	with (new Date(y, m, d))
    if ((getDate()==d) && (getMonth()==m))
		arguments.IsValid = true;
	else
		arguments.IsValid = false;
}

// Start Javascript for the mouse over images
//<![CDATA[
function swapImgRestore() {
	var i,x,a=document.sr; 
	var y = swapImgRestore.arguments;
	if (y.length > 0){
		if (select == y[0]){ return false;}
	}
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function findObj(n, d) { 
	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=findObj(n,d.layers[i].document); return x;
}
function swapImage() { 
	var i,j=0,x,a=swapImage.arguments; document.sr=new Array; 
	if (a[0] == "imgSearchStandards" && select == 0)
		return false;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function swapBgdImage() {
	var i,j=0,x,a=swapBgdImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){
	var image = 'url(' + a[i+2] + ')';
	document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.style.backgroundImage; x.style.backgroundImage=image;
	}
}
function swapBgdImgRestore() {
	var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.style.backgroundImage=x.oSrc;
}//]]>
// End Javascript for the mouse over images


// Search box functions.

function toggleSearch(panelToActivate){
	if (panelToActivate == 'shop')
	{
		document.getElementById('searchCatalogue').className= "searchShow";
		document.getElementById('searchRestOfSite').className= "searchHide";
		document.forms.searchForm.action = '../search.jsp';
		document.images["imgSearchStandards"].src = "images/tabs/tab-searchcatalogue-on.gif";
		document.images["imgSearchROS"].src = "images/tabs/tab-searchrestofsite-off.gif";
		select = 0;
	}
	else if (panelToActivate == 'site')
	{
		document.getElementById('searchCatalogue').className= "searchHide";
		document.getElementById('searchRestOfSite').className= "searchShow";
		document.forms.searchForm.action = 'http://www.standards.co.nz/search.htm';
		document.images["imgSearchROS"].src = "images/tabs/tab-searchrestofsite-on.gif";
		document.images["imgSearchStandards"].src = "images/tabs/tab-searchcatalogue-off.gif";
		select = 1;
	}
}







