var x,y;
function get_mouse(e){
  if (!e) e = window.event;
  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      x = e.pageX;
      y = e.pageY;
    }
    else if (e.clientX || e.clientY)  { 
      x = e.clientX + document.body.scrollLeft;
      y = e.clientY + document.body.scrollTop;
    }  
  }
//window.status = x + ' ' + y + ' ' + document.body.scrollTop;
}
function get_mouseclick(event){
if (!event) event = window.event;
if (event.button == 1){
//	window.status="event2:"+event.type;
}
else {
//window.status="event:"+event.type;
}
}
function popkey(event){
if (!event) event = window.event;
       	
    if (event.keyCode==27) { 
      helpScreen.display='none';
      try {helpScreenMask.display='none'}
      catch (err) {}
      event.returnValue=false;
    }
    if ((event.keyCode == 8) && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password"))
       {
           event.returnValue=false
       }    
    if (event.keyCode == 13)
       {
		var navn;
		try {
			navn = event.target.name; 
		} catch (e) {
			navn = event.srcElement.name;
		}
        	if (navn == 'Query') {
			SearchModule();
        	}   	
        	if (navn == 'nywebpw') {
			document.cookie = 'nywebpw='+escape(document.forms[0].nywebpw.value);
			self.location.reload();
        	}   
           event.returnValue=false
       }    
  }
if (window!= top) {
	top.location.href=location.href
}
function textCount(field, leftfield, maxlimit) {
if (field.value.length > maxlimit) 
	field.value = field.value.substring(0, maxlimit);
	else 
	leftfield.value = field.value.length + ' tegn av maks 200 utfylt.';
}
function trim( str ) {
	var resultStr = "";
	
	resultStr = trimLeft(str);
	resultStr = trimRight(resultStr);
	
	return resultStr;
} 
function trimLeft( str ) {
	var resultStr = "";
	var i = len = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;
	// Make sure the argument is a string
	str += "";
	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;
   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}
  	return resultStr;
} 
//---------------------------------------------------------------------------------------------------------------
function trimRight( str ) {
	var resultStr = "";
	var i = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;
	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
} 
//---------------------------------------------------------------------------------------------------------------
/*used in read forms*/
function SearchModule() { 
	var f = document.forms[0];
	var q = f.Query.value;
		ftSearch(q)
}
/*used in forms*/
function SearchModuleN() { 
	var f = window.document.forms[0];
	var q = f.QueryN.value;
		ftSearch(q)
}
function ftSearch(q)
{
	if( q == "")
	{
		//alert('Du må skrive inn et søkeord.');
			//return false;
	}
	
	f = document.forms[0];
	var path = f.Path_Info.value.toLowerCase();
	order = "&SearchOrder=4"
//'+location.host.substring(4)
	loc = 'http://www.google.no/search?q='+q+' '+'site%3Akolnes.karmoyskolen.no%2Fminskole%2Fkolnes';
	//loc = 'http://www1.minskole.no' + f.ThisDb.value + 'SearchAll?SearchView&Query=' + q + '*' + order+'&Start=1'
	//var comp = replacesubstring(loc, " ", "+");
	window.location = loc
}
/*occur when user press enter*/
function keyDown(DnEvents) { // handles keypress
if( netscape)
{
	k = DnEvents.which;
}
else
{
	k = window.event.keyCode;
}
  if (k ==27) { 
      helpScreen.display='none'
      event.returnValue=false;
   }
if (k == 13) { // enter key pressed
if ( felt == "Freetext1")
{
	SearchModule()
}
else if ( felt == "Freetext2")
{
	SearchModuleN()
}
else if ( felt == "RichText")
{
return k;
}
return false;
      }
   }
