//global "vent på ajax"
var fortsett = 0;

function loginEditModeShow()
{
	$("divLoginEditMode").style.display = "inline";
}


function loginEditModeAbort()
{
	$("divLoginEditMode").style.display = "none";
}

function editModeClose()
{
	//last page på nytt...
	window.location.href=window.location.href;
}

function editModeSave()
{
	$("editForm").submit();
}

function switchEditMode()
{
	var oFCKeditor = new FCKeditor( 'textareaEditMode' ) ;
	oFCKeditor.BasePath = "/fckeditor/" ;
	oFCKeditor.ToolbarSet = 'MyToolbar' ;
	oFCKeditor.Width = "100%";
	oFCKeditor.Height = "100%";
	oFCKeditor.ReplaceTextarea() ;
}

//glob funsjon for lasting av sider inn i div-tag
function loadForm(file, divId, arg, argValue, showWait)
{
	fortsett = 0;	
	ajax = new sack();
	if (showWait)
	{
		document.getElementById(divId).innerHTML = "<br><img src='img/24-0.gif' align='absmiddle'>";
	}
	ajax.resetData();
	ajax.requestFile = file;
	ajax.encodeURIString = false;
	//ta høyde for flere parametere...
	if(argValue.length>0)
	{
		arg = arg.split("|");
		argValue = argValue.split("|");
		for (i=0;i<arg.length;i++ )
		{
			ajax.setVar(arg[i], argValue[i]);
		}
	}
	ajax.setVar("cacheKiller", Date().toString() + Math.random().toString());
	ajax.method = "POST"; 
	ajax.element = divId;
	ajax.onCompletion = function(){fortsett = 1};
	ajax.runAJAX();
	return true;
}

function loadFormLagreSak(file, divId, arg, argValue, showWait)
{
	fortsett = 0;	
	ajax = new sack();
	if (showWait)
	{
		document.getElementById(divId).innerHTML = "<br><img src='img/24-0.gif' align='absmiddle'>";
	}
	ajax.resetData();
	ajax.requestFile = file;
	ajax.encodeURIString = false;
	//ta høyde for flere parametere...
	if(argValue.length>0)
	{
		arg = arg.split("|");
		argValue = argValue.split("|");
		for (i=0;i<arg.length;i++ )
		{
			ajax.setVar(arg[i], argValue[i]);
		}
	}
	ajax.setVar("cacheKiller", Date().toString() + Math.random().toString());
	ajax.method = "POST"; 
	ajax.element = divId;
	ajax.onCompletion = function(){
		//last page på nytt...
		window.location.href=window.location.href;};
	ajax.runAJAX();
	return true;
}

function loadSak(sakId)
{
	loadForm("detSkjerSak.asp", "textContent", "sakId", "" + sakId + "", false);
}

function openDetSkjer(sakId)
{
	loadForm("editDetSkjer.asp", "editSak", "sakId", "" + sakId + "", false);
	$("editSak").style.display = "inline";
}

function lagreSak()
{
	//merk knapp som "vent"
	$("btnLagreSak").value = "Vent";
	$("btnLagreSak").disabled = "disabled";
	editNyhetOverskrift = $("editNyhetOverskrift").value;
	editNyhetOverskrift = editNyhetOverskrift.replace(/ /g,"+");
	editNyhetIngress = $("editNyhetIngress").value;
	editNyhetIngress = editNyhetIngress.replace(/ /g,"+");
	editNyhetIngress = editNyhetIngress.replace(/(\r\n|[\r\n])/g, "<br />");


	loadFormLagreSak("updateSak.asp", "AJAXpipe", "sakID|dato|overskrift|ingress|vis", "" + $("editNyhetId").value + "|" + $("editNyhetDato").value + "|" + editNyhetOverskrift + "|" + editNyhetIngress + "|" + $("editNyhetVis").value + "", false);
	//oppdater side:

	//test nå:
	//alert("id:" + $("editNyhetId").value + ",dato:" + $("editNyhetDato").value + ",Overskrift:" + editNyhetOverskrift + ",Ingress:" + editNyhetIngress + ",vis:" + $("editNyhetVis").value);	
}

function skapNyhet()
{
	loadForm("editDetSkjer.asp", "editSak", "sakId", "ny", false);
	$("editSak").style.display = "inline";
}

function slettNyhet(sakId)
{
	if(confirm("Er du sikker?"))
	{
		loadFormLagreSak("slettSak.asp", "AJAXpipe", "sakId", "" + sakId + "", false);
		//oppdater side:
		//last page på nytt...
		//window.location.href=window.location.href;
	}
}

function ventXMillisek(x)
{
	tid = new Date();
	tidStopp = Date.UTC(tid.getYear(), tid.getMonth(), tid.getDay(), tid.getHours(), tid.getMinutes(), tid.getSeconds()) + x;
	running = true;
	while(running)
	{
		tid = new Date();
		tidNaa = Date.UTC(tid.getYear(), tid.getMonth(), tid.getDay(), tid.getHours(), tid.getMinutes(), tid.getSeconds());
		if(tidNaa>tidStopp)
		{
			running = false;	
		}
	}
}


















/* EOF */

