//<script>
window.onload = doonload;

function doonload()
{
    if (document.attachEvent)
    {
	    document.attachEvent("onkeydown",checkTab);
	    document.attachEvent("onclick",hideContextMenu);
    }
    else 
    {
        document.addEventListener("keydown", checkTab, false);
	    document.addEventListener("click",hideContextMenu, false);
    }
}


function dagSomTillganglig(year, month, day, add) {

    var datum = year + "-" + month + "-" + day;
    window.open("Resurs/RCPageTillgangligaTider.aspx?datum="+datum, "Tider","menubar=0,resizable=0,width=230,height=150"); 

}

///////////////////////// PABUTTON /////////////////////////////////////////////

if (!window.webRoot)
    window.webRoot = "";
    
var btnUpLeft = new Image();
btnUpLeft.src = webRoot+"/images/PAButton/btn_up_left.gif";
var btnUpBg = new Image();
btnUpBg.src = webRoot+"/images/PAButton/btn_up_bg.gif";
var btnUpRight = new Image();
btnUpRight.src = webRoot+"/images/PAButton/btn_up_right.gif";

var btnDownLeft = new Image();
btnDownLeft.src = webRoot+"/images/PAButton/btn_down_left.gif";
var btnDownBg = new Image();
btnDownBg.src = webRoot+"/images/PAButton/btn_down_bg.gif";
var btnDownRight = new Image();
btnDownRight.src = webRoot+"/images/PAButton/btn_down_right.gif";

var btnFocusLeft = new Image();
btnFocusLeft.src = webRoot+"/images/PAButton/btn_focus_left.gif";
var btnFocusBg = new Image();
btnFocusBg.src = webRoot+"/images/PAButton/btn_focus_bg.gif";
var btnFocusRight = new Image();
btnFocusRight.src = webRoot+"/images/PAButton/btn_focus_right.gif";

var btnOverLeft = new Image();
btnOverLeft.src = webRoot+"/images/PAButton/btn_over_left.gif";
var btnOverBg = new Image();
btnOverBg.src = webRoot+"/images/PAButton/btn_over_bg.gif";
var btnOverRight = new Image();
btnOverRight.src = webRoot+"/images/PAButton/btn_over_right.gif";

var focusedBtn = "";

function buttonDown(id)
{
	if (focusedBtn != null && focusedBtn != "")
	{
		var lastFocus = focusedBtn; focusedBtn = id;
		buttonUp(lastFocus);
	}
	else
	{
		focusedBtn = id;
	}
	document.getElementById(id + "_left").style.background = "url(" + btnDownLeft.src + ")";
	document.getElementById(id+"_center").style.background = "url("+btnDownBg.src+")";
	document.getElementById(id + "_right").style.background = "url(" + btnDownRight.src + ")";
}
function buttonUp(id)
{
	if (focusedBtn == id)
	{
	    document.getElementById(id + "_left").style.background = "url(" + btnFocusLeft.src + ")";
		document.getElementById(id+"_center").style.background = "url("+btnFocusBg.src+")";
		document.getElementById(id + "_right").style.background = "url(" + btnFocusRight.src + ")";
	}
	else {

	    if (document.getElementById(id + "_left") != null) {
	        document.getElementById(id + "_left").style.background = "url(" + btnUpLeft.src + ")";
	        document.getElementById(id + "_center").style.background = "url(" + btnUpBg.src + ")";
	        document.getElementById(id + "_right").style.background = "url(" + btnUpRight.src + ")";
	    }
	}
}
function buttonOver(id)
{
    document.getElementById(id + "_left").style.background = "url(" + btnOverLeft.src + ")";
	document.getElementById(id+"_center").style.background = "url("+btnOverBg.src+")";
	document.getElementById(id + "_right").style.background = "url(" + btnOverRight.src + ")";
}

