var browser_IE;
var browser_NS4;
var browser_W3C;
var platForm;
var isMac;
var defaultNumOfAdults=2;
var defaultNumOfRooms=1;
var defaultNumOfKids=0;
//for callendar
var DATE_FORMAT = "MM/dd/yyyy"
var DEFAULT_CHECKIN_OFF_NUM = 21;
var DEFAULT_DURATION = 3;

browser_IE  = (document.all && navigator.appName == 'Microsoft Internet Explorer') ? true : false;
browser_NS4 = (document.layers) ? true : false;
browser_W3C = (!document.all && document.getElementById) ? true : false;

platForm=navigator.platform;
isMac=platForm.indexOf("Mac");

// Trims a string
function trim(str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function getTop(element) {
	var theElement = element;
	var newTop = 0;
	while(theElement.offsetParent) {
		newTop  += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
	return newTop;
}

function getBottom(element) {
	var theElement = element;
	
	return(getTop(theElement) + theElement.clientHeight);
}

function getLeft(element) {
	var theElement = element;
	var newLeft = 0;
	while(theElement.offsetParent) {
		newLeft  += theElement.offsetLeft;
		theElement = theElement.offsetParent;
	}
	return newLeft;
}

function getRight(element) {
	var theElement = element;
	
	return(getLeft(theElement) + theElement.clientWidth);
}

function highlightButton(theImg, useInline) {
	if(useInline) {
		theImg.style.backgroundImage = theImg.style.backgroundImage.replace(".gif", "_over.gif");
	}
	else if(theImg.tagName.toUpperCase() == 'DIV') {
		theImg.className = theImg.className.replace("Normal", "Highlighted");
	}
	else {
		theImg.src = theImg.src.replace(".gif", "_over.gif");
	}
}

function lowlightButton(theImg, useInline) {
	if(useInline) {
		theImg.style.backgroundImage = theImg.style.backgroundImage.replace("_over.gif", ".gif");
	}
	else if(theImg.tagName.toUpperCase() == 'DIV') {
		theImg.className = theImg.className.replace("Highlighted", "Normal");
	}
	else {
		theImg.src = theImg.src.replace("_over.gif", ".gif");
	}
}

function showLayer(lay) {
	if (browser_IE) {		
		document.all[lay].style.visibility = "visible";
		document.all[lay].style.display = "block";
	} 
	if (browser_NS4) {
		document.layers[lay].visibility = "show";
	}
	if (browser_W3C) {
		document.getElementById([lay]).style.visibility = "visible";
		document.getElementById([lay]).style.display = "block";			
	}
}

function hideLayer(lay) {
	if (browser_IE) {			
		document.all[lay].style.visibility = "hidden";
		document.all[lay].style.display = "none";
	}
	if (browser_NS4) {
		document.layers[lay].visibility = "hide";
	}
	if (browser_W3C) {
		document.getElementById([lay]).style.visibility = "hidden";
		document.getElementById([lay]).style.display = "none";			
	}
}

function openPop(url) {
   window.open(url,'ratings', 'width=550,height=600,titlebar=yes, scrollbars=yes');
  // window.open(url)
}

function getVar(varName) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		
		if(pair[0] == varName) {
			if(pair[1]) {
				return URLdecode(pair[1]);
			}
			else {
				return "";
			}
		}
	}
	return '';
}

function URLencode(sStr) {
    if(sStr) {
    	return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
    }
    else {
	return '';
    }
}

function URLdecode(sStr) {
    if(sStr) {
    	return unescape(sStr.replace(/\+/g, ' '));
    }
    else {
	return '';
    }
}

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
    	return r;
	}
}
