﻿/* W I Z Z A I R */
//[UTF-8 w BOM]

//global vars
//==============

//*** encoding workaround ***

//full roman8 - minus some regexp conflicts
//var g_roman8RExp = new RegExp ("[ !#$%&'()*+,\-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz{|}~1ÀÂÈÊËÎÏ´¨̃ÙÛ₤¯Ýý°ÇçÑñ¡¿¤£¥§ƒ¢âêôûáéóúàèòùäëöüÅîØÆåíøæÄìÖÜÉïßÔÁÃãÐðÍÌÓÒÕõŠšÚŸÿÞþ·µ¶¾¼½ªº«■»±]","g");

//reduced roman8, tested by David; blacklist chars: ƒüŠšŸÿ + the ones from invalid (not goodlist): !{}[]^|`<>\\"
var g_roman8RExp = new RegExp ("[ ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzÀÂÈÊËÎÏÙÛÝýÇçÑñ¢âêôûáéóúàèòùäëöÅîØÆåíøæÄìÖÜÉïßÔÁÃãÐðÍÌÓÒÕõÚ0123456789#$%&()+,-./:;=?@]","g");

//proto addons
//==============

Element.reveal = function( pTarget ) { if ($(pTarget)) $(pTarget).style.visibility = 'visible'; }
Element.cloak = function( pTarget ) { if ($(pTarget)) $(pTarget).style.visibility = 'hidden'; }

//functions
//==============

ceize = function(pS) { //yes, I AM lazy
	//we need these in case there's no perl Encode support (new functions for utf to roman and vice versa)
	//BUT even if we have, both methods are just mere workarounds...
	pS = pS.replace(/ő/g,'õ'); pS = pS.replace(/Ő/g,'Õ');
	pS = pS.replace(/ű/g,'û'); pS = pS.replace(/Ű/g,'Û');
	pS = pS.replace(/Š/g,'S'); pS = pS.replace(/š/g,'s');
	pS = pS.replace(/ü/g,'û'); pS = pS.replace(/Ü/g,'Û');
	return pS;
}

cleanFilterString = function(pString,pRegexp) { 
	validChars = pRegexp;
	failed = 0;
	for (var i = 0; i < pString.length; i++)
	{
		selChar = pString.substr(i,1);
		if (selChar.match(validChars)==null)
			{
			failed = 1;
			pString = pString.replace(selChar,'?');
			}
	}
	if (failed == 1) { pString = pString.replace(/\?/gi,''); }
	return(pString);
}

showLoading = function( pState ) {
	var showAction = 'none';
	if ($('divGenPlsWait'))
	{
		if (pState == 1) showAction = 'block';
		$('divGenPlsWait').style.display = showAction;
	}
}

makePopup = function( pW, pH, pContent) {
	wizzPop = window.open ("","wizzPopUp","location=0,status=0,statusbar=no,scrollbars=1,width="+pW+",height="+pH+"");
	wizzPop.moveTo((screen.availWidth - pW) / 2,(screen.availHeight - pH) / 2);
	msg = '';
	msg += '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8">'
	msg += '<title>Wizzair</title><link rel="stylesheet" type="text/css" media="screen" href="/skylights.css" />'
	msg += '<link rel="stylesheet" type="text/css" media="screen" href="/wizzair.css" /></head><body id="popup">'
	msg += pContent + '</body></html>';
	wizzPop.document.write(msg);
	return false;
}

openPopup = function( pW, pH, pUrl) {
	wizzPop = window.open (pUrl,"wizzStaticPopUp","location=0,status=1,statusbar=yes,scrollbars=1,width="+pW+",height="+pH+"");
	wizzPop.moveTo((screen.availWidth - pW) / 2,(screen.availHeight - pH) / 2);
}


