var onloadCommands = new Array();
var sRequestURL = "/stepone/frontend/general/glossary_ajax.php";

$(document).ready(function(){
	loadAjaxMenu();
	initIFrameTeasers();
	initAjaxSearcher();
	initCheckBoxVisibility();
	initWebShopAt();

	
	$('a.googleAnalyticTracker').click(function(){
        try {
              if (pageTracker) {
                    pageTracker._trackPageview($(this).attr('href'));
              }
        } catch(err) {}
        
        try {
	        if (_gaq) {
	        	_gaq.push(['_trackPageview', $(this).attr('href')]);
	        }
		} catch(err) {}
	});

		
	$('.modaliframewindow').hide();
	
	$('a[title!=""]:not(.blocktooltip),img[title!=""]:not(.blocktooltip):parent():not(a)').tooltip({
	    showURL: false,
	    fade: 100,
	    delay: 500,
	    top: 21,
	    left: 0
	});
	
	$('a[title!=""]:hasClass(.blocktooltip), img[title!=""]:hasClass(.blocktooltip)').removeAttr("title");
	
		
	/* Productfinder filter reset */
	$("#reset_button_productfinder").click(function() {
		$(':text, :password, :file', 'form[name=productfilter_form]').val('');  
		$(':input', 'form[name=productfilter_form]').removeAttr('checked').removeAttr('selected');	
		$('form[name=productfilter_form] select option:lt(0)').attr('selected', 'selected');	
		return false;	  
	});
				
	$("#region").change(function() {
		
		$.ajax({
			type: "GET",
			url: "/stepone/frontend/general/getGlobalContactData.php?s_key[0]=region&s_value[0]="+ $(this).val() +"&return=city",		
			dataType: "XML",			
			success: function(data){
		
			$("#city option[value!='']").remove();
					
			var xml;
			
			if ( $.browser.msie ) {
				xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.loadXML(data);											
			} else {
				xml = data;
			}				
						
			$(xml).find('item').each(function(i,item){			
				var text = $(item).attr('text');
				$('#city').append('<option value="'+ text +'">'+ text +'</option>');
			});				
			}
		});		
	});	
	
	
	$("#loyalty_acivities_navigation").change(function() {
		$("#loyalty_acivities").submit();
	});	
	
	
	
	var timeoutHS;	
	$('.hotspot_element').hover(  
			function () {
				$('.hotspot_contentbox').hide();
				var triggerId = $(this).attr('id');			
				var contentId = 'hotspot_content_' + triggerId.substring(11);
				$("#" + contentId).fadeIn("slow");
			},
			function () {
				var triggerId = $(this).attr('id');			
				contentId = 'hotspot_content_' + triggerId.substring(11);				
				timeoutHS = setTimeout(function() {
					$("#" + contentId).fadeOut("slow"); }, 2000);
			});
		
	  $('.hotspot_contentbox').hover(
		function() {	
				clearTimeout(timeoutHS);
		},
		function () {
				$(this).fadeOut("slow"); 
		});
	  
	  
  	/*
  	 * Validate address AJAX Module
  	 * 
  	 * Provides a dynamic ajax function to search for a
  	 * location using a location service and add the result
  	 * to input forms. Will be used at the product registration
  	 * form.
  	 * 
  	 * @author Tobias Schueler <tobias.schueler@vaicon.de>
  	 * @since 1.01.10
  	 */
	function addLocation(mobj) {
		 $('.process_validate_address').each(function() {
			$(this).removeClass('loader_bar');
			$('#submitbutton').removeClass('hidden');
			$('#submitbutton_container').removeClass('loader_bar');
			if (mobj != undefined && mobj != '') {
				$(this).val(mobj[$(this).attr('data-field')]);
				$(this).addClass('disabled');
			} else {
				$(this).removeClass('disabled');
				$(this).attr('readonly', '');
			}
		});
	}

	var htmlclone = $('#validate_address_window').html();
	$('.validate_address').blur(function() {
		var process = true;
		var postdata = '';
		$('.validate_address').each(function() {
			if ($(this).val() == '') {
				process = false;
			} else {
				postdata = postdata + $(this).attr('name') + '=' + $(this).val() + '&';
			}
		});
		if (process == true) {
			$('#submitbutton').addClass('hidden');
			$('#submitbutton_container').addClass('loader_bar');
			$('.process_validate_address').each(function() {
				$(this).addClass('loader_bar');
				$(this).removeClass('disabled');
			});
			$.ajax({
				type: 'POST',
				url: '/stepone/frontend/general/app/validateAddress.php',
				data: postdata,
				 success: function(result) {
					 var addrlist = eval('(' + result + ')');
					 if (addrlist['error']) {
						 addLocation();
						 return false;
					 }
					 var addrcount = addrlist.length;
					 var useaddr = addrlist[0];
					 if (addrcount > 1) {
						 var html = htmlclone;
						 
						 for (i = 0; i < addrcount; i++) {
							 html += '<p><a style="cursor:pointer" class="addLocation" data-id="' + i + '">' + addrlist[i]['street'] + ', ' + addrlist[i]['housenumber'] + ', ' + addrlist[i]['postalCode'] + ', ' + addrlist[i]['city'] + '</a></p>';
						 }
						 
						 $('#validate_address_window').html(html);
						 $('#validate_address_window').modaldialog({
							fadeInTime : 250,
							fadeOutTime : 250
						 });
						 $('#validate_address_window').focus();
						 
						$('.addLocation').click(function() {
							useaddr = addrlist[$(this).attr('data-id')];
							addLocation(useaddr);
							$('#validate_address_window').modaldialog('close');
						});
					 }
					 
					 addLocation(useaddr);
				 }
			});
		}
	});
	// END Validate address AJAX Module
	
	/*
	 * UI-Menu select replacement
	 * 
	 * This snippled replaces a form select element to a well
	 * designed list with same functionality.
	 * 
	 * @author Tobias Schueler <tobias.schueler@vaicon.de>
	 * @since r.1.01.10
	 */
	if ($(".ui-menu").length > 0) {
		// hide select and submit button (should be always there, for deliver a responsive function)
		$('.ui-menu select').css('display', 'none');
		$('.ui-menu button').css('display', 'none');
		
		var source = $(".ui-menu");
	    var selected = source.find("option[selected]");  // get selected <option>
	    var options = $("option", source);  // get all <option> elements
	    
	    // create <dl> and <dt> with selected value inside it
	    $(".ui-menu").append('<dl id="target" class="dropdown"></dl>');
	    $("#target").append('<dt><a href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>');
	    $("#target").append('<dd><ul></ul></dd>');
	    
	    // iterate through all the <option> elements and create UL
	    options.each(function(){
	        $("#target dd ul").append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>');
	    });
	    
	    $(".dropdown dt a").click(function() {
	        $(".dropdown dd ul").slideToggle('fast');
	    });
	    
	    $(document).bind('click', function(e) {
	        var $clicked = $(e.target);
	        if (! $clicked.parents().hasClass("dropdown"))
	        	$(".dropdown dd ul").slideUp('fast');
	    });
	                
	    $(".dropdown dd ul li a").click(function() {
	        var text = $(this).html();
	        $(".dropdown dt a").html(text);
	        $(".dropdown dd ul").slideUp('fast');
	        $(".ui-menu").val($(this).find("span.value").html());
	        $(".ui-menu").find("option[selected]").removeAttr('selected');
	        $('.ui-menu select').val($(this).find("span.value").html());
	        $('.ui-menu form').submit();
	    });
	}
	
});



