function isSSLOff() {
	return (document.location.protocol.indexOf("https")==-1);
}

function determineBasketCounterCookie() {
	if( jQuery.cookie('BasketCounter') != null ) {
		counterValue = jQuery.cookie('BasketCounter');

		if(counterValue == null || counterValue == '') {
			counterValue = '0';
		}
		return counterValue;
	}
	else {
		return '0';
	}
}

function clearInputText(el, value) {
	if(el.val() == value) {
		el.val('');
	}
}

function fillInputText(el, value) {
	if(el.val() == '') {
		el.val(value);
	}
}

var nmLayer = {
	showDiv: function(divID){
		jQuery.fancybox({
					'showCloseButton' :	false,
					'centerOnScroll' : true,
					'padding': 0,
					'href' : '#' + divID,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'speedIn': 0,
					'speedOut':	0,
					'changeSpeed':0
				});
	},
	
	showURL: function(URL){
		jQuery.fancybox({
					'showCloseButton' :	false,
					'centerOnScroll' : true,
					'padding': 0,
					'href' : URL,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'speedIn': 0,
					'speedOut':	0,
					'changeSpeed':0
				});
	},
	
	showIFrame: function(URL){
		jQuery.fancybox({
					'showCloseButton' :	false,
					'centerOnScroll' : true,
					'width' : '90%',
					'height' : '90%',
					'padding': 0,
					'type' : 'iframe',
					'href' : URL,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'speedIn': 0,
					'speedOut':	0,
					'changeSpeed':0
				});
	},
	
	hide: function(){
		jQuery.fancybox.close();
	}
}

function add2basket(url){
	nmLayer.showDiv('add2basket_layer_loading');
    new jQuery.ajax({
    	url: url,
        type: 'GET',
        success: function(response){
        	handleAdd2basketResponse(response);
        }

   });
}

function handleAdd2basketResponse(respjson){

	if (respjson.status=='error') {
		jQuery('#add2basket_layer_title').text(respjson.headline);
		jQuery('#add2basket_layer_content').text(respjson.message);
		nmLayer.showDiv('add2basket_layer');
	} else {
	
		// Falls Package-Produkt, den Teaser zur Anzeige von add2basket ermitteln
		if (respjson.fromProperty != null && '' != respjson.fromProperty) {	 
		   var channelDomain = respjson.channelDomain;
		   var url = '/is-bin/INTERSHOP.enfinity/WFS/'+channelDomain+'/de_DE/-/EUR/ViewLayer-Add2Basket?TeaserName=' 
		   + respjson.fromProperty + '&ProductNr=' + respjson.productnr + '&ProductPrice=' + respjson.productprice;
		   jQuery('#add2basket_layer_teaser').load(url);
		   nmLayer.showDiv('add2basket_layer_teaser');
		} else {
			if (respjson.from != null && (respjson.from == 'add2basket_treueadd' || respjson.from == 'add2basket_treueadd2')){
				if (respjson.from == 'add2basket_treueadd'){
					nmLayer.showDiv('add2basket_layer_treueadd');
				} else {
					nmLayer.showDiv('add2basket_layer_treue');
				}
			} else { 
				if(respjson.showVipPriceMsg == "true") {
					jQuery('#add2basket_layer_info_vip').show();
					jQuery('#add2basket_layer_product_price').hide();
					jQuery('#add2basket_layer_product_price_vip').html(respjson.productprice);		
				} else {
					jQuery('#add2basket_layer_info_vip').hide();
				}
				
				jQuery('#add2basket_layer_title').text('Dieser Artikel wurde gerade in Ihren Warenkorb gelegt:');
				jQuery('#add2basket_layer_product_img').html(respjson.productimg);
				jQuery('#add2basket_layer_product_name').html(respjson.productname);
				nmLayer.showDiv('add2basket_layer');
			}
		}
		
		updateBasketInfos(respjson.currentBasketCount, respjson.currentBasketTotal);
		
		Tracking.track({
			pageName:respjson.pageName,
			ch:respjson.channel,
			events:respjson.events,
			products:respjson.products,
			h1:respjson.h1
		});
		
		
		
	}
	
}

//SiteCatalyst Tracking
var Tracking = {
	myhash : new Hash(),
	
	'track':function(obj){

		if(s && obj) {
			h = $H(obj);

			['events'].each(function(name){
				if (!h.get(name)) {
					s[name] = '';
				}
			});

			h.each(function(pair) {
				s[pair.key] = pair.value;
			});

			s.tl();
		}
		
	},
	
	'trackWithEvents':function(obj){

		if(s && obj) {
			h = $H(obj);

			h.each(function(pair) {
				s[pair.key] = pair.value;
			});

			s.tl();
		}
		
	},
	
	'setProperty':function(property,value){
		this.myhash.set(property,value);
		
	},
	
	'addEvent':function(event) {
		previousEvents = this.myhash.get('events');
		if (typeof(previousEvents) == 'undefined'
			|| previousEvents == null 
			|| previousEvents.blank()) {
			
			this.myhash.set('events', event);
		} else {
			previousEvents = this.myhash.unset('events');
			this.myhash.set('events', previousEvents + ',' + event);
		}
	},
	
	'update':function(obj){	
		
		this.myhash.each(function(pair) {
			s[pair.key] = pair.value;
		});
	}
};

function updateBasketInfos(basketCount, basketTotal){
	if(basketCount != undefined){
		jQuery('#basketcount').html(basketCount);
	}else{
		jQuery('#basketcount').html('0');
	}
	
	if(basketTotal != undefined){
		jQuery('#baskettotal').html(basketTotal);
	}else{
		jQuery('#baskettotal').html('0,00');
	}
};

function setLogoutLink(logoutURL){
	if(logoutURL != undefined){
		jQuery('#loginlogout').html("<a href=\""+logoutURL+"\" rel=\"nofollow\">Abmelden</a>");
	}
};



function OpenHelpMain() {
	OpenHelpPar('hilfe','');
}
