// **************************************************************************
// find out what browser we're using
if (document.getElementById)
{
	DOMtype = "std";
}
else if (document.all)
{
	DOMtype = "ie4";
}
else if (document.layers)
{
	DOMtype = "ns4";
}

// **************************************************************************
// grab object by ID on page
function grabobj(objname) // v1.0
{

var ret = null;
	switch (DOMtype)
	{
		case "std":
		{
			ret = document.getElementById(objname);
		}
		break;

		case "ie4":
		{
			ret = document.all[objname];
		}
		break;
		case "ns4":
		{
			ret = document.layers[objname];
		}
		break;
	}
return ret;
}

function lightup(imageobject, opacity)
{
	var object = imageobject.style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

var fading=0;
var fadertimer;
var faderobj;
function fadein(objid)
{
	if (grabobj(objid))
	{
		grabobj(objid).style.display="";
		fading=0;
		faderobj=objid;
		window.clearInterval(fadertimer);
		fadertimer=setInterval(fadeinset, 20);
	}
}
function fadeinset ()
{
	fading=fading+10;
	lightup(grabobj(faderobj),fading);
	if (fading>=100) window.clearInterval(fadertimer);
}

function fadeout(objid)
{
	if (grabobj(objid))
	{
		faderobj=objid;
		window.clearInterval(fadertimer);
		fadertimer=setInterval(fadeoutset, 20);
	}
}
function fadeoutset ()
{
	fading=fading-20;
	lightup(grabobj(faderobj),fading);
	if (fading<=0)
	{
		window.clearInterval(fadertimer);
		grabobj(faderobj).style.display="none";
	}
}

// Used for highlighting/unhiglighting page input fields.
function hlinput (obj,b)
{
	obj.style.background='#F2F9FD';
	if (b=='border') obj.style.borderColor='#F2F9FD';
}
function unhlinput (obj,b)
{
	obj.style.background='#FFFFFF';
	if (b=='border') obj.style.borderColor='#FFFFFF';
}

function matrixhl(sizeobj,colobj)
{
	//grabobj(sizeobj).style.fontWeight="bold";
	//grabobj(colobj).style.fontWeight="bold";
	if (grabobj(sizeobj)) grabobj(sizeobj).style.textDecoration="underline";
	if (grabobj(colobj)) grabobj(colobj).style.textDecoration="underline";
	try {
	if (grabobj(colobj).childNodes[0])
	{
		grabobj(colobj).childNodes[0].style.textDecoration="underline";
	}
	} catch (e) {}
}

function matrixunhl(sizeobj,colobj)
{
	//grabobj(sizeobj).style.fontWeight="";
	//grabobj(colobj).style.fontWeight="";
	
	if (grabobj(sizeobj)) grabobj(sizeobj).style.textDecoration="none";
	if (grabobj(colobj)) grabobj(colobj).style.textDecoration="";
	
	
	try {
	if (grabobj(colobj).childNodes[0])
	{
		grabobj(colobj).childNodes[0].style.textDecoration="";
	}
	} catch (e) {}
}
function hidetooltip ()
{
	grabobj("tooltip").style.display="none";
}
function displayToolTip (e)
{
	if (grabobj("tooltip").style.display=="none")
	{
	grabobj("tooltip").style.left=mouseX(e)-435;
	grabobj("tooltip").style.top=mouseY(e)+3;
	grabobj("tooltip").style.display="";
	grabobj("tooltip").innerHTML="Sorry, this selection is<br> currently sold out.";
	}
}

function prodImageSwap (opt,obj)
{
if (obj)
{
	obj=grabobj(obj);
	if (obj)
	{
	
		obj.src=obj.src.replace('/opt3/','/opt'+opt+'/');
		obj.src=obj.src.replace('/opt2/','/opt'+opt+'/');
		obj.src=obj.src.replace('/opt1/','/opt'+opt+'/');
	}
}

}
function displayView(pic)
{
	var display=window.open('/csp/smp/wrapn/view.csp?pno='+pic,'_blank','scrollbars=no,resizable=yes,width=375,height=480,left=200,top=150');
	if (!display) return true;
	if (display) return false;
}

function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}

var gloAllowSearch=false;
function chkSearch (obj)
{
gloAllowSearch=false;
	if (obj)
	{
		if (obj.value!="")
		{
			gloAllowSearch=true;
		}
	}
if (!gloAllowSearch) alert("Please enter a search term");
return gloAllowSearch;
}



window.onload=checkheight;

function checkheight ()
{
	
	if (navigator.userAgent.indexOf("Firefox")!=-1) 
	{
	 if (grabobj("contentarea"))
	 {
		if (grabobj("rcontent"))
		{
			if ((parseFloat(grabobj("rcontent").offsetHeight)+112)>520)
			{
				grabobj("contentarea").style.height=parseFloat(grabobj("rcontent").offsetHeight)+112;
			} else {
				grabobj("contentarea").style.height="520px";
			}
		} else {
			grabobj("contentarea").style.height="100%";
		}
	 }
	}
}
// turn ajax off
var ajaxoff=false;

var validajax=false;
function ajaxValidate (url)
{
 if (!ajaxoff)
 {
	if (!validajax)
	{
		runOnce=false;
		var xmlHttpReq;
		try { xmlHttpReq=new XMLHttpRequest(); } catch (e) {
			try { xmlHttpReq=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
				try { xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
		}	}	}
	
		if (xmlHttpReq)
		{
			xmlHttpReq.open("GET", url, true);
			xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttpReq.onreadystatechange = function() {
				if (xmlHttpReq.readyState == 4) {
					validajax=xmlHttpReq.responseText;
					
				}
			}
			xmlHttpReq.send('');
		}
	}
 } else {
	validajax=false;
 }
}

function swapOpt (set,num) {
	var currentnum=imageset[set];
	if (currentnum!=num) {
//		opacity('mainproddiv_'+set+'_'+imageset[set],100,0,50);
// LJB; 24-06-10
		opacity('mainproddiv_'+set+'_'+imageset[set],100,0,1);
		imageset[set]=num;
		changeOpac(0,'mainproddiv_'+set+'_'+imageset[set]);
//		opacity('mainproddiv_'+set+'_'+imageset[set],0,100,49);
// LJB; 24-06-10
		opacity('mainproddiv_'+set+'_'+imageset[set],0,100,0.3);
//		$('mainproddiv_'+set+'_'+imageset[set]).style.display='';
	}
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
//    var speed = Math.round(millisec / 100);
// LJB; 24-06-10
	var speed=millisec;
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	if(0==opacity) object.display='none';
	if(0<opacity) object.display='';
}





/*	Written by Jonathan Snook, http://www.snook.ca/jonathan
	Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
/*	This is a fix for IE8's bug with transparent black pixels.
	It will set the background for the supplied classNames (supply in an Array) to black
*/
function itmentry(classNames) {
//	if(navigator.appVersion.indexOf('MSIE')>-1) {
		if(classNames instanceof Array) {
			if(classNames.length==0) return
			for(var i=0; i<classNames.length; i++) {
				var className	= classNames[i];
				objs	= getElementsByClassName(document,'*',className);
				for(var x=0; x<objs.length; x++) {
//alert(objs[x]+'|'+i+'|'+x);
					objs[x].style.backgroundColor	= '#000000';
				}
			}
		}
//	}
}