/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
/***************************************************************************************
Variables to set:
***************************************************************************************/
messages=new Array()
//Write your descriptions in here.
messages[0]="Innmeldings- , start- og resultatlister alle Norske baner"
messages[1]="Stamtavler, avkomslister, starter og karriere enkelthester"
messages[2]="Trav- og heste-relaterte nettsteder"
//To have more descriptions just add to the array.

fromX=-200 //How much from the actual mouse X should the description box appear?
fromY=-20////How much from the actual mouse Y should the description box appear?

//To set the font size, font type, border color or remove the border or whatever,
//change the clDescription class in the stylesheet.

//Makes crossbrowser object.
function makeObj(obj){
   	this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;	
   	this.wref=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj].document:0;		
  	this.writeIt=b_writeIt;																
  	return this
}
function b_writeIt(text){
    if(bw.ns4){ 
		   this.wref.write(text);
			 this.wref.close();
	  }
    else this.wref.innerHTML=text}

//Capturing mousemove
var descx,descy;
function popmousemove(e){
descx=bw.ns4?e.pageX:event.x; descy=bw.ns4?e.pageY:event.y}

//Initiates page
var isLoaded;
function popupInit(){
	oDesc=new makeObj('divDescription')
	if(bw.ns4)document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove=popmousemove;
	isLoaded=true;
}	
//Shows the messages
function popup(num){
	if(isLoaded){
		oDesc.writeIt('<span class="clDescription">'+messages[num]+'</span>')
		if(bw.ie5) descy=descy+document.body.scrollTop
		oDesc.css.left=descx+fromX; oDesc.css.top=descy+fromY
		oDesc.css.visibility='visible'
  }
}
//Hides it
function popout(num){
	if(isLoaded) oDesc.css.visibility='hidden'
}

//initiates page on pageload.
// onload=popupInit;


/* Function for the From Handler*/
function formHandler() {
   var URL = document.form.site.options[document.form.site.selectedIndex].value;
// location.href = URL;
}


/* function to save the votes for polls */
function Vote() {
var iCheckedGrpCount=0;
	for (var i=0;i < document.forms[0].elements.length;i++) {
		var e = document.forms[0].elements[i];
			if (e.type == "radio") {
				if (e.checked) {
				 iCheckedGrpCount++ ;
			 } 
		 }	
	 }
				
	if(iCheckedGrpCount == 0) { 
		alert("Vennligst velg ett alternativ");
	} else {
	document.frmMain.action="../polls/resultat.asp"
	document.frmMain.method="post"
	document.frmMain.submit()
 }
}

/*=============================================================================*/
/* Drop down menu script */
/*=============================================================================*/
/************************************************************************
Do not remove this notice.
Revenge of the Menu Bar Demo
Copyright 2000-2004 by Mike Hall
Please see http://www.brainjar.com for terms of use. 
************************************************************************/
//	var dom = (document.getElementById)? true:false;

//<![CDATA[
function Browser() {
  var ua, s, i;
  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();
var activeButton = null;

function bClck(event, menuId) {
  var button;
	button = (browser.isIE) ? window.event.srcElement:event.currentTarget;
	// Associate the named menu to this button if not already done. Additionally, initialize menu display.

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null) {menuInit(button.menu);
		}
  }

  if (button.onmouseout == null) { button.onmouseout = buttonOrMenuMouseout;}
  if (button == activeButton) {return false;}

  // Reset the currently active button, if any.
  if (activeButton != null) {resetButton(activeButton);}

  // Activate this button, unless it was the currently active one.

  if (button != activeButton) {depressButton(button);activeButton = button;} else {activeButton = null;}
  return false;
}

function bMovr(event, menuId) {
  var button;
  if (activeButton == null) {bClck(event, menuId);return;}
	button = (browser.isIE) ? window.event.srcElement:event.currentTarget;
  if (activeButton != null && activeButton != button) {bClck(event, menuId);}
}

