function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function submitSSLWindow() 
{ 
    window.open("","sslWindow","width=500,height=450,toolbar=0"); 
    var a = window.setTimeout("document.frmOpenPayment.submit();",500); 
} 

function handleImageError() {
	thumpImg.src = objThumbErrorImg.src;
}

function buildPopLayer() {
		if (document.readyState && (document.readyState != "complete")) { //forhindre en windows alert: "sitet kan ikke loades" i IE hvis man refresher med mus over cam icon helpdesk 3915
		return false; 
	}
	var objThumbImg	= document.createElement("img");
	objThumbImg.src	= "/images/misc/clock.gif";
	objThumbImg.width		= "85";
	objThumbImg.height	= "85";
	objThumbImg.border	= "0";
		
	var objThumbImgDiv = document.createElement("div");
	objThumbImgDiv.align = "center";
	objThumbImgDiv.id = "thumpPic";
	objThumbImgDiv.appendChild(objThumbImg);
		
	var objThumbWrap	= document.createElement("div");
	objThumbWrap.id		= "thumpLayer";
	objThumbWrap.style.visibility	= "hidden";
	objThumbWrap.style.position		= "absolute";
	objThumbWrap.style.top	= "0";
	objThumbWrap.style.left	= "0";
	objThumbWrap.style.zIndex = "9999";
	objThumbWrap.appendChild(objThumbImgDiv);
	document.body.appendChild(objThumbWrap);
}

function showPop(imgName) {
	if (!document.getElementById("thumpLayer")) buildPopLayer();
	if (document.getElementById("thumpLayer") && (thumpImg.width > 0)) {
		clearInterval(thumpInt);
		intImgIntervalCnt = 0;
		imgWidth = thumpImg.width;
		imgHeight = thumpImg.height;
		document.getElementById("thumpPic").innerHTML = "<img src='" + thumpImg.src + "' border='0' style='border:1px solid #666' alt=''>";
		objDivStyle.width		= (imgWidth + 2);
		objDivStyle.height	= (imgHeight + 2);

		if (mouseThumpX + imgWidth + 24 + 20 >= document.body.clientWidth) {	
			objDivStyle.left = mouseThumpX - (imgWidth + 24 + 30);
		}
		if ((mouseThumpY - document.body.scrollTop) + imgHeight + windowPadding > document.body.clientHeight) {
			objDivStyle.top = (mouseThumpY - (((mouseThumpY - document.body.scrollTop) + imgHeight + windowPadding + 10) - document.body.clientHeight));
		}
		if (document.getElementById("minibannerTabel") && hideSwitch) {
			minibannerArray	= new Array();
			if (document.getElementById("minibannerTabel").innerHTML.indexOf(".swf") != -1) {
				minibannerArray[minibannerArray.length]	= document.getElementById("minibannerTabel");
				document.getElementById("minibannerTabel").style.visibility = "hidden"
			}
			else if (document.getElementById("minibannerTabel").getElementsByTagName("SELECT") && document.getElementById("minibannerTabel").getElementsByTagName("SELECT").length > 0) {
				for (i = 0; document.getElementById("minibannerTabel").getElementsByTagName("SELECT")[i]; i++) {
					minibannerArray[minibannerArray.length]	= document.getElementById("minibannerTabel").getElementsByTagName("SELECT")[i];
					document.getElementById.minibannerTabel.getElementsByTagName("SELECT")[i].style.visibility = "hidden";
				}
			}
		}
		document.getElementById("thumpLayer").style.visibility = "visible";
	}
	intImgIntervalCnt = intImgIntervalCnt + 1;
	if (intImgIntervalCnt > 30) {
		clearInterval(thumpInt);
		intImgIntervalCnt = 0;
	}
}

function hidePop() {
	if (document.getElementById && document.getElementById("thumpLayer")) {
		document.getElementById("thumpLayer").style.visibility = "hidden";
		document.getElementById("thumpLayer").style.backgroundColor = strPopBG;
		if (minibannerArray.length > 0)
			for (i = 0; minibannerArray[i]; i++) minibannerArray[i].style.visibility = "visible";
		document.getElementById("thumpPic").innerHTML = "<img src='/images/misc/clock.gif'  alt=''>";
		clearInterval(thumpInt);
		intImgIntervalCnt = 0;
	}
}

