function itemDetWin(iid,lang) {
	var wx = /\/\w{2}(-\w{2})?\//;
	var lang = ''
	if (String(window.location).match(wx) !== null) {
	    lang = String(String(window.location).match(wx)).replace(',','');
    }
	var itemDetWin = window.open(((lang=='')?'/':lang)+'secure/Catalog/ItemDetail.aspx?'+'iid='+iid,'itemDetWin','width=600,height=400,resizable=1,scrollbars=1,menubar=0,status=0,dependent=1');
	itemDetWin.focus();
}

function osAlertWin(s) {
	var wx = /\/\w{2}(-\w{2})?\//;
	var lang = ''
	if (String(window.location).match(wx) !== null) {
	    lang = String(String(window.location).match(wx)).replace(',','');
    }
	var osAlertWin = window.open(((lang=='')?'/':lang)+'secure/OutOfStockItem.aspx?'+'s='+s,'osAlertWin','width=500,height=350,resizable=1,scrollbars=1,menubar=0,status=0,dependent=1');
	osAlertWin.focus();
}

function createMatrixWin() {
	var wx = /\/\w{2}(-\w{2})?\//;
	var lang = ''
	if (String(window.location).match(wx) !== null) {
	    lang = String(String(window.location).match(wx)).replace(',','');
    }
	var createMatrixWin = window.open(((lang=='')?'/':lang)+'secure/CreateMatrix.aspx','createMatrixWin','width=550,height=450,resizable=1,scrollbars=1,menubar=0,status=0,dependent=1');
	createMatrixWin.focus();
}

function labelDetWin(fid) {
	var wx = /\/\w{2}(-\w{2})?\//;
	var lang = ''
	if (String(window.location).match(wx) !== null) {
	    lang = String(String(window.location).match(wx)).replace(',','');
    }
	var labelDetWin = window.open(((lang=='')?'/':lang)+'secure/LabelSelection.aspx?'+'fid='+fid,'labelDetWin','width=600,height=400,resizable=1,scrollbars=1,menubar=0,status=0,dependent=1');
	labelDetWin.focus();
}

var IE = document.all?true:false
var place = 300;
(document.getElementById && !document.all) ? dom = true : dom = false;

if (!IE && dom) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var tempX = 0
var tempY = 0

var request; 

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.documentElement.scrollLeft
    tempY = event.clientY + document.documentElement.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  return true
}

function show(e, object, imageObject, src) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';
    
    document.images[imageObject].src = src
     
    reposition(object,tempX,tempY);
}

function GetElementBounds(Element){
	if(Element){
	var ElementOffset = GetElementLocation(Element)
	var ElementWidth = Element.offsetWidth;
	var ElementHeight = Element.offsetHeight;
	
	return {x: ElementOffset.x, y: ElementOffset.y, width: ElementWidth, height: ElementHeight }
	}
	else{
		return {x:0, y:0, width:0, height:0};
	}
}
function GetElementLocation(Element){
	var OffsetX = 0;
	var OffsetY = 0;
	var ParentElement;
	
	for (ParentElement = Element; ParentElement; ParentElement = ParentElement.offsetParent){
		if (ParentElement.offsetLeft) {
			OffsetX += ParentElement.offsetLeft;
		}
		if (ParentElement.offsetTop) {
			OffsetY += ParentElement.offsetTop;
		}
	}
	return {x: OffsetX, y: OffsetY}
}
function IeCompliantBody(){
	if(document.compatMode && document.compatMode != "BackCompat"){
		return document.documentElement;
	}
	else{
		return document.body;
	}
}

function show2(object) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';
    

}
function hide(object) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
        document.all[object].style.visibility = 'hidden';
}

function reposition(object,x,y) {
    if (document.layers && document.layers[object] != null) {
        document.layers[object].left = x;
        document.layers[object].top = y;
    }
    else if (document.all) {
        document.all[object].style.posLeft = x + 100;
        document.all[object].style.posTop = y;
    }
}

