/*
	dom checker
*/
dom = (document.getElementById)? true : false;
ie4 = (document.all)? true : false;
ns6= (dom && !ie4)? true : false;
ns4 = (document.layers)? true:false;

//main navigation
preload('navhomeoff','/bestwestern/images/nav/btn-home-off.gif');
preload('navhomeovr','/bestwestern/images/nav/btn-home-ovr.gif');
preload('navhomeon','/bestwestern/images/nav/btn-home-on.gif');

preload('navfindhoteloff','/bestwestern/images/nav/btn-findhotel-off.gif');
preload('navfindhotelovr','/bestwestern/images/nav/btn-findhotel-ovr.gif');
preload('navfindhotelon','/bestwestern/images/nav/btn-findhotel-on.gif');
		
preload('navreservationsoff','/bestwestern/images/nav/btn-reservations-off.gif');
preload('navreservationsovr','/bestwestern/images/nav/btn-reservations-ovr.gif');
preload('navreservationson','/bestwestern/images/nav/btn-reservations-on.gif');
		
preload('navtripplanneroff','/bestwestern/images/nav/btn-tripplanner-off.gif');
preload('navtripplannerovr','/bestwestern/images/nav/btn-tripplanner-ovr.gif');
preload('navtripplanneron','/bestwestern/images/nav/btn-tripplanner-on.gif');
		
preload('navpromotionsoff','/bestwestern/images/nav/btn-promotions-off.gif');
preload('navpromotionsovr','/bestwestern/images/nav/btn-promotions-ovr.gif');
preload('navpromotionson','/bestwestern/images/nav/btn-promotions-on.gif');
		
preload('navpackagesoff','/bestwestern/images/nav/btn-packages-off.gif');
preload('navpackagesovr','/bestwestern/images/nav/btn-packages-ovr.gif');
preload('navpackageson','/bestwestern/images/nav/btn-packages-on.gif');	

function toggleDisplay(obj1Name, obj2Name) {
	/*
		function to show and hide the signin and signout ids
		made for the GCCI login bar
	*/

	// get the object
	objSignin = getObject(obj1Name);
	objSignout = getObject(obj2Name);

	if (objSignout.style.display == 'none') {
		// show the singout
		objSignout.style.display = 'block';
		objSignin.style.display = 'none';
	} else {
		// show the singin
		objSignout.style.display = 'none';
		objSignin.style.display = 'block';
	}
}

function getObject(oID) {
	/*
		function that returns the element based on the browser
		capitalities - ns4 will return null if the obj doesn't exist
	*/
	if (dom) {
		obj = document.getElementById(oID);
	} else if (ie4) {
		obj = document.all(oID);
	} else if (ns4) {
		obj = document.layers(oID);
		if (!obj)
			return null;
	}
	return obj;
}

/*
	Track the returnKey
*/
function goReturn(form, form1, event) {
     getEvent=event.keyCode;   
     test = false; 
     try{
     if (getEvent == "13")
		 {	
		 try{	 	
				if(form1.q.value != 0){
					test = true;
				}
			}catch(e){
				if(document.searchBox.q.value != 0){
					test = true;
				}
			}		 	
			if(test)
 			{  						
 			  document.searchBox.submit(); 
 			  return false;			 			  			  			 
 			}
 			else if (  typeof ajaxDIVOpen == "undefined" || ajaxDIVOpen == false ){ 		
			formvalidation(form);			
		   	return false;
		   	}
         } else if(getEvent == "27"){
             getDoubleClickValue(false);
    	}else{
			return true;
		}
		}catch(e){ if(document.searchBox.q.value != 0){
					document.searchBox.submit();
				}
				 }
    }

function goReturnSelectHotel(form, event) {
     getEvent=event.keyCode;    
     if (getEvent == "13")
		 {		 	
			if (  typeof ajaxDIVOpen == "undefined" || ajaxDIVOpen == false ){ 		
			form.submit(); 			
		   	return false;
		   	}
         } else if(getEvent == "27"){
             getDoubleClickValue(false);
    	}else{
			return true;
		}
    }
    
    function goReturnSelectHotel(form, form1, event) {
    
     getEvent=event.keyCode;    
     if (getEvent == "13")
		 {		 	
			if(form1.q.value != 0)
 			{  						
 			  form1.submit(); 
 			  return false;			 			  			  			 
 			}
 			else if (  typeof ajaxDIVOpen == "undefined" || ajaxDIVOpen == false ){ 		
			form.submit(); 			
		   	return false;
		   	}
         } else if(getEvent == "27"){
             getDoubleClickValue(false);
    	}else{
			return true;
		}
    }