// DC'S ONMOUSEENTER EMULATION 
//=============================
function onMouseLeave( pTarget, pAction ) {
  
   pTarget.realLeaveFunction = pAction; //store action
   pTarget.leaveFunction = function() { pTarget.realLeaveFunction(); }

   //Save previous mouseout and reuse later
   if (pTarget.onmouseout) pTarget.onmouseoutSave1 = pTarget.onmouseout;
   pTarget.onmouseout = function() {
       if (pTarget.onmouseoutSave1) pTarget.onmouseoutSave1();
       this.ltimer = setTimeout(this.leaveFunction.bind(this),100);
   }
  
   //Save previous mouseover and reuse later
   if (pTarget.onmouseover) pTarget.onmouseoverSave1 = pTarget.onmouseover;
   pTarget.onmouseover = function() {
       if (pTarget.onmouseoverSave1) pTarget.onmouseoverSave1();
       clearTimeout(this.ltimer);
   }

}


function onMouseEnter( pTarget, pAction ) {
  
   pTarget.enterFunction = pAction; //store action
  
   pTarget.stepPattern = function() { this.epattern = -1; } //reset pattern

   if (pTarget.onmouseover) pTarget.onmouseoverSave2 = pTarget.onmouseover;
   pTarget.onmouseover = function() {
       if (pTarget.onmouseoverSave2) pTarget.onmouseoverSave2();
       if (this.epattern == 1) { this.epattern = 0; clearTimeout(this.etimer); }
           else { (this.epattern = 0); this.enterFunction(); }
   }
  
   if (pTarget.onmouseout) pTarget.onmouseoutSave2 = pTarget.onmouseout;
   pTarget.onmouseout = function() {
       if (pTarget.onmouseoutSave2) pTarget.onmouseoutSave2();
       if (this.epattern == 0) this.epattern = 1;
       this.etimer = setTimeout(this.stepPattern.bind(this),100);
   }
}

// FETCH VALUES OF SELECT INTO ARRAY
//===================================
var fetchSelOpts = function( pTarget ) {
    var target = pTarget;
    if (typeof(target) == 'string') target = $(pTarget);

    var retArr = new Array();
    $A(target.options).each( function(opt) { 
        retArr.push(opt.value);
    });
    return retArr;
}

function checkin() {
    document.getElementById('onlinebooking').style.visibility = 'hidden';
    var oIframe = document.getElementById("skyLightsIFrame");
    var oDoc = oIframe.contentWindow || oIframe.contentDocument;
    if (oDoc.document) {
        oDoc = oDoc.document;
    }
    //oIframe.style.visibility = 'hidden';
    document.getElementById('onlinebooking').style.display = "none";
    var checkin = document.getElementById('checkin').style;
    checkin.visibility = 'visible';
    checkin.display = 'inline';     
    window.frames['skyLightsIFrameCheckIn'].document.getElementById('wrapper').style.width = '210px';
     window.frames['skyLightsIFrameCheckIn'].document.getElementById('wrapper').style.paddingTop = '0px';
     document.getElementById('skyLightsIFrameCheckIn').style.height = '580px';
}

function booking() {
    document.getElementById('onlinebooking').style.visibility = 'visible';
    var oIframe = document.getElementById("skyLightsIFrame");
    var oDoc = oIframe.contentWindow || oIframe.contentDocument;
    if (oDoc.document) {
        oDoc = oDoc.document;
    }
    //oIframe.style.visibility = 'visible';
    document.getElementById('onlinebooking').style.display = "inline-block";
    var checkin = document.getElementById('checkin').style;
    checkin.visibility = 'hidden';
    checkin.display = 'none';
    checkin.zIndex = -1;
   }
 
 
   /*####################################################
   #
   # Function: submitToCheckin()
   #
   # Description:
   # Transfers the user to the web checkin page.
   #
   */
   function submitToCheckin2() {
   	if (document.skylightsForm.firstName) {
   		document.skylightsForm.action = '/checkin/checkin/default.asp';
   	} else {
   	document.skylightsForm.action = '/checkin/default.asp';
   }
   	document.skylightsForm.submit();
   }