function buttonFocus(id)
{
	if (focusedBtn != "")
	{
		var lastFocus = focusedBtn;
		focusedBtn = id;
		if (lastFocus != null)
			buttonUp(lastFocus);
	}
	else
	{
		focusedBtn = id;
	}

	if (id != null)
	{
	    document.getElementById(id + "_left").style.background = "url(" + btnFocusLeft.src + ")";
		document.getElementById(id+"_center").style.background = "url("+btnFocusBg.src+")";
		document.getElementById(id + "_right").style.background = "url(" + btnFocusRight.src + ")";
		
		document.getElementById(id+"_center").focus();
	}
}

function checkTab(e)
{ 	
    setLogoutKeyPressed();  // för utloggning
    
	var code = 0;

	if (!window.event)
	    code = e.which;
	else {
	    code = event.keyCode;
	    e = event;
	}
		
	if (code == 9)
	{
		var activeFound = false;
		var start = 0;
		var inc = 1;

		if (e.shiftKey)
		{
			start = document.all.length-1;
			inc = -1
		}
		
		for (var i = start; i != -1 && i < document.all.length; i+=inc)
		{
			var tag = document.all[i];
			if (!activeFound && tag == document.activeElement)
			{
				activeFound = true;
			}
			else if (activeFound && tag.type != "hidden" && (tag.tagName == "INPUT" || tag.tagName=="SELECT"))
			{
				buttonFocus(null);
				return;
			}
			else if (activeFound && tag.className == "PABUTTON" && tag.id.substring(0, tag.id.length)+"_center" != document.activeElement.id && tag.onclick && !tag.disabled)
			{
			
				buttonFocus(tag.id.substring(0, tag.id.length));
				window.event.returnValue=false;
				return;
			}
		}
		buttonFocus(null);
	}
	else if (code == 13)
	{
		if (focusedBtn != null && focusedBtn != '') {

		    if (document.getElementById(focusedBtn + "") != null)
		        document.getElementById(focusedBtn+"").click();
		}
	}
	else if(code == 116)
	{
        parent.f5pressed = true;
	}
	
}

var contextMenuJustShown = false;
var contextMenu = null;

function showContextMenu(btn, items, postback) {


    // Hämta den inre delen av knappen. TP 18299
	btn = document.getElementById(postback+"_center"); // aka,, konstigt

	if (btn == null) {
	    btn = document.getElementById(postback.replace(/\$/,"_"));
	}

	if (btn == null) {
	    btn = document.getElementById(btn.id.substring(0, btn.id.length - 4) + "_center");
	}

	// Beräkna absolut position för btn
	var abstop = 0;
	var absleft = 0;
	var p = btn;
	do
	{
		abstop += p.offsetTop;
		absleft += p.offsetLeft;
		p = p.offsetParent;
	} while(p != null);

	// Skapa menyn
	if (contextMenu == null)
	{
	    contextMenu=document.createElement("DIV");
	    contextMenu.className = "PABUTTON_CONTEXTMENU";
	    document.body.appendChild(contextMenu);
	}
	contextMenu.style.visibility="visible";
	contextMenu.style.left = absleft;
	contextMenu.style.width = btn.offsetWidth;
	
	var itemArray = items.split(",");
	var code = "<table>";
	for (var i = 0; i < itemArray.length; i++)
	{
		code += "<tr><td><A HREF=\"javascript: __doPostBack('"+postback+"', '"+itemArray[i]+"');\">"+itemArray[i]+"</A></td></tr>";
	}
	code+="</table>";
	contextMenu.innerHTML = code;

	// Beräknar antalet pixlar under knappen på skärmen
	var pixelUnder = document.body.offsetHeight-abstop-21+document.body.scrollTop;

    if (pixelUnder < contextMenu.offsetHeight)
    {
        contextMenu.style.top = abstop-contextMenu.offsetHeight;
    }
    else
    {
        contextMenu.style.top = abstop+21;
    }

	
	contextMenuJustShown = true;
}