function openSmartLocationPopup(theUrl, windowName, width, height)
{
    var safety = 60;
    var left = window.event.screenX;
    var top = window.event.screenY;

    var temp = left + width + safety;
    if (temp > screen.width)
        left = screen.width - width - safety;

    temp = top + height + safety;
    if (temp > screen.height)
        top = screen.height - height - safety;

    if (window.event.screenX < left)
        left = window.event.screenX;
    if (window.event.screenY < top)
        top = window.event.screenY;

    var features = "scrollbars=no,resizable=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
    window.open(theUrl, windowName, features);
}

/*
* This function set the appropriate class for the given id depending upon the 
* content of the element. 
*/
function setOrangeButton(a_RefName){
	try{	
		var a_Ref = document.getElementById(a_RefName);
		var v_text = '';
		v_text = a_Ref.text;
	
		// This is the case of IE	
		if( typeof v_text == "undefined"){	
			v_text = a_Ref.innerText;
		}	
		
		var v_strLen = v_text.length;
		
		if( v_strLen <= 3){
			v_text = 'button_medium_red';
		}else if( v_strLen <= 8){
			v_text = 'button_small_medium';
		}else if( v_strLen <= 13){
			v_text = 'button_small_medium1';
		}else if( v_strLen <= 16){
			v_text = 'button_medium1';
		}else{
			v_text = 'button_large';
		}
		a_Ref.className = v_text;
	}catch(e){
	}		
}

function setOrangeButtonGroup(a_RefName1, a_RefName2){
	try{	
		var a_Ref1 = document.getElementById(a_RefName1);
		var a_Ref2 = document.getElementById(a_RefName2);

		var v_text1 = '';
		var v_text2 = '';		

		v_text1 = a_Ref1.text;
		v_text2 = a_Ref2.text;	

		// This is the case of IE	
		if( typeof v_text1 == "undefined"){	
			v_text1 = a_Ref1.innerText;
		}
		
		if( typeof v_text2 == "undefined"){	
			v_text2 = a_Ref2.innerText;
		}		
			
		var v_strLen1 = v_text1.length;
		var v_strLen2 = v_text2.length;
		
		setOrangeButton(a_RefName1);		
		setOrangeButton(a_RefName2);
		
		if(v_strLen1 > v_strLen2){
			a_Ref2.className = a_Ref1.className;
		}else{
			a_Ref1.className = a_Ref2.className;
		}		
		
	}catch(e){
	}	
	
}

function preload(imgObj,imgSrc) {
	/*
		function to preload images
	*/
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}

