var banners = new Array(
	'images/TopBar-NYC.jpg',
	'images/TopBar-solnedgang.jpg',
	'images/TopBar-svaner-i-vand.jpg',
	'images/TopBar-fugle.jpg');
simplePreloadBanners();
function simplePreloadBanners()
{ 
  document.imageArray = new Array(banners.length);
  for(var i=0; i<banners.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = banners[i];
  }
}

var bannerIndex = 0;

function initbanner()
{
	if (!document.images) return;
	document.images['banner'].src = banners[bannerIndex];
	if (++bannerIndex==banners.length) bannerIndex=0;
	setTimeout('initbanner()',12000);
}
// --------------------------
function DoPrint(){
	window.print();
}
function MemberOf(sString, aArray){
	for(var i in aArray) {
		if(sString == aArray[i])
			return i;
	}
	return -1;
}
function getElement(elementId){
	if( document.getElementById ) {
		var e = document.getElementById( elementId );
	} else {
		if( document.all ) {
		    var e = document.all[ elementId ];
		} else {
		    var e = new Object();
		}
	}
	if( !e ) { return null; }
	return e;
}
function changeDisplay(elementId, bShow) {
	e = getElement(elementId)
	if( e.style ) { e = e.style; }
	if( typeof( e.display ) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) {
		window.alert( 'Din browser supporterer ikke denne funktion. \nYour browser does not support this feature' );
		return null;
	}
	if (e) e.display = (bShow)?"":"none";
}
var toggleDisplayArray = new Object();
function toggleDisplay(elementId) {
	if (toggleDisplayArray[elementId]=="undefined") toggleDisplayArray[elementId] = false;
	toggleDisplayArray[elementId] = !toggleDisplayArray[elementId];
	e = getElement(elementId)
	if( e.style ) { e = e.style; }
	if( typeof( e.display ) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) {
		window.alert( 'Din browser supporterer ikke denne funktion. \nYour browser does not support this feature' );
		return null;
	}
	if (e) e.display = (toggleDisplayArray[elementId])?"":"none";
}
function setDivHTML(divname, text) {
	l = getElement(divname)
	if(l) l.innerHTML = text;
}
function dbalert(){
	var s = ""; for (i=0; i< arguments.length; i++) {s += arguments[i] + " =' " + eval(arguments[i]) + "'\n " };	alert(s);
}
function testWin(x) {
	msg=window.open("","msg","toolbar=no,location=no,status=no,menubar=no,height=400,width=800,left=80,top=80,resizeable=yes,scrollbars=yes");
	msg.document.write("<html><title>TEST</title>");
	msg.document.write("<body bgcolor='white'>");
	msg.document.write("<br><br><table width=150><tr><td>"+x+"</td></tr></table>");
	msg.document.write("</body></html>");
}
// select the option with value 'name'. If it does not exist then the first value is selected.
function chooseSelectedDefaultToFirst(name, checkAgainst) {
  var f,i,v;
  f = eval("document.forms[0]." + name);
	//alert("chooseSelectedDefaultToFirst " + name + " -- " + checkAgainst);
  for(i=0;i<f.options.length;i++) {
    v = f.options[i].value;
    if(checkAgainst == v) {
      f.selectedIndex = i;
      break;
    }
  }
	if (f.selectedIndex==-1) f.selectedIndex = 0;
}
// returns YYMMDD hh:mm
function todaysDate(){
		d = new Date();
		m = d.getMonth() + 1;
		y = d.getYear();
		if(y > 2000)
			y -= 2000;
		else if(y >= 100) 
			y -= 100;
		return z(y) + z(m) + z(d.getDate()) + " " + z(d.getHours()) + ":" + z(d.getMinutes());
}
function z(x){
	return (x<10)? "0"+x:x;
}
// POPUP CONSTRUCTOR
function spawnRoutePopup(routeURL) {
  spawnPopup(routeURL,"ScandlinesPopup",501,450,1);
}
function spawnPopup(desktopURL,windowName,width,height,flag) {
	spawnPopupFull(desktopURL,windowName,width,height,flag,"yes","yes");
}
function spawnPopupFull(desktopURL,windowName,width,height,flag,scrollbars,status) {
	var w = 480, h = 340;
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	if (windowName == "") {
	   windowName = "_blank";
	}

	var leftPos = (w-width)/2, topPos = (h-height)/2;
	
	var resizable = "no";
	if (flag==1) {
		resizable = "yes";
	}
	if (document.all) {
		return window.open(desktopURL, windowName, "toolbar=no,location=no,status="+status+",menubar=no,scrollbars="+scrollbars+",width="+width+",height="+height+",resizable="+resizable+", top=" + topPos + ",left=" + leftPos );
	} else {
		return window.open(desktopURL, windowName, "toolbar=no,location=no,status="+status+",menubar=no,scrollbars="+scrollbars+",width="+width+",height="+height+",resizable="+resizable+",screenY=" + topPos + ",screenX=" + leftPos ); // + ",screenX="+leftpos+",screenY="+topPos );		
	}
}
// radioChoices = document.formName.radioGroupName
function radioSelect(radioChoices, val) {
	for (var c = 0; c<radioChoices.length; c++) { if (radioChoices[c].value == val) {radioChoices[c].checked = true;}}
}
function getSelectedRadioValue(radioChoices){
	for (c in radioChoices) if (radioChoices[c].checked == true) return radioChoices[c].value;
	return "undefined";
}