function hideContextMenu()
{

    setLogoutKeyPressed();  // för utloggning
  
	if (contextMenuJustShown)
		contextMenuJustShown = false;
	else
	{
	    if (contextMenu != null)
		    contextMenu.style.visibility="hidden";
	}
}

///////////////////////// PABOKHYLLA /////////////////////////////////////////////

function openFile(doc)
{
    window.open(this.document.location+'?file='+doc);
}

function openLink(link)
{
    window.open(link);
}

///////////////////////// PAENTITYFORM /////////////////////////////////////////////

function validateInt(field, piNullable)
{
	var val = parseInt(field.value, 10);
	if (isNaN(val))
	{
		if (piNullable)
			field.value='';
		else
			field.value='0';
	}
	else
	{
		field.value = val;
	}
}

function validateDouble(field, piNullable)
{
	var val = parseFloat(field.value.replace(',', '.'));
	if (isNaN(val))
	{
		if (piNullable)
			field.value='';
		else
			field.value='0,0';
	}
	else
	{
		field.value = (''+val).replace('.', ',');
	}
}

function validateDouble3Signed(field, piNullable)
{
	var val = parseFloat(field.value.replace(',', '.'));
	if (isNaN(val))
	{
		if (piNullable)
			field.value='';
		else
			field.value='0,00';
	}
	else
	{
		field.value = (''+val).replace('.', ',');
	}
}

function validateDate(piField, piPrecision, piMin, piMax, piNullable) {

    if (piMin == null || piMin=='')
        piMin = 'January 01, 1899 00:00:00';
    if (piMax == null || piMax=='')
        piMax = 'December 31, 9998 23:59:59';
    if (piNullable != true)
        piNullable = false;

	var ivValidDate = stringToDate(piField, piPrecision, piMin, piMax, piNullable);
	
	// Formatera utdata
	piField.value = '';
	if (ivValidDate != null)
	{
		if (piPrecision == 'Manad')
		{
			piField.value = ivValidDate.getFullYear()+'-'+padStr(ivValidDate.getMonth()+1);
		}
		if (piPrecision == 'Datum' || piPrecision == 'DatumOchTid') {
		    piField.value = ivValidDate.getFullYear() + '-' + padStr(ivValidDate.getMonth() + 1) + '-' + padStr(ivValidDate.getDate());
		    
			
			if (piPrecision == 'DatumOchTid')
			{
				piField.value += ' ';
			}
		}
		if (piPrecision == 'Tid' || piPrecision == 'DatumOchTid')
		{
		    piField.value += padStr(ivValidDate.getHours()) + ':' + padStr(ivValidDate.getMinutes()); //+':'+padStr(ivValidDate.getSeconds());
		}

		if (piPrecision == 'TidTom') 
		{
            var tid = padStr(ivValidDate.getHours()) + ':' + padStr(ivValidDate.getMinutes()); //+':'+padStr(ivValidDate.getSeconds());
            if (tid == '00:00')
                tid = '24:00';
           piField.value += tid;
        }
		
	}
}

function padStr(val)
{
	if (val<10)
	{
		return '0'+val;
	}
	else
	{
		return val;
	}
}

