// **************************************************************************
// 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 + ")"; 
}

/*
02/04/09; LJB; removed as causing Error's in IE6 with high security
function lightup(imageobject, opacity){
 if (navigator.appName.indexOf("Netscape")!=-1
  &&parseInt(navigator.appVersion)>=5)
    imageobject.style.MozOpacity=opacity/100;
 else if (navigator.appName.indexOf("Microsoft")!= -1 
  &&parseInt(navigator.appVersion)>=4)
    imageobject.filters.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";
	grabobj(sizeobj).style.textDecoration="underline";
	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="";
	grabobj(sizeobj).style.textDecoration="none";
	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)-205;
	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/wrapusn/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%";
		}
	 }
	}
}



function displaytopmenu (menuname)
{
	grabobj("mainmenu").style.display="none";
	grabobj("mainmenupr").style.display="none";
	grabobj("mainmenutab").className="hm2unsel";
	grabobj("mainmenuprtab").className="hm2unsel";

	grabobj(menuname).style.display="";
	grabobj(menuname+"tab").className="hm2sel";
}
function $(objname)
{
	return grabobj(objname);
}
var fastorder=false;
function outofstock(stno,type)
{
//	13-05-10; LJB; returned value from ajax check is a string not a boolean value so no equal
//	if (validajax==true)
	if (validajax) {
		var ajax = new ajaxObject('/stockmessage/',evalAjax);
		ajax.update('STNO='+stno+'&type='+type+'&fastorder='+fastorder,'GET');
	} else {
		//window.location='/stockmessage/?STNO='+stno+'&type='+type+'&fastorder='+fastorder+'&viewmode=1&ret='+window.location;
	}
		
}
function evalAjax (t,s)
{	
	displayBox('stock',unescape(t));
}
function ajaxObject(url, callbackFunction)
{

  var that=this;      
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {
		try {
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			that.AJAX=new IFrameXMLHttpRequest();
		}
    }                                              
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4) {             
          that.updating=false;
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();        
	  
	  if ($('ajaxcall')) $('ajaxcall').innerHTML=new Date();
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&stamp='+(that.updating.getTime()); 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }
  }
  var urlCall = url;
  this.callback = callbackFunction || function () { };
}

/*
coded by Kae - http://verens.com/
use this code as you wish, but retain this notice
*/

var kXHR_instances=0;
var kXHR_objs=[];


IFrameXMLHttpRequest=function()
{
	var i=0;
	var url='';
	var responseText='';
	var iframe='';
	this.onreadystatechange=function(){
		return false;
	}
	this.open=function(method,url)
	{
		//TODO: POST methods
		this.i=++kXHR_instances; // id number of this request
		this.url=url;
		iFrame	=	document.createElement('iframe');
		iFrame.id	=	"kXHR_iframe_"+this.i;
		iFrame.style.display = 'none';
		iFrame.style.width = '1px';
		iFrame.style.height = '1px';
		document.body.appendChild(iFrame);
	}
	this.send=function(postdata)
	{
		//TODO: use the postdata
		document.getElementById('kXHR_iframe_'+this.i).src=this.url;
		kXHR_objs[this.i]=this;
		setTimeout('XMLHttpRequest_checkState('+this.i+',2)',2);
	}
	return true;
}
XMLHttpRequest_checkState=function(inst,delay)
{
	var el=document.getElementById('kXHR_iframe_'+inst);
	if(el.readyState=='complete')
	{
		var responseText=document.frames['kXHR_iframe_'+inst].document.body.innerText;
		kXHR_objs[inst].responseText=responseText;
		kXHR_objs[inst].readyState=4;
		kXHR_objs[inst].status=200;
		kXHR_objs[inst].onreadystatechange();
		el.parentNode.removeChild(el);
	}else{
		delay*=1.5;
		setTimeout('XMLHttpRequest_checkState('+inst+','+delay+')',delay);
	}
}

// turn ajax off
var ajaxoff=false;

var validajax=false;
function ajaxValidate ()
{
 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) {
		}	}	}
	
		var url='/csp/smp/wrapn/validajax.csp';
		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 openImgZoom (FS)
{
	var b=displayBox('imgzoom','<iframe id="imgZoomIFrame" style="width:740px;height:585px; #height:595px;" src="/amoimagezoom/?FS='+FS+'" frameborder="0"></iframe>');
}

function swapOpt (set,num)
{
	var currentnum=imageset[set];
	if (currentnum!=num)
	{
		opacity('mainproddiv_'+set+'_'+imageset[set],100,0,50);
		imageset[set]=num;
		changeOpac(0,'mainproddiv_'+set+'_'+imageset[set]);
		opacity('mainproddiv_'+set+'_'+imageset[set],0,100,49);
		$('mainproddiv_'+set+'_'+imageset[set]).style.display='';
	}
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    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 + ")";
} 