// Default for ajax call
		var xmlHttp;

// Function for creating a new xml object.
		function GetXmlHttpObject() { 
			var objXMLHttp=null
			if (window.XMLHttpRequest) {
				objXMLHttp=new XMLHttpRequest()
			}
			else if (window.ActiveXObject) {
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			return objXMLHttp
		}


// These three prototypes remove white space.
String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

String.prototype.ltrim=function(){
    return this.replace(/^\s*/g,'');
}

String.prototype.rtrim=function(){
    return this.replace(/\s*$/g,'');
}

// Make sure they are entering a numeric value into a text field.
function verifyNum(tField) {
	
	if(tField.value<0) tField.value = (tField.value * -1)

	var TO 	= tField.value;
	var nTO = 0;
	var nib = 0;

	if(isNaN(TO)){
		for (i=0;i<TO.length;i++) {
			nib = TO.substring(i,i+1);
			if(!isNaN(nib) && nib != " ") {
				nTO += nib;
			}
		}
	}
	else { nTO = TO }
	
	nTO = Math.round(nTO);

	// Only change the form field if the value has changed.
	if (tField.value != nTO) tField.value = (nTO*1);
}

// Make sure they are entering a numeric value into a text field, allowing for decimals.
function verifyDec(tField) {
	
	if(tField.value<0) tField.value = (tField.value * -1)

	var TO 	= tField.value;
	var nTO = 0;
	var nib = 0;

	if(isNaN(TO)){
		for (i=0;i<TO.length;i++) {
			nib = TO.substring(i,i+1);
			if((!isNaN(nib) && nib != " ")||nib == ".") {
				nTO += nib;
			}
		}
	}
	else { nTO = TO }
	// Only change the form field if the value has changed.
	if (tField.value != nTO) tField.value = (nTO*1);
}


// Function for formatting currency.
	function formatCurrency(num,dolSign) {
		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;
		// If they want a dollar sign and commas include it, otherwise just format it.
		if (dolSign) {
			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);
		} 
		else {
			return (((sign)?'':'-') + num + '.' + cents);
		}
	}

// Function for validating U.S. Zip codes
		function isZip(s) 
		{
		     // Check for correct zip code
		     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		 
		     if (!reZip.test(s)) {
		          return false;
		     }
		 
		return true;
		}
		
// Function for validating Canadian Postal Codes.
		function isPostal(postalcode) {
			if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
			else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z](-|\s)\d[a-zA-Z]\d$/) != -1) return true;
			else return false;
		}
 

// Function for validating an email address.
	var testresults
	function checkEmail(emailIN){
		var str=emailIN
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
			return true
		else{
			return false
		}
	}

// Function for returning how old someone is.
	function getAge(day,month,year) {
		var today = new Date();
		var thisDay = today.getDate(), thisMonth = today.getMonth()+1, thisYear = today.getFullYear();
	    var yearsold = thisYear - year, monthsold = 0, daysold = 0, string = '';
	
	    if (thisMonth >= month) monthsold = thisMonth - month;
	    else { yearsold--; monthsold = thisMonth + 12 - month; }
	
	    if (thisDay >= day)daysold = thisDay - day;
	    else {
	        if (monthsold > 0) monthsold--;
	        else { yearsold--; monthsold+=11; }
	        daysold = thisDay + 31 - day;
	    }
	
	    if (yearsold < 0) return '';
	
	    if ((yearsold == 0) && (monthsold == 0) && (daysold == 0))
	        return '';
	
	    if (yearsold > 0) {
	        string = yearsold + ' year';
	        if (yearsold > 1) string += 's';
	        string += ' ';
	    }
	
	    if (monthsold > 0) {
	        string += monthsold + ' month';
	        if (monthsold > 1) string += 's';
	        string += ' ';
	    }
	
	    if (daysold > 0) {
	        string += daysold + ' day';
	        if (daysold > 1) string += 's';
	        string += ' ';
	    }
	
	    return yearsold;
	}

	
// This is a countdown timer function.
// You just need to pass the year, month, day, hour, minute, second of the 
// future date to countdown to. Also you will pass divID which is the ID
// of the div that will contain the countdown.
	var _countDowncontainer=0;
	var _currentSeconds=0; 

	function ActivateCountDown(strContainerID, initialValue) {
		_countDowncontainer = document.getElementById(strContainerID);        
		if (!_countDowncontainer) {        
			alert("count down error: container does not exist: "+strContainerID+            "\nmake sure html element with this ID exists");        
			return;    
		}        
		SetCountdownText(initialValue);    
		window.setTimeout("CountDownTick()", 1000);
	} 
	function CountDownTick() {    
		if (_currentSeconds <= 0) {        
			var strText = "<b class='re'>Time Expired. Spaces Released.</b>";
			_countDowncontainer.innerHTML = strText;
			
			alert("Time Expired.\n\nThese spaces are no longer being held.\n\nYou will need to select a flight again.");        
	
			document.doChange.submit();
		}        
		SetCountdownText(_currentSeconds-1);    
		window.setTimeout("CountDownTick()", 1000);
	} 
