﻿gIsImagePreloadDone = false; // becomes true after loading of navigation

/*
	dom checker
*/
dom = (document.getElementById)? true : false;
ie4 = (document.all)? true : false;
ns6= (dom && !ie4)? true : false;
ns4 = (document.layers)? true:false;

function toggleDisplay(obj1Name, obj2Name) {
	/*
		function to show and hide the signin and signout ids 
		made for the GCCI login bar
	*/
	
	// get the object
	objSignin = getObject(obj1Name);
	objSignout = getObject(obj2Name);
	
	if (objSignout.style.display == 'none') {
		// show the singout
		objSignout.style.display = 'block';
		objSignin.style.display = 'none';
	} else {
		// show the singin
		objSignout.style.display = 'none';
		objSignin.style.display = 'block';
	}
}

function toggleForm(objName, varStatus) {
	/*
		function to show and hide the form elements 
		made for the review and reserve and join pages
	*/
	
	// get the object
	objSection = getObject(objName);
	
	if (varStatus == 'show') {
		// show the section
		objSection.style.display = 'block';
	} else {
		// hide the section
		objSection.style.display = 'none';
		
	}
}

function makeRand(maxNum) {
	/*
		creates a random number between 1 -> maxNum
	*/
	rnd = Math.round((maxNum * Math.random()));
	rnd = (rnd == 0)? makeRand(maxNum) : rnd;
	return rnd;
}

function changeNavBg(id, bkImage, base) {
	/*
		function to change the background for the navigation. 
		Takes the td id for that navigation item and the name 
		of the background image and replaces them depending
		on the state that they need to change to or out of.
	*/
	
	// get the 3 images to be changed out
	newImagel = "url(" + base + "images/nav/" + bkImage + "-l.gif)";
	newImage = "url(" + base + "images/nav/" + bkImage + ".gif)";
	newImager = "url(" + base + "images/nav/" + bkImage + "-r.gif)";
	
	// get the object
	tdObjl = getObject(id + "l");
	tdObj = getObject(id);
	tdObjr = getObject(id + "r");
	
	// change out the different ids to the new images
	if (tdObj) {
		tdObjl.style.backgroundImage = newImagel;
		tdObj.style.backgroundImage = newImage;
		tdObjr.style.backgroundImage = newImager;
	} else {
		return;
	}
}

function getObject(oID) {
	/*
		function that returns the element based on the browser
		capitalities - ns4 will return null if the obj doesn't exist
	*/
	if (dom) {
		obj = document.getElementById(oID);
	} else if (ie4) {
		obj = document.all(oID);
	} else if (ns4) {
		obj = document.layers(oID);
		if (!obj)
			return null;
	}
	return obj;
}


function promoChanger() {
	/*
		this function changes out the images for 
		the promos so that there are two more
		in the changing area - will loop around 
		and around
	*/
	promoImgName1 = this.promoAreaExt + "Img1";
	promoImgName2 = this.promoAreaExt + "Img2";
	
	obj1 = document.images[promoImgName1];
	obj2 = document.images[promoImgName2];
	
	imgArrayLength = this.imageName.length - 1;
	
	nextPromoPlace = ((this.currentPromoPlace + 1) > imgArrayLength)? 0 : this.currentPromoPlace + 1;
	nextPlusPromoPlace = ((nextPromoPlace + 1) > imgArrayLength)? 0 : nextPromoPlace + 1;
		
	this.currentPromoPlace = nextPlusPromoPlace;
	
	obj1.src = '../images/promo/' + this.imageName[nextPromoPlace]
	obj2.src = '../images/promo/' + this.imageName[nextPlusPromoPlace]
}

function ldLinks() {
	/*
		function to load the images into an array when the 
		loadLinks part of the object is called
	*/
	args=ldLinks.arguments;
	for (var i=0;i<args.length;i++) {
		argsSplt = args[i].split("|")
		this.linkName[i] = argsSplt[0]
		this.linkTarget[i] = ((argsSplt[1] != "") && (argsSplt[1] != null))? argsSplt[1] : "";
	}
}

