/* 
ajax store locator for xt:commerce
author: torsten naujoks -> spacedrops -> wwww.webmith.de
copyright by codecasters gmbh -> eichenstrasse 8b -> d-83083 niedermoosen -> rosenheim -> germany
*/

document.write("<style type=\"text/css\">");
document.write("#cally{height: 246px; width: 554px; z-index: 100; overflow: hidden;}");
if(is.ie){
	document.write("#plzLabel{padding: 1px 0px 0px 0px;}");
	document.write("#plzInput input{margin: -2px 0px 0px 0px;}");
	}
document.write("</style>");

function storeForm(arg1,arg2,arg3,arg4){
switch(arg1){
	case 'showButton' :
		if(is.en && box("stl")){
			box("stl").style.display = 'inline';
			callyDude = box("cally");
			callyDupe = callyDude.innerHTML; 
			if(!is.ie)box("callyBg").setAttribute("src","/images/storelocator_fx.png");
			box("callyBg").style.display = 'block';
			objEvt = 0;
			cDyOffset = 0;
			}
	break;
	case 'apply' :
		if(is.ns)box("callySc").style.overflow = 'hidden';
		if(objEvt == 0){
			if(is.ie)cDyOffset = 9;
			cDy = box("stl").parentNode.offsetTop;
			if(is.ns && cDy <= 216)callyDude.style.clip = 'rect(14px 554px 246px 0px)';
			callyDude.style.top = cDy + cDyOffset - 113 + 'px';
			callyDude.style.left = '216px';
			callyDude.style.visibility = 'visible';
			objEvt = 1;
			it = 2;
			storeForm('slide');
			}
		else{
			objEvt = 0;
			storeForm('slide');
			}
	break;
	case 'slide' :
		switch(objEvt){
			case 1 :
				if(it < 24){
					box("callyA").style.top = 246 - (246 / 575) * (it * it) + 'px';
					timer = setTimeout("storeForm('slide')",10);
					it++;
					}
				else{
					box("callyA").style.top = '0px';
					if(is.ns)box("callySc").style.overflow = 'auto';
					clearTimeout(timer);
					}
			break;
			case 0 :
				if(it > 0){
					box("callyA").style.top = 246 - (246 / 575) * (it * it) + 'px';
					timer = setTimeout("storeForm('slide')",10);
					it--;
					}
				else{
					clearTimeout(timer);
					callyDude.style.top = '-500px';
					callyDude.style.left = '0px';
					callyDude.style.visibility = 'hidden';
					if(is.ns)box("callySc").style.overflow = 'auto';
					}
			break;
			}
	break;
	case 'fire' :
		callyString = '';
		switch(arg2){
			case 'germany' :
				callyPlz = document.storeSearch.plz.value;
				if(callyPlz.match(/^[0-9]{1,2}$/))confirm('Bitte geben Sie mindestens die ersten 3 Ziffern des gesuchten Postleitzahlbereiches an!');
				else{
					if(callyPlz.match(/^[0-9]{2,5}$/)){
						callyString = 'germany&zip='+callyPlz;
						}
					else{
						confirm('Das ist keine Postleitzahl');
						}
					}
			break;
			case 'austria' :
				callyString = 'austria';
				document.forms['storeSearch'].reset();
			break;
			case 'switzerland' :
				callyString = 'switzerland';
				document.forms['storeSearch'].reset();
			break;
			case 'germany_coords':
				callyString = 'germany' + '&lat=' + arg3 + '&lon=' + arg4;
				document.forms['storeSearch'].reset();
			break;
			}
		if(callyString != ''){
			box("callySc").firstChild.innerHTML = '';
			box("loader").style.left = '165px';
			makeRequest(callyString);
			}
	break;
	case 'render' :
		box("loader").style.left = '-165px';
		box("callySc").firstChild.innerHTML = arg2;
		box("callySc").firstChild.style.height = '120px';
		box("callySc").style.height = '159px';
		box("callySc").scrollTop = '0px';
		stimer = setTimeout("self.location.reload()",600000);
	break;
	}
}

function makeRequest(url){
var httpRequest;
if(window.XMLHttpRequest){
	httpRequest = new XMLHttpRequest();
	if(httpRequest.overrideMimeType){
		httpRequest.overrideMimeType('text/plain');
		}
	}
else if(window.ActiveXObject){
	try{
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e){
		try{
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(e){}
		}
	}
if(!httpRequest){
	alert('Sorry :( \nDiese Funktion wird nur von Internet Explorer > 5 , Firefox, Opera > 8 oder Safari > 1.2 in ihren Standard-Einstellungen unterstützt.');
	return false;
	}
httpRequest.onreadystatechange = function(){alertContents(httpRequest);};
httpRequest.open('GET', '/storelocator.php?country=' + url, true);
httpRequest.send('');
}

function alertContents(httpRequest){
if(httpRequest.readyState == 4){
	if(httpRequest.status == 200){
		storeForm('render',unescape(httpRequest.responseText));
		}
	else{
		alert('Unbekannter Fehler!\nDie Verbindung wurde unterbrochen.');
		}
	}
}

function evt(e){
if(!is.ns){
	slTyp = window.event.type;
	slEvt = window.event.srcElement;
	slY = window.event.offsetY;
	slX = window.event.offsetX;
	if(slTyp == 'keyup')e = window.event.keyCode;
	}
else{
	slTyp = e.type;
	slEvt = e.target;
	slY = e.layerY;
	slX = e.layerX;
	if(slTyp == 'keyup')e = e.which;
	}
if(slTyp == 'keyup'){
	if(e == 13){
		if(slEvt.name == 'plz'){
			storeForm('fire','germany');
			}
		}
	}
if(slTyp == 'mousedown'){
	if(slEvt.id == 'callyEv'){
		storeForm('fire','germany_coords',slY,slX);
		}
	}
}

document.onmousedown = evt;
document.onkeyup = evt;
