﻿var	caLanguage;


function caGetLanguage()
{
		try{
		return top.caLanguage;
	}
	catch(e)
	{
		return 'de';
	}
		
}

// JavaScript Datei inkludieren.
function caIncludeJS(scriptFileName)
{
	var		head=document.getElementsByTagName('head')[0];
	var		newElem=document.createElement('script');
	var		node;


	node = document.createAttribute('type');
	node.nodeValue = 'text/javascript';
	newElem.setAttributeNode(node);
	node = document.createAttribute('src');
	node.nodeValue = scriptFileName;
	newElem.setAttributeNode(node);

	head.appendChild(newElem);

	return newElem;
}

function caGetPath(file, dir1, dir2, dir3)
{
	var			path='';


	if (typeof dir1 != 'undefined' && dir1 != '')
		path += dir1 + '/';
	if (typeof dir2 != 'undefined' && dir2 != '')
		path += dir2 + '/';
	if (typeof dir3 != 'undefined' && dir3 != '')
		path += dir3 + '/';

	path += file;

	return path;
}

function caReplaceSpecialChars(string)
{
	return string.replace(/ß/gi, 'ss').replace(/ä/gi, 'ae').replace(/ö/gi, 'oe').replace(/ü/gi, 'ue').replace(/\//gi, '_').replace(/\-/gi, '_').replace(/\s/gi, '_').replace(/&/gi, '_').toLowerCase();
}

function caSetTansparency(elementId, transparency)
{
	var		elemStyle;
	var		percentage;
 	var 	filterValue='';
 	var 	opacityValue='';


	// Prüfen, ob das Element existiert.
	try
	{
		elemStyle = document.getElementById(elementId).style;
	}
	catch (error)
	{
		return;
	}

	// Transparenz in Prozent angeben und invertieren.
	percentage = (typeof transparency == 'undefined') ? 50 : 100 - transparency;

	// Wert für IE.
	filterValue = 'Alpha(opacity='+percentage+');';

	// Wert für CSS opacity [0..1].
	opacityValue = '' + percentage / 100;

	// Für IE setzen.
	elemStyle.filter = filterValue;
	// Für Mozilla setzen.
	elemStyle.MozOpacity = opacityValue;
	// Für Konqueror/Safari setzen.
	elemStyle.KhtmlOpacity = opacityValue;
	// Für CSS-3-Browser setzen.
	elemStyle.opacity = opacityValue;
}

function caGetTransparencyCSS(transparency)
{
	var			retStyle='';
	var		  percentage;
 	var 	  filterValue='';
 	var 	  opacityValue='';


	// Transparenz in Prozent angeben und invertieren.
	percentage = (typeof transparency == 'undefined') ? 50 : 100 - transparency;

	// Wert für IE.
	filterValue = 'Alpha(opacity='+percentage+')';

	// Wert für CSS opacity [0..1].
	opacityValue = '' + percentage / 100;

	// Für IE setzen.
	retStyle += 'filter:' + filterValue + ';';
	// Für Mozilla setzen.
	retStyle += '-moz-opacity:' + opacityValue + ';';
	// Für Konqueror/Safari setzen.
	retStyle += '-khtml-opacity:' + opacityValue + ';';
	// Für CSS-3-Browser setzen.
	retStyle += 'opacity:' + opacityValue + ';';
	
	return retStyle;
}

function caGetShadowTableBegin(tableWidth, tableHeight, imageDir)
{
	var		strOut='';
	var		transparency=80;
	var		slash='';
	var		tmp=''+tableHeight;
	var		leftHeight='';


	if (tmp.indexOf('%') >= 0)
		leftHeight += tableHeight;
	else
		leftHeight += (tableHeight-10);

	if (typeof imageDir == 'undefined' || imageDir == null)
		imageDir = '../../Data/Img/Navi';

	if (imageDir[imageDir.length-1] != '/')
		slash = '/';

	// Tabelle mit Schatten.
	strOut += '<table cellspacing="0" cellpadding="0" border="0" width="'+tableWidth+'" height="'+tableHeight+'">';
	strOut += '  <tr>';
	strOut += '    <td style="background-image:url('+imageDir+slash+'de/schatten_oben_links_ecke.gif);'+caGetTransparencyCSS(transparency)+'" width="3" height="3"></td>';
	strOut += '    <td>';
	strOut += '      <table cellspacing="0" cellpadding="0" border="0" height="3">';
	strOut += '        <tr>';
	strOut += '          <td style="background-image:url('+imageDir+slash+'de/schatten_oben_links_oben.gif);background-repeat:no-repeat;'+caGetTransparencyCSS(transparency)+'" width="8" height="3"></td>';
	strOut += '          <td style="background-image:url('+imageDir+slash+'de/schatten_oben.gif);background-repeat:repeat-x;'+caGetTransparencyCSS(transparency)+'" width="'+(tableWidth-16)+'" height="3"></td>';
	strOut += '          <td style="background-image:url('+imageDir+slash+'de/schatten_oben_rechts_oben.gif);background-repeat:no-repeat;'+caGetTransparencyCSS(transparency)+'" width="8" height="3"></td>';
	strOut += '        </tr>';
	strOut += '      </table>';
	strOut += '    </td>';
	strOut += '    <td style="background-image:url('+imageDir+slash+'de/schatten_oben_rechts_ecke.gif);'+caGetTransparencyCSS(transparency)+'" width="7" height="3"></td>';
	strOut += '  </tr>';
	strOut += '  <tr>';
	strOut += '    <td valign="top">';
	strOut += '      <table cellspacing="0" cellpadding="0" border="0" width="3" height="'+leftHeight+'">';
	strOut += '        <tr><td style="background-image:url('+imageDir+slash+'de/schatten_oben_links_links.gif);'+caGetTransparencyCSS(transparency)+'" width="3" height="5"></td></tr>';
	strOut += '        <tr><td style="background-image:url('+imageDir+slash+'de/schatten_links.gif);background-repeat:repeat-y;'+caGetTransparencyCSS(transparency)+'" width="3"></td></tr>';
	strOut += '        <tr><td style="background-image:url('+imageDir+slash+'de/schatten_unten_links_links.gif);'+caGetTransparencyCSS(transparency)+'" width="3" height="5"></td></tr>';
	strOut += '      </table>';
	strOut += '    </td>';
	strOut += '    <td>';

	strOut += '      <table cellspacing="0" cellpadding="0" border="0" width="'+(tableWidth-10)+'">';
	strOut +=	'	       <tr>';
	strOut += '          <td valign="top">';

	return strOut;
}

function caGetShadowTableEnd(tableWidth, tableHeight, imageDir)
{
	var		strOut='';
	var		transparency=80;
	var		slash='';
	var		tmp=''+tableHeight;
	var		leftHeight='';


	if (tmp.indexOf('%') >= 0)
		leftHeight += tableHeight;
	else
		leftHeight += (tableHeight-10);

	if (typeof imageDir == 'undefined' || imageDir == null)
		imageDir = '../../Data/Img/Navi';

	if (imageDir[imageDir.length-1] != '/')
		slash = '/';

	strOut += '          </td>';
	strOut += '        </tr>';
	strOut += '      </table>';

	// Tabelle mit Schatten:
	strOut += '    </td>';
	strOut += '    <td>';
	strOut += '      <table cellspacing="0" cellpadding="0" border="0" width="7" height="'+leftHeight+'">';
	strOut += '        <tr><td style="background-image:url('+imageDir+slash+'de/schatten_oben_rechts_rechts.gif);background-repeat:no-repeat;'+caGetTransparencyCSS(transparency)+'" width="7" height="8"></td></tr>';
	strOut += '        <tr><td style="background-image:url('+imageDir+slash+'de/schatten_rechts.gif);background-repeat:repeat-y;'+caGetTransparencyCSS(transparency)+'" width="7" height="'+(leftHeight-16)+'"></td></tr>';
	strOut += '        <tr><td style="background-image:url('+imageDir+slash+'de/schatten_unten_rechts_rechts.gif);background-repeat:no-repeat;'+caGetTransparencyCSS(transparency)+'" width="7" height="8"></td></tr>';
	strOut += '      </table>';
	strOut += '    </td>';
	strOut += '  </tr>';
	strOut += '  <tr>';
	strOut += '    <td style="background-image:url('+imageDir+slash+'de/schatten_unten_links_ecke.gif);'+caGetTransparencyCSS(transparency)+'" width="3" height="7"></td>';
	strOut += '    <td>';
	strOut += '      <table cellspacing="0" cellpadding="0" border="0" height="7">';
	strOut += '        <tr>';
	strOut += '          <td style="background-image:url('+imageDir+slash+'de/schatten_unten_links_unten.gif);background-repeat:no-repeat;'+caGetTransparencyCSS(transparency)+'" width="8" height="7"></td>';
	strOut += '          <td style="background-image:url('+imageDir+slash+'de/schatten_unten.gif);background-repeat:repeat-x;'+caGetTransparencyCSS(transparency)+'" width="'+(tableWidth-16)+'" height="7"></td>';
	strOut += '          <td style="background-image:url('+imageDir+slash+'de/schatten_unten_rechts_unten.gif);background-repeat:no-repeat;'+caGetTransparencyCSS(transparency)+'" width="8" height="7"></td>';
	strOut += '        </tr>';
	strOut += '      </table>';
	strOut += '    </td>';
	strOut += '    <td style="background-image:url('+imageDir+slash+'de/schatten_unten_rechts_ecke.gif);'+caGetTransparencyCSS(transparency)+'" width="7" height="7"></td>';
	strOut += '  </tr>';
	strOut += '</table>';

	return strOut;
}

function caClickNavi(level1, level2, level3, level4, productId, colorId)
{
	if (typeof level1 == 'undefined')
	{
		if (typeof top.FrameMainMid.caBreadCrumbClick != 'undefined')
			top.FrameMainMid.caBreadCrumbClick(0);
		return;
	}

	if (level1 == '')
	{
		if (typeof top.FrameMainMid.caBreadCrumbClick != 'undefined')
			top.FrameMainMid.caBreadCrumbClick(0);
		return;
	}

	if (typeof level2 == 'undefined')
		level2 = '';
	if (typeof level3 == 'undefined')
		level3 = '';
	if (typeof level4 == 'undefined')
		level4 = '';

	if (typeof productId == 'undefined' || 
			typeof colorId == 'undefined')
	{
		productId = '';
		colorId = '';
	}
	//top.FrameMainMid.caUpdateHash();
	top.FrameMainMid.caSetNavi(level1, level2, level3, level4);
	top.FrameMainMid.caSetProductId(productId);
	top.FrameMainMid.caSetProductColor(colorId);
	top.FrameMainMid.caUpdateHash();

	try
	{
		top.FrameMainMid.caDeeplink();
	}
	catch (error)
	{
		
	}
}

//Höhe und Breite des/der FaderDivs(Hinweislayer + Bestätigungslayer) bestimmen
function getPageSize(obj, blnScroller){
	if(blnScroller == undefined) blnScroller = true;
	
	if(obj == undefined) obj = this;
	var xScroll, yScroll;
	if (obj.innerHeight && obj.scrollMaxY) {
		xScroll = obj.document.body.scrollWidth;
		yScroll = obj.innerHeight + obj.scrollMaxY;
	} else if (obj.document.body.scrollHeight > obj.document.body.offsetHeight){ // all but Explorer Mac
		xScroll = obj.document.body.scrollWidth;
		yScroll = obj.document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = obj.document.body.offsetWidth;
		yScroll = obj.document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (obj.innerHeight) {	// all except Explorer
		windowWidth = obj.innerWidth;
		windowHeight = obj.innerHeight;
	} else if (obj.document.documentElement && obj.document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = obj.document.documentElement.clientWidth;
		windowHeight = obj.document.documentElement.clientHeight;
	} else if (obj.document.body) { // other Explorers
		windowWidth = obj.document.body.clientWidth;
		windowHeight = obj.document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	pageWidth = (obj.document.body.clientWidth < 826 && !document.all && blnScroller) ? (pageWidth - 16) : pageWidth;
	
	if(!document.all)
		pageWidth = (pageHeight > windowHeight) ? (pageWidth - 16) : pageWidth;
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	
	return arrayPageSize;
}

function caGetCookieVal (offset) {																			 									 //cookie wert auslesen - am 240506	
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)            
  endstr = document.cookie.length;	               
  return clearCookie(unescape(document.cookie.substring(offset, endstr)));
}

function clearCookie(strHaystack)
{	
	return strHaystack.replace(/[^a-zA-Z0-9äÄöÖüÜß=//#~\-%&|,+. ]/gi, '');
}


function caGetCookie(name){																																				 //cookie holen - am 240506
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var tCookie=document.cookie;
  var i = 0;
  while (i < clen) 
  {
    var j = i + alen;
    if(tCookie.substring(i, j) == arg)
      return caGetCookieVal (j);
    i = tCookie.indexOf(" ", i) + 1;
    if (i == 0) 
      break; 
  }
  return "";
}

function caSetCookie(name,value,expires){																			 // schreibt den Cookie "Name" mit dem Wert "Value",
  var AddStr="; path=/";

/*  if(window.location.protocol!="file:")
  	AddStr +="; domain=cunhey.de";																	 // der am "Exprires" seine Gültigkeit verliert
 */


  if(expires!=null)
    AddStr=AddStr+"; expires=" + expires.toGMTString();
  document.cookie = name + "=" + escape (value) +AddStr;
}


// Warenkorb berechnen und im Header anzeigen
function caGetBasketWert()
{
	var 	basket=top.caGetBasketArray();
	var 	artikelAnzahl=0;
	var 	basketAmount=0.00;
	var		i;


	for (i=0;i<basket.length;++i)
	{
		var 	tempWert=parseFloat(basket[i][3].replace(',', '.')) * parseInt(basket[i][4]);							//PriceSale * Menge


		artikelAnzahl += parseInt(basket[i][4]);
		basketAmount += tempWert;
	}

	return '<span style="font-weight:900;">' + artikelAnzahl + '</span>&nbsp;Teil' + ((artikelAnzahl != 1) ? 'e' : '') + ' | <span style="font-weight:900;">' + caToCurrency(basketAmount) + '</span>&nbsp;&euro;';
}

// Wandelt nummerische Werte in Währungsformat um
function caToCurrency(numNeedle)
{
	// ganzzahlig
	numNeedle = String(numNeedle).replace('.', ',');
	
	if(String(numNeedle).indexOf(",") < 0)	
		return numNeedle + ",00";
	// mit einer Nachkommastelle
	if(String(numNeedle).indexOf(",") > 0 && (String(numNeedle).length - String(numNeedle).indexOf(",") == 2))
		return numNeedle + "0";
	// mit zwei Nachkommastellen
	return String(numNeedle);
}

function caTrimString(str)
{
  // Erst führende, dann abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern.
  return str.replace(/^\s+/, '').replace(/\s+$/, '');
}
