// **************************************************************************
// 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 $(objname)
{
	return grabobj(objname);
}
function hideFPImg(event,Obj)
{
	//event.stopPropagation();
	Obj.style.visibility	=	'hidden';
}
function showFPImg(event,Obj)
{
	//event.stopPropagation();
	Obj.style.visibility	=	'visible';
}
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
		chk = url.indexOf("?");
		if(chk)
		{
			url = url+"&CSPCHD="+CSPCHD;
		} else {
			url = url+"?CSPCHD="+CSPCHD;
		}
		txt = document.createElement('div');
		txt.innerHTML = url;
		document.body.appendChild(txt);
		
		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);
	}
}




function openImgZoom (FS,code,colName) {
	var b=displayBox('imgzoom','<iframe id="imgZoomIFrame" style="width:720px;height:625px; #height:556px;" src="/amoimagezoom/?FS='+FS+'&code='+code+'&colName='+colName+'" frameborder="0"></iframe>');
}


// 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 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';
				}
			}
		}
//	}
}