function stringToDate(piField, piPrecision, piMin, piMax, piNullable)
{
	// Variabler
	var output = new Date(0, 0, 0, 0, 0, 0);
	var isNull = piNullable;
	var minDate = new Date(piMin);
	var maxDate = new Date(piMax);	
	var datetime = piField.value.split(' ');
	var datepart = datetime[0].split('-');
	var timepart = new Array();
	if (piPrecision == 'DatumOchTid' && datetime.length >= 2)
	{
		timepart = datetime[1].split(':');
	}
	else if (piPrecision == 'Tid' || piPrecision == 'TidTom') 
    {
        if (datetime[0].toString().indexOf(":") != -1)
            timepart = datetime[0].split(':');
        else 
        {
            if (datetime[0].toString().length > 3) {
                timepart = new Array(2);
                timepart[0] = datetime[0].toString().substring(0, 2);
                timepart[1] = datetime[0].toString().substring(2, 4);
            }
            else 
            {
                timepart = new Array(1);
                timepart[0] = datetime[0].toString().substring(0, 2);
            }

        }
	}

	// Sätt datum
	if (piPrecision == 'Datum' || piPrecision == 'DatumOchTid' || piPrecision == 'Manad')
	{
		if (datepart.length >= 1 && !isNaN(parseInt(datepart[0], 10)))
		{
			output = new Date(parseInt(datepart[0], 10), 0, 1);
			isNull = false;
		}
		if (datepart.length >= 2 && !isNaN(parseInt(datepart[1], 10)))
		{
			output = new Date(output.getFullYear(), parseInt(datepart[1], 10)-1, 1);
			isNull = false;
		}
		if (datepart.length >= 3 && !isNaN(parseInt(datepart[2], 10)))
		{
			output = new Date(output.getFullYear(), output.getMonth(), parseInt(datepart[2], 10));
			isNull = false;
		}	
	}
	
	// Sätt tid
	if (piPrecision == 'Tid' || piPrecision == 'DatumOchTid' || piPrecision == 'TidTom')
	{
		if (timepart.length >= 1 && !isNaN(parseInt(timepart[0], 10)))
		{
			output.setHours(parseInt(timepart[0], 10));
			isNull = false;
		}
		if (timepart.length >= 2 && !isNaN(parseInt(timepart[1], 10)))
		{
			output.setMinutes(parseInt(timepart[1], 10));
			isNull = false;
		}
		if (timepart.length >= 3 && !isNaN(parseInt(timepart[2], 10)))
		{
			output.setSeconds(parseInt(timepart[2], 10));
			isNull = false;
		}
	}

	if (isNull)
	{
		return null;
	}
	
	// Kontrollera gränser
	if (!isNaN(minDate) && output < minDate)
	{
		output = minDate;
	}
	else if (!isNaN(maxDate) && output > maxDate)
	{
		output = maxDate;
	}
	return output;
}

