/************************************************************
 * Start of the old site JS
 ***********************************************************/
var agent=navigator.userAgent.toLowerCase();
var isIE=(agent.indexOf('msie') != -1) ? true : false;
var isDOM=(typeof(document.getElementById) != 'undefined' && !isIE) ? true : false;
var isNav4=(agent.indexOf('mozilla') != -1 && !isDOM && !isIE) ? true : false;

//preload the please wait image
var pleaseWait = new Image(76,13); 
pleaseWait.src="/images/EN/buttons/please_wait.gif"; 

document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

// returns left position
function getLeft(daObj){
	var returnVal;
	// set left if auto-calculated (left=0) or if not specified in-line/with style sheet
	if(isDOM){
		if(typeof(daObj.style.left)=='undefined' || daObj.style.left==''){
			daObj.style.left = 
				document.defaultView.getComputedStyle(daObj, '').getPropertyValue('left');
		}
		returnVal = parseInt(daObj.style.left);
	}
	else if(isNav4){ returnVal = daObj.left; } // daObj.pageY if undef
	else{ returnVal = daObj.style.pixelLeft; } // daObj.offsetLeft if undef
	return returnVal;
}

// sets left position
function setLeft(daObj, newLeft){
	if(isDOM){ daObj.style.left = newLeft + 'px'; }
	else if(isNav4){ daObj.left = newLeft; }
	else{ daObj.style.pixelLeft = newLeft; }
}

// returns top position
function getTop(daObj){
	var returnVal;
	if(isDOM){
		if(typeof(daObj.style.top)=='undefined' || daObj.style.top==''){
			daObj.style.top = 
				document.defaultView.getComputedStyle(daObj, '').getPropertyValue('top');
		}
		returnVal = parseInt(daObj.style.top);
	}
	else if(isNav4){ returnVal = daObj.top; } // daObj.pageX if undef
	else{ returnVal = daObj.style.pixelTop; } // daObj.offsetTop if undef
	return returnVal;
}

// sets top position
function setTop(daObj, newTop){
	if(isDOM){ daObj.style.top = newTop + 'px'; }
	else if(isNav4){ daObj.top = newTop; }
	else{ daObj.style.pixelTop = newTop; }
}

// gets object height
function getObjHeight(daObj){
	var returnVal;
	if(isDOM){
		if(typeof(daObj.style.height) == 'undefined' || daObj.style.height==''){
			daObj.style.height = 
				document.defaultView.getComputedStyle(daObj, '').getPropertyValue('height');
		}
		returnVal = parseInt(daObj.style.height);
	}else if(isIE){ returnVal = daObj.clientHeight; // daObj.offsetHeight if undef
	}else{ returnVal = daObj.clip.height; } // daObj.clip.height if undef
	return returnVal;
}

// gets object width
function getObjWidth(daObj){
	var returnVal;
	if(isDOM){
		if(typeof(daObj.style.width) == 'undefined' || daObj.style.width==''){
			daObj.style.width = 
				document.defaultView.getComputedStyle(daObj, '').getPropertyValue('width');
		}
		returnVal = parseInt(daObj.style.width);
	}else if(isIE){ returnVal = daObj.clientWidth; // daObj.offsetWidth if undef
	}else{ returnVal = daObj.clip.width; } // daObj.clip.width if undef
	return returnVal;
}

// returns window's innner width
function getWindowWidth(){
	var returnVal = isIE ? document.body.clientWidth : window.innerWidth;
	return returnVal;
}

// returns window's innner height
function getWindowHeight(){
	var returnVal = isIE ? document.body.clientHeight : window.innerHeight;
	return returnVal;
}

// return an object for a string or an object (just in case)
function getObject(daName){
	var daObj;
	if(typeof(daName) == "string"){
		if(isDOM){
			daObj = document.getElementById(daName);
		}else if(isIE){
			daObj = eval("document.all." + daName);
		}else{
			daObj = eval("document." + daName);
		}
	}else{
		daObj = daName;
	}
	return daObj;
}

// shows an object
function show(daObj){
	var Obj = getObject(daObj);
		Obj.style.display = '';
}

// hides an object
function hide(daObj){
	var Obj = getObject(daObj);
	Obj.style.display = 'none';
}

