jQuery(document).ready(function(){
// cookie functions
	function setCookie(name, value, expires, path, domain, secure) {
		var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}
	function getCookie(name) {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
		} else
			begin += 2;
		var end = document.cookie.indexOf(";", begin);
		if (end == -1)
			end = dc.length;
		return unescape(dc.substring(begin + prefix.length, end));
	}
	function deleteCookie(name, path, domain) {
		if (getCookie(name)) {
			document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}
/*		
// Fix for links on personal data page			
	var theProtocol = location.href;
	theProtocol = theProtocol.split(':');
	if(theProtocol.length > 1) {
		if(theProtocol[0] == 'https') {
			jQuery('a').each(function(){
				var theHref = jQuery(this).attr('href');
				if(theHref) {
					if(theHref.search(/https/) != -1 && theHref.search(/agentur/) == -1) {
						
						theHref = theHref.replace(/https/, 'http');
						jQuery(this).attr('href', theHref);
					}
				}	
			});
		}
	}		
*/
/*
*	display agent layer and welcome box if url is called with agent parameter
*/
		

	var agentNo = "";
	var theUrl = '';
	var refUrl = '';
// personal data page is reached by a POST so we have to retrieve the parameter from the form	
	refUrl = jQuery('input[name="ref_url"]').val();
	
	if(refUrl != undefined)
		theUrl = refUrl;
	else
		theUrl = location.href;
	
	theUrl = theUrl.split('?');
	
	if(theUrl.length > 1) {

		theUrl = theUrl[1].split('&');
// find out if 'agent' parameter is set
		for(var i = 0; i < theUrl.length;i++){
			var param = theUrl[i].split('=');
			if(param[0] == 'agent')
				agentNo = param[1];
		}
			
		if(agentNo != ''){
// set cookie to prevent layer from showing every time the page is loaded
			var isCookieSet = '';
			isCookieSet = getCookie('agentNo');
			
			if(isCookieSet != agentNo)
				isCookieSet = '';
				
			if(isCookieSet == '' || isCookieSet == null){ 
				setCookie('agentNo',agentNo);
			}
// add 'agent' parameter to all links on the page
			jQuery('a').each(function(){
				var theHref = jQuery(this).attr('href');

				if(theHref){
					var isJavascript = theHref.search(/javascript/);
					if(theHref.search(/javascript/) == -1) {
						if(theHref.search(/\?/) > 1)
							theHref = theHref + '&agent=' + agentNo;
						else
							theHref = theHref + '?agent=' + agentNo;
					
						jQuery(this).attr('href', theHref);
					}
				}		
			});
			if (jQuery('#noSuchAgency').length == 0) {
// show adress box
				jQuery('#agencyFrame').attr('src','https://www.ferien-touristik.de/service/reiseagentur.html?agent=' + agentNo).css('display','block');
// set signature for layer			
				if(jQuery('#company').length) {
					var companySignature = jQuery('#company').text();
					jQuery('#companySignature').text(companySignature);
// display welcome layer
					if(isCookieSet == '' || isCookieSet == null){ 
						jQuery('#agencyMessage').lightbox_me({
							closeSelector: '#closeAgencyMessage'
						});
					}
				}
			}
// set hidden input in start form to agent number
			if(jQuery('#agentNoField'))
				jQuery('#agentNoField').val(agentNo);	
		}
	} else {
// remove tt cookie if necessary
		var isTTCookieSet = getCookie('tt_agent');
		if(isTTCookieSet != null) {
			deleteCookie('tt_agent','/','.ferien-touristik.de');
			isTTCookieSet = getCookie('tt_agent');
		}
	}
});
	
			

/**
* Switch to the URL of the selected Item in the Dropdown-Menu
*/
function go2url(formEl){
 if (formEl.options[formEl.selectedIndex].value != "none") {
	document.location.href = formEl.options[formEl.selectedIndex].value
 }                       
}

function addBookmark(){

  URL = window.location.href;
  Text = document.title;

  if (window.sidebar)
    {
    // firefox
    window.sidebar.addPanel(Text,URL, "");
    }
  else if(window.opera && window.print)
    {
    // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',URL);
    elem.setAttribute('title',Text);
    elem.setAttribute('rel','sidebar');
    elem.click();
    }
  else if(document.all)
    {
    // ie
    window.external.AddFavorite(URL,Text);
    }
    
   return false;
}
 /* User Agent (Browserkennung) auf einen bestimmten Browsertyp prüfen */  
  function checkBrowserName(name){  
    var agent = navigator.userAgent.toLowerCase();  
    if (agent.indexOf(name.toLowerCase())>-1) {  
      return true;  
    }  
    return false;  
  }

/* dirty-hack für footer-Navi */
jQuery(document).ready(function($){
//	$('.fespFooterLeft li a').attr("href", 'http://www.ferien-tourtistik.de/'+$(this).attr('href'));
	$('.bxBoxC .fespPostcard').click(function(){
		window.location.href = $(this).find('.fespPostcardLink').attr('href');
	});
	$('.bxBoxContainerBig .bxBoxC').click(function(){
		window.location.href = $(this).find('.fespPoststickBlockLink').attr('href');
	});
	$('.bxList .bxElement').click(function(){
		window.location.href = $(this).find('.bxListItemLink').attr('href');
	});
	if(checkBrowserName('firefox')){  
		$('.tx-sremailsubscribe-pi1 dd').css('float', 'left');  
	} 
});