// Set text for countdown.
	function SetCountdownText(seconds) {
		//store:    
		_currentSeconds = seconds;        
		//get minutes:    
		var minutes=parseInt(seconds/60);        
		//shrink:    
		seconds = (seconds%60);        
		//get hours:    
		var hours=parseInt(minutes/60);        
		//shrink:    
		minutes = (minutes%60);        
		//build text:    
		
		if (_currentSeconds >= 120) {
			var strText = "<b class='gr'>" + minutes + " minute" + ((_currentSeconds >= 120)?"s ":"&nbsp; ") + AddZero(seconds) + " seconds." + "</b>";
		}
		if (_currentSeconds < 120 && _currentSeconds >= 60) {
			var strText = "<b class='or'>" + minutes + " minute" + ((_currentSeconds < 60)?"s ":"&nbsp; ") + AddZero(seconds) + " seconds." + "</b>";
		}
		if (_currentSeconds < 60) {
			var strText = "<b class='re'>" + minutes + " minutes " + AddZero(seconds) + " seconds." + "</b>";
		}
		/*	Changed to only show minutes and seconds.
			var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);	*/
	
		//apply:    
		_countDowncontainer.innerHTML = strText;
	} 

// Just as it sounds.
	function AddZero(num) {    
		return ((num >= 0)&&(num < 10))?"0"+num:num+"";
	} 


// Function for validating a time field.
// Pass in value timeStr as "h:mm tt"
	function isValidTime(timeStr) {
	
		// Checks if time is in HH:MM:SS AM/PM format.
		// The seconds and AM/PM are optional.
		var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
		
		var matchArray = timeStr.match(timePat);
		if (matchArray == null) {
			//alert("Time is not in a valid format.");
			return false;
		}
		hour = matchArray[1];
		minute = matchArray[2];
		second = matchArray[4];
		ampm = matchArray[6];
		
		if (second=="") { second = null; }
		if (ampm=="") { ampm = null }
		//Hour must be between 1 and 12.
		if (hour < 0  || hour > 12) { return false; }
		//must specify AM or PM.
		if (ampm == null) { return false; }
		//Minute must be between 0 and 59.
		if (minute<0 || minute > 59) { return false; }
		
		//Valid time, return true;
		return true;
	}

// Function for formatting and validating a voucher expiry date.
	function formatExpiryDate(dateIN,doExpired) {
		try {
			// Set dIN to dateIN.value
			var dIN = dateIN.value;
			// Set default var to hold date value.
			var d = "";
			for(i=0;i<dIN.length;i++) { //Strip non-numeric characters and replace with a dash.
				if(!isNaN(dIN.charAt(i))){
					d = d + dIN.charAt(i);
				}
				else d = d + "-";
			}
			// Set d to an array of values.
			d = d.split("-");
	
			// Make sure each field in the array has the right length, if not add a zero for day and month.		
			if(d[0].length == 1) (d[0] = "0" + d[0]) * 1; 	// Pad month with leading zero if it's only one char.
			if(d[1].length == 1) (d[1] = "0" + d[1]) * 1; 	// Pad day with leading zero if it's only one char.
			if(d[2].length == 2) (d[2] = "20" + d[2]) * 1; 	// Pad year with leading 20 if it's only 2 chars.
	
			// Validate month.
			if(d[0] < 1 || d[0] > 12) { //If month isn't between 1 and 12 stop.
				alert("Value entered for month must be between 1 and 12.");
				dateIN.focus();
				return false;
			}
			// Validate day.
			if(d[1] < 1 || d[1] > daysInMonth(d[0],d[2])) {
				alert("Value entered for day must be between 1 and " + daysInMonth(d[0],d[2]) + ".");
				dateIN.focus();
				return false;
			}
			
			// Set var for dOUT to hold formatted date.
			var dOUT = d[0] + "/" + d[1] + "/" + d[2];
			
			// Check the length of dOUT to ensure everything worked ok.
			if(dOUT.length != 10) {
				alert("Date not formatted properly!\n\nFormat: mm/dd/yyyy");
				dateIN.focus();
				return false;
			}
			
			if(doExpired==1) { // If doExpired=1 validate the date against today.
				// make sure start date is before the end date
				var td = new Date();
				if (Date.parse(td) > Date.parse(dOUT)) {
					alert("Expiry Date entered must occur after today.")
					dateIN.focus();
					return false;
				}
		
			}
			// Set date vale.	
			dateIN.value = dOUT;
		}
		catch (err){
			alert("Date not formatted properly!\n\nFormat: mm/dd/yyyy");
			dateIN.focus();
			return false;
		}
	}

//This function will return the days in a given month.
function daysInMonth(month,year) {
	var dd = new Date(year, month, 0);
	return dd.getDate();
} 	
	
/*This function will split a value into an array using space as a delimiter,
convert the first letter of each word to upper case the respost the value.*/
	function capitalize(cIN) {
		// Split value into an array.
		var x = cIN.value.split(" ");
		//Loop through array.
		for(i=0;i<x.length;i++) {
			x[i] = x[i].substring(0,1).toUpperCase() + x[i].substring(1,x[i].length);
		}
		//Set the changed value
		cIN.value = x.join(" ");
	}
	
// This function returns a flash movie as an object.
function getFlashMovieObject(movieName)
{
	if (window.document[movieName]) 
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
    	return document.getElementById(movieName);
	}
}
	