// true if hidden, false if shown
function isHidden(daObj){
	var Obj = getObject(daObj);
	if(isNav4){
		returnVal = (Obj.visibility == 'hidden');
	}else{
		returnVal = (Obj.style.visibility == 'hidden');
	}
	return returnVal;
}

// moxes an object to a new coordinate (left, top) AKA (x, y)
function moveObjTo(daObj, newLeft, newTop){
	daObject = getObject(daObj);
	setLeft(daObject, newLeft);
	setTop(daObject, newTop);
}
function moveObjBy(daObj,left,top){
	newLeft = left + getLeft(daObj);
	currentTop = getTop(daObj);
	newTop = (top + currentTop);
	//alert(newTop);
	moveObjTo(daObj,newLeft,newTop);
}
//clips an object to the new corrdinate (top,right,bottom,left)
function clipObjTo(daObj,t,r,b,l) {
	//these properties are held so that you know where you are in your clipping
	//allowing for the clipObjBy method
	daObj.clpt = t;
	daObj.clpr = r;
	daObj.clpb = b;
	daObj.clpl = l;
	daObj.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}
function clipObjBy(daObj,t,r,b,l){
	clipObjTo(daObj,(daObj.clpt+t),(daObj.clpr+r),(daObj.clpb+b),(daObj.clpl+l));
}
// center an object in the screen
function moveToCenter(daObject){
	daObject = getObject(daObject);
	daHeight = getObjHeight(daObject);
	daWidth = getObjWidth(daObject);
	winHeight = getWindowHeight(daObject);
	winWidth = getWindowWidth(daObject);
	midLeft = (winWidth - daWidth) / 2;
	midTop = (winHeight - daHeight) / 2;
	moveObjTo(daObject, midLeft, midTop);
}

function popup(name, url, width, height, scroll) {
	scrolling = (scroll==1)?'yes':'no';
	mywin = window.open(url, name,"menubar=no,resizable,scrollbars="+scrolling+",status=no,width="+width+",height="+height);
	mywin.focus();
	return false;
}

function checkTerms() {
	if(document.getElementById('TermsCheckboxes')) {
		myInputs = document.getElementById('TermsCheckboxes').getElementsByTagName('input');
		notAllChecked = false;
		arrayLength = myInputs.length;
		for (i=0;i<arrayLength;i++) {
			if(!myInputs[i].checked) {
				notAllChecked = true;
			}
		}
		if(notAllChecked) {
			document.getElementById('book_button').src = document.getElementById('book_button').getAttribute('off');
		} else {
			document.getElementById('book_button').src = document.getElementById('book_button').getAttribute('on');
		}
		document.getElementById('book_button').disabled = notAllChecked;
	}
}

function disableButton(form_ident, button_ident) {
	bttn = getObject(button_ident);
	frm = getObject(form_ident);
	bttn.disabled = true;
	bttn.src = pleaseWait.src;
	setTimeout(function(){frm.submit();},0);
	return false;
}
/************************************************************
 * Start of the new site JS
 ***********************************************************/
function navigation(navItem) {
	navArrows = new Array();
	navArrows['Flights'] = document.getElementById('FlightsArrow');
	navArrows['Hotels'] = document.getElementById('HotelsArrow');
	navArrows['MyBookings'] = document.getElementById('MyBookingsArrow');
	navArrows['About'] = document.getElementById('AboutArrow');
	navArrows['Contact'] = document.getElementById('ContactArrow');
	for (navArrow in navArrows) {
		if(navArrow == navItem && navArrows[navArrow].style) {
			navArrows[navArrow].style.display = 'block';
		} else if(navArrows[navArrow].style) {
			navArrows[navArrow].style.display = 'none';
		}
	}
}

function removeDefault(box){
	if (box.value == box.defaultValue) {
		box.value = '';
		box.className = 'BoxOn';
	}
}

function restoreDefault(box){
	if (box.value == '') {
		box.value = box.defaultValue;
		box.className = 'Box';
	}
} 
function resources(navItem, on, subItem) {
	sub = (subItem)?' Sub':'';
	if(on) {
		navItem.className = 'Button Over'+sub;
	} else {
		navItem.className = 'Button'+sub;
	}
}

