﻿/*	
	------------------------------------------
	Crossbrowser-Helper javascript includefile
	Avancit AB (C) 2005
	------------------------------------------
*/


// ---------------- GLOBALA STARTUPSCRIPT ----------------- //

// tar reda på var musen befinner sig.
var mouseX=0;var mouseY=0;
document.onmousemove=getMousePos;
function getMousePos(moveEvent)
	{
	mouseX=(window.event)? window.event.x : moveEvent.pageX;
	mouseY=(window.event)? window.event.y : moveEvent.pageY;
	}

// ----------------- BROWSER TESTER ----------------------- //

function isIE(){

}

function isMAC(){
}

function isMOZILLA(){
}

// -----------------  GLOBALA FUNKTIONER ------------------ //
function GetObjById(elmId){
	if (document.layers){return document.layers(elmId)}
	else if (document.all){return document.all(elmId)}
	else if (document.getElementById){return document.getElementById(elmId)}
	else {alert("Okänd browser, Javascript kommer ej att fungera.")}
	
}

//Göm eller visa beroende på parametrar.
function ShowHide(BoolShow, elmName){

		if (BoolShow == true) {
			GetObjById(elmName).style.visibility = "visible";
		}
		else {
			GetObjById(elmName).style.visibility = "hidden";
		}
}



//funkar bara i IE
function moveToCenter(obj)
{
	GetObjById(obj).style.left=(10)+'px';
	GetObjById(obj).style.top=(parseInt(event.y - 7))+'px';
	GetObjById(obj).children[0].focus();
}


//Alerta ut med hjälp av Eval det man skickar in.
function EvalAlert(elmId){
	eval("alert(" + GetObjById(elmId).value + ")");
}


//flyttar objektet till där musen är, och om det finns något child, get det fokus.
function moveObj(objId,clicker, focusChildIndex)
{
	if (focusChildIndex == null) {focusChildIndex = 0}
	GetObjById(objId).style.left=(parseInt(mouseX))+'px';
	GetObjById(objId).style.top=(parseInt(mouseY - 7))+'px';
	if  (document.children) 
		{ 
			if  (GetObjById(objId).children[focusChildIndex] && GetObjById(objId).children[focusChildIndex].focus) {
				GetObjById(objId).children[0].focus(); 
			}
		}
	else {
		if  (GetObjById(objId).childNodes[focusChildIndex] && GetObjById(objId).childNodes[focusChildIndex].focus) {
				GetObjById(objId).childNodes[0].focus();
			}
		}
} 

function OpenWin(url, xwidth, yheight){
    window.open(url,'userviewer', 'status=0, toolbar=0, height='+ yheight +', width='+ xwidth +', resizable=1, scrollbars=1').focus()
}

function OpenCustomWin(url, windowname, parameters){
    window.open(url,windowname, parameters).focus()
}

function ConvertNumber(inp){
    var beginsWithZero = inp.charAt(0) == 0;
    var res = parseInt(inp,10);
    if (beginsWithZero == true)  {
        res = String("0") + String(res)
    }
    return res
}
