﻿function GeoLayer() {
	
	GeoDomain = 'esprit.fr';
	GeoLand = 'Frankreich';
	GeoLandEn = 'France';
	GeoDomEnd = 'fr';
	
	//Deutsch
	GeoText = new Array();
	GeoText[0] = 'Sie haben '+GeoDomain+' gew&auml;hlt';
	GeoText[1] = 'In diesem e-Shop sind <span style="font-weight: bold;">nur Lieferungen nach '+GeoLand+'</span>&nbsp;möglich. M&ouml;chten Sie lieber einen anderen e-shop besuchen?';
	GeoText[2] = '<span style="font-weight: bold;">'+GeoDomain+'</span> - '+GeoLand;
	GeoText[3] = 'Immer automatisch zu der ausgewählten Esprit-Webseite weiterleiten.';
	GeoText[4] = 'Sie können die Länderauswahl jederzeit auf der Startseite ändern.';
	GeoText[5] = 'Abbrechen und auf dieser Webseite nicht mehr danach fragen';
	GeoText[6] = 'SCHLIESSEN';
	GeoText[7] = 'geo_weiter_de.gif';
	
	if(QueryData('lkz') != 'de' && QueryData('lkz') != 'at') {	
		GeoText[0] = 'You have selected '+GeoDomain;
		GeoText[1] = 'It is <span style="font-weight: bold;">only possible to deliver to '+GeoLandEn+'</span> when purchasing from this e-shop. Would you like to switch to another e-shop?';
		GeoText[2] = '<span style="font-weight: bold;">'+GeoDomain+'</span> - '+GeoLandEn;
		GeoText[3] = 'Save my selection';
		GeoText[4] = 'You can change the country that you have selected at any time from the homepage.';
		GeoText[5] = 'Cancel and don\'t ask again.';
		GeoText[6] = 'CLOSE'
		GeoText[7] = 'geo_weiter_en.gif';
	}
	
	
	//Domain-Endung | flag_xxx.gif | Domain-Adresse
	GeoFlag = new Array();
	GeoFlag[GeoFlag.length] = 'DE|de|esprit.de';
	GeoFlag[GeoFlag.length] = 'AT|at|esprit.at';
	GeoFlag[GeoFlag.length] = 'CH|ch|espritshop.ch';
	GeoFlag[GeoFlag.length] = 'BE|be|esprit.be';
	GeoFlag[GeoFlag.length] = 'DK|dk|esprit.dk';
	GeoFlag[GeoFlag.length] = 'UK|uk|esprit.co.uk';
	GeoFlag[GeoFlag.length] = 'NL|nl|esprit.nl';
	GeoFlag[GeoFlag.length] = 'FR|fr|esprit.fr';
	GeoFlag[GeoFlag.length] = 'FI|fi|esprit.fi';
	GeoFlag[GeoFlag.length] = 'LU|lu|esprit.lu';
	GeoFlag[GeoFlag.length] = 'SE|se|esprit.se';
	
	GeoFlag[GeoFlag.length] = 'CZ|cz|esprit.eu';
	GeoFlag[GeoFlag.length] = 'EE|est|esprit.eu';
	GeoFlag[GeoFlag.length] = 'GR|gre|esprit.eu';
	GeoFlag[GeoFlag.length] = 'HU|hun|esprit.eu';
	GeoFlag[GeoFlag.length] = 'IE|ire|esprit.eu';
	GeoFlag[GeoFlag.length] = 'IT|it|esprit.eu';
	GeoFlag[GeoFlag.length] = 'LV|lv|esprit.eu';
	
	GeoFlag[GeoFlag.length] = 'MT|mal|esprit.eu';
	GeoFlag[GeoFlag.length] = 'PL|pl|esprit.eu';
	GeoFlag[GeoFlag.length] = 'PO|po|esprit.eu';
	GeoFlag[GeoFlag.length] = 'SK|slv|esprit.eu';
	GeoFlag[GeoFlag.length] = 'SI|slo|esprit.eu';
	GeoFlag[GeoFlag.length] = 'ES|esp|esprit.eu';
	GeoFlag[GeoFlag.length] = 'EU|eg|esprit.eu';
	GeoFlag[GeoFlag.length] = 'US|us|espritshop.com';
	
	if(parent.parent.GetCookie('GeoCancel') != '1' && QueryData('lkz') != '') {	
		if(QueryData('lkz') != GeoDomEnd && QueryData('welt') == '') {
				if(parent.GetCookie('GeoAdresse') == '' && parent.GetCookie('GeoAdresse') != GeoDomain) {
					/*Schatten einblenden*/
					GeoSchatten(parent.FrameStart);
					GeoSchatten(parent.FrameTop1);
					GeoSchatten(parent.FrameTop2);
					GeoSchatten(parent.FrameLogo);
					GeoSchatten(parent.FrameFooter);	
					setTimeout("GeoSchatten(parent.FrameBasket);", 250);
					
					/*Geo-Layer einblenden*/
					GeoShowLayer();
					wt_sendinfo(parent.Lng+'.startseite.mixed.geo_layer.'+QueryData('lkz'));
				} else if(parent.GetCookie('GeoAdresse') == GeoDomain) {					
					removeSchatten();
				} else {
					GeoWeiterleitung(parent.GetCookie('GeoAdresse'));
				}
		}
	}
} 

