// **************************************************************************
// 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);
}
var fastorder=false;
function outofstock(stno,type)
{
	var ajax = new ajaxObject('/stockmessage/',evalAjax);
	ajax.update('STNO='+stno+'&type='+type+'&fastorder='+fastorder,'GET');
}
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);
	}
}




function openImgZoom (FS)
{
	var b=displayBox('imgzoom','<iframe id="imgZoomIFrame" style="width:720px;height:585px; #height:560px;" src="/amoimagezoom/?FS='+FS+'" 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);
		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 + ")";
} 