/* 

esitebuilder v4 standard javascript file

*/


function gOb(id){return document.getElementById(id)}

// seite für falsche browser
wrongBrowserPage = 'browser.htm';

// die default seiten id
homedyn = 0;
homePageID = 'home-003-00'; 
homePageIDde = 'home-003-00-de.htm';
homePageIDfr = 'page-daccueil-003-00-fr.htm';
homePageIDen = 'http://en.nbi.ch/001nvb_00_en.htm';

// wurde die sprache nicht erkannt, diese seite anzeigen
errordyn = 0;
langErrorPage = homePageID; 
langErrorLang = 'de';

// diese sprachen werden unterstüzt
clientLangs = "de, fr, en";

function checkbrowser(){
	if(document.getElementById){
		checklang();
	} else {
		self.location.replace(wrongBrowserPage);
	}
}
function checklang(){
	lang = getCookie('mylang');
	if(clientLangs.indexOf(lang)==-1){
		lang = ((navigator.language)?navigator.language:(navigator.systemLanguage)?navigator.systemLanguage:'--').substring(0,2);
		valid = (clientLangs.indexOf(lang)!=-1)?1:0;
	} else {
		valid = 1;
	}
	loadPage(lang,valid);		
}
function loadPage(lang,valid){
	if(valid){
		if(homedyn){
			self.location.replace('index.taf?id='+homePageID+'&lang='+lang);		
		}else{
			self.location.replace(eval("homePageID"+lang));
			
		}
	} else {
		if(errordyn){self.location.replace('index.taf?id='+langErrorPage+'&lang='+langErrorLang);
		}else{self.location.replace(langErrorPage+"-"+langErrorLang+".htm");}
	}
}
// user lang saver
function setLang(setlang){
	if(document.getElementById){
		var now = new Date();fixDate(now);now.setTime(now.getTime() + 10 * 365 * 24 * 60 * 60 * 1000);
		setCookie('mylang',setlang,now);
	} else {
		self.location.replace(wrongBrowserPage);
	}
}


// window opener

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_openSetWindow(theURL,winName,launchWin,features) { //v1.0
  if (launchWin == ''){
    window.open(theURL,winName,features);
  }
  else{
    var controller = window.open(theURL,winName,features);
    if (controller.opener == null){
      controller.opener = self;
    }
    controller.opener.name = launchWin;
    return controller;
  }
}

// images
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) { //v3.0
  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); 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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// additional scripts
function formfield_colorchanger(){
	var color_1 = "#f5f5f5";
	var color_2 = "#ffffff";
	
	this.change_colors = function(color1,color2){
		color_1 = color1;
		color_2 = color2;
	};
	
	this.set_active_status = function(){
		this.style.backgroundColor = color_1;
	};
	this.set_passive_status = function(){
		this.style.backgroundColor = color_2;
	};
	this.init = function(use_tags,use_inputtypes){
		var tags = use_tags.split(",");
		var inputtypes = use_inputtypes.split(",");
		
		for(var i=0;i<tags.length;i++){
			var elem = document.getElementsByTagName(tags[i]);
			
			for(var a=0;a<elem.length;a++){
				for(var b=0;b<inputtypes.length;b++){
					if((elem[a].tagName == "INPUT" && elem[a].type == inputtypes[b]) || elem[a].tagName != "INPUT"){
						elem[a].onfocus = this.set_active_status;
						elem[a].onblur = this.set_passive_status;	
					}
				}
			}
		}
	};
}

function img_popup(img,width,height){
	var left = screen.width/2 - width/2;
	var top = screen.height/2 - height/2;
	var img_popup = window.open("img_popup/img_popup.htm?img="+img,"img_popup","width="+width+",height="+height+",left="+left+",top="+top);
	img_popup.focus();	
}

function get_para(str_name)
{
	var str_parameters = window.location.search;
	var int_first_pos_name = str_parameters.search(str_name);
	var int_first_pos_result = int_first_pos_name + str_name.length + 1;
	if((str_parameters.charAt(int_first_pos_name - 1) == "?" || str_parameters.charAt(int_first_pos_name - 1) == "&") && (str_parameters.charAt(int_first_pos_result - 1) == "="))
	{
		var int_last_pos_result = str_parameters.indexOf("&",int_first_pos_result);
		if(int_last_pos_result == -1)
		{
			var strResult = str_parameters.slice(int_first_pos_result,str_parameters.length);
		}
		else
		{
			var strResult = str_parameters.slice(int_first_pos_result,int_last_pos_result);
		}
		return strResult;
	}
	else
	{
		//alert("Parameter -" +str_name+ "- nicht vorhanden!");
	}
}



function startupPopup()
{
		var ablauf = getCookie('ablauf');
		
		if (!ablauf)
		{
			var zaehler = getCookie('zaehler');
			
			if (!zaehler || zaehler < 3)
			{
				var aktuell = new Date();
				var ablauf = aktuell.getTime() + (1 * 24 * 60 * 60 * 1000);
				aktuell.setTime(ablauf);
				
				var aktuell2 = new Date();
				var zukunft = aktuell2.getTime() + (100 * 12 * 30 * 1 * 24 * 60 * 60 * 1000);
				aktuell2.setTime(zukunft);
				
				document.cookie = 'ablauf=ablauf; expires=' + aktuell.toGMTString();
				
				zaehler++;
				document.cookie = 'zaehler='+zaehler+'; expires=' + aktuell2.toGMTString();
				
				var x,y;
				if (self.innerHeight) // all except Explorer
				{
					x = self.innerWidth;
					y = self.innerHeight;
				}
				else if (document.documentElement && document.documentElement.clientHeight)
					// Explorer 6 Strict Mode
				{
					x = document.documentElement.clientWidth;
					y = document.documentElement.clientHeight;
				}
				else if (document.body) // other Explorers
				{
					x = document.body.clientWidth;
					y = document.body.clientHeight;
				}
			
				var hintergrund = document.createElement('div');
				hintergrund.setAttribute('id','sp_hintergrund');
				hintergrund.style.position = 'absolute';
				hintergrund.style.zIndex = '50';
				hintergrund.style.backgroundColor = '#000000';
				hintergrund.style.left = '0px';
				hintergrund.style.top = '0px';
				hintergrund.style.width = x+'px';
				hintergrund.style.height = y+'px';
				hintergrund.style.filter = 'Alpha(opacity=50,style=a)';
				hintergrund.style.MozOpacity = '0.5';
				document.getElementsByTagName('body')[0].appendChild(hintergrund);
				stpo = document.getElementById("startupPopup");
				var sp_left = (x - 700) / 2;
				var sp_top = (y - 400) / 2;
				stpo.style.left = sp_left+'px';
				stpo.style.top = sp_top+'px';
				stpo.style.visibility = "visible";
			}
		}
}