function updateDivDetDisplay(sender) {
	    var marginLeft=2;
	    var marginTop=0;
    	
	    var detailsContainer=null;
	    var netscape = window.opera || (-1 != navigator.appName.indexOf("Netscape"));
	    var topOfPage = (netscape ? pageYOffset : IeCompliantBody().scrollTop);
	    var bottomOfPage = ((netscape) ? (innerHeight + pageYOffset) : (IeCompliantBody().clientHeight + IeCompliantBody().scrollTop));
	    var imgBounds = GetElementBounds(sender);
	    var itemRowBounds = GetElementBounds(sender);

        if(document.getElementById("divDet")){
		    detailsContainer=document.getElementById("divDet");
	    }else{
		    detailsContainer=document.createElement('div');
		    detailsContainer.id="divDet";
		    detailsContainer.style.position='absolute';
		    detailsContainer.style.zIndex='250';
		    detailsContainer.style.top=itemRowBounds.y+'px';
		    detailsContainer.style.left=itemRowBounds.x+'px';
	    };
    	
	    detailsContainer.style.display='block';
 	    detailsContainer.style.top=itemRowBounds.y+'px';
	    detailsContainer.style.left=itemRowBounds.x+'px';
	    var containerTop = (detailsContainer.style.top.replace('px','')*1);
	    var containerBounds = GetElementBounds(detailsContainer);
	    detailsContainer.style.top=itemRowBounds.y+marginTop+'px';
	    detailsContainer.style.left=imgBounds.x+imgBounds.width+marginLeft+'px';
	    if((containerTop+containerBounds.height) >= bottomOfPage){
		    detailsContainer.style.top=containerTop-((containerTop+containerBounds.height)-bottomOfPage)+'px';
	    };
	    containerTop = (detailsContainer.style.top.replace('px','')*1);
	    if(containerTop <= topOfPage){
		    detailsContainer.style.top=topOfPage+'px';
	    };
}

var hmh;
function showHint(sender,e,args)
{
	var marginLeft=2;
	var marginTop=0;
	
	var url="/secure/Catalog/CatalogAJAX.aspx";
	var itemNumber=args;

	if(e==0){
		if (request){
            request.abort();
        }
		if(document.getElementById("divDet")){
			document.getElementById("divDet").style.display='none';
		};
		return;
	};
	document.getElementById("divDet").innerHTML = '<div style="background-color:#FFFFFF;border:2px none #999999"><img src="/images/icons/wait-red.gif" /></div>'; //ajaxload.info/
	
	hmh=sender;
	updateDivDetDisplay(sender);

    url=url+"?e="+e+"&args="+args;
    GetHtml(updateDivDet,url);

}

function showRecItems(e,qs)
{
	var url="/controls/RecItems.aspx";

	if(e==0){
		if(document.getElementById("divRecItems")){
			document.getElementById("divRecItems").style.display='none';
		};
		return;
	};
	if(document.getElementById("divRecItems")){
		detailsContainer=document.getElementById("divRecItems");
	}else{
		detailsContainer=document.createElement('div');
		detailsContainer.id="divRecItems";
	};
	
    url=url + '?' + qs;
    //url=url+"&sid="+Math.random();
    
	GetHtml(updateDivRecItems,url);
}
function updateDivDet() { 
    if (request.readyState == READYSTATE_COMPLETE) { 
          document.getElementById("divDet").innerHTML = request.responseText; 
    	updateDivDetDisplay(hmh);
    } 
} 

function updateDivRecItems() { 
    if (request.readyState == READYSTATE_COMPLETE) { 
          document.getElementById("divRecItems").innerHTML = request.responseText; 
    } 
} 

function updateLinksBox() { 
    if (request.readyState == READYSTATE_COMPLETE) { 
          document.getElementById("linksBox").innerHTML = request.responseText; 
    } 
} 

function placeIt() {
  if (dom) {document.getElementById("linksBox").style.top = window.pageYOffset + place + "px";}
  if (document.all) {document.all["linksBox"].style.top = document.documentElement.scrollTop + place + "px"}
  window.setTimeout("placeIt()", 500); 
  }

function moveIt() {
  if (dom) {
        document.getElementById('linksBox').style.left = "0px";
  }
  if (document.all) {
        document.all["linksBox"].style.pixelLeft = 0;
    
  }
}

function backIn() {
  if (dom) {
        document.getElementById('linksBox').style.left = "-225px";
  }
  if (document.all) {
        document.all["linksBox"].style.pixelLeft = -225;
  }

}
function typeStart() {
  if (dom || document.all) {
    document.write('<div id="linksBox" style="position:absolute; top:'+place+'px;left:-225px; visibility:visible; cursor:hand; cursor:pointer" onmouseover="moveIt()" >') }
}

function typeEnd() { if (dom || document.all) { document.write('</div>') } }

function placeIt() {
  if (dom) {document.getElementById("linksBox").style.top = window.pageYOffset + place + "px";}
  if (document.all) {document.all["linksBox"].style.top = document.documentElement.scrollTop + place + "px"}
  window.setTimeout("placeIt()", 500); 
  }

var READYSTATE_COMPLETE = 4;
if (typeof(XMLHttpRequest) == "undefined") {
    XMLHttpRequest = 
    function()   {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {} 
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {} 
        try { return new ActiveXObject("Msxml2.XMLHTTP"); }     catch(e) {}
        try { return new ActiveXObject("Microsoft.XMLHTTP"); }  catch(e) {}
        throw new Error("This browser does not support XMLHttpRequest."); 
        }; 
}  

function GetHtml(funct,url) {
    request = new XMLHttpRequest();
    request.open('GET', url+'&rand='+Math.random(), true); 
    request.onreadystatechange = funct; 
    request.send(null); 
} 

function pausecomp(millis) 
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); } 
    while(curDate-date < millis);
} 
