﻿/*****************/
/* UPDATE ACTION */
/*****************/

// This function sets the action (used before a submit() call)
function updateAction(straction)
{
	//alert("Updating action to " + action);
	document.main_form.Action.value = straction;
	//alert("Updating target to ''");
	document.main_form.target = '';
}

// This function sets the form action
// The form action refers to the page this form will post to
function updateFormAction(straction)
{
    document.main_form.action = straction;
}

// This function sets the form target
// The form target refers to the page this form will post to
function updateFormTarget(strtarget)
{
    document.main_form.target = strtarget;
}

//This function returns a string representing a number in currency format (thousands separator, two decimal places)
function getMoneyFormat(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);
}

/*******************/
/* CHECK ENTER KEY */
/*******************/
// This function returns true if the key pressed is the enter key
function checkEnterKey(evt)
{
    if(evt.keyCode == 13)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/******************/
/* CENTER DISPLAY */
/******************/

// This function places the specified element in the center of the window
function CenterDisplay(tid)
{
    try
    {
        document.getElementById(tid).style.position = 'absolute';
        //Remember the old display style of the element
        var strdisp = document.getElementById(tid).style.display;
        //Make the element visisble. If the element is not visible, offsetHeight and width are zero.
        document.getElementById(tid).style.display = 'block';
        document.getElementById(tid).style.left = ((GetWindowWidth()  / 2) + GetScrollX() - (document.getElementById(tid).offsetWidth  / 2)) + 'px';
        document.getElementById(tid).style.top  = ((GetWindowHeight() / 2) + GetScrollY() - (document.getElementById(tid).offsetHeight / 2)) + 'px';
        document.getElementById(tid).style.display = strdisp;
    }
    catch (ex)
    {
        //alert('Could not center element ' + tid + ':\n' + ex.message);
    }
}

function GetWindowWidth()
{
    if (typeof(window.innerWidth) == 'number')
    {
        //Non-IE
        return window.innerWidth;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        return document.body.clientWidth;
    }
}

function GetWindowHeight()
{
    if (typeof(window.innerWidth) == 'number')
    {
        //Non-IE
        return window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        return document.body.clientHeight;
    }
}

function GetScrollX()
{
    if (typeof(window.pageXOffset) == 'number')
    {
        //Netscape compliant
        return window.pageXOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
    {
        //DOM compliant
        return document.body.scrollLeft;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
    {
        //IE6 standards compliant mode
        return document.documentElement.scrollLeft;
    }
    else
    {
        return 0;
    }
}
function GetScrollY()
{
    if (typeof(window.pageYOffset) == 'number')
    {
        //Netscape compliant
        return window.pageYOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
    {
        //DOM compliant
        return document.body.scrollTop;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
    {
        //IE6 standards compliant mode
        return document.documentElement.scrollTop;
    }
    else
    {
        return 0;
    }
}

/******************/
/* TOGGLE DISPLAY */
/******************/

// This function hides or shows single or multiple items based on ID
// The inputs for tid this function handles are:
//	1 Element:		Element ID		"X2"
//	Multiple:		Element list	"X2,D4,J6"
//	Multiple:		Element range	"X3-15"

// Input:
//	-tid		The element ID to show or hide
//	-obj		The object that requested to show or hide tid (usually a picture or button)
//	-showtxt	The text (or image url) to place on obj when tid is hidden ("Show options")
//	-hidetxt	The text (or image url) to place on obj when tid is shown  ("Hide options")
function toggleDisplay(tid, obj, showtxt, hidetxt)
{
    /*
	if (showtxt == "")
		showtxt = "Show";
	if (hidetxt == "")
		hidetxt = "Hide";
	*/
	var i, s, e, b;
	var validChars = '0123456789';
	var x;

	if(tid.indexOf('-') > -1)
	{
		x = 0;
		s = '';					
		
		//This allows to name elements with a number in them, like td390_1 for example
		//Now we can do toggleDisplay('td390_1-10')
		if(tid.indexOf('_') > -1)
		{
			for(i = tid.indexOf('_'); i < tid.indexOf('-'); i++)
			{
				if(validChars.indexOf(tid.charAt(i)) > -1)
				{
					if(x == 0)
					{
						s = tid.substr(i , tid.indexOf('-') - i);
						b = tid.substr(0, i);
						x = 1;
					}
				}
			} 		
			e = tid.substr(tid.indexOf('-') + 1);
			//alert('Toggling ' + s + ' to ' + e);
			for(i = s; i <= e; i++)
			{
			    //alert('Trying to toggle ' + b + i);
				if(document.getElementById(b + i))
				{
					toggleOne(b + i, obj, showtxt, hidetxt);							
				}					
			}
		}
		else
		{
			for(i = 0; i < tid.indexOf('-'); i++)
			{
				if(validChars.indexOf(tid.charAt(i)) > -1)
				{
					if(x == 0)
					{
						s = tid.substr(i , tid.indexOf('-') - i);
						b = tid.substr(0, i);
						x = 1;
					}
				}
			} 		
			e = tid.substr(tid.indexOf('-') + 1);
			
			for(i = s; i <= e; i++)
			{
				if(document.getElementById(b + i))
				{
					//alert('Toggling ' + b + i);
					toggleOne(b + i, obj, showtxt, hidetxt);							
				}					
			}
		}
	}
	else if(tid.indexOf(',') > -1)
	{
		s = tid;
		while(s.indexOf(',') > -1)
		{
			x=s.indexOf(',');
			b=s.substr(0, x);
			s=s.substr(x + 1);
			if(document.getElementById(b))
			{
				toggleOne(b, obj, showtxt, hidetxt);
			}
		}
	}
	else
	{
		if(document.getElementById(tid))
		{
			toggleOne(tid, obj, showtxt, hidetxt);
		}
	}
}

// This function toggles the display of a single element based on ID
// This is used as a helper for toggleDisplay()
function toggleOne(oid, obj, showtxt, hidetxt)
{
    /*
	if (showtxt == "")
		showtxt = "Show";
	if (hidetxt == "")
		hidetxt = "Hide";
	*/
	if(document.getElementById(oid).style.display == 'none')
	{
		document.getElementById(oid).style.display = '';
		
		if (obj && hidetxt != "")
		{
			if (obj.type == "button")
				obj.value = hidetxt;
			else
				obj.src = hidetxt;
		}
	}
	else
	{
		document.getElementById(oid).style.display = 'none';
		
		if (obj && showtxt != "")
		{
			if (obj.type == "button")
				obj.value = showtxt;
			else
				obj.src = showtxt;
		}
	}
}


/********/
/* SHOW */
/********/

// This function works like toggleDisplay except it will always show the items
//	1 Element:		Element ID		"X2"
//	Multiple:		Element list	"X2,D4,J6"
//	Multiple:		Element range	"X3-15"

// Input:
//	-tid		The element ID to show or hide
//	-obj		The object that requested to show or hide tid (usually a picture or button)
//	-showtxt	The text (or image url) to place on obj when tid is hidden ("Show options")
//	-hidetxt	The text (or image url) to place on obj when tid is shown ("Hide options")
function show(tid, obj, showtxt, hidetxt)
{
    /*
	if (showtxt == "")
		showtxt = "Show";
	if (hidetxt == "")
		hidetxt = "Hide";
	*/
	var i, s, e, b;
	var validChars = '0123456789';
	var x;

	if(tid.indexOf('-') > -1)
	{
		x = 0;
		s = '';					
		
		//This allows to name elements with a number in them, like td390_1 for example
		//Now we can do toggledisplay('td390_1-10')
		if(tid.indexOf('_') > -1)
		{
			for(i = tid.indexOf('_'); i < tid.indexOf('-'); i++)
			{
				if(validChars.indexOf(tid.charAt(i)) > -1)
				{
					if(x == 0)
					{
						s = tid.substr(i , tid.indexOf('-') - i);
						b = tid.substr(0, i);
						x = 1;
					}
				}
			} 		
			e = tid.substr(tid.indexOf('-') + 1);
			//alert('Toggling ' + s + ' to ' + e);
			for(i = s; i <= e; i++)
			{
			    //alert('Trying to toggle ' + b + i);
				if(document.getElementById(b + i))
				{
					showOne(b + i, obj, showtxt, hidetxt);							
				}					
			}
		}
		else
		{
			for(i = 0; i < tid.indexOf('-'); i++)
			{
				if(validChars.indexOf(tid.charAt(i)) > -1)
				{
					if(x == 0)
					{
						s = tid.substr(i , tid.indexOf('-') - i);
						b = tid.substr(0, i);
						x = 1;
					}
				}
			} 		
			e = tid.substr(tid.indexOf('-') + 1);
			
			for(i = s; i <= e; i++)
			{
				if(document.getElementById(b + i))
				{
					//alert('Toggling ' + b + i);
					showOne(b + i, obj, showtxt, hidetxt);							
				}					
			}
		}
	}
	else if(tid.indexOf(',') > -1)
	{
		s = tid;
		while(s.indexOf(',') > -1)
		{
			x=s.indexOf(',');
			b=s.substr(0, x);
			s=s.substr(x + 1);
			if(document.getElementById(b))
			{
				showOne(b, obj, showtxt, hidetxt);
			}
		}
	}
	else
	{
		if(document.getElementById(tid))
		{
			showOne(tid, obj, showtxt, hidetxt);
		}
	}
}

// This function shows a single element based on ID
// This is used as a helper for show()
function showOne(oid, obj, showtxt, hidetxt)
{
    /*
	if (showtxt == "")
		showtxt = "Show";
	if (hidetxt == "")
		hidetxt = "Hide";
	*/
	//document.getElementById(oid).style.display = 'block'; // must be changed to empty string ('') to work correctly with firefox
	document.getElementById(oid).style.display = '';
	
	if (obj && showtxt != "")
	{
		if (obj.type == "button")
			obj.value = showtxt;
		else
			obj.src = showtxt;
	}
}



/********/
/* HIDE */
/********/

// This function works like toggleDisplay except it will always hide the items
//	1 Element:		Element ID		"X2"
//	Multiple:		Element list	"X2,D4,J6"
//	Multiple:		Element range	"X3-15"

// Input:
//	-tid		The element ID to show or hide
//	-obj		The object that requested to show or hide tid (usually a picture or button)
//	-showtxt	The text (or image url) to place on obj when tid is hidden ("Show options")
//	-hidetxt	The text (or image url) to place on obj when tid is shown ("Hide options")
function hide(tid, obj, showtxt, hidetxt)
{
    /*
	if (showtxt == "")
		showtxt = "Show";
	if (hidetxt == "")
		hidetxt = "Hide";
	*/
	var i, s, e, b;
	var validChars = '0123456789';
	var x;

	if(tid.indexOf('-') > -1)
	{
		x = 0;
		s = '';					
		
		//This allows to name elements with a number in them, like td390_1 for example
		//Now we can do toggledisplay('td390_1-10')
		if(tid.indexOf('_') > -1)
		{
			for(i = tid.indexOf('_'); i < tid.indexOf('-'); i++)
			{
				if(validChars.indexOf(tid.charAt(i)) > -1)
				{
					if(x == 0)
					{
						s = tid.substr(i , tid.indexOf('-') - i);
						b = tid.substr(0, i);
						x = 1;
					}
				}
			} 		
			e = tid.substr(tid.indexOf('-') + 1);
			//alert('Toggling ' + s + ' to ' + e);
			for(i = s; i <= e; i++)
			{
			    //alert('Trying to toggle ' + b + i);
				if(document.getElementById(b + i))
				{
					hideOne(b + i, obj, showtxt, hidetxt);							
				}					
			}
		}
		else
		{
			for(i = 0; i < tid.indexOf('-'); i++)
			{
				if(validChars.indexOf(tid.charAt(i)) > -1)
				{
					if(x == 0)
					{
						s = tid.substr(i , tid.indexOf('-') - i);
						b = tid.substr(0, i);
						x = 1;
					}
				}
			} 		
			e = tid.substr(tid.indexOf('-') + 1);
			
			for(i = s; i <= e; i++)
			{
				if(document.getElementById(b + i))
				{
					//alert('Toggling ' + b + i);
					hideOne(b + i, obj, showtxt, hidetxt);							
				}					
			}
		}
	}
	else if(tid.indexOf(',') > -1)
	{
		s = tid;
		while(s.indexOf(',') > -1)
		{
			x=s.indexOf(',');
			b=s.substr(0, x);
			s=s.substr(x + 1);
			if(document.getElementById(b))
			{
				hideOne(b, obj, showtxt, hidetxt);
			}
		}
	}
	else
	{
		if(document.getElementById(tid))
		{
			hideOne(tid, obj, showtxt, hidetxt);
		}
	}
}

// This function hides a single element based on ID
// This is used as a helper for hide()
function hideOne(oid, obj, showtxt, hidetxt)
{
    /*
	if (showtxt == "")
		showtxt = "Show";
	if (hidetxt == "")
		hidetxt = "Hide";
	*/
	document.getElementById(oid).style.display = 'none';
	
	if (obj && hidetxt != "")
	{
		if (obj.type == "button")
			obj.value = hidetxt;
		else
			obj.src = hidetxt;
	}
}


//This function enables all fields to make sure they are submitted with the form
function enableAll()
{
	for(var i = 0; i < document.forms[0].elements.length; i++)
	{
		document.forms[0].elements[i].disabled = false;
	}
}


/**************/
/* BUILD MASK */
/**************/

// This function builds a mask based on the requested rooms
// and sets the form variable "searchmask" with the computed value
// This function REQUIRES the following input elements:
//      numadts
//      numchds
//      chd1age
//      chd2age
// There MUST be the same number of elements of each name
// (4 numadts, 4 numchds, 4 chd1age, 4 chd2age)
// This function returns true if it manages to build a mask, false if it fails.
function buildMask()
{
    var myMask, tempMask;
    var i, j;
    
    myMask = "";
    for (i = 0; i < document.main_form.numadts.length; i++)
    {
        tempMask = "";
        for (j = 1; j <= document.main_form.numadts[i].value; j++)
        {
            tempMask = tempMask + "A";
        }
        for (j = 1; j <= document.main_form.numchds[i].value; j++)
        {
            //Check that at least one adult was selected for this room
            if (document.main_form.numadts[i].value == 0)
            {
                alert("Please select at least one adult for room #" + (i + 1));
                return false;
            }
            tempMask = tempMask + "C";
            if (j == 1)
            {
                //First child
                if (document.main_form.chd1age[i].value == "0")
                {
                    alert("Please select child 1 age for room #" + (i + 1));
                    return false;
                }
                tempMask = tempMask + document.main_form.chd1age[i].value;
            }
            else if (j == 2)
            {
                //Second child
                if (document.main_form.chd2age[i].value == "0")
                {
                    alert("Please select child 2 age for room #" + (i + 1));
                    return false;
                }
                tempMask = tempMask + document.main_form.chd2age[i].value;
            }
        }
        if (tempMask != "")
        {
            if (i > 0)
                myMask = myMask + "/" + tempMask;
            else
                myMask = tempMask;
        }
    }
    //alert("Mask: " + myMask);
    document.main_form.searchmask.value = myMask;
    return true;
}



/******************/
/* IS VALID EMAIL */
/******************/

//This function checks the validity of an email address using a regular expression
//Returns false if the email is invalid or blank, true if the email is valid and not blank
function isValidEmail(strEmail)
{
    //Use this regular expression to match email addresses
    //This regex came from http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=47
    var re = /^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,4}$/;
    //Check for a match
    if (strEmail.match(re))
    {
        //There was a match
        return true;
    }
    else
    {
        //No match found
        return false;
    }
}

function IsInteger(strIn)
{
    var i = 0;
    for (i = 0; i < strIn.length; i++)
    {
        if (strIn.charAt(i) < "0" || strIn.charAt(i) > "9")
            return false;
    }
    
    return true;
}

/****************************/
/* REMOVE AMOUNT FORMATTING */
/****************************/
// This function removes all formatiing except for a decimal from An "Amount" text box
function unformatAmount(strAmt)
{
    
    strAmt = strAmt.replace('$','')
    strAmt = strAmt.replace(',','')
    strAmt = strAmt.replace(' ','')
    strAmt = strAmt.replace('£','')
       
    return strAmt;
    
}

/**** Validates that the Date entered is in a correct format ****/
 function validateDate(dat, obj, min, max, strfieldName)
{
    
    var dat2 = new Date(dat);
    var dat3 = new Date(min);
    var dat4 = new Date(max); //want to make max today if unspecified
    
    if (strfieldName == '' || !strfieldName)
    {
        strfieldName = ''
    }
    else
    {
        strfieldName = ' for the ' + strfieldName
    }
    
    //get max date if empty
    if (dat4 == '' || !dat4 || dat4 == null || dat4 == 'NaN' || isNaN(dat4))
    {
        dat4 = new Date(); // Today
    }
    
    
    if (dat2 == '' || !dat2 || dat2 == null || dat2 == 'NaN' || isNaN(dat2))
    {
        alert('Invalid Date Format. Please enter in the format dd MMM yyyy' + strfieldName);
        obj.focus();
        return false;
    }
    
    if (dat2 < dat3)
    {
        alert('Minimum date allowed is ' + (dat3.getMonth() + 1) + '/' + dat3.getDate() + '/' + dat3.getFullYear() + strfieldName);
        obj.focus();
        return false;
    }
   
   if (dat4 < dat2)
    {
        alert('Maximum date allowed is ' + (dat4.getMonth() + 1) + '/' + dat4.getDate() + '/' + dat4.getFullYear()  + strfieldName);
        obj.focus();
        return false;
    }
    
    
        obj.value = FormatDate(dat, 'dd MMM yyyy');
        return true;
    
}

/*
    FormatDate
    ----------
        Returns a string representation of the specified date object
        Input:
            dat     The date to format
            frm     The formatting string
                        yyyy - 4-digit year
                        yy   - 2-digit year
                        MM   - 2-digit month
                        MMM  - Short month (Jan, Feb etc.)
                        MMMM - Full month (January, February etc.)
                        d    - Date (without padding/zeros)
                        dd   - 2-digit day
*/
//Full month names
var fullmonths  = new Array(12);
fullmonths[0]   = 'January';
fullmonths[1]   = 'February';
fullmonths[2]   = 'March';
fullmonths[3]   = 'April';
fullmonths[4]   = 'May';
fullmonths[5]   = 'June';
fullmonths[6]   = 'July';
fullmonths[7]   = 'August';
fullmonths[8]   = 'September';
fullmonths[9]   = 'October';
fullmonths[10]  = 'November';
fullmonths[11]  = 'December';

//Short month names
var shortmonths = new Array(12);
shortmonths[0]  = 'Jan';
shortmonths[1]  = 'Feb';
shortmonths[2]  = 'Mar';
shortmonths[3]  = 'Apr';
shortmonths[4]  = 'May';
shortmonths[5]  = 'Jun';
shortmonths[6]  = 'Jul';
shortmonths[7]  = 'Aug';
shortmonths[8]  = 'Sep';
shortmonths[9]  = 'Oct';
shortmonths[10] = 'Nov';
shortmonths[11] = 'Dec';

function FormatDate(dat, frm)
{
    try
    {
    
        var strout;   
        if (!frm || frm == '')
        {
            frm = 'dd MMM yyyy'
        }
        
        strout = frm;
        
        dat = new Date(dat);
        if (dat == '' || !dat || dat == null || dat == 'NaN' || isNaN(dat)) 
        {        
            return '';
        }
        //Year
        //yyyy
        strout = strout.replace(/yyyy/g, dat.getFullYear());
        //yy
        strout = strout.replace(/yy/g, ('' + dat.getFullYear()).substring(2, 4));
        
        //Day
        //dd
        if (dat.getDate() < 10)
        {
            strout = strout.replace(/dd/g, '0' + dat.getDate());
        }
        else
        {
            strout = strout.replace(/dd/g, dat.getDate());
        }
        //d
        strout = strout.replace(/d/g, dat.getDate());
        
        //Month
        //MMMM
        strout = strout.replace(/MMMM/g, fullmonths[dat.getMonth()]);
        //MMM
        strout = strout.replace(/MMM/g, shortmonths[dat.getMonth()]);
        //MM
        if ((dat.getMonth() + 1) < 10)
        {
            strout = strout.replace(/MM/g, '0' + (dat.getMonth() + 1));
        }
        else
        {
            strout = strout.replace(/MM/g, dat.getMonth() + 1);
        }
        
        //Done
        return strout;
    }
    catch (ex)
    {
        alert('FormatDate() Failed: ' + ex.message);
    }
}

/******************/
/* IS NUMBER KEY */
/******************/

//This function checks phone numbers,fax numbers, and zip codes to make sure only numbers are entered
function isNumberKey(evt)
{
     var charCode = evt.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

/*****************/
/*  CHANGE PHONE */
/*****************/
//This function changes the phone formats depending on if this Country is US/CA or not
function changePhone()
{
    if(document.getElementById('selcountry').value != 'US' && document.getElementById('selcountry').value != 'CA' && document.getElementById('selcountry').value != '')
    {
        document.getElementById('usphonetd').style.display = 'none';
        document.getElementById('usmobilephonetd').style.display = 'none';
        document.getElementById('usfaxtd').style.display = 'none';
        document.getElementById('nonusfaxtd').style.display = '';
        document.getElementById('nonusmobilephonetd').style.display = '';
        document.getElementById('nonusphonetd').style.display = '';
        if(document.getElementById('usemergencyphonetd'))
        {
           document.getElementById('usemergencyphonetd').style.display = 'none';
           document.getElementById('nonusemergencyphonetd').style.display = '';
        }
    }
    else
    {
        document.getElementById('nonusphonetd').style.display = 'none';
        document.getElementById('nonusmobilephonetd').style.display = 'none';
        document.getElementById('nonusfaxtd').style.display = 'none';
        document.getElementById('usfaxtd').style.display = '';
        document.getElementById('usmobilephonetd').style.display = '';
        document.getElementById('usphonetd').style.display = '';
        if(document.getElementById('usemergencyphonetd'))
        {
           document.getElementById('usemergencyphonetd').style.display = '';
           document.getElementById('nonusemergencyphonetd').style.display = 'none';
        }
    }
}

/*******************/
/*  COUNTRY CHANGE */
/*******************/
//Function changes the display of state/province textbox or dropdown based on US address or not
function countryChange()
{
    if(document.getElementById('selcountry').value != 'US' && document.getElementById('selcountry').value != '') //Non-US, show textbox
    {
        document.getElementById('txtstate').style.display='';
        document.getElementById('selstate').style.display='none';
    }
    else //US, show dropdown
    {
        document.getElementById('txtstate').style.display='none';
        document.getElementById('selstate').style.display='';
    }
}


/********/
/* IIF */
/********/
function Iif(bln, trueval, falseval)
{
    if (bln == true)
    {
        return trueval;
    }
    else
    {
        return falseval;
    }
}

/**********************/
/* IS VALID CHARACTER */
/**********************/

//This function field to make sure no Invalid Character (listed below) are being typed in.
function isValidChar(evt)
{        
    var charCode = evt.keyCode;
   
    /*--------EXCLUDE THE FOLLOWING CHAR CODES--------------
        ! " # $ % &                   = 33 to 38
         ( ) * +                      = 40 to 43
          /                           = 47 
         0 1 2 3 4  5 6 7 8 9         = 48 to 57
         : ; < = > ? @                = 58 to 64   
         [ \ ] ^ _ `                  = 91 to 96
         { | } ~                      = 123 to 126
     -------------------------------------------------------*/      
   
        if ((charCode >= 33 && charCode <= 38) ||(charCode >= 40 && charCode <= 43) || (charCode == 47) || (charCode >= 48 && charCode <= 57) || (charCode >= 58 && charCode <= 64) || (charCode >= 91 && charCode <= 96) || (charCode >= 123 && charCode <= 126) )
        {
         
            return false;
        }
    return true;
}



//<!-- Coded by Larry & Tim 10/28/04 -->
function BGNew(obj, new_style, message)
{ 
    obj.className = new_style; 
    window.status = message; 
}

//reloads the window if Nav4 resized
function MM_reloadPage(init)
{
    if (init==true) with (navigator)
    {
        if ((appName=="Netscape")&&(parseInt(appVersion)==4))
        {
            document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
        }
    }
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
        location.reload();
}
MM_reloadPage(true);

//v4.01
function MM_findObj(n, d)
{
    var p, i, x; 
    if(!d)
        d = document;
    if((p = n.indexOf("?")) > 0 && parent.frames.length)
    {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if(!(x = d[n]) && d.all)
        x = d.all[n];
    
    for(i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][n];
    for(i = 0; !x && d.layers && i < d.layers.length; i++)
        x = MM_findObj(n, d.layers[i].document);
    if(!x && d.getElementById)
        x = d.getElementById(n);
    
    //Done
    return x;
}

//v6.0
function MM_showHideLayers()
{
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3)
    {
        if ((obj=MM_findObj(args[i]))!=null)
        {
            v = args[i + 2];
            if (obj.style)
            {
                obj = obj.style;
                v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v;
            }
            obj.visibility = v;
        }
    }
}

function timeout()
{
    setTimeout("MM_showHideLayers('europe-menu','','hide','asia-menu','','hide','americas-menu','','hide','med-menu','','hide','sp-menu','','hide','cruises-menu','','hide');", 15000);
}//-->


// Validate Credit Card Number
function ValidateCC(sCC)
{
	var i, t1, t2, t3, t4;
		
	if (sCC.charAt(sCC.length) == 'X') {
		return false;	
	}
	if (sCC.length < 13) {
		return false;	
	}
		
	t1 = parseInt(sCC.charAt(sCC.length - 1));
	t2 = 0;
	t3 = 0;
		
	for (i = sCC.length - 1; i >= 1; i--){
	    t2 = parseInt(t2) + 1;
	    t4 = sCC.charAt(i - 1);
	    if (t2 % 2 == 0)
	        t3 = parseInt(t3) + parseInt(t4)
	    else {
	        t4 = parseInt(t4) * 2;
	        if (parseInt(t4) > 9) 
				t3 = parseInt(t3) + 1 + (parseInt(t4) - 10);
	        if (t4 <= 9)
				t3 = parseInt(t3) + parseInt(t4);
	    }
	}
	t2 = parseInt(t3) + parseInt(t1);
	if (t2 % 10 > 0) return false;
	if (t2 == 0) return false;
	return true;	
}

// Validate the card type from the card number prefix and length
function ValidateCCType(sCC, sType)
{
	var prefix;
	
	switch(sType)
	{
		case "MC":
			prefix = parseInt(sCC.substr(0,2));
			if( sCC.length == 16 && prefix >= 51 && prefix <= 55 ) 
				return true;
			break
		case "VI":
			if ( (sCC.length == 16 || sCC.length == 13) && sCC.charAt(0) == '4' )
				return true;
			break
		case "AX":
			prefix = sCC.substr(0,2);
			if( sCC.length == 15 && (prefix == '34' || prefix == '37' ) )
				return true;
			break
		case "DS":
			prefix = sCC.substr(0,4);
			if( sCC.length == 16 && prefix == '6011') 
				return true;
			break
		case "DI":
			prefix = parseInt(sCC.substr(0,3));
			if( sCC.length == 14 && ((prefix >= 300 && prefix <= 305) || sCC.substr(0,2) == '36' || sCC.substr(0,2) == '38') ) 
				return true;
			break
		case "LA":
			if( sCC.length == 19 )
				return true;
		default:
			return false;
	}
	return false;
}

//All used in PKGRates
function buildQS()
{
    var iPreDur, iPostDur;
    var QS;
    var datIn, datOut;
    QS = "";
    iPreDur = 0;
    iPostDur = 0;
    
    //Pre/Post options
    if (document.getElementById('chkAirY'))
    {
        if (document.getElementById('chkAirY').checked)
            QS = QS + '&chkAir=Y';
        else
        {
            if (document.getElementById('chkAirG'))
            {
                if (document.getElementById('chkAirG').checked)
                    QS = QS + '&chkAir=Y';
            }
            else
                QS = QS + '&chkAir=N';
        }
    }
      
    if (document.getElementById('airfromcity'))
    {
        QS = QS + '&airfromcity=' +  document.getElementById('airfromcity').value;
	QS = QS + '&airrettocity=' + document.getElementById('airfromcity').value;
    }
    if (document.getElementById('airtocity'))
        QS = QS + '&airtocity=' + document.getElementById('airtocity').value;
    if (document.getElementById('airdateout'))
        QS = QS + '&airdateout=' + document.getElementById('airdateout').value;
    if (document.getElementById('airdateret'))
        QS = QS + '&airdateret=' + document.getElementById('airdateret').value;
    if (document.getElementById('aircabinclass'))
        QS = QS + '&aircabinclass=' + document.getElementById('aircabinclass').value;
    if (document.getElementById('aircarrier'))
        QS = QS + '&aircarrier=' + document.getElementById('aircarrier').value;
    //if (document.getElementById('airrettocity'))
    //    QS = QS + '&airrettocity=' + document.getElementById('airrettocity').value;
    if (document.getElementById('airretfromcity'))
        QS = QS + '&airretfromcity=' + document.getElementById('airretfromcity').value;
    if (document.getElementById('airoutstopcity'))
        QS = QS + '&airoutstopcity=' + document.getElementById('airoutstopcity').value;
    if (document.getElementById('blockonly'))
        QS = QS + '&blockonly=' + document.getElementById('blockonly').value;

	if (document.getElementById('airpreference') && document.getElementById('airpreference').checked == true)
	{
	        QS = QS + '&airpreference=' + document.getElementById('airpreference').value;
	}
        
    //see if we need to extend StopOver due to pre- and -post options.        
    if(document.getElementById('preacc'))
    {
        if(document.getElementById('preaccdur').value != '0' && document.getElementById('preaccdur').value != '' && document.getElementById('preacc').checked)
        {
            iPreDur = parseInt(document.getElementById('preaccdur').value);
        }
    }
    if(document.getElementById('postacc'))
    {
        if(document.getElementById('postaccdur').value != '0' && document.getElementById('postaccdur').value != '' && document.getElementById('postacc').checked)
        {
            iPostDur = parseInt(document.getElementById('postaccdur').value);
        }
    }
    if (document.getElementById('airoutstopduration'))
        QS = QS + '&airoutstopduration=' + (parseInt(document.getElementById('airoutstopduration').value) + iPreDur);
    if (document.getElementById('airretstopcity'))
        QS = QS + '&airretstopcity=' + document.getElementById('airretstopcity').value;
    if (document.getElementById('airretstopduration'))
        QS = QS + '&airretstopduration=' + (parseInt(document.getElementById('airretstopduration').value) + iPostDur);
    if (document.getElementById('dtime'))
        QS = QS + '&dtime=' + document.getElementById('dtime').value;
    if (document.getElementById('atime'))
        QS = QS + '&atime=' + document.getElementById('atime').value;
    if (document.getElementById('airoffset'))
        QS = QS + '&airoffset=' + document.getElementById('airoffset').value;
    if (document.getElementById('numairadts'))
        QS = QS + '&numairadts=' + document.getElementById('numairadts').value;
    if (document.getElementById('numairchds'))
        QS = QS + '&numairchds=' + document.getElementById('numairchds').value;
    if (document.getElementById('airfaretype'))
        QS = QS + '&airfaretype=' + document.getElementById('airfaretype').value;
    if (document.getElementById('aircontract'))
        QS = QS + '&aircontract=' + document.getElementById('aircontract').value;
    if (document.getElementById('airmarket'))
        QS = QS + '&airmarket=' + document.getElementById('airmarket').value;
    
    //see about inner air
    if (document.getElementById('chkInnerAir'))
    {
        if (document.getElementById('chkInnerAir').checked)
        {//mark that we have inner air so STRES will pull airInfo from ProductCode
            QS = QS + '&innerair=Y';
        }
    }
    //Everything else always gets sent
    QS = QS + '&productcode=' + document.getElementById('productcode').value;
    //send over the plan/selectedservicegroup/itemnumber
    if (document.getElementById('txtItemNumber'))
        QS = QS + '&ItemNumber=' + document.getElementById('txtItemNumber').value;
    datIn = new Date();
    datIn.setTime(Date.parse(document.getElementById('tbCheckIn').value));
    QS = QS + '&tbCheckIn=' + datIn.getFullYear() + '-' + (datIn.getMonth() + 1) + '-' + datIn.getDate();
    datOut = new Date();
    datOut.setTime(Date.parse(document.getElementById('tbCheckOut').value));
    QS = QS + '&tbCheckOut=' + datOut.getFullYear() + '-' + (datOut.getMonth() + 1) + '-' + datOut.getDate();
    QS = QS + '&searchmask=' + document.getElementById('searchmask').value;
    QS = QS + '&SelectedSeq=' + document.getElementById('SelectedSeq').value;
    //Pre/Post options
    
    if(document.getElementById('preacc'))
    {
        if(document.getElementById('preaccdur').value != '0' && document.getElementById('preaccdur').value != '' && document.getElementById('preacc').checked)
        {
            QS = QS + '&preacc=' + document.getElementById('preacc').value;
            QS = QS + '&preaccduration=' + document.getElementById('preaccdur').value;
        }
    }
    if(document.getElementById('postacc'))
    {
        if(document.getElementById('postaccdur').value != '0' && document.getElementById('postaccdur').value != '' && document.getElementById('postacc').checked)
        {
            QS = QS + '&postacc=' + document.getElementById('postacc').value;
            QS = QS + '&postaccduration=' + document.getElementById('postaccdur').value;
        }
    }
    
    //Custom Headers and Footers
    if(document.getElementById('custom'))
    {
        if(document.getElementById('custom').value != '')
        {
            QS = QS + '&custom=' + document.getElementById('custom').value;
            QS = QS + '&customCode=' + document.getElementById('customCode').value;
        }
    }
    //Quote Currency
    if(document.getElementById('QC'))
    {
        if(document.getElementById('QC').value != '')
        {
            QS = QS + '&QC=' + document.getElementById('QC').value;
        }
    }
    //Theme
    //QS = QS + '&Theme=[Theme]';
    //Shares
    if (document.getElementById('allowShares') && document.getElementById('chksharey'))
    {
        if (document.getElementById('allowShares').value == 'Y' && document.getElementById('chksharey').checked)
        {
            if (document.getElementById('rdosharem').checked)
                QS = QS + '&Shares=' + document.getElementsByName('numadts').item(0).value + 'M';
            else
                QS = QS + '&Shares=' + document.getElementsByName('numadts').item(0).value + 'F';
        }
    }
    
    //Return the QueryString    
    return QS;
}
function BuildVacBuilder()
{
    var QS;
    var numAdts, numChds, numRooms;
    var date1, date2, date3, date4;
    var oneday;
    
    var Months;
    
    Months = new Array(12);
    Months[0]  = "Jan";
    Months[1]  = "Feb";
    Months[2]  = "Mar";
    Months[3]  = "Apr";
    Months[4]  = "May";
    Months[5]  = "Jun";
    Months[6]  = "Jul";
    Months[7]  = "Aug";
    Months[8]  = "Sep";
    Months[9]  = "Oct";
    Months[10] = "Nov";
    Months[11] = "Dec";
    
    QS = '';
    numAdts = 0;
    numChds = 0;
    numRooms = 0;
    
    //Theme
    //QS = QS + '&Theme=[Theme]';
    //Trip Type
    if (document.getElementById('chkAirY'))
    {
        if (document.getElementById('chkAirY').checked)
        {
            QS = QS + '&chkAir=Y';
            QS = QS + '&trip_type=AIRFHTL';
            
            //Set the air input fields if we have Air
	        if (document.getElementById('cbOrigCity'))
	            document.getElementById('airfromcity').value = document.getElementById('cbOrigCity').value;
	        if (document.getElementById('cbcabin'))
	            document.getElementById('aircabinclass').value = document.getElementById('cbcabin').value;
	        if (document.getElementById('cbcarrier'))
	            document.getElementById('aircarrier').value = document.getElementById('cbcarrier').value;
	        if(document.getElementById('cbairfaretype'))
	        {
	            document.getElementById('airfaretype').value = document.getElementById('cbairfaretype').value;
	        }
        }
        else
        {
            QS = QS + '&chkAir=N';
            QS = QS + '&trip_type=HTL';
        }
    }
    if (document.getElementById('airfromcity'))
        QS = QS + '&airfromcity=' + document.getElementById('airfromcity').value;
    QS = QS + '&airtocity=' + document.getElementById('datespeccitycode1').value;
    QS = QS + '&airretfromcity=' + document.getElementById('datespeccitycode' + document.getElementById('numitindest').value).value;
    if (document.getElementById('airdateout'))
        QS = QS + '&airdateout=' + document.getElementById('airdateout').value;
    if (document.getElementById('aircabinclass'))
        QS = QS + '&aircabinclass=' + document.getElementById('aircabinclass').value;
    if (document.getElementById('aircarrier'))
        QS = QS + '&aircarrier=' + document.getElementById('aircarrier').value;
    if (document.getElementById('airoffset'))
        QS = QS + '&airoffset=' + document.getElementById('airoffset').value;
    if (document.getElementById('numairadts'))
        QS = QS + '&numairadts=' + document.getElementById('numairadts').value;
    if (document.getElementById('numairchds'))
        QS = QS + '&numairchds=' + document.getElementById('numairchds').value;
    if (document.getElementById('airfaretype'))
        QS = QS + '&airfaretype=' + document.getElementById('airfaretype').value;
    //ProductCode
    QS = QS + '&productcode=' + document.getElementById('productcode').value;

    //Destinations
    QS = QS + '&totaldest=' + document.getElementById('numitindest').value;
    date1 = new Date();
    
    //Get Departure date
    date1 = Date.parse(document.getElementById('txtitindepdate').value + ' 01:00:00');
    oneday = 1000 * 60 * 60 * 24;
    for (var i = 1; i <= document.getElementById('numitindest').value; i++)
    {
        QS = QS + '&destination' + i + '=' + document.getElementById('datespeccitycode' + i).value;
        
        //Get the dates
        date2 = new Date();
        date4 = date1;
        date4 = date4 + (oneday * parseInt(document.getElementById('datespeconday' + i).value));
        date4 = date4 - oneday;
        date2.setTime(date4);
        
        date3 = new Date();
        date4 = date1;
        date4 = date4 + (oneday * parseInt(document.getElementById('datespeconday' + i).value)) + (oneday * parseInt(document.getElementById('datespecseldest' + i).value));
        date4 = date4 - oneday;
        date3.setTime(date4);
        
        QS = QS + '&checkin' + i + '=' + date2.getDate() + ' ' + Months[date2.getMonth()] + ' ' + date2.getFullYear();
        QS = QS + '&checkout' + i + '=' + date3.getDate() + ' ' + Months[date3.getMonth()] + ' ' + date3.getFullYear();
        
        if (i > 1)
        {
            if (document.getElementById('datespecintertype' + (i-1)).value == 'TRA')
                QS = QS + '&radiointer' + i + '=rail';
            else
                QS = QS + '&radiointer' + i + '=airf'
        }
        if (i == document.getElementById('numitindest').value)
        {
            QS = QS + '&airdateret=' + date3.getDate() + ' ' + Months[date3.getMonth()] + ' ' + date3.getFullYear();
        }
    }
    
    //Num Rooms/Adults/Children
    for (i = 0; i < document.main_form.numadts.length; i++)
    {
        if (document.main_form.numadts[i].value != 0)
        {
            numRooms = numRooms + 1;
            QS = QS + '&NumAdts' + (i + 1) + '=' + document.main_form.numadts[i].value;
            numAdts = numAdts + parseFloat(document.main_form.numadts[i].value);
            
            QS = QS + '&NumChds' + (i + 1) + '=' + document.main_form.numchds[i].value;
            numChds = numChds + parseFloat(document.main_form.numchds[i].value);
            for (j = 1; j <= document.main_form.numchds[i].value; j++)
            {
                //Check that at least one adult was selected for this room
                if (document.main_form.numadts[i].value == 0)
                {
                    alert("Please select at least one adult for room #" + (i + 1));
                    return false;
                }
                if (j == 1)
                {
                    //First child
                    if (document.main_form.chd1age[i].value == "0")
                    {
                        alert("Please select child 1 age for room #" + (i + 1));
                        return false;
                    }
                    QS = QS + '&Chd1Age' + (i + 1) + '=' + document.main_form.chd1age[i].value;
                }
                else if (j == 2)
                {
                    //Second child
                    if (document.main_form.chd2age[i].value == "0")
                    {
                        alert("Please select child 2 age for room #" + (i + 1));
                        return false;
                    }
                    QS = QS + '&Chd2Age' + (i + 1) + '=' + document.main_form.chd2age[i].value;
                }
                 else if (j == 3)
                {
                    //Third child
                    if (document.main_form.chd3age[i].value == "0")
                    {
                        alert("Please select child 3 age for room #" + (i + 1));
                        return false;
                    }
                    QS = QS + '&Chd3Age' + (i + 1) + '=' + document.main_form.chd3age[i].value;
                }
            }
        }
    }
    QS = QS + '&NumRooms=' + numRooms;
    //NumAdts/NumChds
    QS = QS + '&NumAdts=' + numAdts;
    QS = QS + '&NumChds=' + numChds;
    
    //Send the Request
    return QS;
    //document.location.href = '[ResPath]/STWMain.aspx?Action=FITSeqList' + QS;
}
function setAir(strChecked)
{
    if (strChecked == 'Y')
    {
        document.getElementById('Air').style.display = 'block';
        if (document.getElementById('itindepdateair'))
        {
            document.getElementById('itindepdateair').style.display = 'block';
            document.getElementById('itindepdatenoair').style.display = 'none';
        }
    }
    else
    {
        document.getElementById('Air').style.display = 'none';
        if (document.getElementById('itindepdateair'))
        {
            document.getElementById('itindepdateair').style.display = 'none';
            document.getElementById('itindepdatenoair').style.display = 'block';
        }
    }
}
function UpdateUpgrades(strDate)
{
    var i;
    var strSeq;
    
    if (document.getElementsByName('upgrade_' + strDate).length > 0)
    {
        for (i = 0; i < document.getElementsByName('upgrade_' + strDate).length; i++)
        {
            if (document.getElementsByName('upgrade_' + strDate).item(i).id.indexOf('_') > 0)
            {
                //Get the Seq for this item first
                strSeq = document.getElementsByName('upgrade_' + strDate).item(i).id.split('_')[2];
                
                if (document.getElementById('upgrade_' + strSeq))
                {
                    if (parseFloat(document.getElementsByName('upgrade_' + strDate).item(i).value) > 0)
                    {
                        //Greater than 0, add the "+"
                        document.getElementById('upgrade_' + strSeq).innerHTML = '<b class="red">Upgrade from +$' + parseFloat(document.getElementsByName('upgrade_' + strDate).item(i).value.replace(',','')) + '</b>';
                    }
                    else if(parseFloat(document.getElementsByName('upgrade_' + strDate).item(i).value) < 0)
                    {
                        //Less than 0, add the "-"
                        document.getElementById('upgrade_' + strSeq).innerHTML = '<b class="red">Reduction from -$' + -parseFloat(document.getElementsByName('upgrade_' + strDate).item(i).value.replace(',','')) + '</b>';
                    }
                    else
                    {
                        //0 means this is included
                        document.getElementById('upgrade_' + strSeq).innerHTML = '(included)';
                    }
                    
                    //Update the date for this Upgrade
                    if (document.getElementById('upgrade_date_' + strSeq))
                    {
                        document.getElementById('upgrade_date_' + strSeq).value = strDate;
                    }
                }
            }
        }
    }
}
function UpdateOtherDate()
{
    try
    {
        var datIn;
                
        var Months;
        
        Months = new Array(12);
        
        Months[0]  = "Jan";
        Months[1]  = "Feb";
        Months[2]  = "Mar";
        Months[3]  = "Apr";
        Months[4]  = "May";
        Months[5]  = "Jun";
        Months[6]  = "Jul";
        Months[7]  = "Aug";
        Months[8]  = "Sep";
        Months[9]  = "Oct";
        Months[10] = "Nov";
        Months[11] = "Dec";
        
        datIn = new Date();
        
        datIn.setTime(Date.parse(document.getElementById('txtotherdate').value));
        //Set Other Date to correct format
        document.getElementById('txtotherdate').value = datIn.getDate() + ' ' + Months[datIn.getMonth()] + ' ' + datIn.getFullYear();
        //Set Check-In
        document.getElementById('tbCheckIn').value = Months[datIn.getMonth()] + ' ' + datIn.getDate() + ', ' + datIn.getFullYear();
        //Add the number of days to get the correct Check-Out Date
        datIn.setDate(datIn.getDate() + [ProductNumDays]);
        
        //Set Check-Out
        document.getElementById('tbCheckOut').value = Months[datIn.getMonth()] + ' ' + datIn.getDate() + ', ' + datIn.getFullYear();
        
        //alert('CheckIn: ' + document.getElementById('tbCheckIn').value);
        //alert('Checkout: ' + document.getElementById('tbCheckOut').value);
    }
    catch (ex)
    {
        //alert('Error: ' + ex.message);
    }
}
function UpdateReturnDate()
{
    if (document.getElementById('chkAirY'))
    {
        try
        {
            var dat1, dat2, oneday;
            //var dat3;
            
            var Months;
            
            Months = new Array(12);
            
            Months[0]  = "Jan";
            Months[1]  = "Feb";
            Months[2]  = "Mar";
            Months[3]  = "Apr";
            Months[4]  = "May";
            Months[5]  = "Jun";
            Months[6]  = "Jul";
            Months[7]  = "Aug";
            Months[8]  = "Sep";
            Months[9]  = "Oct";
            Months[10] = "Nov";
            Months[11] = "Dec";
            
            oneday = 1000 * 60 * 60 * 24;
            
            //alert('tbCheckOut: ' + document.getElementById('tbCheckOut').value);
            dat1 = Date.parse(document.getElementById('tbCheckOut').value + ' 01:00:00');
            
            /*
            dat3 = new Date();
            dat3.setTime(dat1 + oneday);
            
            alert('Checkout + oneday: ' + dat3.toDateString());
            */
                        
            if (document.getElementById('postacc') != null)
            {
                if (document.getElementById('postacc').getAttribute('checked') != '')
                {
                    //alert('Updating the date, adding ' + document.getElementById('postaccdur').value + ' days to the date.');
                    dat1 = dat1 + oneday * (parseInt(document.getElementById('postaccdur').value));
                }
            }
            //dat1 = dat1 - oneday;
            dat2 = new Date();
            dat2.setTime(dat1);
            
            //alert('Checkout - oneday: ' + dat2.toDateString());
            document.getElementById('airdateret').value = dat2.getDate() + ' ' + Months[dat2.getMonth()] + ' ' + dat2.getFullYear();
        }
        catch (ex)
        {
            //alert('Error: ' + ex.message);
        }
    }
}
function UpdateOutboundDate()
{
    if (document.getElementById('chkAirY'))
    {
        try
        {
            //alert('1');
            var dat1, dat2, oneday;
            //alert('2');
            var Months;
            //alert('3');
            Months = new Array(12);
            //alert('4');
            Months[0]  = "Jan";
            Months[1]  = "Feb";
            Months[2]  = "Mar";
            Months[3]  = "Apr";
            Months[4]  = "May";
            Months[5]  = "Jun";
            Months[6]  = "Jul";
            Months[7]  = "Aug";
            Months[8]  = "Sep";
            Months[9]  = "Oct";
            Months[10] = "Nov";
            Months[11] = "Dec";
            //alert('5');
            oneday = 1000 * 60 * 60 * 24;

            //alert('tbCheckin: ' + document.getElementById('tbCheckIn').value);
            dat1 = Date.parse(document.getElementById('tbCheckIn').value + ' 01:00:00');
            
            if (document.getElementById('preacc') != null)
            {
                if (document.getElementById('preacc').getAttribute('checked') != '')
                {
                    //alert('Updating the date, subtracting ' + document.getElementById('preaccdur').value + ' days to the date.');
                    dat1 = dat1 - (oneday * parseInt(document.getElementById('preaccdur').value));
                }
            }
            
            dat2 = new Date();
            dat2.setTime(dat1);
            
            document.getElementById('airdateout').value = dat2.getDate() + ' ' + Months[dat2.getMonth()] + ' ' + dat2.getFullYear();
        }
        catch (ex)
        {
            //alert('Error: ' + ex.message);
        }
    }
}
function SetDefaultCarrier()
{
    var sdefaultcarrier;
    var sairportlist;
    var sairport;
    var i = 0;

    sdefaultcarrier = document.getElementById('defaultcarrier').value.toUpperCase();
    //alert('default carrier: ' + sdefaultcarrier);
    if (sdefaultcarrier == '')
    {
        return;
        //no default carrier, exit
    }
    sairport = document.getElementById('cbOrigCity').value.toUpperCase();
    //alert('selected airport: ' + sairport);
    if (sairport == '')
    {
        return;
        //no departure city selected.
    }
    sairportlist = document.getElementById('defaultcarriercities').value.toUpperCase();
    //alert('default carrier cities: ' + sairportlist);
    if (sairportlist.indexOf(sairport) >= 0)
    {
    //default the carrier and exit.
        //document.getElementById('cbcarrier').options.value = sairport;
        for (i = 0;i < document.getElementById('cbcarrier').options.length-1; i++)
        {
            if (document.getElementById('cbcarrier').options[i].value == sdefaultcarrier)
            {
                document.getElementById('cbcarrier').options.selectedIndex = i;
                return;
            }
        }        
        //alert('after setting airport: ' + document.getElementById('cbcarrier').value);
    }
    else
    {
        document.getElementById('cbcarrier').options.selectedIndex = 0;//any
    }
    //done!
}

function trim(text)
{
	return text.replace(/^\s+|\s+$/g,'');
}
function ltrim(text)
{
	return text.replace(/^\s+/,'');
}
function rtrim(text)
{
	return text.replace(/\s+$/,'');
}