function depressButton(button) {
  var x, y;
  button.className += " mActive";
  if (button.onmouseout == null){button.onmouseout = buttonOrMenuMouseout;}
  if (button.menu.onmouseout == null){button.menu.onmouseout = buttonOrMenuMouseout;}

  x = (button.offsetLeft + 5);
  y = (button.offsetTop)  + button.offsetHeight;

  // For IE, adjust position.

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

	if (x > 700) {x = button.offsetLeft - (button.offsetWidth + 17);}

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";

  // For IE; size, position and show the menu's IFRAME as well.

  if (button.menu.iframeEl != null) {
    button.menu.iframeEl.style.left = button.menu.style.left;
    button.menu.iframeEl.style.top  = button.menu.style.top;
    button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
    button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
    button.menu.iframeEl.style.display = "";
  }

	var e=document.createElement("DIV");
	e.className="menuShadow";
	var sLeft = button.menu.style.left;
	e.style.left = (x + 2) + "px" ;
	e.style.top  = (y + 2) + "px" ;
	e.style.width  = button.menu.offsetWidth + "px";
	e.style.height = button.menu.offsetHeight + "px";
	button.menu.e = button.menu.parentNode.insertBefore(e, button.menu);
}

function resetButton(button) {
  removeClassName(button, "mActive");
  if (button.menu != null) {button.menu.previousSibling.style.display = "none";closeSubMenu(button.menu); button.menu.style.visibility = "hidden";}
	if (button.menu.iframeEl != null){button.menu.iframeEl.style.display = "none";}
}

function mOvr(event) {
  var menu;
	menu = (browser.isIE) ? getContainerWith(window.event.srcElement, "DIV", "hnMnu"):event.currentTarget;
  if (menu.activeItem != null){closeSubMenu(menu);}
}

function iOvr(event, menuId) {
  var item, menu, x, y;

	item = (browser.isIE) ? getContainerWith(window.event.srcElement, "A", "mItem"):event.currentTarget;
  menu = getContainerWith(item, "DIV", "hnMnu");

  if (menu.activeItem != null){closeSubMenu(menu);}
  menu.activeItem = item;
  item.className += " miActive";

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null){menuInit(item.subMenu);}
  }

  if (item.subMenu.onmouseout == null){item.subMenu.onmouseout = buttonOrMenuMouseout;}

	x = (item.parentNode.offsetLeft + item.parentNode.offsetWidth) - 2;
  y = getPageOffsetTop(item) - 5;

  // Adjust position to fit in view.

  var maxX, maxY;

  if (browser.isIE) {
    maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
							  (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  if (browser.isOP) {
    maxY = document.documentElement.scrollTop  + window.innerHeight;
  }
  if (browser.isNS) {
    maxY = window.scrollY + window.innerHeight;
  }
	
  maxX = (x + item.offsetWidth);
  maxY -= item.subMenu.offsetHeight;

  if (maxX > 730) {
   x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  }
	y = Math.max(0, Math.min(y, maxY));

  // Position and show the sub menu.

  item.subMenu.style.left = x + "px";
  item.subMenu.style.top = y + "px";
  item.subMenu.style.visibility = "visible";

  // For IE; size, position and display the menu's IFRAME as well.
  if (item.subMenu.iframeEl != null) {
    item.subMenu.iframeEl.style.left = item.subMenu.style.left;
    item.subMenu.iframeEl.style.top = item.subMenu.style.top;
    item.subMenu.iframeEl.style.width = item.subMenu.offsetWidth + "px";
    item.subMenu.iframeEl.style.height = item.subMenu.offsetHeight + "px";
    item.subMenu.iframeEl.style.display = "";
  }

	var e=document.createElement("DIV");
	e.className="menuShadow";
	var sLeft = item.subMenu.style.left;
	e.style.left = (x + 2) + "px" ;
	e.style.top  = (y + 2) + "px" ;
	e.style.width  = item.subMenu.offsetWidth + "px";
	e.style.height = item.subMenu.offsetHeight + "px";
	item.subMenu.e = item.subMenu.parentNode.insertBefore(e, item.subMenu);

  // Stop the event from bubbling.
  if (browser.isIE){window.event.cancelBubble = true;} else {event.stopPropagation();}
}

function closeSubMenu(menu) {
  if (menu == null || menu.activeItem == null){return;}

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    if (menu.activeItem.subMenu.iframeEl != null) {menu.activeItem.subMenu.iframeEl.style.display = "none";}
		menu.activeItem.subMenu.previousSibling.style.display = "none";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "miActive");
  menu.activeItem = null;
}