function changeImage(imgName,imgObj,layer) {
	/*
		function to do rollovers of images
	*/
	if (document.images) {
		if (document.layers) {
			if (layer!=null){
				eval('document.layers.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
			} else {
				document.images[imgName].src = eval(imgObj+".src");
			}
		} else {
			document.images[imgName].src = eval(imgObj+".src");
		}
	}
}

/************************************************************************
* NewWindow
*	opens a new browser window with the specified url, window name
*	and other parameter specs
************************************************************************/
function NewWindow(URL, name, specs) 
{
	var anon_win = window.open(URL, name, specs);
}

var oWinInfo=null;
function showWindow( m_url, winname, winwidth, winheight, wndparams)
{	
	
	if(oWinInfo != null){
		try{
			oWinInfo.close();
		}catch(e){}
		oWinInfo = null;		
	}
		
	if ((winname == null) || (winname == "")) winname = "lvs";
	
	winleft = (screen.availWidth / 2) - (winwidth / 2);
	wintop = (screen.availHeight / 2) - (winheight / 2);
	
	if (wndparams == null) wndparams = "scrollbars=no,resizable=no";
	
	oWinInfo=(window.open(m_url, winname,"left=" + winleft + ",top=" + wintop + ",width=" + winwidth + ",height=" + winheight + "," + wndparams));
	//	registerWindow(oWinInfo);
	
	if (!Browser.ie) {
		if(oWinInfo.self != null)  oWinInfo.focus();
	}
	
}

var Browser = new Object();
with (Browser) {
	Browser.b = Browser;
	b.a = navigator.userAgent.toLowerCase();
	b.v = navigator.appVersion;
	b.version = parseFloat(v);
	b.major = parseInt(v);
	b.opera = (a.indexOf('opera') != -1)?true:false;
	b.hotjava = (a.indexOf('hotjava') != -1)?true:false;
	b.webtv = (a.indexOf('webtv') != -1)?true:false;
	b.nav = (a.indexOf('mozilla') != -1 && a.indexOf('spoofer') == -1 && 
		a.indexOf('compatible') == -1 && !opera && !webtv && !hotjava)?true:false;
	b.nav4 = (nav && major == 4)?true:false;
	b.nav6 = (nav && major == 5)?true:false;
	b.nav6up = (nav && major >= 5)?true:false;
	b.aol = (a.indexOf('aol') != -1)?true:false;
	//b.ie = (!opera && a.indexOf('msie') != -1)?true:false;
	b.ie = (opera || a.indexOf('msie') != -1)?true:false;
	b.ie4 = (ie && major == 4 && a.indexOf('msie 4') != -1)?true:false;
	b.ie4up = (ie && major >= 4)?true:false;
	b.ie5 = (ie4up && a.indexOf('msie 5.0') != -1)?true:false;
	b.ie5up = (ie4up && !ie4)?true:false;
	b.macie5=(ie4 && v.indexOf("macintosh")!=-1)?true:false;
	b.ie55 = (ie5up && a.indexOf('msie 5.5') != -1)?true:false;
	b.ie55up = (ie5up && !ie5)?true:false;
	b.ie6 = (ie4up && a.indexOf('msie 6.') != -1)?true:false;
	b.ie6up = (ie55up && !ie55)?true:false;
	b.win95 = (a.indexOf('win95') != -1 || a.indexOf('windows 95') != -1)?true:false;
	b.win98 = (a.indexOf('win98') != -1 || a.indexOf('windows 98') != -1)?true:false;
	b.mac = (a.indexOf('macintosh') != -1)?true:false;
	b.win9x = (win95 || win98)?true:false;
	b.sun = (a.indexOf('sunos') != -1)?true:false;
}

function setStyle(objId, style)
{
	if (navigator.userAgent.indexOf("Opera") != -1)
	{ //Opera
		styleObj = eval('document.all.' + objId);
		styleObj.style.display = style;
	}
	else if (document.getElementById)
	{ //Netscape 6 & IE 5
		myObj = document.getElementById(objId);
		myObj.style.display = style;
	}
	else
	{
		alert('This website uses DHTML. We recommend you upgrade your browser.');
	}
}

function toggleDisplayWithParams(thisform)
{
	setStyle('lnavid', 'none');
	setStyle('interstl', 'block');

	thisform.submit();
}

function formvalidation(thisform)
{
	test=toggleDisplay(thisform);
	if (test==true)
	{
		thisform.submit();
	}
}

/************************************************************************
* Trim
*	Trims leading and trailing spaces and tabs. 
************************************************************************/
function Trim(sData) 
{
	var sTrimmed = String(sData);
	sTrimmed = sTrimmed.replace(/(^[ |\t]+)|([ |\t]+$)/g, '');
	return sTrimmed;
}

function toggleForm(objName, varStatus) {
	/*
		function to show and hide the form elements
		made for the review and reserve and join pages
	*/

	// get the object
	objSection = getObject(objName);

	if (varStatus == 'show') {
		// show the section
		objSection.style.display = 'block';
	} else {
		// hide the section
		objSection.style.display = 'none';

	}
}

/************************************************************************
* setDisplayAllHotels
*	In case of amenities search, setting value in select hotel form to display 
*	All hotels or excat matched amenities hotels.
************************************************************************/
function setDisplayAllHotels(val){			    
		    document.selectHotelForm.displayAllHotels.value=val;		    		
}

/************************************************************************
* validiteCity
*	Call from search and select hotel page on bodyload. This function validate that
*	the city element is not null and then call to Ajax.js SmartLogic_SetCity function.
************************************************************************/

function validateCity(city , stateCode, countryCode){	
	if(city != null){		
		SmartLogic_SetCity(city , stateCode, countryCode);
	}
}

function checkTabIsPressed(e, t){				
	if(e.keyCode == 9){		
		SmartLogic_SetCity(t,document.selectHotelForm.stateCode,document.selectHotelForm.countryCode);
	}
}