﻿// JScript File
// Håller koll på vart musen är på sidan
/*
var Xpos = 0;
var Ypos = 0;
if (document.all || document.getElementById)	//Explorer, Netscape 6
{
	document.onmousemove = set_position;	//musen_flyttar anropas då musen flyttas
}
else if (document.layers)			//Netscape
{
	window.captureEvents(Event.MOUSEMOVE);
	window.onMouseMove = set_position;	//musen_flyttar anropas då musen flyttas
}

function set_position(ev)			//Lagrar vart musen finns
{
	if (document.all)			//Explorer
	{
		Xpos = window.event.x;
		Ypos = window.event.y;
	}
	else if (document.layers || document.getElementById)		//Netscape
	{
		Xpos = ev.pageX;
		Ypos = ev.pageY;
	}
}
*/
// Hanterar defaultknapp på sidan
function clickButton(e, buttonid){ 
    var bt = document.getElementById(buttonid); 
    if (typeof bt == 'object'){ 
        if(navigator.appName.indexOf("Netscape")>(-1)){ 
            if (e.keyCode == 13){ 
                bt.click(); 
                return false; 
            } 
        } 
        if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
            if (event.keyCode == 13){ 
                bt.click(); 
                return false; 
            } 
        } 
    } 
} 
function cursorPosition(lay, hide) {   
    if (document.all)				//Explorer 4,5
	{
	//document.writeln(document.all.scrollTop);
	//document.writeln(Xpos+document.body.scrollLeft);
	//document.writeln(Xpos);
	document.writeln(Ypos+document.body.scrollTop);
	document.writeln(Ypos);
		document.alllay.style.left = Xpos+document.body.scrollLeft;
		document.alllay.style.top = Ypos+document.body.scrollTop;
	}
	else if (document.layers)			//Netscape 4
	{
		document.layerslay.left = Xpos;
		document.layerslay.top = Ypos;
	}
	else if (document.getElementById)	//Netscape 6
	{
		document.getElementById(lay).style.left = Xpos;
		document.getElementById(lay).style.top = Ypos;
	}
	HideLayer(lay, hide);
}


function HideLayer(lay, hide) {
    if (document.all)				//Explorer 4,5
	{
		document.alllay.style.visibility = (hide) ? 'hidden' : 'visible';
	}
	else if (document.layers)			//Netscape 4
	{
		document.layerslay.visibility = (hide) ? 'hidden' : 'visible';
	}
	else if (document.getElementById)	//Netscape 6
	{
		document.getElementById(lay).style.visibility = (hide) ? 'hidden' : 'visible';
	}
}
// Fokussättningen på inloggningen (
function clearContents(orgvalue, textbox, type){
    if (type == 2) {
        fhide(true);
    }
    else if (orgvalue == textbox.value){
        textbox.value = "";
    }
}
function restoreContents(orgvalue, textbox, type){
    if (type == 1 && textbox.value == "") 
        textbox.value = orgvalue;
    if (type == 2 && textbox.value == ""){
        fhide(false);
        textbox.value = "";
    }
}

function fhide(hide)
{
	var x = document.getElementById('passwordlayer');
	x.style.visibility = (hide) ? 'hidden' : 'visible';
}

var winOpenHelp
function f_OpenHelpWin(s_Url)
{  	
	if (winOpenHelp && winOpenHelp.open && !winOpenHelp.closed) winOpenHelp.close();
	winOpenHelp = window.open(s_Url,'WinHelp','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,left=40,top=40,copyhistory=no,width=500,height=300');
	winOpenHelp.focus();
}

function CheckQty(minqty, tbx, intype) {
	var qtysaveok, okqty, minqty, qty;
	qty = document.all(tbx).value;

	qtysaveok = false;
	okqty = qty % minqty;
	if (okqty == 0) 
		qtysaveok = true;
	else
		okqty = minqty;
	// Angivet antal är ej ok, sätt minsta tillåtna och meddela att ändring gjorts.
	if (qtysaveok == false) {
		document.all(tbx).value = okqty;
		if (intype == 1)
		    return window.confirm('OBS: Vald artikel är ej lagervara, vilket innebär en längre leveranstid \noch att ni endast kan beställa hela prissatta förpackningar. \nBeställt antal har satts till minsta tillåtna förpackning(' + okqty + '). \n\nBekräfta genom att trycka på OK.');
		else
		    return window.confirm('OBS: Vald artikel kan endast beställas i hela prissatta förpackningar. \nBeställt antal har satts till minsta tillåtna förpackning(' + okqty + '). \n\nBekräfta genom att trycka på OK.');
	}
	else if (intype == 1)
		return window.confirm('OBS: Vald artikel är ej lagervara, vilket innebär en längre leveranstid \noch att ni endast kan beställa hela prissatta förpackningar. \nEventuell frakt tillkommer. \n \nBekräfta genom att trycka på OK.'); 
}
function CheckQtyHelm(minqty, tbx, intype) {
	var qtysaveok, okqty, minqty, qty;
	qty = document.all(tbx).value;

	qtysaveok = false;
	okqty = qty % minqty;
	if (okqty == 0) 
		qtysaveok = true;
	else
		okqty = minqty;
	// Angivet antal är ej ok, sätt minsta tillåtna och meddela att ändring gjorts.
	if (qtysaveok == false) {
		document.all(tbx).value = okqty;
		if (intype == 1)
		    return window.confirm('OBS: Vald artikel är ej lagervara, vilket innebär en längre leveranstid \noch att ni endast kan beställa hela prissatta förpackningar. \nBeställt antal har satts till minsta tillåtna förpackning(' + okqty + '). \n\nBekräfta genom att trycka på OK.');
		else
		    return window.confirm('OBS: Vald artikel kan endast beställas i hela prissatta förpackningar. \nBeställt antal har satts till minsta tillåtna förpackning(' + okqty + '). \n\nBekräfta genom att trycka på OK.');
	}
	else if (intype == 1)
		return window.confirm('OBS: Vald artikel är ej lagervara, vilket innebär en längre leveranstid \noch att ni endast kan beställa hela prissatta förpackningar. \nEventuell frakt och hemtagningskostnad (85kr) tillkommer. \n \nBekräfta genom att trycka på OK.'); 
}

// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function doSomething(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
}

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
    while(1) 
    {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function ChangeBigImage(obj, BigImageID, storBildUrl){

    var imgagen =  document.getElementById(BigImageID);
    if (imgagen.src!=storBildUrl) {
        imgagen.src=storBildUrl;
        
        var storDiven =  document.getElementById('storBildDiv');
        storDiven.style.visibility = 'visible';
        
        
        storDiven.style.top = yMousePos + 'px';//imgagen.style.top;
        storDiven.style.left = xMousePos + 'px';//imgagen.style.left;
    }
}
function HideBigImage(obj){
    document.getElementById('storBildDiv').style.visibility = 'hidden';
}

function setTdWidth()
{
    //tabellen: tblArticleInfo, celler: td_descr, td_image
    //window.defaultStatus = "This is the status bar";
    //document.getElementById("ctl00_Main_tblArticleInfo").offsetHeight
    
    var descrHeight = 0;
    var descrWidth = 0;
    var imgHeight = 0;
    
    if (document.getElementById)			//Netscape 6
    {
        descrHeight = document.getElementById('ctl00_Main_td_descr').offsetHeight;
        descrWidth = document.getElementById('ctl00_Main_td_descr').offsetWidth;
        imgHeight = document.getElementById('ctl00_Main_td_image').offsetHeight;
        //alert('test3' + descrWidth);
    }
    else if (document.layers)				//Netscape 4
    {
        descrHeight = document.layers['ctl00_Main_td_descr'].document.height;
        descrWidth = document.layers['ctl00_Main_td_descr'].document.width;
        imgHeight = document.layers['ctl00_Main_td_image'].document.height;
        //alert('test2' + descrWidth);
    }
    else if (document.all)					//Explorer 4,5
    {
        descrHeight = document.all['ctl00_Main_td_descr'].clientHeight;
        descrWidth = document.all['ctl00_Main_td_descr'].clientWidth;
        imgHeight = document.all['ctl00_Main_td_image'].clientHeight;
        //alert('test' + descrWidth);
    }
        
    //var imgWidth = document.getElementById("ctl00_Main_td_image").offsetWidth;
    //var tblWidth = document.getElementById("ctl00_Main_tblArticleInfo").offsetWidth;
    if ((descrWidth < 200 && descrWidth > 100) || (imgHeight > 20 && imgHeight < descrHeight))
    {
        if (document.getElementById)			//Netscape 6
            document.getElementById("ctl00_Main_tblArticleInfo").style.width = '660px';
        else if (document.layers)				//Netscape 4
            document.layers['ctl00_Main_tblArticleInfo'].style.width = '660px';
        else if (document.all)					//Explorer 4,5
            document.all['ctl00_Main_tblArticleInfo'].style.width = '660px';
            
    }
     
    if (descrWidth == 0) {
        if (document.getElementById)			//Netscape 6
        {
            document.getElementById("ctl00_Main_td_descr").style.width = '220px';
            document.getElementById("ctl00_Main_td_descr").appendChild(document.createTextNode('&nbsp;&nbsp;&nbsp;'));
        }
        else if (document.layers)				//Netscape 4
        {
            document.layers("ctl00_Main_td_descr").style.width = '220px';
            document.layers("ctl00_Main_td_descr").appendChild(document.createTextNode('&nbsp;&nbsp;&nbsp;'));
        }
        else if (document.all)					//Explorer 4,5
        {
            document.all("ctl00_Main_td_descr").style.width = '220px';
            document.all("ctl00_Main_td_descr").appendChild(document.createTextNode('&nbsp;&nbsp;&nbsp;'));
        }
    }
}