function buttonOrMenuMouseout(event) {
  var el;
  if (activeButton == null) return;
  if (browser.isIE){el = window.event.toElement;}  else if (event.relatedTarget != null) {el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);}
  if (getContainerWith(el, "DIV", "hnMnu") == null) { resetButton(activeButton); activeButton = null;}
}


function menuInit(menu) {
  if (browser.isIE) {
    var iframeEl = document.createElement("IFRAME");
    iframeEl.frameBorder = 1;
    iframeEl.src = "javascript:;";
    iframeEl.style.display = "none";
    iframeEl.style.position = "absolute";
    menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
  }
	menu.isInitialized = true;
}

function initPg() {
	var mLyr = document.getElementById("topMenu");
	var sMnu = mLyr.getElementsByTagName("div");	
	for(k = 0; k < sMnu.length; k++) {
		if (sMnu[k].id != "mnuBar" && sMnu[k].className != "mSep") {sMnu[k].className = "hnMnu";}		
	}
	for(k = 0; k < sMnu.length; k++) {
		if(sMnu[k].className == "hnMnu" ) {
			var sLnk = sMnu[k].getElementsByTagName("a");
			for(m = 0; m < sLnk.length; m++) {
				sLnk[m].className = (sLnk[m].onclick) ? "mItem hSub":"mItem";
			}
		}		
	}
	document.getElementById("topMenu").style.display = "block";
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {
// Starting with the given node, find the nearest containing element with the specified tag name and style class.
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName && hasClassName(node, className)) {return node;}
    node = node.parentNode;
  }
  return node;
}

function hasClassName(el, name) {
  var i, list;
// Return true if the given element currently has the given class name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++) {
    if (list[i] == name) {return true;}
	}
  return false;
}

function removeClassName(el, name) {
  var i, curList, newList;
  if (el.className == null){return;}
// Remove the given class name from the element's className property.
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {
  var x = el.offsetLeft;
  if (el.offsetParent != null){x += getPageOffsetLeft(el.offsetParent);}
  return x;
}

function getPageOffsetTop(el) {
  var y = el.offsetTop;
  if (el.offsetParent != null){y += getPageOffsetTop(el.offsetParent);}
  return y;
}
//]]>

/*=================================================*/
/* Add Event and window load events */
/*=================================================*/
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() {obj["e"+type+fn]( window.event  ); 
		}
		obj.attachEvent("on"+type, obj[type+fn]);
	} 
}

////////////////Ajax call on homepage///////////////////////


var ajaxpack = new Object()
	ajaxpack.basedomain = "http://" + window.location.hostname
	ajaxpack.ajaxobj = createAjaxObj()
	ajaxpack.filetype = "txt"

	ajaxpack.postAjaxRequest = function(url, parameters, callbackfunc, filetype){
		ajaxpack.ajaxobj = createAjaxObj() //recreate ajax object to defeat cache problem in IE
		if (this.ajaxobj){
			this.filetype = filetype
			this.ajaxobj.onreadystatechange = callbackfunc;
			this.ajaxobj.open('POST', url, true);
			this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.ajaxobj.setRequestHeader("Content-length", parameters.length);
			this.ajaxobj.setRequestHeader("Connection", "close");
			this.ajaxobj.send(parameters);
		}
	}


 function createAjaxObj(){
		var httprequest=false
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc
			httprequest=new XMLHttpRequest()
			if (httprequest.overrideMimeType)
				httprequest.overrideMimeType('text/xml')
		}
		else if (window.ActiveXObject){ // if IE
			try {
				httprequest=new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
			}
		}
		return httprequest
	}
////////////////////////////////////////////////////////////////


addEvent(window,"load", initPg);
