// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


// This is used for Drop Downs to submit the form on change
function changeDD(Obj)
{
	Obj.submit();
}

//This is used to Open a Popup Window
function openWind(url,width,height,status,scrollbars,resize,menubar,left,top)
{
    var bbWindow;
	bbWindow=window.open(url,"commonpopup","toolbar=no,width=" + width + ",height=" + height + ",status=" + status + ",scrollbars=" + scrollbars+ ",resizable=" + resize + ",menubar=" +  menubar+ ",left=" + left + ",top=" + top);
}

//this is used to open a pop up win if the usr is not null
function openWindow(url)
{
  if(url != "")
   window.open(url)
}


function openPopup(popupURL) {
	var win = window.open(popupURL,'','menubar=no,toolbar=no,width=550,height=350');
	if(win.opener == null)win.opener=self;
}

function openPopupScrolling(popupURL) {
	var win = window.open(popupURL,'','scrollbars=yes,menubar=no,resizable=yes,toolbar=no,width=550,height=350');
	if(win.opener == null)win.opener=self;
}


function openPopupScrollingWithMenu(popupURL) {
	var win = window.open(popupURL,'','scrollbars=yes,menubar=no,resizable=yes,toolbar=no,width=770,height=550');
	if(win.opener == null)win.opener=self;
}

// used to open pop-ups for the footer
function footerWind(urlx,width,height)
{
	window.open(urlx,"footerpop","toolbar=no,width="+width+",height="+height+",status=no,scrollbars=yes,resizable=yes,menubar=no,left=50,top=25");
}

function printWindow(){
   version = parseInt(navigator.appVersion)
   if (version >= 4) window.print()
}


/* common show wait stuff */
var g_iSpeed = 200;
var g_iLeft = 60;
var g_iRight = 320;
var g_iIncrement = 20;
var g_o = null;
var g_iDir = 1;
var g_bBounce = false;

function setParameters() {
	var w=0;
	if(document.body && document.body.clientWidth) {
		w = parseInt(document.body.clientWidth);
	} else if (window.innerWidth) {
		w = parseInt(window.innerWidth);
	}
	//g_iLeft = (w/2) - 300;
	//g_iRight = (w/2) + 50;
   g_iLeft = 60;
   g_iRight = 320;
	
}

function animate() {
	g_o.style.posLeft += (g_iDir * g_iIncrement);
	if(g_bBounce) { // set to false for bounce
		if (g_o.style.posLeft >= g_iRight) {
			g_iDir = -1; //bounce
			g_o.style.posLeft = g_iRight;  // force to safe area
		} else if (g_o.style.posLeft <= g_iLeft) {
			g_iDir = 1;
			g_o.style.posLeft = g_iLeft;  // force to safe area
		}
	}
	else if (g_o.style.posLeft > g_iRight) {
		// Start over
		g_o.style.posLeft = g_iLeft;
	}
	setTimeout('animate()', g_iSpeed);
}

var g_cGif = 9;
var g_ixGif = 1;
var g_rgGif = new Array(g_cGif);
var g_cLoops = 1; //old
var g_cLoopsMax = 300; //old


function ShowWait() {
	if (navigator.userAgent.indexOf('MSIE')>0) {
		
		window.attachEvent('onresize', setParameters);
		setParameters();
		g_o = document.all.imgDot;
		wait.style.display = 'inline';
		body.style.display = 'none';
		layoutContentAdminControls.style.display = 'none';
		if( g_o != null ) {
			animate();
		}
	} else {
		//setParameters();
		//g_o = document.all.imgDot;
		
		if(navigator.userAgent.indexOf('Safari')>0) {
		
		} else {
		wait.style.display = 'inline';
		body.style.display = 'none';
		layoutContentAdminControls.style.display = 'none';
		
		 for (i = 1 ; i <= 9 ; i++)
        {
               g_rgGif[i - 1] = document.createElement("IMG");
               g_rgGif[i - 1].src = "/images/07/wait" + i + "_1.gif";
               g_rgGif[i - 1].alt = "Please wait...";
        }
                UpdateGif();
		
		}
	}
}