function ldImages() {
	/*
		function to load the images into an array when the 
		loadImages part of the object is called
	*/
	args=ldImages.arguments;
	for (var i=0;i<args.length;i++) {
		this.imageName[i] = args[i]
	}
}

function linkOut(lID) {
	/*
		function that controls what the user will link out to when
		a promotion is clicked
	*/
	imgArrayLength = this.imageName.length - 1;
	if (lID == 1) {
		place = this.currentPromoPlace;
	} else if (lID == 2) {
		place = ((this.currentPromoPlace + 1) > imgArrayLength)? 0 : this.currentPromoPlace + 1;
	}
	if (this.linkTarget[place] != "") {
		alert(this.linkName[place])
		window.open(this.linkName[place], this.linkTarget[place]);
	} else {
		document.location.href = this.linkName[place];
	}
}

function promoImageChange(AreaExt) {
	/*
		object to handle the promo images movements
		
		it changes out the two images within the based on the
		promoAreaExt variable as long as that extension has the Img1 and Img2
		attached to the end of the image. eg. ptnrImg1
	*/
	this.currentPromoPlace = 0;
	this.imageName = Array();
	this.linkName = Array();
	this.linkTarget = Array();
	this.loadImages = ldImages;
	this.loadLinks = ldLinks;
	this.promoAreaExt = AreaExt;
	this.promoNext = promoChanger;
	this.promoLink = linkOut;
}

partners = new promoImageChange('ptnr');
partners.loadImages("promo-holding-partner.jpg","promo-holding-partner-1.jpg","promo-holding-partner-2.jpg","promo-holding-partner-3.jpg","promo-holding-partner-4.jpg");
partners.loadLinks("http://www.digitaria.com", "http://www.google.com", "http://www.yahoo.com","http://www.google.co.nz");

offers = new promoImageChange('offr');
offers.loadImages("promo-holding-partner.jpg","promo-holding-partner-1.jpg","promo-holding-partner-2.jpg","promo-holding-partner-3.jpg","promo-holding-partner-4.jpg");
offers.loadLinks("http://www.digitaria.com|blank", "http://www.google.com", "http://www.yahoo.com|blank","");