// [0004794] SEO: Flyout Menu Optimierung
function loadAjaxMenu() {		
	// Setzen der Request Parameter
	var AjaxRequestURL = '/stepone/frontend/general/ajaxHandler.php';
	var phpClass = 'flyoutMenu';
	var phpFunction = 'returnFlyOutMenu';
	var phpSessionId = $('#session-id');
	var layerCounter = 1;
		
	// Each Schleife für jedes <li> Element der Hauptmenüleiste
	$('.navbalken_inner').children().each(function () {
		
		// Auslesen der layerID
		var menuId = $(this).attr('id');
		menuId = menuId.substr(menuId.length - 1, 1)
		
		// Parameter Array für das AJAX PHP Script (structurID sowie LayerCounter)
		var phpParam = ($(this).attr('rel') + ', ' + layerCounter);		

		// Request welches sich die weiteren MenuLevel holt
		// Danach folgen ein paar DOM Anpassungen, damit der Aufbau wie früher aussieht.
		$.post(AjaxRequestURL, { requestClass: phpClass,  requestFunction: phpFunction,  requestParam: phpParam, PHPSESSID: phpSessionId}, function(responseMessage) {		
			$('#layer_show_' + menuId).append(responseMessage);			
			$('#layer_' + menuId).hide();
		});	
		
		// erhöhen des Layer Counters
		layerCounter = layerCounter + 1;
		
		// Hover Modus für das SubMenu
		$(this).hover(  
			function () {
				$("#layer_" + menuId).show();
			},
			function () {
				$("#layer_" + menuId).hide();
			});
			
	});	
}