function UpdateGif()
{
               imgAnim = document.imgDot;
               imgAnim.src = g_rgGif[g_ixGif%g_cGif].src;
               imgAnim.alt = g_rgGif[g_ixGif%g_cGif].alt;
               g_ixGif++;
               setTimeout("UpdateGif()", 250);
}
 



function ShowFareSearchWait() {
	if (navigator.userAgent.indexOf('MSIE')>0) {
		window.attachEvent('onresize', setParameters);
		setParameters();
		g_o = document.all.imgDotFareSearch;
		FareSearchWait.style.display = 'inline';
		body.style.display = 'none';
		if( g_o != null ) {
			animate();
		}
	}
}

function ShowFlightAvailWait() {
	if (navigator.userAgent.indexOf('MSIE')>0) {
		window.attachEvent('onresize', setParameters);
		setParameters();
		g_o = document.all.imgDotFlightAvail;
		FlightAvailWait.style.display = 'inline';
		body.style.display = 'none';
		if( g_o != null ) {
			animate();
		}
	}
}


function redirectWithWait( url ){
    ShowWait();
    alert("rediect");
    self.location.href = url;
}
/* end show wait stuff */

//THIS FUNCTION IS FOR CRUISE PATH NET WORK INFORMATION
function PortGuide(SeaPortCode)
{
  var strURL = "http://portguide.cruisepath.com/FrameSet.asp?SeaPortCode=" + SeaPortCode;
  PopWin = window.open(strURL, "PortGuide", "toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,width=625,height=480,width=680,resizable");
  PopWin.window.focus();
}

// copy the OPTION elements from one SELECT to another
function copySelect(src, dest) {
    clearOptions(dest);
    for (i = 0; i < src.length; i++) {
    	var selected = src.options[i].defaultSelected;
        addOption(dest.options, src.options[i].value, src.options[i].text, selected);
    }
}

// remove all OPTION elements from a SELECT
function clearOptions(select) {
    for (i = select.length; i >= 0; i--) {
      select.options[i] = null;
    }
}

// add a new OPTION to a SELECT
function addOption(select, value, text, selected) {
	var newOption = new Option(text, value);
	select[select.length] = newOption;
	if (selected) {
		select.selectedIndex = select.length - 1;
	}
}

// Validate a string to be sure it's a valid-ish email address
// One and only one @ sign; at least one . after @; no spaces; no commas
function validateEmail( email ) {
	var atpos = email.indexOf("@");
	return ( 0 < atpos
		&& atpos == email.lastIndexOf("@")
		&& atpos < email.lastIndexOf(".")
		&& email.indexOf(" ")<0
		&& email.indexOf(",")<0
		);
}

// open a popup window with the given editorial displayed within it
function openEditorialPopup(winName, edKey, rawText, edTitle) {
	openEditorialPopupEx(winName, edKey, null, rawText, edTitle);
}