function preload(imgObj,imgSrc) {
	/*
		function to preload images
	*/
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

function changeImage(imgName,imgObj,layer) {
	/*
		function to do rollovers of images
	*/
	if (gIsImagePreloadDone == true) {
		if (document.images) {
			if (document.layers) {
				if (layer!=null){
					eval('document.layers.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
				} else {
					document.images[imgName].src = eval(imgObj+".src");
				}
			} else {
				document.images[imgName].src = eval(imgObj+".src");
			}
		}
	}
}

function call_jumpMenu(selObj,restore){ //v3.0
  if(selObj.options[selObj.selectedIndex].value != " ")
  {
	  target='parent';
	  eval("parent.location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
  }else{
  return false;
  }
}
//RESERVATION FORM FUNCTIONS
function setResvFormAction(hotelId){
	var f = document.room_reservations;
	var myFormAction = f.action;

	myFormAction = updateQueryStringElement(myFormAction, "pHotelId", hotelId);

	f.hdshowHotelRooms.value = "1";
	f.action = myFormAction;
	f.submit();
}

function updateQueryStringElement(myQueryString, elementName, elementValue)
{
	var pairs = myQueryString.split("&");
	var newQueryString = ""
	var paramFound = false;

	for (var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos== -1) continue;
		var argName = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);

		if (argName==elementName)
		{
			value = elementValue;
			paramFound = true;
		}
		if (i == 0)
			newQueryString = argName + "=" + value
		else
			newQueryString = newQueryString + "&" + argName + "=" + value;
	}
	// if we didn't find the param in the string, let's add it
	if (! paramFound)
		newQueryString = newQueryString + "&" + elementName + "=" + elementValue;

	return newQueryString;
}

function chkDate(txtBoxName, txtBox)
{
	var today = new Date(2006, 11, 7, 20, 56, 26);
	var tomorrow = new Date();;
	var nextDate = today.getDate() + 1;
	var val = txtBox.value;
	var defaultDate = today;

	tomorrow.setDate(nextDate);
	if (txtBoxName == "Check-Out")
		defaultDate = tomorrow;

	if (val == "")
	{
		alert("The " & txtBoxName + " Date cannot be left blank.");
		txtBox.value = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
	}
	else
	{
		var newValue = Date.parse(val);
		var realDate = new Date(val);
		var realYear = realDate.getFullYear();

	//	set the value of today (w/ only mm/dd/yyyy) i.e. not incl time so we can parse it later and compare them
		var todaysDate = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();

	 //if use 2 digit years, need to convert to post 2k
		if (realYear < 2000)
			realYear = realYear + 100;

		realDate = (realDate.getMonth() + 1) + "/" + realDate.getDate() + "/" + realYear;
		newValue = Date.parse(realDate)

		// check to see if we're dealing with a date or numbers
		if( isNaN(newValue))
		{
			alert(val + " is not a valid Date.\nPlease enter a valid date.");
		}
		else
		{
			// next need to check wh/ this is a valid date
			if (val != realDate)
			{
				val = realDate
				txtBox.value = val
			}
			// need to check to see whether it is after today
			if (newValue < Date.parse(todaysDate))
			{
				var alertVal =	"You are not allowed to book any days earlier than " + todaysDate + " (0 days in the future).\nIt has been changed."
				alert(val + " is before today's date.\nIt has been changed.");
			}
			else
			{
				return;
			}
	    }
		txtBox.value = (defaultDate.getMonth() + 1) + "/" + defaultDate.getDate() +"/" + defaultDate.getFullYear();
	}
	if (txtBoxName == "Check-In") updateOut(txtBox.value)

	if (txtBox.type != "hidden")
	{
	    txtBox.focus();
	}
	else
	{
		// need to update individual drop downs
		updateDropDowns (txtBoxName, txtBox);
	}
    return false;
}

/*
This file contains javascript functions that are used globally in various 
web pages throughout the web site.  NOTE: functions are ALPHABETICAL so
if you add a function to the file please place it accordingly and list it
below...

FUNCTIONS IN THIS FILE:
	CharacterLimiterCounter
	CheckboxArrayValidation
	CheckboxValidation
	ConcatDateFields
	CreateSubmitDataString
	DateValidation
	DigitValidation
	EmailAddressValidation
	EmptyValidation
	FutureDateValidation
	GoToURL
	IsActualDate
	IsValidDate
	LengthValidation
	LimitTextArea	
	MembershipNumberValidation
	MinLengthValidation
	NewWindow
	RadioGroupValidation
	SelectValidation
	SpecialCharValidation
	StateValidation
	SubmitEnter
	SubmitFormOnlyOnce
	Trim
*/
	
// GLOBAL VARIABLES				// USED BY FUNCTION
var submitCount = 0;			// SubmitFormOnlyOnce
var g_aUSStates = new Array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","AE","AP","AA");
var g_aCanadianStates = new Array("AB","BC","MB","NB","NF","NT","NS","ON","PE","PQ","SK","YT","QC","NL");
var g_aAustralianStates = new Array("AC","NW","NO","QL","SA","TS","VC","WT","SU");
var g_strAsiaCountries = new Array("BGD","BTN","BRN","KHM","TMP","HKG","IND","IOT","IDN","JPN","KAZ","LAO","MAC","MYS","MDV","MNG","MMR","NPL","PHL","KOR","LKA","TWN","THA","UZB","VNM");


/************************************************************************
* CharacterLimiterCounter
*	limits character count and shows dynamic count of characters as user 
*   is typing them in the text area
************************************************************************/
function CharacterLimiterCounter(field, maxlimit, cntfield) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}


