// Prevent cross-frame scripting (XSF)
if (window != top) top.location.href=location.href;

function popupbiac(url,name,w,h){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	var win=window.open(url,name,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function clearDefaultText(textField) {
     if (textField.value == textField.defaultValue) {
         textField.value = "";
     }
}

function resetDefaultText(textField) {
     if (textField.value == "") {
         textField.value = textField.defaultValue;
     }
}

function initWeatherInfo(rootUrl,timezone,stationIcaoCode,index,weatherAlt) {
	var url = rootUrl + "?" + Object.toQueryString({timezone: timezone, stationIcaoCode: stationIcaoCode});
	var myAjax = new Ajax(
   		url,
   		{method: 'get',
		 onComplete: function(response){
		 	  var result = Json.evaluate(response);
		 	  if (result.time != null ) {
		     	   $('timebox' + index).innerHTML = result.time + '<br/>' + result.date;
		      }
		      
		      if (result.displayName != null && result.displayName != "null") {
				$('weatherImage' + index).innerHTML = '<img src="/image/ico_' + result.displayName + '.gif" alt="' + weatherAlt + '"/>';
		      } else {
				$('weatherImage' + index).innerHTML = '<img src="/image/ico_default.gif" alt="' + weatherAlt + '"/>';
		      }
		      
		      if (result.temperature != null && result.temperature != "null") {
				$('temperature' + index).innerHTML = result.temperature + '&deg;C';
		      }
			}
		});
   myAjax.request();
}

function initTicker(language,arrivalsTicker,departuresTicker) {
   initTickerText(language,arrivalsTicker,departuresTicker,true);
}

function initTickerText(language,arrivalsTicker,departuresTicker,isFirstRun) {
	var url = "/dyn/ticker?" + Object.toQueryString({language: language});
	var myAjax = new Ajax(
   		url,
   		{method: 'get',
		 onComplete: function(response){
		 	  var result = Json.evaluate(response);
		 	  if (result.arrivals != null ) {
		 	  	$(arrivalsTicker).setHTML(result.arrivals);
		    	ticker_start(arrivalsTicker,1,isFirstRun);
		 	  }
		 	  
		 	  if (result.departures != null ) {
		 	  	$(departuresTicker).setHTML(result.departures);
			    ticker_start(departuresTicker,2,isFirstRun);
		 	  }
		 	  
			}
		});
   myAjax.request();
   
   // The 'firstRun' parameter is false here because otherwite the TICKER_tick() function would 
   // be called twice every 30 milliseconds.
   window.setTimeout("initTickerText('" + language + "','" + arrivalsTicker + "','" + departuresTicker + "',false)", 60000);
}

function getValue(arrayVar) {
	return arrayVar[0].childNodes[0].nodeValue;
}

function initYearSelectBox(id) {
	var selectElement = document.getElementById(id);
	var today = new Date();
	var d = new Date();
	d.setYear(2006);
	
	var i = 1;
	while (d.getFullYear() <= today.getFullYear()) {
		selectElement.options[i] = new Option(String(d.getFullYear()), String(d.getFullYear()));
		d.setYear(d.getFullYear() + 1);
		i++;
	}
}

function shoppingBasketAutoCopy() {
	if($('invoice').checked) {
		$('invoiceCompany').value = $('company').value;
		$('invoiceStreet').value = $('street').value;
		$('invoiceNumber').value = $('number').value;
		$('invoicePostalCode').value = $('postalCode').value;
		$('invoiceCity').value = $('city').value;
		$('invoiceState').value = $('state').value;
		$('invoiceCountry').value = $('country').value;
	} else {
		var fields = ['invoiceCompany','invoiceStreet','invoiceNumber','invoicePostalCode',
			'invoiceCity','invoiceState','invoiceCountry'];
		fields.forEach(function(item){
			$(item).value = '';
		});
	}
}

function shoppingBasketToggle(isDisabled) {
	var fields = ['invoiceCompany','invoiceStreet','invoiceNumber','invoicePostalCode',
		'invoiceCity','invoiceState','invoiceCountry','invoiceTavNumber'];
	fields.forEach(function(item){
		$(item).disabled=isDisabled;
	});
}

function sendToAFriend(url) {
	opener.location.href = '/pictures/sendToAFriend?imageUrl=' + url; window.close();
}
function openInParent(url) {
	opener.location.href = url; window.close();
}

/**
 * Returns the value of the cookie 'name'.
 */
function getCookie(name){
	return Cookie.get(name);
}

function cookieEnabled(){
	var cookie = Cookie.set("cookie_enabled", "true", {duration: 0, path: "/"});
	return Cookie.get("cookie_enabled");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function show(elmnt){
	divElement = document.getElementById(elmnt);
	if (divElement != null) {
		divElement.style.visibility = "visible";
	}
}

function hide(elmnt){
	divElement = document.getElementById(elmnt);
	if (divElement != null) {
		divElement.style.visibility = "hidden";
	}
}

// WebTicker by Mioplanet
// www.mioplanet.com
// Adapted by Pieter Coucke
TICKER_RIGHTTOLEFT = false;
TICKER_SPEED = 1;
TICKER_STYLE = "";
TICKER_PAUSED_1 = false;
TICKER_PAUSED_2 = false;

function ticker_pause(tickerIndex,doPause) {
	if (tickerIndex == 1) {
		TICKER_PAUSED_1 = doPause;
	} else if (tickerIndex == 2) {
		TICKER_PAUSED_2 = doPause;
	}
}

function ticker_isPaused(tickerIndex) {
	if (tickerIndex == 1) {
		return TICKER_PAUSED_1;
	} else if (tickerIndex == 2) {
		return TICKER_PAUSED_2;
	}
}

function ticker_start(tickerId,tickerIndex,firstRun) {
	var tickerSupported = false;
	var TICKER = document.getElementById(tickerId);
	var TICKER_CONTENT = TICKER.innerHTML;
	var TICKER_WIDTH = TICKER.style.width;
	var img = '<img src=/image/spacer.gif width="'+TICKER_WIDTH+'" height="0">';

	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
		TICKER.innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY" + tickerIndex + "' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
		tickerSupported = true;
	}
	// IE
	if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
		TICKER.innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY" + tickerIndex + "' width='100%'></SPAN>"+img+"</DIV>";
		tickerSupported = true;
	}
	if(!tickerSupported) TICKER.outerHTML = ""; else {
		TICKER.scrollLeft = TICKER_RIGHTTOLEFT ? TICKER.scrollWidth - TICKER.offsetWidth : 0;
		document.getElementById("TICKER_BODY" + tickerIndex).innerHTML = TICKER_CONTENT;
		TICKER.style.display="block";
		if (firstRun) {
			TICKER_tick(tickerId,tickerIndex);
		}
	}
}

function TICKER_tick(tickerId,tickerIndex) {
	var TICKER = document.getElementById(tickerId);
	if(!ticker_isPaused(tickerIndex)) TICKER.scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
	if(TICKER_RIGHTTOLEFT && TICKER.scrollLeft <= 0) TICKER.scrollLeft = TICKER.scrollWidth - TICKER.offsetWidth;
	if(!TICKER_RIGHTTOLEFT && TICKER.scrollLeft >= TICKER.scrollWidth - TICKER.offsetWidth) TICKER.scrollLeft = 0;
	window.setTimeout("TICKER_tick('" + tickerId + "','" + tickerIndex + "')", 30);
}