function closeChildWindow (winObject) 
{
  if (winObject &&(!winObject.closed)) 
  {
    winObject.close();
  }
} // End closeChildWindow()

function openExternalWindow (url)
{
  attrib = " toolbar=yes,scrollbars=yes,location=yes,status=yes,menubar=yes,resizable=yes,width=800,height=405,left = 100,top = 60";
  var externalWin  = window.open(url, 'external', attrib);
  childWinObject = externalWin;
  externalWin.focus();
}

function openMptnWindow (url)
{
  attrib = " toolbar=yes,scrollbars=yes,location=yes,status=yes,menubar=yes,resizable=yes,width=793,height=405,left = 100,top = 60";
  var mptnWin  = window.open(url, 'mptn', attrib);
  childWinObject = mptnWin;
  mptnWin.focus();
}

function openMenuWindow (url, name, width)
{
  attrib = " toolbar=yes,scrollbars=yes,location=yes,status=yes,menubar=yes,resizable=yes,width=600,height=405,left = 100,top = 60";
  var menuWin  = window.open(url, 'menu', attrib);
  childWinObject = menuWin;
  menuWin.focus();
}

function openImageWindow(url, image) {
  var winWidth = 670;
  var winHeight = 405;
  var xPos = (screen.availWidth-winWidth)/4 + 20;
  var yPos = (screen.availHeight-winHeight)/4 + 20;
  attrib = "menubar=yes,status=yes,personalbar=no,titlebar=no,toolbar=yes,location=yes,top=" + yPos + ",left=" + xPos + ",width=" + winWidth + ",height=" + winHeight +",resizable=yes,scrollbars=yes";
  var subWin = window.open(url, 'pressKitImagePopup', attrib);
  childWinObject = subWin;
  self.image = image;
}

function openSubWindow (url)
{
   var winWidth = 670;
   var winHeight = 405;
    if (parseInt(navigator.appVersion) >= 4)
    {
     var xPos = (screen.availWidth-winWidth)/4;
     var yPos = (screen.availHeight-winHeight)/4;
    } 
    else
    {
     var xPos = 300;
     var yPos = 400;
    }
   //attrib = ' toolbar=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=670,height=480,left = 100,top = 60';
   attrib = "menubar=yes,status=yes,personalbar=no,titlebar=no,toolbar=yes,location=yes,top=" + yPos + ",left=" + xPos + ",width=" + winWidth + ",height=" + winHeight +",resizable=yes,scrollbars=yes";
  // IE has periodic issues with these two lines, probably when you click too fast 
  // var subWin = window.open(url, 'popup', attrib);
  // subWin.focus();
  //window.open(url, 'popup', attrib);
  var subWin = window.open(url, 'popup', attrib);
  childWinObject = subWin;
  //new_window.focus();
}

function openPrintWindow (url)
{
   var winWidth = 670;
//   var winHeight = 480;
   var winHeight = 405;
    if (parseInt(navigator.appVersion) >= 4)
    {
     var xPos = (screen.availWidth-winWidth)/4;
     var yPos = (screen.availHeight-winHeight)/4;
    } 
    else
    {
     var xPos = 300;
     var yPos = 400;
    }
   //attrib = ' toolbar=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=670,height=480,left = 100,top = 60';
   attrib = "menubar=yes,personalbar=no,titlebar=no,toolbar=yes,location=no,top=" + yPos + ",left=" + xPos + ",width=" + winWidth + ",height=" + winHeight +",resizable=no,scrollbars=yes";
  // IE has periodic issues with these two lines, probably when you click too fast 
  // var subWin = window.open(url, 'printPop', attrib);
  // subWin.focus();
  //window.open(url, 'printPop', attrib);
  var subWin = window.open(url, 'printPop', attrib);
  //new_window.focus();
}


