//bilder loeschen
function del_img(image_default,image,alt,fliesstext,caption) {
	eval ('document.' + image_default + '.src="/imperia/md/defaults/images/default5.jpg"');
	eval ('document.imperia.' + image + '.value=""');
	eval ('document.imperia.' + alt + '.value=""');
	if(fliesstext) eval ('document.imperia.' + fliesstext + '.value="ja"');
	if(caption) eval ('document.imperia.' + caption + '.value=""');
}


// gib die filesize beim download zurück
function size(filesize) {
	var size=filesize;
	var round_size_k = Math.round((size*10)/1024) / 10;
	var round_size;
	if (round_size_k < 1024) {
	  	round_size = round_size_k+'&nbsp;KByte';
	} else {
  		round_size = Math.round((round_size_k*10)/1024) / 10;
 	 	round_size = round_size+'&nbsp;MByte';
	}
	
	var down_time_s = Math.round(round_size_k / 5.5);
	var down_time;
	if (down_time_s < 60) {
		down_time = down_time_s+' sec';
	} else {
		down_time = Math.round((down_time_s*10)/60) / 10;
		down_time = down_time+' min';
	}
	document.write(round_size + ' | ' + down_time + ' / 56k' );
	return true;
}

// seite empfehlen
function seiteempfehlen(subject,bodybegin,bodyend) {
	var link  = location.href;
	var titel = document.title;
	mail_str  = "mailto:?subject="+escape(subject +" "+ titel);
  mail_str += "&body="+escape(bodybegin +" "+ titel +" "+ bodyend +" "+ link);
	location.href = mail_str;
}

//bookmark setzen
function addbookmark() {
	bookmarkurl=self.location.href;
	bookmarktitle=document.title;
	if (document.all) {
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
	} else alert("STRG + D drücken"); 
}

//zoom fenster öffnen
function show_zoom(pic,buttonname,titel,width_zoom,height_zoom) {
	var ziel = "/js/zoom.htm?buttonname=" +buttonname+ "&bild=" +pic+ "&titel=" +titel;
	
	// default
	var breite=600;
	var hoehe=590;
	
	// hoehe,breite zoombild
	var width_zoom_bild    = width_zoom;
  var height_zoom_bild   = height_zoom;
  	
	
	// breite und heohe des fenster in abhaenigkeit vom zoombild
	if (navigator.appName == "Microsoft Internet Explorer") {
      breite  = width_zoom_bild   + 48;
      hoehe = height_zoom_bild  + 200;
  } else {
      breite  = width_zoom_bild   + 32;
      hoehe = height_zoom_bild  + 160;
  }
	

	// breite, hoehe des bildschirms
 	var	br_screen	=	screen.availWidth;
	var	ho_screen	=	screen.availHeight;


	var	left = Math.round((br_screen/2)-(breite/2));
	var	top  = Math.round((ho_screen/2)-(hoehe/2));
	

	
	var params="width="+breite+",height="+hoehe+",left="+left+",top="+top+",resize=yes,menubar=yes,resizable=yes,scrollbars=1";
	
	
	
	zoomwindow=window.open(ziel,"ZoomWindow",params);
	//zoomwindow.moveTo(Math.round((br-breite)/2),Math.round((ho-hoehe)/2)-menuoffset);
}

//produktfamilie fenster öffnen
function show_info(ziel,brei,hoe,menubar,warart) {
	var warart = warart;	
	var ziel = ziel;
	var hoehe;
	var breite;
	if (brei) {	breite = brei	} else {breite =620};
	if (hoe) {hoehe = hoe} else {hoehe=590};		
	if (menubar) {menubar = menubar } else {menubar="yes"};

	var menuoffset=40;
	var	ho	=	screen.availHeight;
	var	br	=	screen.availWidth;
	var	left = Math.round((br-breite)/2);
	var	top = Math.round((ho-hoehe)/2);
	
	//var name = "ArtInfo" + warart 
	var name = "ArtInfo"; 
	
	var params="width="+breite+",height="+hoehe+",left="+left+",top="+top+",resize=yes,menubar=" + menubar + ",resizable=yes,scrollbars=1";
	
	zoomwindow=window.open(ziel,name,params);
	//zoomwindow.moveTo(Math.round((br-breite)/2),Math.round((ho-hoehe)/2)-menuoffset);
	zoomwindow.focus();
	
}