/********************************************************************************/
/*validate options i checkboxes based on the boxName parameter*/
/*******************************************************************************************************************/
function validateOptions(boxName)
{
var f = window.document.forms[0];
var box = eval("window.document.forms[0]." + boxName); 
var length = box.length;
var flag = "yes";
var number = 0;
for (i = 0; i < length; i++)
{
if(box[i].checked == false)
{
number = number +1
}
}
if (number == length)
{
flag = "no";
}
return flag;
}
/*******************************************************************************************************************/
function findPosY(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}
function setDivFilter(deleted, usedForm){
var divhidden = "hidden";
if (deleted == "Yes")
{
divhidden = "visible"
}
if (window.document.layers) {
                handle="window.document.layers";
                stylevar="";
         }else{
                handle="document.all";
                stylevar=".style";
                }
eval(handle+'["'+'divFilter'+'"]'+stylevar+'.visibility = divhidden');
}
var runSkiftDiv = false;
function skiftDiv(del,yOffset)
{
if (runSkiftDiv == true){
	var i = 0;
	var diver;
	var gY;
	var yOff;
	var yHeight;
	try {
		divPos = document.getElementById('s'+del).offsetLeft + document.getElementById("topMenu").offsetLeft;	
	} catch (e) {}
	
	try {
		gY = document.getElementById("topMenu").offsetLeft-3;
	//alert('gy:'+gY);
		yOff = document.getElementById("Gruppe0").offsetTop;
		yHeight = document.getElementById("Gruppe0").offsetHeight;
//alert(yOff+' '+yHeight);
	}
	catch (e) {
		gY = x-20;
		yOff = 100;
	}
	diver = 'Gruppe1.#Gruppe2.#Gruppe3.#Gruppe4.#Gruppe5.#Gruppe6.#Gruppe7.'.split("#"); 
	for (i == 0; i < diver.length; i++)
	{
		if( diver[i] == del)
		{
			try {
			document.getElementById(del).style.visibility="visible";
			document.getElementById(del).style.left=-5+divPos+"px";
			//document.getElementById(del).style.left=gY+yOffset+"px";
			document.getElementById(del).style.top=yOff+yHeight+"px";
			//document.getElementById(del).style.top=yHeight+"px";
			//eval('document.all.' + del + '.style.visibility ="visible"');
			//eval('document.all.' + del + '.style.left = tmp');
			}
			catch (e) {}
		}
		else
		{
			try {
			document.getElementById(diver[i]).style.visibility="hidden";
			} catch (e) {}
		}
	}	
}
}
/*******************************************************************************************************************/
function oWin(url,properties){
hurl = 'http://'+window.location.host+url;
wwin = window.open( hurl, "newWindow", properties);
}
function oWinName(url,name,properties){
hurl = 'http://'+window.location.host+url;
wwin = window.open( hurl, name, properties);
}
/*******************************************************************************************************************/
//COOKIE 
//-----------------------------------------------------------------------------------------------------
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);   
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var expDays = 1;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
   }
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//END COOKIES
//------------------------------------------------------------------------------------------------------
function imageOnClick()
{
var dis = '';
	for( i=0; i<document.images.length ; i++ ) {
		dis = document.images[i].src.toLowerCase();
		if (dis.indexOf('minskolev4') == -1 && dis.indexOf('luconfig') == -1 && dis.indexOf('lupicg') == -1 && dis.indexOf('alledoc') == -1 && dis.indexOf('treedocad') == -1) {
			document.images[i].onclick= function() { popUpMx('<center><img width=100% border=0 src=' +escape(this.src)+'>',120) };
			document.images[i].style.cursor = 'hand';
			document.images[i].alt = 'Klikk for å vise større bilde';
			//alert(document.images[i].src);
		}
	}
}
function imageOnClickGall()
{
var dis = '';
var id = '';
	for( i=0; i<document.images.length ; i++ ) {
		dis = document.images[i].src.toLowerCase();
		if (dis.indexOf('alledoc') > 1) {
			document.images[i].onclick= function() { popUpGall('<img id="gallPic" border=0 src=' +escape(this.src)+'>',10,this.id) };
			document.images[i].style.cursor = 'hand';
			document.images[i].alt = 'Klikk for å vise større bilde';
		}
	}
}
netscape = "";
felt = "";
ver = navigator.appVersion; 
len = ver.length;
for(iln = 0; iln < len; iln++) 
{
	if (ver.charAt(iln) == "(") break;
}
	netscape = (ver.charAt(iln+1).toUpperCase() != "C");