function zoomElement() {
	$('#box_lightbox_list').modaldialog({
		fadeInTime : 250,
		fadeOutTime : 250
	});
}

function showMoreProductImages(){
	$("#product_more_images_div").modaldialog({
		fadeInTime : 250,
		fadeOutTime : 250,
		closeOnCanvasClick : true
	});
}

function changeProductImage(url, url_smallImage, url_bigImage, name, description, OrgImageDimensionX, OrgImageDimensionY){
	var spacer   = document.getElementById('spacer');
	var bigImage = document.getElementById('bigProductImage');
	var zoomImage = document.getElementById('zoomImage');
	var zoomImageLink = document.getElementById('zoomImageLink');
	var bigFlash = document.getElementById('bigProductFlash');
	var type = 0;  //0=image  1=flash
	
	$('#delete').remove();
	
	if(url.slice(url.length-4).toLowerCase()==".flv")
	{
		spacer.style.display="none";
		bigImage.style.display="none";
		bigFlash.style.display="";
		bigFlash.innerHTML = '<br/><br/><br/><embed width="600" height="360" flashvars="file='+url+'&amp;autostart=false&amp;bufferlength=15&amp;fullscreen=true" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" quality="high" bgcolor="#FFFFFF" name="ply" id="ply" style="" src="/swf/player.swf" type="application/x-shockwave-flash"></embed>';;
		return;
	}
	
	if (bigImage){
		spacer.style.display="";
		bigImage.style.display="";
		bigFlash.style.display="none";
		
		
		if (OrgImageDimensionX > 640 || OrgImageDimensionY > 470) {
			bigImage.src = url_smallImage;
					
		} else {
			bigImage.src = url_bigImage;			
		}
		
		bigFlash.innerHTML = "";
		zoomImage.src = url;	
		
		//oboeck changed this link to image big size
		zoomImageLink.href = url_bigImage;
		
		$('#imgholder_zoom_container_inner').empty();
		
		var options = {
			zoomWidth: 640,
			zoomHeight: 470,
			xOffset: 0,
			yOffset: 0,
			position: "topLeft",
			preloadText: 'Zoom wird geladen'
			};
			
		$(".jqzoom").unbind();
		
		if (OrgImageDimensionX > 640 && OrgImageDimensionY > 470) {
			bigImage.src = url_smallImage;
			$('.imgholder_zoom').css("visibility","visible");
			$('#zoomImageLink').addClass("jqzoom");
			$('.jqzoom').jqzoom(options);			
		} else {
			$('.imgholder_zoom').css("visibility","hidden");
		}
		
		return false;	
	}
	
	element = document.getElementById('imgholder_headline_name');
	if (element){
		element.innerHTML = name;
	}
	element2 = document.getElementById('imgholder_headline_description');
	if (element2){
		element2.innerHTML = description;
	}

}


function printPage(){
	window.print();
	return true;
}

function switchProductTab(tabnr){
	alert(tabnr);
}

