/** standard javascript functions, which are included in all (frontend) pages
*/

/**
  * replace the given text
*/

//String.prototype.replace = stringReplace;


function stringReplace(findText, replaceText) {

	var originalString = new String(this);

	var pos=0;
	var len = findText.length;
	pos = originalString.indexOf(findText);
	while (pos != -1) {
		preString = originalString.substring(0,pos);
		postString = originalString.substring(pos + len, originalString.length);
		originalString = preString + replaceText + postString;
		pos = originalString.indexOf(findText);
	}

	return originalString;
}

/** change a class name for a certain item, neede for a rollover effect of
  * a form submit button.
  * parameters
  * styleChange new style for the item
  * item item to change
 */
function classChange(styleChange, item) {
	item.className=styleChange;
}

/**
	Display the shipping costs popup box.
*/
function shipping_costs()
	{
		window.open("/web/shop/checkout/shippingCost.jsp","Shipping","height=360,width=640,menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,top=0")
	}


/**
	Display a popup window which contains a large image of the
	currently selected product
*/
function productImage(a) {
     anewwindow = window.open(a,"Detailansicht","width=430,height=470,resizable=NO")
}


//
// Bubblehelp infoboxes, (C) 2002 Klaus Knopper <infobox@knopper.net>
// You can copy/modify and distribute this code under the conditions
// of the GNU GENERAL PUBLIC LICENSE Version 2.
//
var IWIDTH=250  // Tip box width
var ns4         // Are we using Netscape4?
var ie4         // Are we using Internet Explorer Version 4?
var ie5         // Are we using Internet Explorer Version 5 and up?
var kon         // Are we using KDE Konqueror?
var x,y,winW,winH  // Current help position and main window size
var idiv=null   // Pointer to infodiv container
var px="px"     // position suffix with "px" in some cases

function nsfix(){setTimeout("window.onresize = rebrowse", 2000);}

function rebrowse(){window.location.reload();}

function hascss(){ return gettip('infodiv')?true:false }

function infoinit(){
 ns4=(document.layers)?true:false, ie4=(document.all)?true:false;
 ie5=((ie4)&&((navigator.userAgent.indexOf('MSIE 5')>0)||(navigator.userAgent.indexOf('MSIE 6')>0)))?true:false;
 kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
 x=0;y=0;winW=800;winH=600;
 idiv=null;
 document.onmousemove = mousemove;
 if(ns4&&document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
 // Workaround for just another netscape bug: Fix browser confusion on resize
 // obviously conqueror has a similar problem :-(
 if(ns4||kon){ nsfix() }
 if(ns4) { px=""; }
}

function untip(){
 if(idiv) idiv.visibility=ns4?"hide":"hidden";
 idiv=null;
}

function gettip(name){return (document.layers&&document.layers[name])?document.layers[name]:(document.all&&document.all[name]&&document.all[name].style)?document.all[name].style:document[name]?document[name]:(document.getElementById(name)?document.getElementById(name).style:0);}

// Prepare tip boxes, but don't show them yet
function maketip(name,image){
 if(browser()) {
 	if(hascss()) {
 		document.write('<div id="'+name+'" name="'+name+'" style="position:absolute; visibility:hidden; z-index:20; top:0'+px+'; left:0'+px+';" class="gtitle">'+image+'</div>');
 	}
  }
}

// Only works with these browsers
function browser() {
	var browserType = navigator.userAgent;

	if(browserType.indexOf('MSIE 6') > 0 || browserType.indexOf('MSIE 5') > 0
		|| browserType.indexOf('Mozilla/5.0') >= 0) {
		return true;
	}
	return false;
}

function tip(name){
 if(hascss()){
  if(idiv) untip();
  idiv=gettip(name);
  if(idiv){
   winW=(window.innerWidth)? window.innerWidth+window.pageXOffset-16:document.body.offsetWidth-20;
   winH=(window.innerHeight)?window.innerHeight+window.pageYOffset  :document.body.offsetHeight;
   if(x<=0||y<=0){ // konqueror can't get mouse position
    x=(winW-IWIDTH)/2+(window.pageXOffset?window.pageXOffset:0); y=(winH-50)/2+(window.pageYOffset?window.pageYOffset:0); // middle of window
   }
   showtip();
  }
 }
}

function showtip(){
  idiv.left=(((x+2600)<winW)?x+12:x-255)+px; idiv.top=(((y+90)<winH)?y+12:y-90)+px;
  idiv.visibility=ns4?"show":"visible";
//  window.status="idiv="+idiv+"X:"+(idiv.left?idiv.left:"NAN")+", Y:"+(idiv.top?idiv.top:"NAN")+", x:"+x+", y:"+y;
}

function mousemove(e){
 if(e)   {x=e.pageX?e.pageX:e.clientX?e.clientX:0; y=e.pageY?e.pageY:e.clientY?e.clientY:0;}
 else if(event) {x=event.clientX; y=event.clientY;}
 else {x=0; y=0;}
 if(document.documentElement) // Workaround for scroll offset of IE
  {
    x+=document.documentElement.scrollLeft;
    y+=document.documentElement.scrollTop;
  }
 if(idiv) showtip();
}

// Initialize after loading the page
window.onload=infoinit;

// EOF infobox.js

function ShowCertOne() {
    window.open('http://www.trustcenter.de/cgi-bin/Search.cgi?Template=printable&SN=741813285621112279959606458672050','Zertifikat','width=640,height=480,resizable,scrollbars,status');
}

function getCookie (name) {
    var dcookie = document.cookie;
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) {
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
    return null;
}

function setCookie (name, value, expires) {
	if (!expires) expires = new Date();
	document.cookie = name + "=" + escape (value) +     //<-- save cookie value
	"; expires=" + expires.toGMTString() +  "; path=/"; //<-- set expiration date
}


function displayCoupon(value) {


    var vstart = window.document.cookie.indexOf("ncc=")+4;
    var vend   = window.document.cookie.indexOf(";", vstart);
    if (vend == -1)
        vend = document.cookie.length;
    if (value == 0) {
        value = document.cookie.substring(vstart, vend);
    }

    if (value != 0 && vstart > 3) {
	    window.document.getElementById('newcust').width = 142
	    window.document.getElementById('newcust').height = 258
	    window.document.getElementById('newcust').src =
	        "/images/coupons/" + value + "euro_gutschein.gif"
	    window.document.getElementById('newcust').vspace = 10
	}

}