function positionPop(evt,imgName,hideSwitch) {
 if (document.getElementById && evt) {
		if (!document.getElementById("thumpLayer")) buildPopLayer();
		if (document.getElementById("thumpLayer")) {
			pos = getCords(evt);
			mouseThumpX = pos[0];
			mouseThumpY = pos[1]; 

			objDivStyle = document.getElementById("thumpLayer").style;
			objDivStyle.left = mouseThumpX + "px";
			objDivStyle.top = mouseThumpY + "px";
			objDivStyle.zIndex = 999;
			if (typeof hideSwitch != "number") hideSwitch = 0;
			thumpImg.src = imgName;
			windowPadding = 24;
			thumpInt = window.setInterval("showPop('" + imgName + "')",100);
		}
	}
}

function getCords(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information

	var pos = new Array(2);
        pos[0] = posx;
        pos[1] = posy;
        return pos;
}

//TODO fix up
function getStockInfo(ItemNo,ItemVariantCode)
 {
  if (document.getElementById('itemInventory') == null) return;
	var checkStockItemNo = ItemNo
	var checkStockItemVariantCode = ItemVariantCode
	
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { document.getElementById('itemInventory').innerHTML = oXML.responseText; };
	myConn.connect("_includes/ajaxActions.asp?ajaxAction=doInventory", "POST", "ItemNo="+checkStockItemNo+"&ItemVariantCode="+encodeURIComponent(checkStockItemVariantCode), fnWhenDone);
}

function ajax_getStockInfo(ItemNo,ItemVariantCode)
 {
  if (document.getElementById('itemInventory') == null) return;
	var checkStockItemNo = ItemNo
	var checkStockItemVariantCode = ItemVariantCode
	
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { document.getElementById('itemInventory').innerHTML = oXML.responseText; };
	myConn.connect("/?AJAX=GetStock", "POST", "ItemNo="+checkStockItemNo+"&ItemVariantCode="+encodeURIComponent(checkStockItemVariantCode), fnWhenDone);
	//myConn.connect("/?AJAX=GetStock", "GET", "ItemNo="+checkStockItemNo+"&ItemVariantCode="+encodeURIComponent(checkStockItemVariantCode), fnWhenDone);
}

function ajax_getImages(ItemNo, VariantCode)
{
  window.location = "/?ItemNo="+ItemNo+"&variant="+VariantCode;
  /*
  var prodImgs = remmah.DOM.getElementsByClassName("prodImgs");
  for (var i = 0; i < prodImgs.length; i++)
  {
    var prodImg = prodImgs[i];
    //alert(prodImg.src);
    var no = queryParams("No", prodImg.src)
    if (no)
    {
      alert(no);
    }
  };
  */ 
}

function queryParams(ji, hu) {
  //hu = window.location.search.substring(1);
  gy = hu.split("&");
  for (i=0;i<gy.length;i++)
  {
    ft = gy[i].split("=");
    if (ft[0] == ji)
    {
      return ft[1];
    }
  }
}

//TODO fix up
function getStockStatusBtn(strItemNo) 
{
	document.getElementById('itemInventory').innerHTML = "<a href=# onClick=getStockInfo('"+strItemNo+"',(document.getElementById('frmItemVariant')?document.getElementById('frmItemVariant').value:''))><img src=../_grfx/_icons/btn_Selagerstatus.gif alt=Lagerstatus align=absmiddle border=0/></a>"
}

function clearFieldDefaultValue(defaultText, field)
{
	if (field.value == defaultText)
	{
		field.value = "";
	}
}
function checkFieldDefaultValue(defaultText, field)
{
	if (field.value == "")
	{
		field.value = defaultText;
	}
}

var tst = 0;

function resizeImgsToFitParent()
{
  //alert('resizeImgsToFitParent');
  //$('.imgWrapper').imagefit();
  //$('.imgWrapper').each(function(){
  //  $('img', $(this)).not($("table img")).width('10%');
  //});
};


