//preload images places on the body onload event // menu images are non page sensitive so ok to load imediatly
function MM_preloadImages() { //v3.0 from dreamweaver
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 
}

function loadDestaque(id)
{
	var nImagens = 10;
	var genRandom;
	//var obj = getObject(id);
	
	genRandom = (Math.floor(Math.random() * nImagens) + 1);
	document.getElementById(id).src = ("images/home_img" + [genRandom] + ".jpg");
}
   

function reloadHome(){
	setTimeout('window.location="home_quotes.aspx";',10000);
}

//this function alerts for non available links - delete from final deployment
function na() {
	alert("funcionalidade não disponível");
}

function ftrLoc(id,strstyle,strval){
	var obj = getObject(id);
	if(obj){
		if (strstyle='bottom') {obj.style.bottom=strval}
	}
}

function doSubmit(url) {
	document.forms[0].action=url;
	document.forms[0].method='get';
	document.forms[0].submit();
}

//generic function to get reference to object by id
function getObject(id) {
	if (document.all){return(document.all(id))}
	if (document.getElementById){return(document.getElementById(id))}
}

//generic function that handles input text
function searchText(action,string){
	var obj = getObject(string);
	if(obj){
		if (action=='focus'){obj.className='on'} else {obj.className='text'}
		if (action=='focus' && obj.value==string){obj.value='';}
		if (action=='blur' && obj.value==''){obj.value=string;}
	}
}

// Generic function to label textboxes
function setLabel(id, texto){
	var obj = getObject(id);
	if(obj.value == texto){
		obj.value = "";
		obj.style.color = "#000000";
	}else if(obj.value == ""){
		obj.value = texto;
		obj.style.color = "#666666";
	}
}

//generic function that handles input fields focus and blur 
function swapClass(cls,id){
	var obj = getObject(id);
	if(obj){
		obj.className = cls;
	}
}

//generic function that handles input text
function swapClassTxt(cls,id,string){
	var obj = getObject(id);
	if(obj){
		obj.className = cls;
		if (obj.value==string){obj.value=''} else if (obj.value==''){obj.value=string}
	}
}

//generic function that handles text areas
function textareaOn(cls,action,obj,string){
	if(document.getElementById){
		if (action=='focus' && document.getElementById(obj).value==string){document.getElementById(obj).value='';document.getElementById(obj).className = cls;}
		if (action=='blur' && document.getElementById(obj).value==''){document.getElementById(obj).value=string;document.getElementById(obj).className = cls;}
	}
	else if(document.all){
		if (action=='focus' && document.all(obj).value==string){document.all(obj).value='';document.all(obj).className = cls;}
		if (action=='blur' && document.all(obj).value==''){document.all(obj).value=string;document.all(obj).className = cls;}
	}
}

//generic functions that highlite image by swapping the style associated to the object
// need to set up event processing and listners for cross platform compliance
//*** this function sets attaches the onmouseover events
function doLoad() {
	// Do Loading
	if (window.document.captureEvents==null)
	return // Not IE4 or NS4
	if (window.document.captureEvents!=null)  // NS - capture events
	window.document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
	window.document.onmouseover = imageFrame;
	window.document.onmouseout = imageFrame;
}
//*** this function processes events called when user mouses over a foto or banner
function setupEventObject(e) {
	// Map NS event object to IEs
	if (e==null) return // IE returns object by default
	window.event = e
	if (e.type=='mouseover'){window.event.srcElement = e.target} else {window.event.srcElement = e.relatedTarget}
	window.event.x = e.x
	window.event.y = e.y
	// Route the event to the original element
	window.event.srcElement.handleEvent(e);
}
//*** this function process the mouse over and out events to change image frames
function imageFrame(obj) {
	setupEventObject(obj);
	obj = window.event.srcElement
	if(obj){
		var classNames = obj.className.split('_');
		if (classNames.length==1){obj.className=classNames[0]+'_on'}
		else {obj.className=classNames[0]}
	}
}

//generic pop window funtion that accepts window settings and url parameters
//if no window settings defaults to set small pop-up window
function popUpWindow(URLStr, windowSettings) {
var popUpWin;
if (windowSettings=='privacy'){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=400,height=400,top=100,left=100,screenX=100,screenY=100'}
if (windowSettings=='photo'){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=700,height=500,top=50,left=100,screenX=100,screenY=100'}
if (windowSettings=='bikes'){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=700,height=680,top=50,left=100,screenX=100,screenY=100'}
if (windowSettings=='jerseys'){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=700,height=500,top=50,left=100,screenX=100,screenY=100'}
if(popUpWin) {if(!popUpWin.closed) popUpWin.close();}popUpWin = open(URLStr, 'popUpWin', windowSettings);
}

// these functions return the x,y,width and height of an object
function getRealLeft(obj){var curleft = 0;if (obj.offsetParent) {while (obj.offsetParent){curleft += obj.offsetLeft;obj = obj.offsetParent;}} else if (obj.x) curleft += obj.x; return curleft;}
function getRealTop(obj){var curtop = 0;if (obj.offsetParent) {while (obj.offsetParent){curtop += obj.offsetTop;obj = obj.offsetParent;}} else if (obj.y) curtop += obj.y; return curtop;}
function getHeight(objID) {return objID.offsetHeight}
function getWidth(objID) {return objID.offsetWidth}

//hide and show reservations or fina a hotel on the homepage quick reservations box
function quickRes(tab) {
	var hotel = getObject('findhotel');var res = getObject('qres');var fields = getObject('resfields')
	if (tab=='hotel'){hotel.style.top = getRealTop(res) + 'px';hotel.style.left = getRealLeft(res) + 'px';fields.style.display='none';hotel.style.display='block';}
	else {hotel.style.display='none';fields.style.display='block';}
}

//because of the quick reservation box must cange position on screen with window resizing
//must reposition the find a hotel box when screen is resized - only do this if find a hotel is activiated
function posQuickRes() {
	var hotel = getObject('findhotel');var res = getObject('qres');
	if (hotel&&res){if (hotel.style.display=='block') {	hotel.style.top = getRealTop(res) + 'px';hotel.style.left = getRealLeft(res) + 'px';}}
}

function showHideJerseySize(value){
	//alert('teste12346');
	
	if (value == "yes"){
		document.getElementById('jersey').disabled = '';
	}else if(value == "no"){
		document.getElementById('jersey').disabled = 'true';
	}
	
}

function change_tour(id){
	if(id != "0"){
		document.location.href = "form_reserve.aspx?id=" + id;
	}
}

//call the window load event to initialize event listning
window.onload = doLoad