function dateFieldKeyPress()
{
	var sender = window.event.srcElement;
	var pos = -document.selection.createRange().move('character', -0x7FFFFFFF);
	
	if (pos == 2)
	{
	    if (sender.value.charAt(0) == '0')
	    {	        
	        sender.value = "20"+sender.value.substring(0,2)+'-'+sender.value.substring(5);
	        pos = 4;
	    }
	}

    window.status =pos+", "+window.event.keyCode+", "+sender.value.charAt(pos);
	
	if ((pos==4 || pos == 7) && window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{
	    sender.value = sender.value.substring(0, pos)+'-'+sender.value.substring(pos+2);
		pos++;
	}
	else
	{
		if ((window.event.keyCode >= 48 && window.event.keyCode <= 57))
		{
			sender.value = sender.value.substring(0, pos)+sender.value.substring(pos+1);
		}
		else if(window.event.keyCode == 45)
		{
			pos++;
		}
		else
		{
    	    window.event.cancelBubble=true;
		    window.event.returnValue=false;
		    return;
		}
	}
	
	var rng = sender.createTextRange();
	rng.move('character', pos);
	rng.select();

	if (pos == 9)
	{
		sender.value += String.fromCharCode(window.event.keyCode);
		gotoNextComponent(sender);
	}
}

function timeFieldKeyPress()
{
	var sender = window.event.srcElement;
	var pos = -document.selection.createRange().move('character', -0x7FFFFFFF);
		
	if (pos==2 && window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{
		sender.value = sender.value.substring(0, pos)+sender.value.charAt(pos)+sender.value.substring(pos+2);
		pos++;
	}
	else
	{
		if ((window.event.keyCode >= 48 && window.event.keyCode <= 57))
		{
			sender.value = sender.value.substring(0, pos)+sender.value.substring(pos+1);
		}
		else if(window.event.keyCode == 58)
		{
			pos++;
		}
	}
	
	var rng = sender.createTextRange();
	rng.move('character', pos);
	rng.select();

	if (pos == 4)
	{
		sender.value += String.fromCharCode(window.event.keyCode);
		gotoNextComponent(sender);
	}
}

function gotoNextComponent(sender)
{
    if (window.event != null)
    {
    	window.event.cancelBubble=true;
		window.event.returnValue=false;
    }
	var found = false;
	for (var i = 0; i < document.all.length; i++)
	{
		if (found && ((document.all[i].tagName=='INPUT' && document.all[i].type != 'hidden') || document.all[i].tagName=='SELECT'))
		{
			document.all[i].focus();
			return;
		}
		if (document.all[i] == sender)
		{
			found = true;
		}
	}
}

///////////////////////// PAGRID /////////////////////////////////////////////

var ivGridHiddenField = "";
var ivSelectedHidden = ""
var ivSelectedCell = ""
var ivSelectedCellBgColor = ""
		
//activate
function cellActivate(id, cell)
{
  var hiddenfield = document.getElementById(id);
  document.getElementById(ivGridHiddenField).value = hiddenfield.value
  ivSelectedHidden = id;
  ivSelectedCell = cell;
  ivSelectedCellBgColor = cell.style.backgroundColor;
  cell.style.backgroundColor = 'white';		
}
                
//deActivate
function cellDeactivate(cell)
{
  cell.style.backgroundColor = ivSelectedCellBgColor;
  updateHiddenFromText();
  document.getElementById(ivGridHiddenField).value = "";
}					
				
//setTextFromHidden
function setTextFromHidden()
{
  if (ivSelectedCell != "")
  {
    ivSelectedCell.style.backgroundColor = 'white'
  }
	if (ivSelectedHidden != "") 
  {
    var hiddenfield = document.getElementById(ivSelectedHidden);
    var textbox = document.getElementById(ivGridHiddenField);
    textbox.value = hiddenfield.value
    textbox.readOnly = false
  }
}

//setHiddenFromText
function setHiddenFromText()
{
  if (ivSelectedCell != "")
  {
    ivSelectedCell.style.backgroundColor = ivSelectedCellBgColor;
  }
  updateHiddenFromText();
}

//updateFromText
function updateHiddenFromText()
{
  if (ivSelectedHidden != "")
  {
	  var hiddenfield = document.getElementById(ivSelectedHidden);
    hiddenfield.value = document.getElementById(ivGridHiddenField).value;				
  }
}

function checkOne(id, cnt, val)
{
    var box = document.getElementById(val); 
    var avallt = 1; 
			
    if (box.checked == true) {avallt = 0; } // samma som vald, avcheckar bar den
	
	for(var i = 0; i < cnt; i++) { 
        box = document.getElementById(id+'_chk' + i); 
        if (box != null){
            if (box.checked == true) box.checked = false; // avcheckar allt
        }
    }  // end for
    box = document.getElementById(val); 
			
    if(avallt == 0) {
        box.checked = true;
        
        var chk = document.getElementById(id+'_checked');
        if (chk != null)
        {
		    chk.value=val;
		    box.form.submit();
		}
    } 
}

///////////////////////// PAMAINPANEL /////////////////////////////////////////////

	var currentObj = null;
	var offsetX = 0;
	var offsetY = 0;

	document.onmousemove = doDrag;
	document.onmouseup = endDrag;

    function setPanelPos(obj, x, y)
    {
        obj.style.pixelLeft = x;
	    obj.style.pixelTop = y;
        obj.style.position='relative';
    }

    function getPanelPosX(obj)
    {
        return obj.style.pixelLeft;
    }

    function getPanelPosY(obj)
    {
        return obj.style.pixelTop;
    }

	function doDrag()
	{
		if (currentObj != null)
		{
			currentObj.style.pixelLeft = event.clientX-offsetX;
			currentObj.style.pixelTop = event.clientY-offsetY;
		}
	}
	
	function endDrag()
	{
		currentObj = null;
	}
	
	function activateDragging(obj)
	{
		offsetX = event.clientX;
		offsetY = event.clientY;
		
		if (obj.style.pixelLeft != 0)
		{
			offsetX -= obj.style.pixelLeft;
			offsetY -= obj.style.pixelTop;
		}

		currentObj = obj;
		currentObj.style.position='relative';
	}
	
function normalizeframe()
{
    parent.document.getElementById('vertikaldelning').cols = '*, 180';
}

///////////////////////// PATABCONTROL /////////////////////////////////////////////

var tabid = "";
var lastSelected = null;

	function setSelectedTab(tabid) {
	    var msg = document.getElementById('Inladdningsmeddelande');
	    if (msg != null)
		    msg.style.visibility='visible';
		var tab = document.getElementById(tabid);
		lastSelected.className='PATABCONTROL_TAB';
		lastSelected = tab;
		tab.className='PATABCONTROL_SELECTEDTAB';
	}
	function gotoNextTabPage() {
		gotoTabPage((1+parseInt(lastSelected.id.substring(lastSelected.id.lastIndexOf('_')+1), 10)));
	}
	function gotoPrevTabPage() {
		gotoTabPage((parseInt(lastSelected.id.substring(lastSelected.id.lastIndexOf('_')+1))-1));
	}
	function gotoTabPage(index)
	{
		var nextTab = document.getElementById(lastSelected.id.substring(0, lastSelected.id.lastIndexOf('_')+1)+index);
		if (nextTab != null){
			setSelectedTab(nextTab.id);
			document.getElementById(tabid).src=nextTab.all[0].href;
		}
	}
	
///////////////////////// PATIDTEXTBOX /////////////////////////////////////////////
	
			function checkTime(textbox)
			{
				if (textbox.value == '')
				{
					return;
				}
				
				if (textbox.value.length == 1 || textbox.value.length == 2)
				{
					textbox.value = textbox.value + ':00';
				}
				else if (textbox.value.indexOf(':') == -1)
				{
					if (textbox.value.length == 3)
					{
						textbox.value = textbox.value.substr(0, 1) + ':' + textbox.value.substr(1,2);
					}
					else if (textbox.value.length == 4)
					{
						textbox.value = textbox.value.substr(0, 2) + ':' + textbox.value.substr(2,2);
					}
				}		
			}
//</script>

/*************** *******************/
var currentPopUp = null;

function windowPopUp(url, title)
{

   currentPopUp = window.open(url, title, "status=0,toolbar=0,width=100,height=100");
}

function closeCurrentPopUp()
{
    try
    {
        if(currentPopUp)
            currentPopUp.close();
    }
    catch(e)
    {
    }
}



//document.onkeypress = setLogoutKeyPressed;
//document.onmouseup = setLogoutKeyPressed;

var logoutIntervall = null;
var logoutkeypressed = false;


function updateLogout()
{
try
{
    if(logouttime)
    {

    if(logoutIntervall)
         window.clearInterval(logoutIntervall);    
    
    logoutIntervall = window.setInterval("checkIfLogout()", logouttime);
    
    logoutkeypressed = false;
    }
    }
    catch(e)
    {
    }
}

function updateTime()
{
    if (request.readyState == 4)
    {
       if (request.status == 200)
         updateLogout();
       else if (request.status == 404)
         alert("Request URL does not exist");
       else
         alert("Error: status code is " + request.status);
    }
}

function setLogoutKeyPressed()
{
    logoutkeypressed = true;
}

var neverlogout = false;

function checkIfLogout() {
    if(logoutkeypressed || neverlogout)
    {
        createRequest();
        
        var url = window.webRoot + "/UpdateTime.aspx?ran=" + Math.random();
        request.open("GET", url, true);
        request.onreadystatechange = updateTime;
        request.send(null);
   }
   else
   {
       // Inget har hänt, logga ut
       window.location = window.webRoot + "/Login.aspx";
   }
    
}
var request;
function createRequest() {
  try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = false;
      }
    }
  }

  if (!request)
    alert("Error initializing XMLHttpRequest!");
}