function openSignInWindow (url)
{
  var winWidth = 370;
  var winHeight = 300;
  var xPos = (screen.availWidth-winWidth)/2;
  var yPos = (screen.availHeight-winHeight)/2;
  //attrib = ' toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=yes,width='+winWidth+',height='+winHeight+',left = '+xPos+',top = '+yPos+', screenX='+xPos+', screenY='+yPos;
  attrib = "menubar=no,personalbar=no,titlebar=no,toolbar=yes,location=yes,top=" + yPos + ",left=" + xPos + ",width=" + winWidth + ",height=" + winHeight +",resizable=yes,scrollbars=yes";
  var signInWin = window.open(url, 'sign_in_popup', attrib);
  childWinObject = signInWin;
  signInWin.focus();
}
function getRandomNumber(x)
{
  var randNum = Math.random();
//  randNum = randNum*(Math.pow(10,x));
  var randStr = new String(randNum);
  return randStr.substr(randStr.indexOf('.')+1, x);
}
function convertStringToDate (str)
{
  if (str != null && str.length >= 8)
  {
    var yearStr = str.substring(0,4);
    var monthStr = str.substring(4,6);
    var dayStr = str.substring(6,8);
    document.write(monthStr+"/"+dayStr+"/"+yearStr);
  }
}
function convertStringToExpDate (str)
{
  if (str != null && str.length >= 4)
  {
    var yearStr = str.substring(2,4);
    var monthStr = str.substring(0,2);
    document.write(monthStr+"/20"+yearStr);
  }
}

function convertStringToPhoneNumber (str)
{
  if (str!=null)
  {
    if (str.length == 10)
    {
      var areaCode = str.substring(0,3);
      var exchange = str.substring(3,6);
      var number = str.substring(6,10);
      document.write("("+areaCode+")"+exchange+"-"+number);
    }
    else if (str.length == 7)
    {
      var exchange = str.substring(0,3);
      var number = str.substring(3,7);
      document.write(exchange+"-"+number);
    }
    else
    {
      // we don't know what format the phone number is in, so
      // just leave it as is.
      document.write(str)
    }
  }
}

function getPhoneNumberFromString (str)
{
  if (str!=null)
  {
    if (str.length == 10)
    {
      var areaCode = str.substring(0,3);
      var exchange = str.substring(3,6);
      var number = str.substring(6,10);
      return "("+areaCode+")"+exchange+"-"+number;
    }
    else if (str.length == 7)
    {
      var exchange = str.substring(0,3);
      var number = str.substring(3,7);
      return exchange+"-"+number;
    }
  }
  else
  {
    // we don't know what format the phone number is in, so
    // just leave it as is.
    return str;
  }
}


function convertStringToTime (str)
{
  if (str != null && str.length == 4)
  {
    var hourInt = parseInt(str.substring(0,2));
    var AMPM;
    if (hourInt > 12)
    {
      hourInt = hourInt - 12;
	AMPM = 'PM'
    }else if (hourInt == 12)
    {
	AMPM = 'PM'
    }else
    {
	AMPM = 'AM'
    }
    var minStr = str.substring(2,4);
    document.write(hourInt+":"+minStr+" "+AMPM);
  }
}

function printError()
{
  var queryStr = location.search.substring(1);  //get the query string from the location without the question mark
  var eqPos = queryStr.indexOf('ec=');		//look for the ec parameter
  if (eqPos != -1)
  {
	var errorCode = queryStr.substring(eqPos+3, eqPos+7);
	var errorMsg = "An unknown error has occured.";
	if (errorCode == "0001") {
		errorMsg = "Transaction Failed";
	} else if (errorCode == "0002") {
		errorMsg = "You have entered an invalid Wampum Club number or PIN.  Please try again. If you cannot locate the correct numbers, please select the re-establish PIN option or visit any Wampum Club location during your next visit for assistance.";
	} else if (errorCode == "0003") {
		errorMsg = "You have entered an invalid Wampum Club number or PIN.  Please try again. If you cannot locate the correct numbers, please select the re-establish PIN option or visit any Wampum Club location during your next visit for assistance.";
	} else if (errorCode == "0004") {
		errorMsg = "You need to establish a personal identification number (PIN).";
	} else if (errorCode == "0006") {
		errorMsg = "We are sorry. There is a problem accessing your account. Please stop by any of our Wampum Club locations during your next visit for assistance.";
	} else if (errorCode == "0007") {
		errorMsg = "You have entered information that does not match our records for this account.  Please try again or visit any Wampum Club location during your next visit for assistance.";
	} else if (errorCode == "0008") {
		errorMsg = "You have entered information that does not match our records for this account.  Please try again or visit any Wampum Club location during your next visit for assistance.";
	} else if (errorCode == "8041") {
		errorMsg = "You have entered an invalid reservation number. Please try again. If problems persist, call 800.FOXWOODS.";
	} else if (errorCode == "8042") {
		errorMsg = "You have entered an invalid reservation number. Please try again. If problems persist, call 800.FOXWOODS.";
	} else if (errorCode == "8043") {
		errorMsg = "This reservation has been cancelled. If you have any questions, call 800.FOXWOODS.";
	} else if (errorCode == "8045") {
		errorMsg = "You must enter the credit card number that was used to make this reservation. If you have any questions, call 800.FOXWOODS.";
	} else if (errorCode == "8124") {
	  errorMsg = "Credit card, patron or phone number is required.";
	} else if (errorCode == "8125") {
		errorMsg = "Confirmation Number Unknown";
	} else if (errorCode == "8126") {
		errorMsg = "Reservation Not For This Account, Phone or Credit Card";
	} else if (errorCode == "8128") {
		errorMsg = "Reservation Not Active";
	} else if (errorCode == "9996") {
		errorMsg = "Session expired.";
	} else {
		errorMsg = "System failure. error code:"+errorCode;
	}
	document.write('<p class="error">'+errorMsg+'</p>');
  }
}

