
// wrapper for getElementById
function $(id) {
	return document.getElementById(id);	
}

// initilisation function called onload
function init() {
	var rand = Math.floor(3*Math.random())+1;
	$('banner').innerHTML = '<a href="http://web.travelonline.com/specials/'+rand+'.html"><img src="http://web.travelonline.com/specials/'+rand+'.gif" alt="" class="banner" /></a>';
}

// onfocus for search box in nav
function search_focus() {
	var q = $('q');
	if (q.value == 'Search...') {
		q.value = '';
		q.style.fontStyle = 'normal';
		q.style.color = '#000000';
	}
}
// onblur for search box in nav
function search_blur() {
	var q = $('q');
	if (q.value == '') {
		q.value = 'Search...';	
		q.style.fontStyle = 'italic';
		q.style.color = '#999999';
	}
}
// submit for search
function search_submit() {
	var q = $('q');
	if (q.value != '' && q.value != 'Search...') {
		return true;
	}
	return false;
}

// get url parameters (_GETish)
function getUrlParameters(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];
	}
}



//////////////////////////////////
// iframe quote wizard code
//////////////////////////////////
af_value = getUrlParameters('af');

function findPosY(objName) {
	eval("obj = document.getElementById('" + objName + "')");
    var curtop = 0;
    if(obj.offsetParent)
        while(1){
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.y) curtop += obj.y;
	curtop = curtop -1;
    return curtop;
}

/*function findPosX(objName) {
	eval("obj = document.getElementById('" + objName + "')");
    var curleft = 0;
    if(obj.offsetParent)
        while(1){
          curleft += obj.offsetLeft;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.x) curleft += obj.x;
	curleft = curleft - 1;
    return curleft;
}*/

function findScrollY() {
	scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && document.body.scrollTop) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && document.documentElement.scrollTop) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

function findScrollX() {
	scrOfX = 0;
	if( typeof( window.pageXOffset ) == 'number' ) {
		//Netscape compliant
		scrOfX = window.pageXOffset;
	} else if( document.body && document.body.scrollLeft) {
		//DOM compliant
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && document.documentElement.scrollLeft) {
		//IE6 standards compliant mode
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfX;
}


function showInline(id, i, supplier_code_id) {	// id = which window to display, i = 1:show window OR 0:close window, supplier_code_id = the supplier code index
	if (i == 1) {
		$('rate_buttons').style.display = 'none';
		$(id+'_div').style.display = 'block';
		if(af_value !="") agent_value = "1"; else agent_value = $('agent').value;	// affiliates always get agent rates
		switch (id) {
			case 'wizard': {
				$(id+'_iframe').src = 'http://dm.travelonline.com/w/wizard.php?agent='+agent_value+'&supplier_code='+$('supplier_code-'+supplier_code_id).value+'&option_code='+$('option_code').value+'&referer='+$('referer').value+'&acctour='+$('acctour').value+'&tour='+$('tour').value+'&pass='+$('pass').value+'&af='+af_value+'&iframe=1';
				break;
			}
			case 'bookingwizard': {
				$(id+'_iframe').src = 'http://dm.travelonline.com/w/wizard.php?agent='+agent_value+'&supplier_code='+$('supplier_code-'+supplier_code_id).value+'&option_code='+$('option_code').value+'&referer='+$('referer').value+'&acctour='+$('acctour').value+'&tour='+$('tour').value+'&pass='+$('pass').value+'&af='+af_value+'&iframe=1';
				break;
			}
			case 'lastminute': {
				$(id+'_iframe').src = $('last_minute').value;
				break;
			}
			case 'specials': {
				$(id+'_iframe').src = 'http://www.specials.travelonline.com/fp_search.php?'+$('specials').value;
				break;
			}
		}
		growInline("'"+id+"'");
		smoothScrollTo(findScrollX(), findScrollY(), 0, (findPosY('rate')-50))
	} else {
		$('rate_buttons').style.display = 'block';
		$(id+'_div').style.display = 'none';
		$(id+'_iframe').src = 'http://web.travelonline.com/loading.html';
	}
}

function smoothScrollToProcess(from_x, from_y, to_x, to_y) {
	if ((from_y <= (to_y-10)) || (from_y >= (to_y+10))) {
		window.scrollTo(from_x, from_y);
		if (from_y < to_y) {
			timer = window.setTimeout("smoothScrollToProcess("+findScrollX()+", "+(findScrollY()+10)+", "+to_x+", "+to_y+");", 4);
		} else {
			timer = window.setTimeout("smoothScrollToProcess("+findScrollX()+", "+(findScrollY()-10)+", "+to_x+", "+to_y+");", 4);
		}
	}
}

function smoothScrollTo(from_x, from_y, to_x, to_y) {
	if (from_y < to_y) {
		timer = window.setTimeout("smoothScrollToProcess("+findScrollY()+", "+(findScrollY()+10)+", "+to_x+", "+to_y+");", 4);
	} else {
		timer = window.setTimeout("smoothScrollToProcess("+findScrollY()+", "+(findScrollY()-10)+", "+to_x+", "+to_y+");", 4);
	}
}

function growInlineProcess(id, height) {
	height = height + 10;
	$(id+'_iframe').style.height = height+'px';
	$(id+'_middle').style.height = height+'px';
	if (height < 440) {
		window.setTimeout("growInlineProcess('"+id+"', "+height+");", 4);
	}
}

function growInline(id) {
	timer = window.setTimeout("growInlineProcess("+id+", 100);", 4);
}

function showSeasonRates() {
	window.open("http://dm.travelonline.com/common/show_seasons.php?supplier_code="+$('supplier_code-0').value+"", "seasonrates", "menubar=0,location=0,resizable=0,scrollbars=1,width=350,height=350");
}

/* Navigation Expand/Collapse System */

function nav_toggle_action(id) {
	if ($('nav-'+id).style.display == 'none') {
		$('nav-'+id).style.display = 'block';
		$('link-'+id).style.backgroundImage = 'url(/images/collapse.gif)';
	} else {
		$('nav-'+id).style.display = 'none';
		$('link-'+id).style.backgroundImage = 'url(/images/expand.gif)';
	}
}
function nav_expand_start() {

}
function nav_expand_finish(id) {
	$('nav-basic').innerHTML = '';
	$('nav-basic').style.display = 'none';
	$('nav-full').style.display = 'block';
	nav_toggle_action(id);
}
function nav_toggle(id) {
	
	var download = new Array('australia', 'pacific', 'europe', 'asia');
	
	c = 0;
	for (i = 0; i < download.length; i++) {
		if (id == download[i]) {
			c++;	
		}
	}
	
	if (c > 0) {
		if ($('nav-basic').innerHTML) {
			var page = '/destinations.php';
			var request = '';
			var type = 'div';
			var el = 'nav-full';
			var status_start = 'nav_expand_start()';
			var status_finish = 'nav_expand_finish(\''+id+'\')';
			ajax(page, request, type, el, status_start, status_finish);
		} else {
			nav_toggle_action(id);
		}
	} else {
		nav_toggle_action(id);
	}
}