function GeoSchatten(FrameName) {
	try {
		var PageSize = parent.getPageSize(FrameName);
		var Breite = PageSize[2];
		
		if(FrameName.document.getElementById('GeoSchatten')) {
			FrameName.document.getElementById('GeoSchatten').style.display = '';
		} else {
			//Schatten einblenden
			var SchattenLayer  = document.createElement('div');
			SchattenLayer.setAttribute('id', 'GeoSchatten');			
			SchattenLayer.setAttribute('style', 'position:absolute; left: 0; top: 0; width: '+Breite+'px; height: '+(parent.parent.getPageSize(FrameName)[1])+'px; background-color: #000000; opacity: 0.25;filter:Alpha(opacity=25); -moz-opacity:0.50; z-index:1000;');
			
			if(FrameName.document.getElementsByTagName('body')[0]) {
				FrameName.document.getElementsByTagName('body')[0].style.overflow = 'hidden';
			}
			
			if(document.all && FrameName) {
				if(FrameName.document.getElementsByTagName('body')[0]) {
					FrameName.document.getElementsByTagName('body')[0].insertAdjacentHTML("AfterBegin",SchattenLayer.outerHTML);
					var aa = FrameName.document.getElementById('GeoSchatten');			
					aa.style.position = 'absolute';
					aa.style.left = '0px';
					aa.style.top = '0px';
					aa.style.width = Breite+'px';
					aa.style.height = parent.parent.getPageSize(FrameName)[1] + 'px';
					aa.style.backgroundColor = '#000000';
					aa.style.zIndex = '1000';
					aa.style.filter="Alpha(opacity='25')";
					aa.onclick = function() {
						top.removeSchatten();
					}							
				}					
			} else if(FrameName) {
				FrameName.document.body.appendChild(SchattenLayer);
				SchattenLayer.onclick = function() {
					top.removeSchatten();
				}						
			}	
		}
	} catch(e) {}
}

function removeSchatten() {
	//Schatten ausblenden
	closeSchatten(parent.FrameStart);
	closeSchatten(parent.FrameTop1);
	closeSchatten(parent.FrameTop2);
	closeSchatten(parent.FrameLogo);
	closeSchatten(parent.FrameBasket);
	closeSchatten(parent.FrameFooter);	
	if($('GeoInfo')) {
		$('GeoInfo').remove();
	}
}

function closeSchatten(FrameName) {
	if(FrameName.document.getElementById('GeoSchatten')) {
		FrameName.document.getElementById('GeoSchatten').style.display = 'none';
		document.getElementsByTagName('body')[0].style.overflow = '';
	}
}

