var isShowpage = false;

// hide the waitlayer and tooltip onload and setup the mousemove observer
Event.observe(window, 'load', function() {

    $('overlay').setOpacity(0.90);

    if(isShowpage == false){
	$('ajaxwait','overlay').invoke('hide');
    }

    checkBrowser();
});

Event.observe(window, 'resize', function() {
    var dimensions = getWindowSize();

    $('overlay').setStyle( {
	height :dimensions['height']+'px'
    });
});

function checkBrowser(){
    BrowserDetect.init();
    if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version <=6){
	$('body').innerHTML = langitems['browser-not-supported'];
    }
}

function showWait() {
    centerElement('ajaxwait');// center it on the screen
    showOverlay();
    $('ajaxwait').show();
}

function hideWait() {
    $('ajaxwait').hide();
    hideOverlay();
}

function showOverlay() {
    var dimensions = getWindowSize();

    $('overlay').setStyle( {
	height :dimensions['height']+'px'
    });

    $('overlay').show();
}

function hideOverlay() {
    $('overlay').hide();
}

function getWindowSize(w) {
    var dimensions = new Array();
    w = w ? w : window;
    dimensions['width'] = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
    dimensions['height'] = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);


    return dimensions;
}

function centerElement(id) {
    // var dimensions = document.viewport.getDimensions(); // cannot be uset due
    // to bug in prototype
    var dimensions = getWindowSize();

    bw = dimensions['width'];
    bh = dimensions['height'];

    el_width = $(id).getWidth();
    new_pos_x = (bw / 2) - (el_width / 2);

    $(id).setStyle( {
	position :'absolute',
	left :new_pos_x + 'px'
    });
}

function in_array(what, where) {
    var a = false;
    for ( var i = 0; i < where.length; i++) {
	if (what == where[i]) {
	    a = true;
	    break;
	}
    }
    return a;
}

function getParamsFromURL(name){
    //name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if(results == null){
	return "";
    }else{
	return results[1];
    }
}

function goToBasket(){
    if(selectedSeatsCount == undefined){
	var selectedSeatsCount = 0;
    }

    if(selectedSeatsCount > 0){
	var yes=confirm(langitems['gotobasket-confirm']);

	if(yes){
	    document.location.href = '/basket/viewbasket/';
	}
    }else{
	document.location.href = '/basket/viewbasket/';
    }
}