function clearInputContent(field){
	field.value = '';
	return true;
}

function reloadBasketView(dateval,urlpart){
	day = dateval.substring(0,2);
	month = dateval.substring(3,5);
	year = dateval.substring(6,10);
	document.location.href=urlpart+'?deliverydate='+year+'-'+month+'-'+day
}

function doOrderCreate(){
	if (document.getElementById('createOrderForm')){
		document.getElementById('createOrderForm').submit();
	}

}

function setTablerowVisibility(clickedElement, rowname)
{
	if(element = document.getElementById(clickedElement))
	{
		if(element.checked == true){
			var rowDisplayMode = "";
		} else {
			var rowDisplayMode = "none";
		}
		trElements = document.getElementsByTagName('tr');
		for (var i = 0; i < trElements.length; i++) {
			e = trElements[i];
			if(e.id && e.id.indexOf(clickedElement+'_') == 0){
				e.style.display = rowDisplayMode;
			}
		}
	}
	
}

function setCheckboxVisibility(name)
{
	var e = document.getElementById('pulldown');
	if(e==null) return;
	var type0 = document.getElementById('downloads_type0');
	if(type0 == null) e.style.display = "none";
	inputElements = document.getElementsByTagName('input');
	for (var i = 0; i < inputElements.length; i++) {
		e  = inputElements[i];
		if(e.id && e.id.indexOf('category_') == 0){
			var subCategory  = e.name.replace(/category_/g,'');
			var parentNode = e.parentNode;
			
			if( subCategory == name || type0 == null || name == "pleaseselect"){
				parentNode.style.display = "";
				e.checked = true;
			}
			else{
				parentNode.style.display = "none";
				e.checked = false;
			}
			setTablerowVisibility(e.id,"")
		}
	}
}

function uncheckSubcategories(formName)
{
	var type = '';	
	var eLength = document.forms[formName].elements.length;
	for(var i=0; i < eLength; i++) 
	{
		type = document.forms[formName].elements[i].type;
        if(type == "checkbox" && document.forms[formName].elements[i].checked)
        {
        	document.forms[formName].elements[i].checked = false;         
        }
	}	
}

function hideAllTablerows()
{
	var rowDisplayMode = "none";
	trElements = document.getElementsByTagName('tr');
	for(var i=0; i < trElements.length; i++) 
	{
		e = trElements[i];		
		if(e.id && e.id.substr(0, 9) == 'category_')
		{
			e.style.display = rowDisplayMode;
		}
	}
}

function checkIfHideTotalDownloadListIsSet()
{
	var e = document.getElementById('hide_total_downloadlist');
	if(e)
		return e.value;
}

function initCheckBoxVisibility(){
	var b=document.getElementById("pulldown");
	var a=checkIfHideTotalDownloadListIsSet();
	var $deselect = $('#deselect-all');
	var $select = $('#select-all');
	var $checkboxes = $deselect.parent('div').prev('ul').find('input[type="checkbox"]');
	var $deselectContainer = $deselect.parents('div.deselect');
	var $selectContainer = $select.parents('div.deselect');
	if(b!=null)
	{setCheckboxVisibility(b.options[0].value);
		if(a)
		{
			uncheckSubcategories("downloadlist_filter");
			$deselectContainer.hide();
			$selectContainer.show();
			hideAllTablerows()
		}
	}
}

