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] );
	}
} 

/* Changes type of element to newType. Does so by replacing the element */
function changeType(oldElm, newType){
	var newElm = document.createElement('input');
	newElm.type = newType;
	if(oldElm.name) newElm.name = oldElm.name;
 	if(oldElm.id) newElm.id = oldElm.id;
 	if(oldElm.value) newElm.value = oldElm.value;
 	if(oldElm.onfocus) newElm.onfocus = oldElm.onfocus;
 	if(oldElm.onblur) newElm.onblur = oldElm.onblur;
 	oldElm.parentNode.replaceChild(newElm,oldElm);
	return newElm;
}

/* If element has the value text it will be cleared. If (password) then it will change type to password */
function clearInput(element, text, password){
	element.select();
	if(element.value == text){
		element.value = "";
		if(password){
			var newElm = changeType(element, "password");
			if(newElm){
				window.tempElm = newElm;
    			setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
    		}
		}
	}
}

/* If element has the value "" it will be changed to text. If (password) then it will change type to text */
function fillInput(element, text, password){
	if(element.value == ""){
		element.value = text;
		if(password){
			changeType(element, "text");
		}
	}
}

function initInput(formname, name, text, password){
	//changeType crashes Konqueror 3.3 and 3.4 and Safari 1.0
	var ua = navigator.userAgent.toLowerCase();
	if( ((ua.indexOf('konqueror')!=-1) && (document.all || (ua.indexOf('khtml/3.4')!=-1))) ||
	    (((ua.indexOf('safari')!=-1) && !window.print) || (document.defaultCharset && !window.print))){
		changeType = function(){};
	}
	document[formname][name].value=text;
	if(password){
		changeType(document[formname][name], "text");
	}
}

function makeSelectsExclusive() {
	select1 	= 	document.getElementById("question1");
	select2 	= 	document.getElementById("question2");
	
	for(i = 0; i < select1.length; i++) {
		if(select1.options[i].selected == true) {
			select2.options[i].disabled = true;
		} else {
			select2.options[i].disabled = false;
		}
	}
	for(i = 0; i < select2.length; i++) {
		if(select2.options[i].selected == true) {
			select1.options[i].disabled = true;
		} else {
			select1.options[i].disabled = false;
		}
	}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var n = 1;
var total = 3;
function slideShow() {
	if(!document.getElementById("slideshow")){
		return;
	}
	preload();
	setTimeout("loadBkg()", 9000);
}
function preload() {
	image1 = new Image();
	image1.src = "/images/startpage_slide1.jpg";
	image2 = new Image();
	image2.src = "/images/startpage_slide2.jpg";
	//image3 = new Image();
	//image3.src = "/images/startpage_slide3.jpg";
}
function switchImage() {
	thisImage = eval("image" + n)
	image = document.getElementById("slideshow").getElementsByTagName("img")[0];
	image.src = thisImage.src;
	fadeIn(0);
	setTimeout("loadBkg()", 9000);
}
function smoothIt() {
	image = document.getElementById("slideshow").getElementsByTagName("img")[0];
	setOpacity(image, 0);
	setTimeout("switchImage()", 2000);
}
function loadBkg(){ 
	lastImage = eval("image" + n)
	lastBkg = lastImage.src
	lastBkgValue = "url(" + lastBkg + ")"
	document.getElementById("slideshow").style.backgroundImage = lastBkgValue ;
	if (n >= total) {
		n = 1;
	} else {
		n++;
	}
	setTimeout("smoothIt()", 2000);
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";	// IE/Win
	obj.style.KHTMLOpacity = opacity/100;				// Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100;					// Older Mozilla and Firefox
	obj.style.opacity = opacity/100;					// Safari 1.2, newer Firefox and Mozilla, CSS3
}

function fadeIn(opacity) {
	if (document.getElementById) {
		obj = document.getElementById("slideshow").getElementsByTagName("img")[0];
		if (opacity < 101) {
			setOpacity(obj, opacity);
			opacity += 5;
			window.setTimeout("fadeIn("+opacity+")", 50);
		}
	}
}

addEvent(window,"load",slideShow);

var BrowserDetect = {
    init: function() {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
		|| this.searchVersion(navigator.appVersion)
		|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function(data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function(dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
	{ string: navigator.userAgent,
	    subString: "OmniWeb",
	    versionSearch: "OmniWeb/",
	    identity: "OmniWeb"
	},
	{
	    string: navigator.vendor,
	    subString: "Apple",
	    identity: "Safari"
	},
	{
	    prop: window.opera,
	    identity: "Opera"
	},
	{
	    string: navigator.vendor,
	    subString: "iCab",
	    identity: "iCab"
	},
	{
	    string: navigator.vendor,
	    subString: "KDE",
	    identity: "Konqueror"
	},
	{
	    string: navigator.userAgent,
	    subString: "Firefox",
	    identity: "Firefox"
	},
	{
	    string: navigator.vendor,
	    subString: "Camino",
	    identity: "Camino"
	},
	{		// for newer Netscapes (6+)
	    string: navigator.userAgent,
	    subString: "Netscape",
	    identity: "Netscape"
	},
	{
	    string: navigator.userAgent,
	    subString: "MSIE",
	    identity: "Explorer",
	    versionSearch: "MSIE"
	},
	{
	    string: navigator.userAgent,
	    subString: "Gecko",
	    identity: "Mozilla",
	    versionSearch: "rv"
	},
	{ 		// for older Netscapes (4-)
	    string: navigator.userAgent,
	    subString: "Mozilla",
	    identity: "Netscape",
	    versionSearch: "Mozilla"
	}
],
    dataOS: [
	{
	    string: navigator.platform,
	    subString: "Win",
	    identity: "Windows"
	},
	{
	    string: navigator.platform,
	    subString: "Mac",
	    identity: "Mac"
	},
	{
	    string: navigator.platform,
	    subString: "Linux",
	    identity: "Linux"
	}
]

};
BrowserDetect.init();

GB_myShow = function(caption, url, height, width, callback_fn) {
    var options = {
        caption: caption,
        height: height || 700,
        width: width || 500,
        fullscreen: false,
        overlay_click_close: true,
        center_win: true,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}