/************************************************************************
* CheckboxArrayValidation
*	shows a message (alertText) and returns false if no items in checkbox 
*   have been checked
************************************************************************/
function CheckboxArrayValidation(entered, alertText)
{
	var countChecked = 0;
	for (var i = 0; i < entered.length; i++)
	{
		// check to see if each is checked 
		if (entered[i].checked == true)
			// if any checked, validation passed 
			{ 
				return true;
			}
	}
	// if got to here, no checkboxes checked 
	if (alertText)
	{
		alert(alertText);
	} 
	return false;
}


/************************************************************************
* CheckboxValidation
*	shows a message (alertText) and returns false if checkbox has not been 
*	checked
************************************************************************/
function CheckboxValidation(entered, alertText)
{
	var strValue = entered.checked;
//alert('str'+strValue);
	if (strValue == false) 
	{
		if (alertText)
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}


/************************************************************************
* ConcatDateFields
* 	takes values from month, day and year fields and concatenates 
* 	them into MM/DD/YY(YY) format
************************************************************************/
function ConcatDateFields(fldMonth, fldDay, fldYear)
{
	var strDate = fldMonth.options[fldMonth.selectedIndex].value + "/" + fldDay.options[fldDay.selectedIndex].value + "/" + fldYear.options[fldYear.selectedIndex].value;
	return strDate;
}


/************************************************************************
* CreateSubmitDataString
* 	for the passed form returns a string of all form inputs in the 
*   format [field name]: [field value][new line]
************************************************************************/
function CreateSubmitDataString(theForm)
{
	var strValues = "";
	with (theForm)
	{
		// clear any current value
		submit_data.value = "";
		
		for (var i = 0; i < length; i++)
		{
			strValues = strValues + elements[i].name + ": ";
			if (elements[i].type == "select-one")
				strValues = strValues + elements[i].options[elements[i].selectedIndex].value + "\r\n";
			else
				strValues = strValues + elements[i].value + "\r\n";
		}
	}
	return strValues;
}


/************************************************************************
* DateValidation
* 	Accepts numeric month, date and year and determines if the date 
* 	specified is actually a valid calendar date
*	(eg: no such date as February, 31...)
************************************************************************/
function DateValidation(inputDate, inputMonth, inputYear, alertText)
{
	var bValid = true;
	var i_Date = parseInt(inputDate);
	var i_Month = parseInt(inputMonth);
	var i_Year = parseInt(inputYear);
	
	switch(i_Month) 
   	{
		case 2:
        //February
	        if (i_Year == Math.round(i_Year / 4) * 4)
	       	//leap year
			{
		       	if (i_Date > 29)
		       		bValid = false;
			}
           	else
			//non-leap year
			{
    	        if (i_Date > 28)
					bValid = false;									
			}
			break;
		case 4 :
        //April
        	if (i_Date > 30)
				bValid = false;
	        break;
        case 6:
		//June
	        if (i_Date > 30)
    			bValid = false;
		    break;		
        case 9:
        //September
	        if (i_Date > 30)
    			bValid = false;
			break;
        case 11:
        //November
        	if (i_Date > 30)
				bValid = false;
			break;
    }

	if (bValid == false)
	{
	  	alert(alertText);
		return false;
	}
	else
		return true;
}	


/************************************************************************
* DigitValidation
* 	verifies numeric value was entered and that it's length is between
* 	the passed min and max
************************************************************************/
function DigitValidation(entered, lenMin, lenMax, alertText)
{
	var strValue = Trim(entered.value);	
	var checkvalue=parseFloat(strValue);
	if ( (parseFloat(lenMin)==lenMin && strValue.length<lenMin) || (parseFloat(lenMax)==lenMax && strValue.length>lenMax) || strValue!=checkvalue || (strValue.indexOf(".")>0) )
	{
		if (alertText) 
			alert(alertText);
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}


/************************************************************************
* EmailAddressValidation
*	shows a message (alertText) and returns false if no e-mail address 
*	has been specified in the input text box (entered) or if the
*	address appears invalid due to a number of conditions checked
************************************************************************/
function EmailAddressValidation(entered, alertText)
{
	with (entered)
	{
		var len=value.length
		var apos=value.indexOf("@");
		var dotpos=value.lastIndexOf(".");
		var lastpos=value.length-1;
		// if length = 0
		// or "@" is the first character or doesn't exist
		// or "." doesn't follow "@" with at least 2 spaces between them
		// or there are more than 3 characters following the "."
		// or there are less than 2 characters following the "."
		if (len==0 || apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) 
		{
			if (alertText) 
				alert(alertText);
			entered.focus();
			return false;
		}
		else 
			return true;
	}
}

/************************************************************************
* EmptyValidation
*	shows a message (alertText) and returns false if no data has been 
*	entered in the input text box (entered)
************************************************************************/
function EmptyValidation(entered, alertText)
{
	var strValue = Trim(entered.value);
	if (strValue == null || strValue == "" || strValue == "undefined")
	{
		if (alertText)
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}


/************************************************************************
* FutureDateValidation
*	Accepts string in date format ("mm/dd/yyyy") and verifies that date
*   is the current day OR occurs in the future.
************************************************************************/
function FutureDateValidation(inputDate, alertText)
{
	var t_day;
	var t_month;
	var t_year;
	var t_date;
	var i_day;
	var i_month;
	var i_year;
	var i_date;
	var now = new Date();
	var compareDate = new Date(inputDate);
	
	// create "yyyymmdd" string out of today's date
	t_day = now.getDate();
	if (t_day < 10)
		t_day = "0" + t_day.toString();
	else
		t_day = t_day.toString();
	t_month = now.getMonth() + 1;
	if (t_month < 10)
		t_month = "0" + t_month.toString();
	else
		t_month = t_month.toString();
	t_year = now.getFullYear().toString();
	t_date = t_year + t_month + t_day;

	// create "yyyymmdd" string out of input date
	i_day = compareDate.getDate();
	if (i_day < 10)
		i_day = "0" + i_day.toString();
	else
		i_day = i_day.toString();
	i_month = compareDate.getMonth() + 1;
	if (i_month < 10)
		i_month = "0" + i_month.toString();
	else
		i_month = i_month.toString();
	i_year = compareDate.getFullYear().toString();
	i_date = i_year + i_month + i_day;

	// if input date occurs before today's date
	if (i_date < t_date)
	{
		// show alert and return false (did not pass validation)
		alert(alertText);
		return false;
	}
	// otherwise, passed validation
	else
		return true;
}


/************************************************************************
* GoToURL
*	Redirects the main frame in a frameset to page or anchor specified
*	in value property of select or option item named "dest"
************************************************************************/
function GoToURL(form) {
        var myindex=form.dest.selectedIndex
        window.open(form.dest.options[myindex].value, target="_self"); //change these both to "yes" to get the toolbar
}


/************************************************************************
* IsValidDate
* 	Checks for the following valid date formats: 
* 	MM/DD/YYYY OR MM-DD-YYYY 
************************************************************************/
function IsValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// To require a 4 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		return false;
	}
	if (day < 1 || day > 31) {
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			return false;
   		}
	}
	return true;  // date is valid
}