function updateCompareDialog(removeProduct, changeProduct) {
	products = new Array();
	products[1] = "";
	products[2] = "";
	products[3] = "";
	productModels = new Array();
	productModels[1] = "";
	productModels[2] = "";
	productModels[3] = "";
	element = document.getElementById("hidden_current_structure_id");
	structureId = element.value;


	if(element = document.getElementById("product_id_for_update_1")){
		products[1] = element.value;
	}
	if(element = document.getElementById("product_id_for_update_2")){
		products[2] = element.value;
	}
	if(element = document.getElementById("product_id_for_update_3")){
		products[3] = element.value;
	}
	if(element = document.getElementById("model_for_update_1")){
		productModels[1] = encodeURIComponent(element.value)
	}
	if(element = document.getElementById("model_for_update_2")){
		productModels[2] = encodeURIComponent(element.value);
	}
	if(element = document.getElementById("model_for_update_3")){
		productModels[3] = encodeURIComponent(element.value);
	}

	switch(removeProduct){
		case 1:
			products[1] = products[2];
			products[2] = products[3];
			products[3] = "";
			productModels[1] = productModels[2];
			productModels[2] = productModels[3];
			productModels[3] = "";
		break;
		case 2:
			products[2] = products[3];
			products[3] = "";
			productModels[2] = productModels[3];
			productModels[3] = "";
		break;
		case 3:
			products[3] = "";
			productModels[3] = "";
		break;
	}
	switch(changeProduct){
		case 1:
			products[1] = "";
			productModels[1] = "";
		break;
		case 2:
			products[2] = "";
			productModels[2] = "";
		break;
		case 3:
			products[3] = "";
			productModels[3] = "";
		break;
	}


	$(document).ready(function() {
        $.get("/stepone/frontend/general/productcache/getProductCacheContent.php?firstcall=0"+
        																		"&product1="+products[1]+
        																		"&product2="+products[2]+
        																		"&product3="+products[3]+
        																		"&model1="+productModels[1]+
        																		"&model2="+productModels[2]+
        																		"&model3="+productModels[3]+
        																		"&structureid="+structureId,
        																		function(text){
			$('#box_lightbox_list_compare').html(text);
			updateCollapsibles();
		});
	});
}

function prepareDataForComparePrint(){
	products = new Array();
	products[1] = "";
	products[2] = "";
	products[3] = "";
	productModels = new Array();
	productModels[1] = "";
	productModels[2] = "";
	productModels[3] = "";
	element = document.getElementById("hidden_current_structure_id");
	structureId = element.value;


	if(element = document.getElementById("product_id_for_update_1")){
		products[1] = element.value;
	}
	if(element = document.getElementById("product_id_for_update_2")){
		products[2] = element.value;
	}
	if(element = document.getElementById("product_id_for_update_3")){
		products[3] = element.value;
	}
	if(element = document.getElementById("model_for_update_1")){
		productModels[1] = element.value;
	}
	if(element = document.getElementById("model_for_update_2")){
		productModels[2] = element.value;
	}
	if(element = document.getElementById("model_for_update_3")){
		productModels[3] = element.value;
	}
	productData = new Array();
	productData["product1"] = products[1];
	productData["product2"] = products[2];
	productData["product3"] = products[3];
	productData["model1"] = productModels[1];
	productData["model2"] = productModels[2];
	productData["model3"] = productModels[3];
	return productData;

}
function showCompareDialog(structureId, productid) {
	products = new Array();
	products[1] = "";
	products[2] = "";
	products[3] = "";
	if (productid){
		products[1] = productid;
	} else {
		for (var object_id in comparebuttonsChecked)
		{

			if (products[1] == ""){
				products[1] = object_id.substr(8);
			}
			else if (products[2] == ""){
				products[2] = object_id.substr(8);
			} else {
				products[3] = object_id.substr(8);
			}
		}
	}


	$(document).ready(function() {
        $.get("/stepone/frontend/general/productcache/getProductCacheContent.php?firstcall=1"+
        																		"&product1="+products[1]+
        																		"&product2="+products[2]+
        																		"&product3="+products[3]+
        																		"&structureid="+structureId,
        																		function(text){
			$('#box_lightbox_list_compare').html(text);
			$('#box_lightbox_list_compare').modaldialog({
				fadeInTime : 250,
				fadeOutTime : 250
			});
			updateCollapsibles();
		});
	});
}

function filterProducts(currentStructureId){
	var temp = $('.productfilter_form').serialize();
	$(document).ready(function() {
	    $.get("/stepone/frontend/general/productfilter/getProductfilterCacheContent.php?currentStructureId="+currentStructureId+"&"+temp
	    																		,
	    																		function(text){
			$('#product_list_holder').html(text);

		});
	});
}