// Kalendern webben script
var lastobj;
function javaSimplePopUp(e,maino,obj,msg,cap)
{
    // sätter ett popupid och kollar så att det inte redan finns uppoppat, dvs, max en per dag
    var popid = 'popidkal';
    var onlyone = document.getElementById(popid);

    if (onlyone != null) {
        javaSimplePopUpClose();
    }
    else if (skippNew && onlyone != null) {
        skippNew = false;
        return;
    }

    if (insidePopup) {
        insidePopup = false;
        return;
    }

    if (document.getElementById('storningar').style.left != '100px' && document.getElementById('storningar').style.left != '-100px') {
        return;
    }
    skippNew = false;

    lastobj = obj;

    if(!e) 
        e = window.event;
    
    var object = document.getElementById(maino);
    var divi = document.createElement('div');

    var top = (e.clientY + document.body.scrollTop);
    var left = (e.clientX + document.body.scrollLeft);

    var availheight = document.body.scrollTop + document.body.clientHeight;
    var availleft = document.body.scrollLeft + document.body.clientWidth;


    divi.style.position = 'absolute';
    divi.className = 'simplePopUp';
    divi.id = divi.name = popid;
    divi.onclick = javaSimplePopUpChangeZIndex;
    divi.style.zIndex = currentZIndex++;

    divi.onclick = clickedPopUp;

    // tabletaggen
    var table = document.createElement('table');
    table.className = 'simplePopUpTable';
    divi.appendChild(table);

    // cationtaggen
    var caption = document.createElement('caption');
    caption.className = 'simplePopUpCaption';
    caption.innerHTML = '<nobr>'+cap+'</nobr>';
    caption.dragobject = divi;
    caption.onmousedown = doStartDragging;

    table.appendChild(caption);

    // tbodyn
    var tbody = document.createElement('tbody');
    tbody.className = 'simplePopUpTbody';
    table.appendChild(tbody);

    // tr
    var tr = document.createElement('tr');
    tbody.appendChild(tr);

    // td
    var td = document.createElement('td');
    td.innerHTML = msg;
    tr.appendChild(td);

    // Lägger till en knapp
    var tr2 = document.createElement('tr');
    tbody.appendChild(tr2);
    // td2
    var td2 = document.createElement('td');

    var knapp = '<table align=\"center\"><tr><td class=\"simplePopUpButton\"  onClick=\"javaSimplePopUpClose();\"';
    knapp += '>St&auml;ng</td></tr></table>';

    td2.innerHTML = knapp;
    tr2.appendChild(td2);

    divi.style.top = top;
    divi.style.left = left;

    object.appendChild(divi);

    if ((top + divi.clientHeight) > availheight)
        divi.style.top = availheight - divi.clientHeight;

    if ((left + divi.clientWidth) > availleft)
        divi.style.left = availleft - divi.clientWidth;

}

var insidePopup = false;

function clickedPopUp() {
    //cancelEvent();
    insidePopup = true;
}

// simple close

var lastclose = null;
function javaSimplePopUpClose() {

    var mainO = document.getElementById(lastobj);
    var pop = document.getElementById("popidkal");
    
    mainO.removeChild(pop);
    skippNew = true;
}

// simple ZindexChange
function javaSimplePopUpChangeZIndex()
{
    this.style.zIndex = currentZIndex++;
}
var skippNew = false;



function cancelEvent() {
    if (window.event) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
}


function checkallgrid(gridden) {
    
    var allacheck = true;
    var i = 0;

    while (true) {
        box =  document.getElementsByName(gridden + "_chk" + i);
        
        if (box.length != 0) {
            if (box[0].checked == false) {
                allacheck = false;
                break;
            }
        }
        else
            break;

        i++;


    }

    i = 0;

    while (true) {
        box = document.getElementsByName(gridden + "_chk" + i);

        if (box.length != 0)
            box[0].checked = !allacheck;
        else
            break;
        i++;
    }

}