/************************************************************************
* IsValidDate - OLD DO NOT USE
* 	Checks for the following valid date formats: 
* 	MM/DD/YYYY OR MM-DD-YYYY 
*	Also separates date into month, day, and year variables 
************************************************************************/
/*
function IsValidDate(dateField) 
{ 

	var dateStr = dateField.value;

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; 

	var matchArray = dateStr.match(datePat); // is the format ok? 
	if (matchArray == null) 
	{ 
		alert("\"Date of Birth\" must be in entered in the format mm/dd/yyyy.") 
		dateField.select();
		dateField.focus();
		return false; 
	} 

	var month = matchArray[1]; // parse date into variables 
	var day = matchArray[3]; 
	var year = matchArray[4]; 

	if (month < 1 || month > 12) 
	{ // check month range 
		alert("\"Date of Birth\" month must be between 1 and 12."); 
		dateField.select();
		dateField.focus();
		return false; 
	} 

	if (day < 1 || day > 31) 
	{ // check day range
		alert("\"Date of Birth\" day must be between 1 and 31."); 
		dateField.select();
		dateField.focus();
		return false; 
	} 
	
	return true; // date is valid 
} 
*/

/************************************************************************
* LengthValidation
*	shows a message (alertText) and returns false if the length of
*	the input text (entered) is too short or too long
************************************************************************/
function LengthValidation(entered, lenMin, lenMax, alertText)
{
	var strValue = Trim(entered.value);
	if (strValue.length < lenMin || strValue.length > lenMax)
	{
		if (alertText) 
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}


/************************************************************************
* LimitTextArea
*	limits number of characters entered into textarea input.
*	once character count exceeds limit, characters are trimmed 
*   as they are typed
************************************************************************/
function LimitTextArea(field, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}


/************************************************************************
* MembershipNumberValidation
*	shows a message (alertText) and returns false if the membership
*	number (entered) does not meet the criteria set up in the function
************************************************************************/
function MembershipNumberValidation(entered, alertText)
{
	var strValue = Trim(entered.value);
	// requirements:
	//		- begin with '600663'
	//		- length of exactly 16 digits
	//		- numeric only
	if ((strValue.substring(0,6) != '600663') ||
		(strValue.length != 16) ||
		(strValue != parseFloat(value)) )
	{
		if (alertText) 
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}

/************************************************************************
* MinLengthValidation
*	shows a message (alertText) and returns false if the length of
*	the input text (entered) is too short
************************************************************************/
function MinLengthValidation(entered, lenMin, alertText)
{
	var strValue = Trim(entered.value);
	if (strValue.length < lenMin )
	{
		if (alertText) 
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}

/************************************************************************
* NewWindow
*	opens a new browser window with the specified url, window name
*	and other parameter specs
************************************************************************/
function NewWindow(URL, name, specs) 
{
	var anon_win = window.open(URL, name, specs);
}

/************************************************************************
* RadioGroupValidation
*	shows a message (alertText) and returns false if no selection has 
*	been made between the items in the radio group (groupName)
************************************************************************/
function RadioGroupValidation(groupName, alertText)
{
	var allEmpty = true;
	for (index = 0; index < groupName.length; index++)
	{
  		if (groupName[index].checked)
	  	{
	   		allEmpty = false; //found one to be selected
	    	break;            //get out of the loop
	  	}
	}
	if (allEmpty)
	{
		if (alertText)
			alert(alertText);
		return false;
	}
	else
		return true;
}

/************************************************************************
* SelectValidation
*	shows a message (alertText) and returns false if no data has been 
*	selected in the dropdown list (entered)
************************************************************************/
function SelectValidation(entered, alertText)
{
	var idx = entered.selectedIndex;

	with (entered.options[idx])
		{
		if ( (value == 0) || (value == "") || (value == null) )
		{
			if (alertText) 
			{
				alert(alertText);
			}
			entered.focus();
			return false;
		}
		else 
			return true;
	}
}


/************************************************************************
* SpecialCharValidation
* 	allows only certain characters to be entered (to prevent foreign
*   character issues)
************************************************************************/
function SpecialCharValidation(entered, alertText)
{
	var strValidate = entered.value;
	with (strValidate)
	{
		for (i = 0; i < length; i++)
		{
			ch = charAt(i);
			if ( !(ch >= 'a' && ch <= 'z') 
				&& !(ch >= 'A' && ch <= 'Z') 
				&& !(ch == ' ') 
				&& !(ch == ',')
				&& !(ch == '-')
				&& !(ch == '.') 
				&& !(ch == '\'')
				&& !(ch == '\/')
				&& !(ch == '(')
				&& !(ch == ')')
				&& !(ch == '@')
				&& !(ch == '_')
				&& !(ch >='0' && ch <='9'))
			{
				if (alertText) 
					alert(alertText);
				entered.focus();
				entered.select();
				return false;
			}
		}
	}
	return true;
}


/************************************************************************
* StateValidation
*	shows a message and returns false if no state has been selected 
*	in the state dropdown list (stateField) when the country selected
*	in the country dropdown list (countryField) is United States, Canada
*   or Australia.  if United States, Canada or Austraili is selected,
*   verify a valid State/Province/Territory is selected for the country.
* 	if the country is NOT one of the afforementioned, no state may be 
*   selected so an alert is shown and false is returned.
************************************************************************/
function StateValidation(countryField, stateField)
{
	var strCountry = countryField.value;
	var strState = stateField.options[stateField.selectedIndex].value;
	if ( ( (strCountry=="US") || (strCountry=="USA") ) ||
		 ( (strCountry=="CA") || (strCountry=="CAN") ) ||
		 ( (strCountry=="AU") || (strCountry=="AUS") ) )
	{
		if ( (strState == 0) || (strState=="") || (strState == null) )
		{
			alert("Please select a State/Province/Territory for US/Canada/Australia.");
			stateField.focus();
			return false;
		}
		else
		{
			switch (strCountry)
			{
				case "USA":
				{			     
				    for (i=0;i<g_aUSStates.length;i++) {
			                if (strState==g_aUSStates[i]) {
			                        return(true);
			                }
			        }
					alert("Please select a valid State for the United States.");
					stateField.focus()
					return false;
				}
				case "CAN":
				{			     
				    for (i=0;i<g_aCanadianStates.length;i++) {
			                if (strState==g_aCanadianStates[i]) {
			                        return(true);
			                }
			        }
					alert("Please select a valid Province for Canada.");
					stateField.focus()
					return false;
				}
				case "AUS":
				{			     
				    for (i=0;i<g_aAustralianStates.length;i++) {
			                if (strState==g_aAustralianStates[i]) {
			                        return(true);
			                }
			        }
					alert("Please select a valid Territory for Australia.");
					stateField.focus()
					return false;
				}
			}
		}				
		return true;
	}
	else
	{
		if ( (strState != 0) && (strState != "") && (strState != null) )
		{
			alert("Please review your State/Province/Territory and Country selections for accuracy.");
			stateField.focus();
			return false;
		}
		else
			return true;
	}
}


/************************************************************************
* SubmitEnter
*	used in onkeypress event of form inputs to allow enter key to 
*   kick off form submission process.  works with ie and netscape.
************************************************************************/
function SubmitEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return false;
	
	if (keycode == 13)
	   return true;
	else
	   return false;
}


/************************************************************************
* SubmitFormOnlyOnce
*	once the form's submit button is clicked, prevents the form from 
*   being submitted more than once.  
*   NOTE: Make sure to call this function AFTER all validation functions
************************************************************************/
function SubmitFormOnlyOnce()
{
   if (submitCount == 0)
   {
      submitCount++;
      return true;
   }
   else 
   {
      alert("This form has already been submitted.  Thanks!");
      return false;
   }
}

/************************************************************************
* Trim
*	Trims leading and trailing spaces and tabs. 
************************************************************************/
function Trim(sData) 
{
	var sTrimmed = String(sData);
	sTrimmed = sTrimmed.replace(/(^[ |\t]+)|([ |\t]+$)/g, '');
	return sTrimmed;
}