//zoom fenster öffnen
function show_content_popup(ziel) {
	var ziel = ziel;
	var breite = 620;
	var hoehe = 590;

	var menubar="no";

	var menuoffset=40;
	var	ho	=	screen.availHeight;
	var	br	=	screen.availWidth;
	var	left = Math.round((br-breite)/2);
	var	top = Math.round((ho-hoehe)/2);
	
	var name = "Schmalz";
 	
	var params="width="+breite+",height="+hoehe+",left="+left+",top="+top+",resize=yes,menubar=" + menubar + ",resizable=yes,scrollbars=1";
	
	zoomwindow=window.open(ziel,name,params);
	zoomwindow.focus();
}




function suche_start(suchstring, katsuche, websuche, lng) {
	var auswahl = document.suchekurz.GROUP.options[document.suchekurz.GROUP.selectedIndex].value;

	if (document.suchekurz.GROUP.options[document.suchekurz.GROUP.selectedIndex].value == "KAT") {
		document.suchekurz.action = katsuche;
	}	else {
		document.suchekurz.action = websuche;
	}
	return true;
}

/*
function printpage(lng) {
	var page = self.location.href;
	 	

	var sess = page.match( /\/S[^\/]+/ )
	if( sess ) {
		openprintwindow( page, sess[0], lng);
	} else {
		openprintwindow( page, '', lng );
	}
}
*/


function printpage(lng,host,url) {
	var page;
	
	if(url) {
		page = 'http://' + host + '/' + url;
	} else {
		page = self.location.href;
	}
	
	var sess = page.match( /\/S[^\/]+/ )
	if( sess ) {
		openprintwindow( page, sess[0], lng);
	} else {
		openprintwindow( page, '', lng );
	}
}

function printformpage(fname ) {
	if( document.forms[fname] && document.forms[fname].elements["notreally"] ) {
		document.forms[fname].elements["notreally"].value = 'yes';
		document.forms[fname].elements["notreally"].value = 'yes';
		document.forms[fname].submit();
	} else {
		alert( "No print version available for this page." );
	}
}


function openprintwindow(page, session, lng ) {
	var breite=600;
	var hoehe=590;

	if( session ) {
		window.open( session + "/np/pg/print?lng=" + lng + "&page=" + escape(page), "Print", "width="+breite+",height="+hoehe+" , resize=yes,menubar=yes,resizable=yes,scrollbars=1" );
	} else {
		window.open( "/np/pg/print?lng=" + lng + "&page=" + escape(page) , "Print", "width="+breite+",height="+hoehe+" , resize=yes,menubar=yes,resizable=yes,scrollbars=1" );
	}
}


function getFormData( formname ) {

	var formobj = document.forms[formname];

	var data = new Array();
	var t = '';
	for( var i = 0; i <formobj.elements.length; i++ ) {
		var elm = formobj.elements[i];


		var datarry;
		if( data[""+elm.name] ) {
			datarry = data[""+elm.name];
		} else {
			datarry = new Array();
			data[""+elm.name] = datarry;
		}

		var value = '';
		if( elm.options && elm.options.length) {
			value = elm.options[elm.options.selectedIndex].value;
		} else {
			value = elm.value;
		}

		t += 't: ' + elm.type + ', n: ' + elm.name + ', v: ' + value + "\n";	
		
		datarry[datarry.length] = value;	
	}

	alert( t );

	var txt = '';
	for( var name in data ) {
		txt += name + '<-->' + data[name] + "\n";
	}	
	alert( txt );
	return data;
}

function checkProspekt(field) {
	field.checked = true ;
}

//stripped den Printbereich raus
function stripPrintStuff( html ) {
	html = html.replace( /\n|\r/g, "" );
	html = html.replace(/^.*<!-- print start -->/, '');
	html = html.replace(/<!-- print end -->.*$/, '');
	
	return html;
}

