
// wrapper for getElementById
function $(id) {
	return document.getElementById(id);	
}

// 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 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");
}