function resetFilterProducts(currentStructureId)
{
	$(document).ready(function() {
	    $.get("/stepone/frontend/general/productfilter/getProductfilterCacheContent.php?currentStructureId="+currentStructureId
	    																		,
	    																		function(text){
			$('#product_list_holder').html(text);

		});
	});
}

function productcategoryfilterCheck(targetlocation){
	if (element = document.getElementById("productcategoryfinder_select_1")){
		if(element.value != ""){
			document.location.href=element.value;
		}
	}
}


function onSlideChange(){
	element = document.getElementById("hidden_current_structure_id");
	filterProducts(element.value);
}


function openIFrameModalWindow(targetUrl)
{
	
}


function initIFrameTeasers()
{
	$('a.modalTeaser').live("click", function()
	{
		var triggerId = $(this).attr('name');
		
		var iFrameId = 'iframe_' + triggerId.substring(8);
		var $iFrame = $("#"+iFrameId);

		if($iFrame.attr('src') === "about:blank" || $iFrame.attr('src') === "") {
			$iFrame.attr('src', $iFrame.attr('title'))
		}

		$iFrame.modaldialog({ fadeInTime : 250, fadeOutTime : 250, closeOnCanvasClick : true });
		
		//Manually correct top-margin
		$('.box_lightbox').css('top', '1.8333em');
		return false;
	});
}

function initAjaxSearcher()
{
	
	/*
	$('input.installerSearch').each(function()
	{
		$(this).keyup(function(){
			var value = $(this).val();
			var name = $(this).attr('name');
			var dataForAutocomplete = new Array()
			$.getJSON("/stepone/frontend/general/getGlobalContactData.php?s_key[0]=" + name + "&s_value[0]="+ value +"&return=region",
			function(data)
			{
				var html = '';
				if(data.status == "ok")
				{
					delete data.status; //status should be displayed
					
					$.each(data, function(i,item)
					{
						/*
						if(i > 0)
						{
							if(i <= 1)
							{
								html += data[i];
							}
							else
							{
								html += '<br>'+data[i];
							}
						}
						*//*
						//alert(data[i]);
						dataForAutocomplete[i] = data[i];
					});
					$('.ac_input').autocomplete(dataForAutocomplete);
				}
				/*
				$.each(data.items, function(i,item)
				{
					alert(item.status);
					if(i==0)
					{
						alert(item.status);
					}
				});*//*
			});
		});
	});
	*/
	$('.region-select-autocomplete').autocomplete("/stepone/frontend/general/getGlobalContactData.php",{  
						extraParams : {"s_key": 'region', 
									   "s_value":function() { return $('.region-select-autocomplete').val();},
									   "return":"region", 
									   "returnformat":"jquery_autocomplete"}
	});
	
	
	/*
	 // for get ing the city depending on the region
	$('.region-select-autocomplete').result(function() {
		alert("/stepone/frontend/general/getGlobalContactData.php?s_key[0]=region&s_value[0]="+ $('.region-select-autocomplete').val() +"&return=city");
		$.getJSON("/stepone/frontend/general/getGlobalContactData.php?s_key[0]=region&s_value[0]="+ $('.region-select-autocomplete').val() +"&return=city",
		function(data)
		{
			var html = '';
			if(data.status == "ok")
			{
				delete data.status; //status should be displayed
				
				$.each(data, function(i,item)
				{
						if(i <= 1)
						{
							html += data[i];
						}
						else
						{
							html += '<br>'+data[i];
						}
					
					alert(data[i]);
					dataForAutocomplete[i] = data[i];
				});
				//$('.ac_input').autocomplete(dataForAutocomplete);
			}
			
		});
		
		$.each(selectValues, function(key, value) {
			$('.city-select').append('<option value="'+ key +'">'+ value +'</option>');
		});
		
		$('#select_installer_dropdown').show();
		});
     });*/

}
function initInstallersearchPtEu() {
	if ($('#service-country').attr('lang') == 'ru') {
		var AjaxRequestURL = '/stepone/frontend/general/ajaxHandler.php?language_id=2';
	} else if ($('#service-country').attr('lang') == 'en') {
		var AjaxRequestURL = '/stepone/frontend/general/ajaxHandler.php?language_id=1';
	}
		
	$('.form_inlineblock #select_installer_radio .select_installer_radio_btn').live('click',function() {	
		var sType = $(this).children('input').attr('value');
		var countryLang = $('#service-country').attr('lang');
		
		var phpClass = 'pt_eu';
		var phpFunction = 'returnCountryOption';
		var phpParam = (sType + ', ' + countryLang);

		// jQuery post sends always in UTF-8. 
		// 1. convert back in target script
		// 2. user .ajax (method: post, beforeSend: function(){ XMLHttpRequest.setRequestHeader("Content-Type", "text/plain;charset=' + $charset + '"); }
		$.post(AjaxRequestURL, { requestClass: phpClass,  requestFunction: phpFunction,  requestParam: phpParam }, function(responseMessage) {
			$('#country').html(responseMessage);						
		});		
		
		var test = 'reset';
		var phpClass = 'pt_eu';
		var phpFunction = 'returnCityOption';
		var phpParam = (test);

		$.post(AjaxRequestURL, { requestClass: phpClass,  requestFunction: phpFunction,  requestParam: phpParam }, function(responseMessage) {
			$('#region_city').html(responseMessage);
		});									
	});
	

	$('#select_installer #service-country #country').change(function () {
		// Parameterlist
		var sType = $(":checked").val();
		var sCountry = document.getElementById("country").value;
		var language = $('#service-country').attr('lang');

		var phpClass = 'pt_eu';
		var phpFunction = 'returnCityOption';
		var phpParam = (sType + ', ' + sCountry + ', ' + language);

		console.log(phpParam);
		
		// jQuery post sends always in UTF-8. 
		// 1. convert back in target script
		// 2. user .ajax (method: post, beforeSend: function(){ XMLHttpRequest.setRequestHeader("Content-Type", "text/plain;charset=' + $charset + '"); }
		$.post(AjaxRequestURL, { requestClass: phpClass,  requestFunction: phpFunction,  requestParam: phpParam }, function(responseMessage) {
			$('#region_city').html(responseMessage);
		});	  
	});
}