// Alternative Drucksache ohne Request
function doJSPrint( session, lng, printform ) {
	var win = window.open( "/S" + session + "/np/pg/printjs?lng=" + lng + "&printform=" + printform );
}



//
// Bitte Dokumentieren woher der Code kommt...
//
// cookie construktor und functions

// format der Speicherung:
// name=value; name2=value2; ...
// wobei value = "k1=v1&k2=v2..."

function CookieData(){
 
  this.put = function(key, value){
    this[key] = value;
  };
  
  this.get = function(name){
    if(this[name])
      return this[name];
    else
      return null;
  };
  
  this.contains = function( key ){
    return (typeof this[key] != undefined)?true:false;
  };
  
  this.join = function(){
    var tmp = "";
    var counter = 0;
    for(var i in this){
      if (typeof this[i] == "function" || typeof this[i] == "object") 
        continue;
      if(counter > 0) tmp += "&";
      tmp += escape(i) + ":" + escape(this[i]);
      counter++;
    }
    return tmp;
  }
  
  this.set = function(str){
    if(str.length == 0)
      return false;
    var arr = unescape(str).split("&");
    var datas = new Array();
    for(var i = 0; i < arr.length; i++){
      datas[i] = arr[i].split(":");
    }
    for(var i = 0; i < datas.length; i++){
      this.put(datas[i][0], datas[i][1]);
    }
    return true;
  }

  this.toString = function(){
    var ret = "{";
    for(p in this ){
      if (typeof this[p] == "function" || typeof this[p] == "object") continue;
      if(ret.length > 1)
        ret += ",";
      ret += p + ":" + this[p];
    }
    return ret + "}";
  }
  
  this.setData = function(cookies, cookieName){
    var a = cookies.split("; ");
    var val = "";
    for(var i = 0; i < a.length; i++){
      // name steht am Anfang des cookie-Strings
      if( a[i].search(cookieName) == 0 ){
        var paramString = a[i].substring(cookieName.length+1);
        this.set( paramString );
        return paramString;
      }
    }
    return false;
  }
}

// format der Speicherung:
// name=value; name2=value2; ...
// wobei value = "k1=v1&k2=v2..."

function Cookie(name, cookieTest){
  this.name = name;
  this.expires = new Date().getTime() + 24 * 60 * 60 * 1000;
  
	//alert(new Date().toGMTString())
	//alert(new Date().getTime())
		
	this.data = new CookieData();
  this.domain;
  this.path;
  this.paramString = this.data.setData(document.cookie, this.name);
  this.fromUser = this.paramString.length > 0 ? true : false;
  this.enabled = false;
  
  if(typeof cookieTest != "undefined" && cookieTest == true)
    this.test();
}

Cookie.prototype.getName = function(){
  return this.name;
}
Cookie.prototype.setExpires = function(timestamp){
  this.expires = timestamp;
}
Cookie.prototype.setPath = function(path){
  this.path = path;
}
Cookie.prototype.setDomain = function(domain){
  this.domain = domain;
}
Cookie.prototype.setValue = function(key, value){
  this.data.put(key, value);
}
Cookie.prototype.getValue = function(name){
  return this.data.get(name);
}
Cookie.prototype.getParamString = function(){
  return this.paramString;
}
Cookie.prototype.send = function(){
  document.cookie = this.name +"=" + this.data.join() +
                    "; expires=" + new Date(this.expires).toGMTString() +
                    (this.path ? "; path=" + this.path : "") +
                    (this.domain ? "; domain=" + this.domain : "");

}
Cookie.prototype.test = function(){
  if(this.fromUser == true) return true;
  var now = new Date().getTime();
  document.cookie = "cookieEnabled="+now + 
                    "; expires=" + new Date(now + 5000).toGMTString() +
                    "; path=/";
  var re = new RegExp("cookieEnabled="+now, "g");
  this.enabled = re.test(document.cookie);
}

Cookie.prototype.remove = function(){
  this.expires = new Date().getTime();
  this.data = new CookieData();
  this.send();
}