function doProtocolSwitch(noSwitchStr)
{
  if (document.location.protocol == "https:")
  {
    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    // *** BROWSER VERSION ***

    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

    // Note: On IE, start of appVersion return 3 or 4
    // which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string

    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
       is_major = parseInt(is_minor);
    }

    var is_ie   = (iePos!=-1);
    var is_ie3  = (is_ie && (is_major < 4));

    var is_ie4   = (is_ie && is_major == 4);
    var is_ie4up = (is_ie && is_minor >= 4);
    var is_ie5   = (is_ie && is_major == 5);
    var is_ie5up = (is_ie && is_minor >= 5);
  // end browser version
    linksArray = document.links;
    for (i=0; i<linksArray.length;i++)
    {
      noSwitchPos = noSwitchStr.indexOf(linksArray[i].pathname);
      //alert(linksArray[i].href+"\n"+noSwitchStr);
      //alert(noSwitchPos);
      if (linksArray[i].protocol == "https:" && noSwitchPos == -1)
      {
    	linksArray[i].protocol = "http:";
    	if (is_ie) linksArray[i].port = "80";
      }
      //alert(linksArray[i].href);
    }
  }
}

/* ---------------------------
   String validation functions 
------------------------------ */
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var defaultEmptyOK = false;
var ZIPCodeDelimiters = "-";
var digitsInZIPCode1 = 5;
var digitsInZIPCode2 = 6;
var digitsInZIPCode3 = 9;
var whitespace = " \t\n\r";

/* manipulators */
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}
/* low-level boolean functions */
function isInteger (s) {
   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}
function isEmpty(s)
{   return ((s == null) || (s.length == 0));
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"));
}
function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}
function xmlEncode(src)
{
  var encodedSrc = src.replace(/&/g ,"&amp;");
  encodedSrc =encodedSrc.replace(/</g,"&lt;");
  encodedSrc =encodedSrc.replace(/>/g,"&gt;");
  encodedSrc =encodedSrc.replace(/'/g,"&apos;");
  encodedSrc =encodedSrc.replace(/"/g,"&quot;");
  return encodedSrc;
}
/* interface level functions */
function checkZIPCode (theField, emptyOK){   
    if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { 
      var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters);
      if (!isZIPCode(normalizedZIP, false)) 
        // return warnInvalid (theField, iZIPCode);
        return false;
      else 
      {  // if you don't want to insert a hyphen, comment next line out
         // theField.value = reformatZIPCode(normalizedZIP);
         theField.value = normalizedZIP;
         return true;
      }
    }
}
function isZIPCode (s)
{  
   if (isEmpty(s)) 
   {
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   }
   // the line below has been revised to allow for alphanumeric characters in zip for canada and 10 digit zip codes
   //return (isInteger(s) && ((s.length == digitsInZIPCode1) || (s.length == digitsInZIPCode2) || (s.length == digitsInZIPCode3)));
   return ((s.length == digitsInZIPCode1) || (s.length == digitsInZIPCode2) || (s.length == digitsInZIPCode3)); 
}

function checkUSZIPCode (theField, emptyOK)
{   
    if (checkUSZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) {alert("returning true");return true;}
    else
    { 
      var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters);
      if (!isUSZIPCode(normalizedZIP, false)) 
      {
        // return warnInvalid (theField, iZIPCode);
        return false;
      }
      else 
      {  // if you don't want to insert a hyphen, comment next line out
         // theField.value = reformatZIPCode(normalizedZIP);
         theField.value = normalizedZIP;
         return true;
      }
    }
}
function isUSZIPCode (s)
{  
   if (isEmpty(s)) 
   {
       if (isUSZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isUSZIPCode.arguments[1] == true);
   }
   return (isInteger(s) && ((s.length == digitsInZIPCode1) || (s.length == digitsInZIPCode3))); 
}