// 0004713: AT Webshop ReDesign || r.1.01.10
function initWebShopAt() {
	// DESC sorting
	$('#sort_price_down').click(function(){
		$('#sort_price_up').attr("src","/img/layout/icons/shop_price_up.gif");
		$('#sort_price_down').attr("src","/img/layout/icons/shop_price_down_akt.gif");
		
		var mylist = $('.shop_listing');
		var listitems = mylist.children('.listItem').get();
		listitems.sort(function(a, b) { 
		   var compA = parseInt($(a).find('.sortPrice').html());
		   var compB = parseInt($(b).find('.sortPrice').html());
		   return (compA > compB) ? 1 : (compA < compB) ? -1 : 0;
		})
		$.each(listitems, function(idx, itm) { mylist.append(itm); });
	});	
	
	// ASC sorting
	$('#sort_price_up').click(function(){
		$('#sort_price_up').attr("src","/img/layout/icons/shop_price_up_akt.gif");
		$('#sort_price_down').attr("src","/img/layout/icons/shop_price_down.gif");
		
		var mylist = $('.shop_listing');
		var listitems = mylist.children('.listItem').get();
		listitems.sort(function(a, b) { 	
		   var compA = parseInt($(a).find('.sortPrice').html());
		   var compB = parseInt($(b).find('.sortPrice').html());
		   return (compA < compB) ? 1 : (compA > compB) ? -1 : 0;
		})
		$.each(listitems, function(idx, itm) { mylist.append(itm); });		
	});	
	
	
	// adding and deleting amount of products
	$('.qty_plus').click(function(){
		$input = $(this).parent().parent().find('input');
		$input.val(parseInt($input.val()) + 1);
	});	
	
	$('.qty_minus').click(function(){
		$input = $(this).parent().parent().find('input');
		$input.val(parseInt($input.val()) - 1);
	});	
}