document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}
function popUpMx(msg,ix){
var vidde = msg.indexOf('img')>1?"":"WIDTH=330";
var content="<TABLE  "+ vidde +" BORDER=0 BORDERCOLOR=#000000 CELLPADDING=3 CELLSPACING=5 "+
"BGCOLOR=#ffffff><TD ALIGN=left><FONT COLOR=black SIZE=1>"+unescape(msg)+"</FONT></TD><tr><td><center><input class=button_main type=Button value='Lukk vindu (esc)' onclick=\"helpScreen.display='none';\"></td></tr></TABLE>";
helpScreen.left=ix+Xoffset;
helpScreen.top=document.body.scrollTop+50;
//alert(y/2 +document.body.scrollTop);
var hS = document.getElementById("helpScreen");
hS.innerHTML=content;
helpScreen.display='';
var nX = 20;
	try {
		nX = (document.body.offsetWidth-hS.offsetWidth)/2; 
		} catch (e) {}
	helpScreen.left = nX;
}
function popUpMx2(msg,ix){
var content="<div id=\"helpScreenTop640\"></div><div id=\"helpScreenMiddle640\">"+unescape(msg)+
"<p><center><input class=button_main type=Button value='Lukk vindu (esc)' onclick=\"helpScreen.display='none';\"></p>"+
"</div><div id=\"helpScreenBottom640\"></div>";
helpScreen.left=ix+Xoffset;
helpScreen.top=document.body.scrollTop+50;
//alert(y/2 +document.body.scrollTop);
document.getElementById("helpScreen").innerHTML=content;
//picH = document.getElementById('zoomPic');
//helpScreenMiddle = document.getElementById('helpScreenMiddle640');
helpScreen.display='';
//alert(picH.height);
//helpScreenMiddle.style.height= picH.height + 40 + "px";
}
var nId;
function popUpGall(msg,ix,id){
nId = new Number(id)+1; 
var butten = "<input class=button_main type=Button value='Neste bilde &gt;&gt;' onclick=\"try{document.getElementById('gallPic').src = eval('document.getElementById(\\\''+ nId +'\\\').src');nId++}catch(e){this.style.display='none';}\">&nbsp;";
var buttenSS = "<input id='bSS' class=button_main type=Button value='Automatisk bildefremvisning >>' onclick=\"if(t==null){this.value='Stopp bildefremvisning';document.getElementById('loadslide').style.display = 'inline';j=(j==0?nId-1:j);runSlideShow();}else{this.value='Fortsett bildefremvisning';document.getElementById('loadslide').style.display = 'none';clearTimeout(t);t=null;}\">&nbsp;";
var content="<TABLE width=100% style=\"border-collapse: collapse; border: 25px solid #000;\" CELLPADDING=3 CELLSPACING=5 "+ 
"BGCOLOR=#000000><TD><center><FONT COLOR=black SIZE=1>"+unescape(msg)+"</FONT></TD><tr><td><center><img src=\"/minskoleV3/loading.gif\" id=\"loadslide\" style=\"display:none;width:32px;float:left;\">"+
buttenSS+butten+"<input class=button_main type=Button value='Lukk vindu (esc)' onclick=\"helpScreenMask.display='none';helpScreen.display='none';clearTimeout(t);t=null;\"></td></tr></TABLE>";
helpScreen.top=document.body.scrollTop+10;
//alert(y/2 +document.body.scrollTop);
document.getElementById("helpScreen").innerHTML=content;
helpScreen.display='';
helpScreenMask.display='block';
helpScreen.left=document.body.clientWidth/2-document.getElementById("helpScreen").offsetWidth/2;
fadeIn('dialogMask',0);
}
function nwts(s) { // no white space
return s.replace(/\s+/g, '');
}
function replacesubstring(sourceList,fromList,toList) 
{
	for (var i=0; i<sourceList.length; i++) 
		{ 
		if (sourceList.substring(i,i+fromList.length) == fromList) 
				{ 
					sourceList = sourceList.substring(0,i)+toList+sourceList.substring(i+fromList.length,sourceList.length)
				} 
		} 
	return sourceList
}
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
	//alert(opacity);
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 30);
    }
  }
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
