var gLogger = LogFactory.getLog("global.js");

var xmlHttpRequestErrorPage = "/BrowserError.html";

// *********************************************************************
// Function to get an XML HTTP Object
// *********************************************************************
function getHTTPObject() {
    gLogger.debug("Enter getHTTPObject()");
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        window.location.replace(xmlHttpRequestErrorPage);
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      gLogger.warn("XMLHttpRequest not supported!");
      xmlhttp = false;
      window.location.replace(xmlHttpRequestErrorPage);
    }
  }
    gLogger.debug("Exit getHTTPObject()");
  return xmlhttp;
}

/*
 * Finds the source HTML Element for an event e.
 * From www.quirksmode.org
 */
function getEventSource(e) {
    gLogger.debug("Enter getEventSource()");
	var targ;
    if (!e) var e = window.event;
	if (e.target) {
        targ = e.target;
    } else if (e.srcElement) {
        targ = e.srcElement;
    }
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
    gLogger.debug("Exit getEventSource()");
    return targ;
}

/*
 * Function to format a number as US currency.
 */
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
        num = num.substring(0,num.length-(4*i+3))+','+
              num.substring(num.length-(4*i+3));
    }
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}
/*
// ***** Btn Rollover *****
function roll(imgName,imgState) {
   try{
      document.images[imgName].src = imgState
   }catch( e ){}
}
// ***********************************************************************

// ***** Preload Rollover Images ***************************************
if (document.images) {

    var imgArray = new Array();
	preloadImage( imgArray, "/images/nav/accommodations_ON.gif" );
	preloadImage( imgArray, "/images/nav/amenities_ON.gif" );
	preloadImage( imgArray, "/images/nav/dining_ON.gif" );
	preloadImage( imgArray, "/images/nav/meetings_ON.gif" );
	preloadImage( imgArray, "/images/nav/reservations_ON.gif" );
	preloadImage( imgArray, "/images/nav/weddings_events_ON.gif" );
	preloadImage( imgArray, "/images/spacer.gif" );

}

function preloadImage( imageArray, imageSrc ) {
    var img = new Image();
    img.onerror = function() {
        alert("Image [" + imageSrc + "] not found!");
    }
    img.src = imageSrc;
    imageArray[ imageSrc ] = img;
}
*/
// *********************************************************************

// *********************************************************************
// Function to create pop-up windows at a custom size.
// w = width
// h = height
// d = directories
// l = location
// m = menubar
// r = resizeable
// sc = scrollbars
// st = status
// t = toolbar
// EXAMPLE CALL: <a href="javascript:popUp('[URL]','[WINDOW NAME]',400,300,1,1,0,0,0,0,0);">LINK</a>
// *********************************************************************
function popUp(URL,name,w,h,d,l,m,r,sc,st,t) {
	var featureStr = "";
	featureStr = "width=" + w + ",height=" + h + ",directories=" + d + ",location=" + l + ",menubar=" + m + ",resizable=" + r + ",scrollbars=" + sc + ",status=" + st + ",toolbar=" + t;
	window.open(URL,name,featureStr);
}

// *********************************************************************
// Function to create pop-up window for Ballroom Floor Plans (ex: /AtlanticStation/events/Ballroom.do).
// w = width
// h = height
// d = directories
// l = location
// m = menubar
// r = resizeable
// sc = scrollbars
// st = status
// t = toolbar
// EXAMPLE CALL: <a href="javascript:popUp('/images/fp_ballroom_01.gif','[WINDOW NAME]',400,300,1,1,0,0,0,0,0);">LINK</a>
// *********************************************************************
function popUpBallroomFP(imgPath,pgTitle,w,h) {
	var featureStr = "";
	featureStr = "width=640,height=530,directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0";

	var generator = window.open('','ballroomFP',featureStr);
	generator.document.write('<html><head><title>Ballroom Floor Plan</title>');
	generator.document.write('<link rel="stylesheet" href="/resources/global.css">');
	generator.document.write('</head><body id="popup" onLoad="window.focus();" >');
	generator.document.write('<div align="center"><div id="popUpContainer">');
	generator.document.write('<table cellspacing="0" width="600"><tr>');
	generator.document.write('<td align="left" valign="top"><h2>' + pgTitle + '</h2></td>');
	generator.document.write('<td align="right" valign="top" width="100"><a href="javascript:window.close();"><b>Close Window</b></a></td>');
	generator.document.write('</tr></table>');
	generator.document.write('<div align="center"><img src="' + imgPath + '" alt="' + pgTitle + '"></div>');
	generator.document.write('</div></div>');
	generator.document.write('</body></html>');
	generator.document.close();
}

function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}

function checkChars(e, validChars)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;

keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
checks = validChars.toLowerCase();

if (checks.indexOf(keychar) != -1)
	return true;

if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   return true;

return false;
}

function checkNumeric(e){
   return checkChars(e,'01234567890');
}