function checkCanadaZIPCode (theField, emptyOK)
{   
    if (checkCanadaZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { 
      var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters);
      if (!isCanadaZIPCode(normalizedZIP, false)) 
      {
        // return warnInvalid (theField, iZIPCode);
        return false;
      }
      else 
      {  // if you don't want to insert a hyphen, comment next line out
         // theField.value = reformatZIPCode(normalizedZIP);
         theField.value = normalizedZIP;
         return true;
      }
    }
}

function isCanadaZIPCode (s)
{  
   if (isEmpty(s)) 
   {
       if (isCanadaZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isCanadaZIPCode.arguments[1] == true);
   }
   if (s.length != digitsInZIPCode2) return false;
   if (isInteger(s.charAt(0)) || isInteger(s.charAt(2)) || isInteger(s.charAt(4))) return false;
   if (!isInteger(s.charAt(1)) || !isInteger(s.charAt(3)) || !isInteger(s.charAt(5))) return false;
   return true;
//   return (s.length == digitsInZIPCode2); 
}


function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isPhone (s)
{
    if (isEmpty(s)) 
       if (isPhone.arguments.length == 1) return defaultEmptyOK;
       else return (isPhone.arguments[1] == true);
    if (isWhitespace(s)) return false;
//    if (s.charAt(0) == '1' || s.charAt(0) == '0' || s.charAt(3) != '-' || s.charAt(7) != '-')
    if (s.charAt(0) == '0')
    {
    	return false;
    }
    sStripped = stripCharsNotInBag(s, digits);
    if (!isInteger(sStripped) || sStripped.length < 5 || sStripped.length > 15)
    {
    	return false;
    }
    return true;
}

function isStandardPhone (s)
{
    if (isEmpty(s)) 
       if (isStandardPhone.arguments.length == 1) return defaultEmptyOK;
       else return (isStandardPhone.arguments[1] == true);
    if (isWhitespace(s)) return false;
//    if (s.charAt(0) == '1' || s.charAt(0) == '0' || s.charAt(3) != '-' || s.charAt(7) != '-')
    if (s.charAt(0) == '0')
    {
    	return false;
    }
    sStripped = stripCharsNotInBag(s, digits);
    if (!isInteger(sStripped) || sStripped.length < 10 || sStripped.length > 10)
    {
    	return false;
    }
    return true;
}

function isCreditCard(st) {
  // This is the Luhn-Mod 10 Algorithm
  // Encoding only works on cards with fewer than 19 digits
  if (st.length > 19)
    return (false);
  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) == 0) {
    return (true);
  } else {
    return (false);
  }
}
//Date stuff
function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function daysInFebruary (year)
{   return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
function isDate (year, month, day)
{   if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
    return true;
}
function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}
function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);
    if (!isInteger(s, false)) return false;
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}
function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}
function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}
function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;
    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}
function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);
   else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;
        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// =======================================
// Check Date functions borrowed from www.IISFAQ.com, article # 131