// philip - 5/6/2003 - created this to have this functionality with website fallback
function openEditorialPopupEx(winName, edKey, edKeyDefault, rawText, edTitle) {
    var url = "../cruises/popup.jsp?BV_UseBVCookie=yes";
    if (winName == null) {
        winName = "win_popup";
    }
    if (edKey == null) {
        alert("bad editorial key; aborting");
        return;
    }
    if (edKeyDefault != null) {
        url += "&edKeyDefault=" + edKeyDefault;
    }
    if (rawText != null && rawText) {
        url += "&rawText=true";
    }
    if (edTitle != null) {
        url += "&edTitle=" + edTitle;
    }
    url += "&edKey=" + edKey;
    var win = open(url, winName, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=400,top=100,left=100");
    win.focus();
}

// open a popup window with the given editorial displayed within it, by pageName..so works for all websites
//will always be of type center content
function openEdPopupByPageName(winName, pageName) {
    var url = "../packages/popup.jsp?BV_UseBVCookie=yes";
    if (winName == null) {
        winName = "win_popup";
    }
    if (pageName == null) {
        alert("bad editorial pageName; aborting");
        return;
    }

    url += "&pageName=" + pageName;
    var win = open(url, winName, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=400,top=100,left=100");
    win.focus();
}

function openNetworkEdPopupByPageName(winName, pageName) {
    var url = "/travelca.dll/travel/templates/template_two_column/popup.jsp?BV_UseBVCookie=yes"; 
    if (winName == null) {
        winName = "win_popup";
    }
    if (pageName == null) {
        alert("bad editorial pageName; aborting");
        return;
    }

    url += "&pageName=" + pageName;
    var win = open(url, winName, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=400,top=100,left=100");
    win.focus();
}

// get the selected value, if any, of the radio button array
function getRadioValue(radioArray) {
	var value = null;
	for (i = 0; i < radioArray.length; i++) {
		if (radioArray[i].checked == true) {
			value = radioArray[i].value;
		}
	}
	return value;
}

// Undo Java's URLEncode() method
function URLDecode(string) {
	var unencoded = unescape(string);
	unencoded = unencoded.replace(/[+]/g, " ");
	return unencoded;
}

//Common Date Functions used through out the site.


var today = new Date();
var thisyear = today.getYear();
if (!(thisyear >= 2000))
{
	thisyear+=1900;
}
var thismonth = today.getMonth() + 1;
var thisday = today.getDay() + 1;

function fixString(strXmlCkIn)
{
	//Parse strings for special chars and change so no xml parse error
	var sStr = strXmlCkIn;
	var ampRegExp = /&/;
	var squoteRegExp = /'/;
	var gtRegExp = />/;
	var ltRegExp = /</;
	var quoteRegExp = /"/;

	sStr = sStr.replace(ampRegExp, '&amp;');
	sStr = sStr.replace(squoteRegExp, '&#39;');
	sStr = sStr.replace(gtRegExp, '&gt;');
	sStr = sStr.replace(ltRegExp, '&lt;');
	sStr = sStr.replace(quoteRegExp, '&quot;');

	return sStr;
}

function ChangeStr(StringIN, CharToChange, CharToChangeTo)
{
    var iCount=0;
	var iLastFound="";
    var sNewString="";
	var sLastString=StringIN;

	for (;;)
	{
		iLastFound=sLastString.indexOf(CharToChange);	
		if (iLastFound == -1)
		{
			break;
		}
		sNewString += sLastString.substring(0, iLastFound) + CharToChangeTo;
		sLastString = sLastString.substring(iLastFound + CharToChange.length
					  ,sLastString.length);
	}
	sNewString += sLastString;

	return(sNewString);
}

function getQueryStringValue(QueryString, ReqName)
{
    var searchList = QueryString;
    var result = "";
    var hostIdx;
    var hostStr;
    var andIdx;

    hostIdx=searchList.indexOf( ReqName + "=" );

    if (hostIdx >= 0)
    {
        hostStr=searchList.substring(hostIdx + ReqName.length + 1
         ,searchList.length);
        andIdx=hostStr.indexOf("&");
        if (andIdx >= 0)
        {
            hostStr=hostStr.substring(0, andIdx);
        }
        result=hostStr;
    }
    return(result);
}

function getRequestName(ReqName, Index)
{
    var searchList = window.location.search;
    var result = "";
    var hostIdx;
    var hostStr;
    var andIdx;
	var i=0;

	for (i=0; i<=Index-1; i++)
	{
		hostIdx=searchList.indexOf( ReqName + "=" );
		searchList=searchList.substring(hostIdx + ReqName.length + 1
		 ,searchList.length);
	}


	hostIdx=searchList.indexOf( ReqName + "=" );

    if (hostIdx >= 0)
    {
        hostStr=searchList.substring(hostIdx + ReqName.length + 1
         ,searchList.length);
        andIdx=hostStr.indexOf("&");
        if (andIdx >= 0)
        {
            hostStr=hostStr.substring(0, andIdx);
        }
        result=hostStr;
    }
    return(result);
}

function getUBoundReqName(ReqName, Index)
{
    var searchList = window.location.search;
    var result = "";
    var hostIdx;
    var hostStr;
    var andIdx;
	var i=0;

	for (;;)
	{
		hostIdx=searchList.indexOf( ReqName + "=" );
		if (hostIdx == -1)
		{
			break;
		}
		searchList=searchList.substring(hostIdx + ReqName.length + 1
		 ,searchList.length);
		i++;
	}
    return(i);
}

function doCalendar(month, year, fieldname)
{
	document.all(fieldname).value=doCalendarByDate(month + "/01/" + year);
}

function doCalendarByDate(date)
{
	//var sReturn=doModal("/include/Calendar.asp?date=" + date, 350, 255);
	var sReturn=doModal("/include/Calendar.asp?date=" + date, 350, 255);
    if (sReturn == null || sReturn == "")
    {
		sReturn=date;
    }
    return(sReturn);
}

function doColor(color)
{
	var sReturn=doModal("../include/Color.asp?color=" + color, 320, 130);
    if (sReturn == null || sReturn == "")
    {
		sReturn=color;
    }
    return(sReturn);
}

function davetest()
{
    
    alert("test");
}


function calclastday(month,year)
{
    if ((month == 2) && ((year % 4) == 0))
    {
        return(29);
    }
    if ((month == 2) && ((year % 4) != 0))
    {
        return(28);
    }
    if ((month == 1) || (month == 3) || (month == 5) || (month == 7)
     || (month == 8) || (month == 10) || (month == 12))
    {
        return(31);
    }
    return(30);
}

function getDate(theDate)
{
	var Year = theDate + "";
	var Day, Month;
	var Temp, Temp2, Temp3;
	
	Temp = Year.indexOf( "/" );
	Month = Year.substring(0, Temp) - 1;
		
	Temp2 = Year.substring(Temp + 1, Year.length);
	Temp3 = Temp2.indexOf( "/" );
	Day =  Temp2.substring(0, Temp3);
		
	Year = Temp2.substring(Temp3 + 1, Temp2.length);				
		
	return(new Date(Year, Month, Day));
}

function isDate(dtValue)
{
    return(doDate(dtValue, false));
}

function doDate(dtValue, bInsert, bOnlyAdd19, bNoAlert)
{
	var nValue=doNumber(dtValue, true, false, false, false);
	var firstDash=dtValue.indexOf("-");
	var secondDash=dtValue.substring(firstDash + 1).indexOf("-");
	var isDash=(firstDash != -1 && secondDash != -1);
	var firstSlash=dtValue.indexOf("/");
	var secondSlash=dtValue.substring(firstSlash + 1).indexOf("/");
	var isSlash=(firstSlash != -1 && secondSlash != -1);
	var sReturnValue=null;

	
	if (isDash)
	{
		// non-zero padded dash date (can contain character months)
		sReturnValue=doFixDate(dtValue, firstDash, secondDash, bOnlyAdd19)
	}
	else if (isSlash)
	{
		// non-zero padded slash date (can contain character months)
		sReturnValue=doFixDate(dtValue, firstSlash, secondSlash, bOnlyAdd19)
	}
	else if (nValue != dtValue && (dtValue.length == 7 || dtValue.length == 9))
	{
		// Date with character months
		if (dtValue.substring(0, 1) >= '0' && dtValue.substring(0, 1) <= '9')
		{
			// day first
			var sDay = dtValue.substring(0, 2);
			var sMonth = dtValue.substring(2, 5);
			var sYear = dtValue.substring(5);			
		}
		else
		{
			// day in middle
			var sDay = dtValue.substring(3, 5);
			var sMonth = dtValue.substring(0, 3);
			var sYear = dtValue.substring(5);
		}
		sDay = trim(sDay);
		if (sDay.length == 1)
		{
			sDay = "0" + sDay;
		}
		sYear = trim(sYear);
		sMonth = doMonth(trim(sMonth));	
		if (sDay.length = 2 && sMonth.length == 2 && (sYear.length == 2 || sYear.length == 4))
		{
			sReturnValue = doFormatDate(sMonth + sDay + sYear, bOnlyAdd19);		
		}
	}
	else if (nValue.length == 6 || nValue.length == 8 )
	{
		sReturnValue=doFormatDate(nValue, bOnlyAdd19);
	}
	if (sReturnValue != null)
	{
		if (bInsert) {
			return(sReturnValue);
		}
		return(true);
	}
	if (trim(dtValue) != "" && bInsert && !(bNoAlert))
	{
		alert("The date you have entered \"" + dtValue + "\" is invalid.  Please enter a valid date (MMDDYYYY).");
		return("mm/dd/yyyy");
	}
	if (bInsert) {
		return(dtValue);
	}
	return(false);
}

function doFixDate(dtValue, nFirstSlash, nSecondSlash, bOnlyAdd19)
{
	var sMonth, sDay, sYear, sTemp;

	sMonth = (dtValue.substring(0, nFirstSlash));
	sTemp = dtValue.substring(nFirstSlash + 1);	
	sDay =  sTemp.substring(0, nSecondSlash);
	sYear = sTemp.substring(nSecondSlash + 1);
	
	sDay = trim(sDay);
	if (sDay.length == 1)
	{
		sDay = "0" + sDay;
	}
	sYear = trim(sYear);
	sMonth = doMonth(trim(sMonth));	
	if (sDay.length = 2 && sMonth.length == 2 && (sYear.length == 2 || sYear.length == 4))
	{
		return(doFormatDate(sMonth + sDay + sYear, bOnlyAdd19));
	}
	return(null);
}

function doMonth(sMonth)
{
	sMonth=sMonth.toUpperCase();
	if (sMonth == "JAN" || sMonth == "JANUARY")
	{
		sMonth="01";
	}
	else if (sMonth == "FEB" || sMonth == "FEBRUARY")
	{
		sMonth="02";
	}
	else if (sMonth == "MAR" || sMonth == "MARCH")
	{
		sMonth="03";
	}
	else if (sMonth == "APR" || sMonth == "APRIL")
	{
		sMonth="04";
	}
	else if (sMonth == "MAY")
	{
		sMonth="05";
	}
	else if (sMonth == "JUN" || sMonth == "JUNE")
	{
		sMonth="06";
	}
	else if (sMonth == "JUL" || sMonth == "JULY")
	{
		sMonth="07";
	}
	else if (sMonth == "AUG" || sMonth == "AUGUST")
	{
		sMonth="08";
	}
	else if (sMonth == "SEP" || sMonth == "SEPTEMBER")
	{
		sMonth="09";
	}
	else if (sMonth == "OCT" || sMonth == "OCTOBER")
	{
		sMonth="10";
	}
	else if (sMonth == "NOV" || sMonth == "NOVEMBER")
	{
		sMonth="11";
	}
	else if (sMonth == "DEC" || sMonth == "DECEMBER")
	{
		sMonth="12";
	}
	else if (sMonth.length == 1)
	{
		sMonth = "0" + sMonth;
	}
	return(sMonth);
}

function doFormatYear(dtValue, bYearOnly)
{
	var sYear = thisyear + "";
	if (bYearOnly)
	{
		sYear=doNumber(dtValue, true, false, false, false);
	}
	else
	{
		sYear=doNumber(dtValue.substring(6), true, false, false, false);
	}

	if (sYear.length == 2)
    {
		if (sYear > 50)
		{
			sYear="19"+sYear;	
		}
		else
		{
			sYear="20"+sYear;
		}
	}
	else if (sYear.length == 0) 
	{
		sYear=thisyear+"";
	}
	else if (sYear.length != 4)
	{
		return(null);
	}
	if (sYear <= 1700)
	{
		sYear="1700"
	}
	return(sYear);
}

function doFormatDate(dtValue, bOnlyAdd19)
{
	var ltoday = new Date();
	if (!(dtValue.length == 6 || dtValue.length == 8))
	{
	    return(null);
	}
	var sMonth=dtValue.substring(0, 2);
	var sDay=dtValue.substring(2, 4);
	var sYear=doNumber(dtValue.substring(4), true, false, false, false);
	
	if ((sMonth.substring(0,1) != "0" && sMonth.substring(0,1) != "1") || sMonth.substring(1,2) < "0" || sMonth.substring(1,2) > "9") 
	{
	    return(null);
	}
	else if (sMonth < 1) 
	{
	    return(null);        
	}
        else if (sMonth > 12)
        {
	    return(null);
        }      

	if ((sDay.substring(0,1) != "0" && sDay.substring(0,1) != "1" && sDay.substring(0,1) != "2" && sDay.substring(0,1) != "3") || sDay.substring(1,2) < "0" || sDay.substring(1,2) > "9") 
	{
	    return(null);
	}
        else if (sDay < "01")
        {
	    return(null);
        }
        else if (sDay > calclastday(sMonth, sYear))
        {
            sDay=calclastday(sMonth, sYear);
        }
	if ((sMonth + sDay + sYear) != dtValue)
	{
	    return(null);
	}	
	if (sYear.length == 2)
	{		
        // Make sure the year is not greater than the current date's year
		var ltodayyear = ltoday.getFullYear();
		var lcentury = ltodayyear - (ltodayyear % 100);
		var lshortyear = ltodayyear % 100;
		
		if(sYear > lshortyear)
		{
			lcentury = lcentury - 100;
			sYear = lcentury.toString().substring(0,2) + sYear;
		}
		else
		{
			sYear = (lcentury.toString().substring(0,2)) + sYear;
		}
	}
	else if (sYear.length == 0) 
	{
		sYear=thisyear+"";
	}
	else if (sYear.length != 4)
	{
		return(null);
	}
	if (sYear <= 1700)
	{
		sYear="1700"
	}
	
	var thedate = new Date(sYear, (sMonth - 1), sDay);
	if(isNaN(thedate) || thedate > ltoday)
	{
		return null;
	}
	return(sMonth + "/" + sDay + "/" + sYear);
}

function isNumber(nValue)
{
    return(doNumber(nValue, false, true, true, false));
}

function isBetween(nValue, nMin, nMax)
{
    if (!isNumber(nValue))
    {
        return(false);
    }
    return(eval(nValue) >= eval(nMin) && eval(nValue) <= eval(nMax));
}

function doNumber(nPassedValue, bInsert, bDecimal, bMinus, bAlert)
{
    nPassedValue+="";
    var nValue=trim(nPassedValue);
    var hasMinus=false;
    var hasPeriod=false;
    var isValid=true;
    var sNewString="", sUnexpectedChars="";

    for (iCount=0; iCount < nValue.length; iCount++)
    {
    	if (nValue.substring(iCount, iCount + 1) == '-' && iCount == 0 && !hasMinus && bMinus)
    	{
    	    hasMinus=true;
    	    sNewString+=nValue.substring(iCount, iCount + 1);
    	}
    	else if (nValue.substring(iCount, iCount + 1) == '.' && !hasPeriod && bDecimal)
    	{
    	    hasPeriod=true;
    	    sNewString+=nValue.substring(iCount, iCount + 1);
    	}
    	else if (nValue.substring(iCount, iCount + 1) >= '0' && nValue.substring(iCount, iCount + 1) <= '9')
    	{
    	    sNewString+=nValue.substring(iCount, iCount + 1);
    	}
    	else
        {
            isValid=false;
            if (!bInsert)
            {
                break;
            }
			  if (sUnexpectedChars != "")
			  {
			  	  sUnexpectedChars+=", ";
			  }
			  sUnexpectedChars+=nValue.substring(iCount, iCount + 1);
				
        }
    }
    if (sNewString == "" || sNewString == "-" || sNewString == ".")
    {
        sNewString="0";
        isValid=false;
    }
    if (sNewString.indexOf(".") == (sNewString.length - 1))
    {
        sNewString=sNewString.substring(0, (sNewString.length - 1));
    }
    if (bInsert)
    {
	    if (bAlert && !(isValid))
	    {
			if (trim(nPassedValue) != "")
			{
				alert("The number you entered \"" + nPassedValue + "\" is not valid and contained the following unexpected characters: " + sUnexpectedChars + ".");
			}
			return(trim(nPassedValue));
	    }
        return(sNewString);
    }
    return(isValid);
}


function doTime(sValue, bInsert, bNoAlert)
{
	if (sValue.length == 8 && sValue.charAt(5) == ":")
	{
		sValue=sValue.substring(0, 5);
	}
	var nIndex=sValue.indexOf(":");
	var sHour="00";
	var sMinute="00";	
	var isValid=true;

	if (trim(sValue) == "")
	{
		isValid=false;
	}
	else if (nIndex == -1)
	{
		if (sValue.length == 4) {
			sHour=sValue.substring(0, 2);
			sMinute=sValue.substring(2, 4)
		}
		else if (sValue.length == 2)
		{
			sHour=sValue;
			sMinute="00";
		}
		else {
			isValid=false;
		}
	}
	else
	{
		if (nIndex > 0)
		{
			sHour=sValue.substring(0, nIndex);
		}
		if ((sValue.length - 1) > nIndex)
		{
			sMinute=sValue.substring(nIndex + 1, sValue.length);
		}
		else
		{
			isValid=false;
		}
	}
	if (isValid)
	{
		sHour=doNumber(sHour, true, false, false, false);
		sMinute=doNumber(sMinute, true, false, false, false);
		if (sHour > 23)
		{
			isValid=false;
			sHour=23;
		}
		if (sHour < 0)
		{
			isValid=false;	
			sHour=0;
		}
		if (sMinute > 59)
		{
			isValid=false;
			sMinute=59;
		}
		if (sMinute < 0)
		{
			isValid=false;
			sMinute=0;
		}
		sHour+="";
		sMinute+="";
		if (sHour.length == 1)
		{	
	       isValid=false;
			sHour="0" + sHour;
		}
		if (sMinute.length == 1)
		{	
	        isValid=false;
			sMinute+="0";
		}
	}
	if (bInsert)
	{
		if (!(isValid))
		{
			if (trim(sValue) != "" && !(bNoAlert))
			{
				alert("The time you entered \"" + sValue + "\" is not valid, please enter the time military format \"HH:MM\".");
			}
			return(trim(sValue));
		}
		return(sHour + ":" + sMinute);
	}
	return(isValid);
}


 function doDecimal(nValue, nPreDec, nPostDec, bPad, bNoAlert)
{
	nValue+="";

	var isValid=true, iCount, sMaxValue="";
	var sValue=doNumber(nValue, true, true, true, false);
	
	if (nValue.substring(nValue.length - 1, nValue.length) != ".")
	{
		isValid=(isValid && (nValue == sValue));
	}
	var nIndex=sValue.indexOf(".");
	var nAddZeros=-1;
	var hasMinus=false;
	var nPre, nPost;

	if (nIndex == -1)
	{
		if (bPad)
        {
            sValue+=".";
        }
		nAddZeros=nPostDec;
		nIndex=sValue.length;
	}
	else if ((sValue.length - nIndex - 1) > nPostDec)
	{
		isValid=false;
		nPre=sValue.substring(0, nIndex);
		nPost=sValue.substring(nIndex + 1, nIndex + nPostDec + 1);
		if (sValue.charAt(nIndex + nPostDec + 1) >= 5)
		{
			var nPostLength=nPost.length;
			
			nPost++;
			nPost+="";
			if (nPost.length > nPostLength) 
			{
				nPost="";
				var iCount;
				for (iCount=0; iCount < nPostDec; iCount++)
				{
					nPost+="0";
				}
				nPre=eval(nPre) + 1 + "";
			}
			else if (nPost.length < nPostLength)
			{
				nPost="0" + nPost;
			}
		}
		sValue=nPre + "." + nPost + "";	
	}
	else if ((sValue.length - nIndex - 1) < nPostDec)
	{
		nAddZeros=sValue.length-nIndex-1;		
	}

	if (bPad)
	{
    		for (iCount=0; iCount < nAddZeros; iCount++)
	    	{
    			sValue+="0";
	    	}
	}
	
	if (nPreDec != -1 && nIndex > nPreDec)
	{
		isValid=false;
		hasMinus=(sValue.substring(0,1)=='-');
		sValue=sValue.substring(nIndex - nPreDec, sValue.length);
		if (hasMinus)
		{
			sValue="-"+sValue;
		}
	}

	if (!(isValid) && !(bNoAlert))
	{
		for (iCount=0; iCount < nPreDec; iCount++)
		{
			sMaxValue=sMaxValue+"9";
		}
		if (nPostDec > 0)
		{
			sMaxValue=sMaxValue+".";
			for (iCount=0; iCount < nPostDec; iCount++)
			{
				sMaxValue=sMaxValue+"9";
			}
		}
		if (trim(nValue) != "")
		{
			alert("The number you entered \"" + nValue + "\" is not valid, the number may be no more than \"" + sMaxValue + "\".");
		}
		return(trim(nValue));
	}
	return(sValue);	
}

function rTrim(sValue)
{
    var i;

    for (i=sValue.length; i > 0; i--)
    {
    	if (sValue.substr(i-1,1) != " ")
    	{
    	    return sValue.substr(0,i);
       	}
    }

    

    return( "" );
}

function lTrim(sValue)
{
    var i;

    for (i=0; i < sValue.length; i++)
    {
    	if (sValue.substr(i,1) != " ")
    	{
    	    return sValue.substr(i);
    	}
    }

    

    return( "" );
}

function trim(sValue)
{
    return rTrim(lTrim(sValue));
}


function doDateChange(sDate, nDays)
{
	var sNewDate;
	var dtDate=getDate(sDate);
	dtDate.setDate(dtDate.getDate() + eval(nDays));
	sNewDate=(dtDate.getMonth() + 1) + "/" + dtDate.getDate() + "/" + dtDate.getYear();
	return(doDate(sNewDate, true));
}

function doDateTime(sDateTime, bInsert, bOnlyAdd19, bNoAlert, bForceTime)
{
	var sNewDate, sNewTime;
	var sNewDateTime;
	var sDate, sTime;
	var nIndex, bValid=true;
	
	sDateTime+="";
	nIndex = sDateTime.indexOf(" ");
	if (nIndex == -1)
	{
		sDate=sDateTime;
		sTime="";
	}
	else
	{
		sDate=sDateTime.substring(0, nIndex);
		sTime=sDateTime.substring(nIndex + 1);
	}
	
	sNewDate=doDate(sDate, true, bOnlyAdd19, true);
	sNewTime=doTime(sTime, true, true);
	
	if (nIndex == -1 && !(bForceTime))
	{		
		bValid=isDate(sNewDate);
		sNewDateTime=sNewDate;
	}
	else
	{
		bValid=(isDate(sNewDate) && doTime(sNewTime, false, true));
		sNewDateTime=sNewDate + " " + sNewTime;
	}	
	
	if (!(bInsert))
	{
		return(bValid);
	}
	else if (!(bValid) && !(bNoAlert))
	{
		alert("The timestamp entered was not valid!  Please enter a valid timestamp \"mm/dd/yyyy hh:mm\".");
		return(sDateTime);		
	}
	return(sNewDateTime);
}


function doModal(url, width, height)
{
    window.showModalDialog( url, 0, 
                            "dialogWidth:" + width + "px;" + 
                            "dialogHeight:" + height + "px");	
}

function SetEndDate()
{
    var dtStart = document.all.Search_Date;
    var dtEnd = document.all.Search_Date;
    var txtStart = dtStart.value;
    var txtEnd = dtEnd.value;
    var strStart;

    if (txtStart != "")
    {
        if (!doDate(txtStart, false))
        {
			return false;
        }

        strStart = doDate(txtStart, true);
        dtStart.value = strStart;
        if (strStart != null)
        {
            txtStart = strStart;
            dtEnd.value = doDateChange(strStart, 0);
            //dtEnd.focus();
        }
    }
}

// Searches for a checked checkbox on a page.
// If there is a checked checkbox, return true. Otherwise, return false.
function isCheckboxChecked()
{
	var isChecked = false;
	var inputTags = document.getElementsByTagName("input");
	for (var i=0; i<inputTags.length; i++)
	{
		var inputType = inputTags[i].getAttribute("type");
		if (inputType == "checkbox")
		{
			if (inputTags[i].checked == true)
			{
				isChecked = true;
				break;
			}
		}
	}
	return isChecked;
}