var meldung = '';
function PreisPopup(url,frm,warart,meldung,breite,hoehe) { 
	var menge = eval("document." +frm + "." + warart + ".value");
	
	var c = Math.round((Math.random(10)*100000))
	var art = warart + c;
	
	if(!menge || isNaN(menge) ) {
		alert(meldung)	
		eval("document." +frm + "." + warart + ".focus()");
	}else { 
		url = url + "&menge=" + menge
		show_info(url,breite,hoehe,"no",art)
	}
}

function MengenAlert(warart,frm,meldung) { 
	var menge = eval("document." +frm + "." + warart + ".value");
	if(!menge || isNaN(menge) ) {
		alert(meldung)
	} else {
	 eval("document." + frm + ".submit()");
	}  
  
}




function WarenkorbPopup(url,breite,hoehe) { 
	var art = Math.round((Math.random(10)*100000));
	show_info(url,breite,hoehe,"no",art)
}

// funktion zum einblenden
function showOneDiv(prefix) 
{		
	if (document.getElementById(prefix)) 
	{
		document.getElementById(prefix).className="visible";
	}
}

// funktion zum ausblenden
function hideOneDiv(prefix) 
{		
	if (document.getElementById(prefix)) 
	{
		document.getElementById(prefix).className="unvisible";
	}
}


$(function () {
	// funktion für die Logik der Reiternavigation
	var tabContainers = $('div#reiterBox div#reiterContent div.tab');

	$('div#reiterBox div#reiterNav ul a.enabled').click(function () {
		tabContainers.hide().filter(this.hash).show();
		$("input:text:first").focus(); // reset focus

		$('div#reiterBox div#reiterNav ul a').removeClass('current');
		$(this).addClass('current');
        
		return false;
	}).filter(':first').click();



        $('#laenderauswahl').change(function() {
	        if ( $(this).val() != '' )
	                location.href = $(this).val();
	})
	$('#laenderauswahl2').change(function() {
		if ( $(this).val() != '' )
			location.href = $(this).val();
	})
});

function getDivN(prefix) {
	var n = 1;

	while( (document.getElementById(prefix + (n+1) ) )
			&& (document.getElementById(prefix + (n+1) ).className == "visible") ) {
		n += 1;
	}

	return n;
}

function showDiv(prefix) {
	var n = getDivN(prefix);
	n = n + 1;
	if (document.getElementById(prefix + n)) {
		document.getElementById(prefix + n).className="visible";
	}
}

// funktionen für das ein und ausblenden von divs anhand der Auswahl in einer Selectbox

var old_val = '';
	
function showdiv_selectbox(val,name) {
 
  var val = val;

  if (val) {
    if ( old_val && (val != old_val)) {
      document.getElementById(name + old_val).className='unvisible';
    }
     document.getElementById(name + val).className='visible';
     old_val = val;
  }
}


  var old_val = '';
	
function artikelarchiv(val) {
 
  var val = val;
 
  //alert(val);
  if (val) {
    if ( old_val && (val != old_val)) {
      document.getElementById('artikelarchiv_' + old_val).style.display='none';
    }
     document.getElementById('artikelarchiv_' + val).style.display='block';
     old_val = val;
  }
}

function ShowMessen(val) {
  
  document.getElementById('artikelarchiv_all').style.display='none';
 
  var val = val;
 
  //alert(val);
  if (val) {
    if ( old_val && (val != old_val)) {
      document.getElementById('artikelarchiv_' + old_val).style.display='none';
    }
     document.getElementById('artikelarchiv_' + val).style.display='block';
     old_val = val;
  }
}

// funktion für das "Highlighting" der Loginbox und dem Setzen des Focuses auf den Benutzernamen

function login() {
	window.login.uid.focus();
	
}

// Funktion zur Linkmanipulation der Downloadlinks aus Imperia, damit die Downloads per Etracker erfasst werden können.

function etrackerLink(fileurl,obj) {
  var etracker = 'http://www.etracker.de/lnkcnt.php?et=Ou9Tl3&url=';
  var eturl = (etracker + encodeURIComponent('http://' + location.host + fileurl));
  obj.href = eturl;
}