function GeoClose() {
	removeSchatten();
	wt_sendinfo(parent.Lng+'.startseite.mixed.geo_layer.close', 'click');
}

function GeoShowLayer() {
	
	var GeoMeldung = new Element('div', { 'id':'GeoInfo' }).setStyle('position:absolute; top:2px; left:235px; width:490px; z-index:1001; height: 315px; background-color: #FFFFFF;');
	$$('body')[0].appendChild(GeoMeldung);
	
	var GeoForm = new Element('form');
	GeoMeldung.appendChild(GeoForm);
	
	var GeoCloseText = new Element('a');
	GeoCloseText.href = 'javascript:GeoClose();';
	GeoCloseText.setStyle('font-family: Verdana, Helvetica; font-size: 10px; font-weight: bold; position: absolute; right: 24px; top: 8px; color: red; text-decoration: underline; cursor: pointer;');
	GeoCloseText.innerHTML = GeoText[6];
	GeoForm.appendChild(GeoCloseText);
	
	var GeoLinkClose = new Element('a');
	GeoLinkClose.href = 'javascript:GeoClose();';
	var GeoCloseImg = new Element('img');
	GeoCloseImg.border = 0;
	GeoCloseImg.setStyle('position: absolute; right: 10px; top: 9px; cursor: pointer;');
	GeoCloseImg.src = 'Img/Product/'+parent.Lng+'/close_window_btn_small.gif';
	GeoLinkClose.appendChild(GeoCloseImg);
	GeoForm.appendChild(GeoLinkClose);
	
	var GeoTitle = new Element('div');
	GeoTitle.innerHTML = this.GeoText[0];
	GeoTitle.setStyle('position: absolute; top: 40px; left: 25px; font-family: Verdana, Helvetica; font-size: 14px; font-weight: bold; color: red;');
	GeoForm.appendChild(GeoTitle);
	
	var GeoInfo = new Element('div');
	GeoInfo.innerHTML = this.GeoText[1];
	GeoInfo.setStyle('font-family: Verdana, Arial; font-size: 12px; position: absolute; top: 60px; left: 25px; width: 430px;');
	GeoForm.appendChild(GeoInfo);
	
	if(document.all) {
		//IE Bug
		GeoForm.innerHTML += '<input type="radio" name="LKZAuswahl" checked="true" style="position: absolute; top: 118px; left: 22px;">';
	} else {
		var GeoOption1 = new Element('input', { 'type':'radio', 'name':'LKZAuswahl', 'checked':'true' });
		GeoOption1.setStyle('position: absolute; top: 118px; left: 22px;');
		GeoForm.appendChild(GeoOption1);		
	}
	
	var GeoOptionText = new Element('div');
	GeoOptionText.innerHTML = this.GeoText[2];
	GeoOptionText.setStyle('position: absolute; top: 119px; left: 45px; font-family: Verdana, Arial; font-size: 12px;');
	GeoForm.appendChild(GeoOptionText);
	
	var GeoOption2 = new Element('input', { 'type':'radio', 'name':'LKZAuswahl' });
	GeoOption2.setStyle('position: absolute; top: 145px; left: 22px;');
	GeoForm.appendChild(GeoOption2);	
	
	var GeoOption = new Element('input', { 'type':'checkbox' });
	GeoOption.setStyle('position: absolute; top: 175px; left: 22px;');
	GeoForm.appendChild(GeoOption);	
	
	var GeoOptionText = new Element('div');
	GeoOptionText.innerHTML = this.GeoText[3];
	GeoOptionText.setStyle('position: absolute; top: 177px; left: 45px; font-family: Verdana, Arial; font-size: 11px;');
	GeoForm.appendChild(GeoOptionText);
	
	var GeoOptionText = new Element('div');
	GeoOptionText.innerHTML = this.GeoText[4];
	GeoOptionText.setStyle('position: absolute; top: 255px; left: 25px; font-family: Verdana, Arial; font-size: 11px;');
	GeoForm.appendChild(GeoOptionText);
	
	var GeoOptionText = new Element('a');
	GeoOptionText.href = 'javascript:void(0);';
	GeoOptionText.innerHTML = this.GeoText[5];
	GeoOptionText.setStyle('position: absolute; left: 25px; font-family: Verdana, Arial; font-size: 11px; position: absolute; top: 285px; left: 25px; color: red; text-decoration: underline; cursor: pointer;');
	GeoOptionText.observe('click', function() {		
		parent.parent.SetCookie('GeoCancel', '1', GeoCookieTime());
		removeSchatten();
	});
	GeoForm.appendChild(GeoOptionText);		
	
	var GeoAuswahl = new Element('div');
	GeoAuswahl.setStyle('border:1px solid #A4ABB3; cursor: pointer; left:45px; height: 15px; overflow:auto; position:absolute; top:145px; width:200px; z-index:10000;');
	GeoForm.appendChild(GeoAuswahl);
	GeoAuswahl.observe('click', function() {
		if(GeoListLng.style.display == '') {
			GeoListLng.hide();
		} else if(GeoListLng.style.display == 'none') {
			GeoListLng.show();
		}		
	});
	
	var GeoListLng = new Element('div');
	GeoListLng.setStyle('border:1px solid #A4ABB3; display: none; background-color:#FFFFFF; height:200px; left:45px; overflow:auto; position:absolute; top:163px; width:200px; z-index:10000;');
	GeoForm.appendChild(GeoListLng);	
	
	var GeoAuswahlImg = new Element('img');
	GeoAuswahlImg.setStyle('position: absolute; top: 144px; left: 245px; cursor: pointer;');
	GeoAuswahlImg.src = 'Img/Startseite/'+parent.Lng+'/Standard/button.gif';
	GeoAuswahlImg.observe('click', function() {
		if(GeoListLng.style.display == '') {
			GeoListLng.hide();
		} else if(GeoListLng.style.display == 'none') {
			GeoListLng.show();
		}
		GeoOption2.checked = true;
	});
	GeoForm.appendChild(GeoAuswahlImg);
	
	for(var i=0; i < GeoFlag.length; ++i) {
		if(GeoFlag[i].split('|')[1] == 'eg' || GeoFlag[i].split('|')[1] == 'us') {
			var LngList = new Element('div').setStyle('margin: 5px 0 0 6px; padding: 2px; cursor: pointer;');		
		} else {
			var LngList = new Element('div').setStyle('margin: 5px 0 0 2px; padding: 2px; cursor: pointer;');		
		}
		LngList.appendChild(new Element('img', { 'src':'Img/Startseite/'+parent.Lng+'/Standard/flag_'+GeoFlag[i].split('|')[1]+'.gif' }));
		LngList.observe('mouseover', function() {
			this.setStyle('margin: 5px 0 0 2px; padding: 2px; cursor: pointer; background-color:#9DD337; color:#000000;');
			if(this.innerHTML.indexOf('flag_eg') != -1 || this.innerHTML.indexOf('flag_us') != -1) {
				this.setStyle('margin: 5px 0 0 6px;');
			}				
		});
		LngList.observe('mouseout', function() {
			this.setStyle('margin: 5px 0 0 2px; padding: 2px; cursor: pointer; background-color:#FFFFFF;');
			if(this.innerHTML.indexOf('flag_eg') != -1 || this.innerHTML.indexOf('flag_us') != -1) {
				this.setStyle('margin: 5px 0 0 6px;');
			}				
		});	
		LngList.observe('click', function() {
			GeoListLng.hide();
			GeoAuswahl.innerHTML = this.innerHTML;
		});			
		
		var LngText = new Element('span', { 'id':'selectLng' }).setStyle('margin-left: 3px; font-size: 11px;');
		LngText.innerHTML = GeoFlag[i].split('|')[2];
		LngList.appendChild(LngText);		
		GeoListLng.appendChild(LngList);
		
		if(QueryData('lkz').toLowerCase() == GeoFlag[i].split('|')[0].toLowerCase()) {
			var LngList = new Element('div').setStyle('margin: 0 0 0 2px;');		
			LngList.appendChild(new Element('img', { 'src':'Img/Startseite/'+parent.Lng+'/Standard/flag_'+GeoFlag[i].split('|')[1]+'.gif' }));
			
			var LngTextSelect = new Element('span', { 'id':'selectLng' }).setStyle('margin-left: 3px; font-size: 11px;');
			LngTextSelect.innerHTML = GeoFlag[i].split('|')[2];
			LngList.appendChild(LngTextSelect);		
			GeoAuswahl.appendChild(LngList);
		}
		
		if(GeoFlag.length == (i+1)) {
			if(GeoAuswahl.innerHTML == '') {
				var LngList = new Element('div').setStyle('margin: 0 0 0 2px;');		
				LngList.appendChild(new Element('img', { 'src':'Img/Startseite/'+parent.Lng+'/Standard/flag_eg.gif' }));
				
				var LngTextSelect = new Element('span', { 'id':'selectLng' }).setStyle('margin-left: 3px; font-size: 11px;');
				LngTextSelect.innerHTML = 'esprit.eu';
				LngList.appendChild(LngTextSelect);		
				GeoAuswahl.appendChild(LngList);				
			}
		}
		
	}
	
	var GeoButton = new Element('img');
	GeoButton.src = 'Img/Startseite/'+parent.Lng+'/'+GeoText[7];
	GeoButton.setStyle('position: absolute; top: 208px; left: 25px;cursor: pointer;');
	GeoForm.appendChild(GeoButton);
	GeoButton.observe('click', function() {
		if(document.forms[0].LKZAuswahl[0].checked == true) {
			if(GeoOption.checked == true) {
				parent.parent.SetCookie('GeoAdresse', GeoDomain, GeoCookieTime());
			} else {
				parent.parent.SetCookie('GeoAdresse', '', GeoCookieTime());
			}
			removeSchatten();
		} else if(document.forms[0].LKZAuswahl[1].checked == true) {
			if(GeoOption.checked == true) {							
				parent.parent.SetCookie('GeoAdresse', $('selectLng').innerHTML, GeoCookieTime());			
			} else {				
				parent.parent.SetCookie('GeoAdresse', '', GeoCookieTime());			
			}
			GeoWeiterleitung($('selectLng').innerHTML);
		} else {
			parent.parent.SetCookie('GeoAdresse', '', GeoCookieTime());
		}
		wt_sendinfo(parent.Lng+'.startseite.mixed.geo_layer.weiter', 'click');
	});	
	
}

function GeoCookieTime() {
	var ZeitObj = new Date();
	var ZeitMilli = ZeitObj.getTime();
	var gueltigBis = ZeitMilli + (3600*24000*180);
	ZeitObj.setTime(gueltigBis);
	return ZeitObj;
}	

function QueryData(info) {
	var code = '';
	var uriParam = parent.window.location.search.replace('?', '');		// Alle Parameter zwischenspeichern
	var splitParam = uriParam.split("&");
	if(splitParam.length > 0) {			
		for(var i=0;i < splitParam.length; ++i) {			// Parameter durchsuchen
			var urlq = splitParam[i].toLowerCase();
			if(urlq.indexOf(info) != -1) {
				code = urlq.split('=')[1];
				break;
			}
		}
	}
	return code;
}

function GeoWeiterleitung(dropdown) {
	
	//Query
	var camp_code = QueryData('camp');
					
	//DropDown --> Ausnahmen-Url				
	if(camp_code != '') {				
		parent.window.location = 'http://www.'+dropdown + '?camp='+camp_code;
	} else {
		parent.window.location = 'http://www.'+dropdown;
	}
}