function chkdate(objName) {
  var strDatestyle = "US"; //United States date style Month Day Year
  //var strDatestyle = "EU"; //European date style Day Month Year
  var runTime = new Date();
  var strCurrentYear = runTime.getYear();
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var datefield = objName;
  var strSeparatorArray = new Array("-"," ","/",".");
  var intElementNr;
  var err = 0;

  var strMonthArray = new Array(12);
  strMonthArray[0] = "Jan";
  strMonthArray[1] = "Feb";
  strMonthArray[2] = "Mar";
  strMonthArray[3] = "Apr";
  strMonthArray[4] = "May";
  strMonthArray[5] = "Jun";
  strMonthArray[6] = "Jul";
  strMonthArray[7] = "Aug";
  strMonthArray[8] = "Sep";
  strMonthArray[9] = "Oct";
  strMonthArray[10] = "Nov";
  strMonthArray[11] = "Dec";

  var strFullMonthArray = new Array(12);
  strFullMonthArray[0] = "JANUARY";
  strFullMonthArray[1] = "FEBRUARY";
  strFullMonthArray[2] = "MARCH";
  strFullMonthArray[3] = "APRIL";
  strFullMonthArray[4] = "MAY";
  strFullMonthArray[5] = "JUNE";
  strFullMonthArray[6] = "JULY";
  strFullMonthArray[7] = "AUG";
  strFullMonthArray[8] = "SEPTEMBER";
  strFullMonthArray[9] = "OCTOBER";
  strFullMonthArray[10] = "NOVEMER";
  strFullMonthArray[11] = "DECEMBER";

  strDate = datefield.value;

  if (strDate.length < 1) {
    return false;
  }

  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if ((strDateArray.length < 2) || (strDateArray.length > 3)) {
        err = 1;
        //alert('X');
        return false;
      }
      else {
        strDay = strDateArray[0];
        strMonth = strDateArray[1];
        if (strDateArray.length == 2) 
          strYear = strCurrentYear
        else
          strYear = strDateArray[2];
      }
      booFound = true;
    }
  }
  if (booFound == false) {
    if (strDate.length>5) {
      strDay = strDate.substr(0, 2);
      strMonth = strDate.substr(2, 2);
      strYear = strDate.substr(4);
    }
  }

  if (strYear == null) {
    return false;
  }

  if (strYear.length == 1) {
    strYear = '0' + strYear
  }

  if (strYear.length == 2) {
    if (strYear > 90)
    {
      strYear = '19' + strYear;
    }
    else
    {
      strYear = '20' + strYear;
    }
  }

  // US style
  if (strDatestyle == "US") {
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    err = 2;
    return false;
  }
  if (intday < 10) strDay = "0" + intday;
  else strDay = "" + intday;
   

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i = 0;i<12;i++) {
      if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase() || strMonth.toUpperCase() == strFullMonthArray[i]) {
        intMonth = i+1;
        strMonth = ""+intMonth;
        i = 12;
      }
    }

    if (isNaN(intMonth)) {
      err = 3;
      return false;
    }
  }
  if (intMonth < 10) strMonth = "0" + intMonth;
  else strMonth = "" + intMonth;

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    err = 4;
    return false;
  }

  if (intMonth>12 || intMonth<1) {
    err = 5;
    return false;
  }

  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
    err = 6;
    return false;
  }

  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
    err = 7;
    return false;
  }

  if (intMonth == 2) {
    if (intday < 1) {
    err = 8;
    return false;
  }
  if (LeapYear(intYear) == true) {
    if (intday > 29) {
      err = 9;
      return false;
    }
  }
  else {
    if (intday > 28) {
      err = 10;
      return false;
    }
  }
}

if (strDatestyle == "US") {
//  datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
  datefield.value = strMonth + "/" + strDay+ "/" + strYear;
}
else {
  datefield.value = strDay + "/" + strMonth + "/" + strYear;
}

return true;

}

function LeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { alert("valid"); return true; }
  }
  else {
    if ((intYear % 4) == 0) { alert("valid"); return true; }
  }
  return false;
}

// ===========================

function isTimedOut( timeOutMinutes, pageLoadTime )
{
  // since Time() returns the UTC time in milliseconds, we'll need to 
  // compare the difference against the time out converted to milliseconds.
  var timeOutMillSec = timeOutMinutes * 60 * 1000;

  // we have the date/time when the page was loaded as UTC milliseconds
  // get the current date in the same format.
  var newDateTime = new Date();
  var nowTime = newDateTime.getTime();

  if (parseInt(nowTime) - parseInt(pageLoadTime) > parseInt(timeOutMillSec))
  {
    // time difference is greater than deadline for timing out.
    return true;
  }
  else
  {
    return false;
  }
}

function dimField(fieldName)
{
	var field = fieldName;
	if (field.style) field.style.backgroundColor="#d9e0e4";
	field.disabled = true;
}

function unDimField(fieldName)
{
	var field = fieldName;
	if (field.style) field.style.backgroundColor="#FFFFFF";
	field.disabled = false;
}

