function checkTextAreaMaxLength(textBox,e, length,element)
	{
		var mLen = textBox["MaxLength"];
		if(null==mLen)
			mLen=length;
		
		var maxLength = parseInt(mLen);
		if(!checkSpecialKeys(e,textBox,element,maxLength))
		{
		 if(textBox.value.length > maxLength-1)
		 {
			if(window.event)//IE
			  e.returnValue = false;
			else//Firefox
				e.preventDefault();
		 }
		 else
		 {
		 document.getElementById(element).value=maxLength - (textBox.value.length + 1);
		 }
		}  
}
function checkSpecialKeys(e,textBox,element,maxLength)
{
if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
	return false;
else
	{
	if(textBox.value.length>0)
		document.getElementById(element).value=maxLength - (textBox.value.length-1);
	return true;
	}
} 

function openNewWindow(path)
{
	window.location.target='_blank';		
	window.location.href=path;		
}

<!-- tab section -->

var isChecked=false;
function usrtoggle(chkbox){
	isChecked=chkbox
	if(isChecked){
		document.getElementById('usrDetail').style.display='none';
		document.getElementById('usrTable').style.display='';
	}
	else{
		document.getElementById('usrDetail').style.display='';
		document.getElementById('usrTable').style.display='none';
	}
}
function billinfo(chkbox,frm){
	isChecked=chkbox
	if(isChecked){
		frm.billing_firstname.value = frm.firstname.value;
		frm.billing_lastname.value = frm.lastname.value;
		frm.billing_address1.value = frm.address1.value;
		frm.billing_address2.value = frm.address2.value;
		frm.billing_city.value = frm.city.value;
		frm.billing_state.value = frm.state.value;
		frm.billing_country.value = frm.country.value;
		frm.billing_zipcode.value = frm.zipcode.value;
		frm.billing_phone.value = frm.phone.value;
		frm.billing_email.value = frm.email.value;
		frm.billing_alternatephone.value = frm.alternatephone.value;
		frm.billing_cellphone.value = frm.cellphone.value;
	}
	else{
		frm.billing_firstname.value = '';
		frm.billing_lastname.value = '';
		frm.billing_address1.value = '';
		frm.billing_address2.value = '';
		frm.billing_city.value = '';
		frm.billing_state.value = '';
		frm.billing_country.value = '';
		frm.billing_zipcode.value = '';
		frm.billing_phone.value = '';
		frm.billing_email.value = '';
		frm.billing_alternatephone.value = '';
		frm.billing_cellphone.value = '';
	}
}

function redirection(path)
{
	window.location.href=path;		
}

function hidemsgbox(id) {
	document.getElementById(id).style.display = 'none';	
}

function setDefaultText(frm,setvalue,setclass)
{
	frm.couponcode.className = setclass;
	frm.couponcode.value = setvalue;
}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= (MaxLen));
}

// to display the text areas length 
function len_display(Object,MaxLen,element){
   var len_remain = MaxLen-Object.value.length;
   if(len_remain >=0){
   document.getElementById(element).value=len_remain; }
}


function checkTextAreaMaxLength(textBox,e, length,element)
{
	var mLen = textBox["MaxLength"];
	if(null==mLen)
		mLen=length;
	
	var maxLength = parseInt(mLen);
	if(!checkSpecialKeys(e,textBox,element,maxLength))
	{
	 if(textBox.value.length > maxLength-1)
	 {
		if(window.event)//IE
		  e.returnValue = false;
		else//Firefox
			e.preventDefault();
	 }
	 else
	 {
	 document.getElementById(element).value=maxLength - (textBox.value.length + 1);
	 }
	}  
}
function checkSpecialKeys(e,textBox,element,maxLength)
{
if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
	return false;
else
	{
	if(textBox.value.length>0)
		document.getElementById(element).value=maxLength - (textBox.value.length-1);
	return true;
	}
}   

function modWindow(url,w,h) 
{
	if (window.showModalDialog)
		window.showModalDialog(url, window, 'dialogHeight:'+h+'px;dialogWidth:'+w+'px;center:yes','resizable: yes; help: no; status: no; scroll: no;');
	else
		alert('You need Internet Explorer 5 or higher.');
}

function checkTourAvailability(time,scheduleid,bookdate)
{
document.getElementById('displaydiv').innerHTML = 'Loading...';
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
	{
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
  catch (e)
	{
	try
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	catch (e)
	  {
	  alert("Your browser does not support AJAX!");
	  return false;
	  }
	}
  }
  xmlHttp.onreadystatechange=function()
	{
	if(xmlHttp.readyState==4)
	  {
		document.getElementById('displaydiv').innerHTML = xmlHttp.responseText;
	  }
	}
  xmlHttp.open("GET","pages/schedulertime.cfm?time="+time+"&scheduleid="+scheduleid+"&bookdate="+bookdate,true);
  xmlHttp.send(null);
}

function blankfield(id) {
	document.getElementById(id).innerHTML='Loading...';	
}

function loadDateList(tourid,tourtype,path)
{
document.getElementById('datelist'+tourid).style.display = 'block';
document.getElementById('datelist'+tourid).innerHTML = '<img src="'+path+'/tour/images/ajax-loader.gif" border="0" />';
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
	{
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
  catch (e)
	{
	try
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	catch (e)
	  {
	  alert("Your browser does not support AJAX!");
	  return false;
	  }
	}
  }
  xmlHttp.onreadystatechange=function()
	{
	if(xmlHttp.readyState==4)
	  {
		document.getElementById('datelist'+tourid).innerHTML = xmlHttp.responseText;
	  }
	}
  xmlHttp.open("GET", path+"/tour/pages/tourdatelist.cfm?tourid="+tourid+"&tourtype="+tourtype,true);
  xmlHttp.send(null);
}

function unloadDateList(id) {
	document.getElementById(id).innerHTML = '';	
	document.getElementById(id).style.display = 'none';
}

function setDateFromlist(dat,dateid,divid) {
	document.getElementById(dateid).value = dat;
	document.getElementById(divid).innerHTML = '';	
	document.getElementById(divid).style.display = 'none';
}

function countdown_clock1(year, month, day, hour, minute, format)
     {
     html_code = '<div id="countdown1"></div>';
    
     document.write(html_code);
     countdown1(year, month, day, hour, minute, format);                
 }

function countdown_clock2(year, month, day, hour, minute, format)
     {
      html_code = '<div id="countdown2"></div>';
    
     document.write(html_code);
	 
     countdown2(year, month, day, hour, minute, format);                
 }

function countdown2(year, month, day, hour, minute, format)
     {
     Today = new Date();
	 
     Todays_Year = Today.getFullYear() - 2000;
  
     Todays_Month = Today.getMonth();                  
     
     Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                             Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); 
                                                        
     Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
    
     Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
     
     if(Time_Left < 0)
        Time_Left = 0;
     
     switch(format)
           {
           case 0:
                 document.all.countdown2.innerHTML = Time_Left + ' seconds';
                break;
           case 1:
                days = Math.floor(Time_Left / (60 * 60 * 24));
                Time_Left %= (60 * 60 * 24);
                hours = Math.floor(Time_Left / (60 * 60));
                Time_Left %= (60 * 60);
                minutes = Math.floor(Time_Left / 60);
                Time_Left %= 60;
                seconds = Time_Left;
                
                dps = 's'; hps = 's'; mps = 's'; sps = 's';
                if(days == 1) dps ='';
                if(hours == 1) hps ='';
                if(minutes == 1) mps ='';
                if(seconds == 1) sps ='';
                
                document.all.countdown2.innerHTML = days + ' day' + dps + ' ';
                document.all.countdown2.innerHTML += hours + ' hour' + hps + ' ';
                document.all.countdown2.innerHTML += minutes + ' minute' + mps + ' and ';
                document.all.countdown2.innerHTML += seconds + ' second' + sps;
                break;
           default: 
                document.all.countdown2.innerHTML = Time_Left + ' seconds';
           }
         
     setTimeout('countdown2(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
 }
   
function countdown1(year, month, day, hour, minute, format)
     {
     Today = new Date();
	 
     Todays_Year = Today.getFullYear() - 2000;
  
     Todays_Month = Today.getMonth();                  
     
     Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                             Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); 
                                                        
     Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
    
     Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
     
     if(Time_Left < 0)
        Time_Left = 0;
     
     switch(format)
           {
           case 0:
                 document.all.countdown1.innerHTML = Time_Left + ' seconds';
                break;
           case 1:
                days = Math.floor(Time_Left / (60 * 60 * 24));
                Time_Left %= (60 * 60 * 24);
                hours = Math.floor(Time_Left / (60 * 60));
                Time_Left %= (60 * 60);
                minutes = Math.floor(Time_Left / 60);
                Time_Left %= 60;
                seconds = Time_Left;
                
                dps = 's'; hps = 's'; mps = 's'; sps = 's';
                if(days == 1) dps ='';
                if(hours == 1) hps ='';
                if(minutes == 1) mps ='';
                if(seconds == 1) sps ='';
                
                document.all.countdown1.innerHTML = days + ' day' + dps + ' ';
                document.all.countdown1.innerHTML += hours + ' hour' + hps + ' ';
                document.all.countdown1.innerHTML += minutes + ' minute' + mps + ' and ';
                document.all.countdown1.innerHTML += seconds + ' second' + sps;
                break;
           default: 
                document.all.countdown1.innerHTML = Time_Left + ' seconds';
           }
      
     setTimeout('countdown1(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
 }

// ---------------- Start Ajax Calendar script --------------//

var req;

function calc_calendar_request(month,year,transcode,common_id, item_uid,item_ref,timezone_offset,coupon,show,initial,tour_new) {
	var url = "includes/calendar_popup.cfm?month="+month+"&year="+year+"&transcode="+transcode+"&common_id="+common_id+"&tourid="+item_uid+"&name="+item_ref+"&timezone_offset="+timezone_offset+"&coupon_code="+coupon+"&show="+show+"&initial="+initial+"&tour_new="+tour_new;
	//alert(url);
	//document.write(url); return;
	if ($('calc_popup_availability')) {
		obj_popup = $$$("calc_popup_availability");
		obj_popup.style.display = "none";
	}
	render_loading();
	
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
}

function calc_combo_calendar_request(month,year,transcode,common_id, item_uid,item_ref,timezone_offset,coupon,show,initial,tour_new) {
	var url = "includes/combocalendar_popup.cfm?month="+month+"&year="+year+"&transcode="+transcode+"&common_id="+common_id+"&tourid="+item_uid+"&name="+item_ref+"&timezone_offset="+timezone_offset+"&coupon_code="+coupon+"&show="+show+"&initial="+initial+"&tour_new="+tour_new;
	//alert(url);
	//document.write(url); return;
	if ($('calc_popup_availability')) {
		obj_popup = $$$("calc_popup_availability");
		obj_popup.style.display = "none";
	}
	render_loading();
	
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
}

function callback() {        
	obj = $$$("calendar");
	objx = $$$("cal_loading");
	setFade(0);
	
	if(req.readyState == 4) {
		if(req.status == 200) {
			response = req.responseText;
			obj.innerHTML = response;
			objx.style.display = "none";
			obj.style.display = "block";
			fade(0);
		}
		else {
			alert("There was a problem retrieving the data:\n" + req.statusText);
		}
	}
	else {
	// while not ready, load the loader spinner
		obj.style.display = "none";
		objx.style.display = "block";
		objx.innerHTML = '<div style="margin:auto; text-align:center;"><div style="height: 80px">&nbsp;</div><div style="margin:auto; text-align:center;"><img src="public/images/pictures/calendar_loading.gif" alt="Processing."</div><h3>Loading calendar...</h3></div>';
	}
}

function render_loading() { 
	obj = $$$("calendar");
	objx = $$$("cal_loading");
	
	obj.style.display = "none";
	objx.style.display = "block";
	objx.innerHTML = '<div style="margin:auto; text-align:center;"><div style="height: 80px">&nbsp;</div><div style="margin:auto; text-align:center;"><img src="public/images/pictures/calendar_loading.gif" alt="Processing."</div><h3>Loading calendar...</h3></div>';
}

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
	}
}

function setFade(amt) {
	obj = $$$("calendar");
	
	amt = (amt == 100)?99.999:amt;
	
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
	
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}


function check_event(date_stamp){
	//alert(document.check.item.value);
	var selectedMonth = document.check.month.selectedIndex;
	var m = document.check.month.options[selectedMonth].value;
	var selectedYear = document.check.year.selectedIndex;
	var y = document.check.year.options[selectedYear].value;
	document.check.cal_date.value = m + '-' + y;
	document.check.d.value = date_stamp;
	document.check.submit();
}

var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

// Calendar code
var currentPage = 1;
var currentDateStamp = '';
var newEl;
// scriptaculous animation lock		
var lock = 0;
function activateLock() {
	lock = 1;
}
function releaseLock() {
	lock = 0;
}


function display_availability_info(date_stamp, date_string, clac_class) {
	if (lock != 1) {
		// initialize global variables
		currentDateStamp = date_stamp;
		currentPage = 1;
		
		// setup pointers
		var popup_box = document.getElementById('calc_popup_availability');
		var popup_date = document.getElementById('calc_popup_date');
		var popup_options = document.getElementById('calc_popup_options');
		var day_box = document.getElementById('day_'+date_stamp);
		
		if (popup_date) {
			popup_date.innerHTML = date_string;
		}
		if (popup_options) {
			var cur_date_options = document.getElementById(currentDateStamp+'-1');
			//alert(cur_date_options.innerHTML);
			if (cur_date_options) {
				popup_options.innerHTML = cur_date_options.innerHTML;
			}
			//alert(popup_options.innerHTML);
		}
		
		// Unselect all the other days, and select the clicked date
		var selected = getElementsByClassName('selected');
		for (var i=0; i<selected.length; i++) {
			selected[i].className = clac_class;
		}
		
		if (day_box) {
			day_box.className = "selected "+clac_class;
		}
		
		// Activate Block
		
		Effect.Appear("calc_popup_availability", {duration: 0.3, beforeStart: activateLock});
		new Effect.Highlight("calc_popup_date", {startcolor: '#666666', endcolor: '#93b0ca', duration: 0.5, afterFinish: releaseLock});
		
	}
}

function prevOptionsPage() {
	newPage = currentPage-1;
	var new_date_options = document.getElementById(currentDateStamp+'-'+newPage);
	var oldEl = document.getElementById('calc_popup_options');

	if (new_date_options && lock != 1) {
		newEl = document.getElementById(currentDateStamp+'-'+newPage);

		new Effect.Fade(oldEl,{
			duration: 0.5,
			beforeStart: activateLock,
			afterFinish: update_options
		});
		
		currentPage--;
		new Effect.BlindDown(oldEl, {
			duration: 1,
			queue: 'end',
			afterFinish: releaseLock
		});
	}
	return;
}

function nextOptionsPage() {
	newPage = currentPage+1;
	var new_date_options = document.getElementById(currentDateStamp+'-'+newPage);
	var oldEl = document.getElementById('calc_popup_options');

	if (new_date_options && lock != 1) {
		newEl = document.getElementById(currentDateStamp+'-'+newPage);

		new Effect.Fade(oldEl,{
			duration: 0.5,
			beforeStart: activateLock,
			afterFinish: update_options
		});
		
		currentPage++;
		new Effect.BlindDown(oldEl, {
			duration: 1,
			queue: 'end',
			afterFinish: releaseLock
		});
	}
	return;
}
function update_options() {
	var popup_options = document.getElementById('calc_popup_options');
	if (popup_options) {
		popup_options.innerHTML = newEl.innerHTML;
	}
}

// ---------------- End Ajax Calendar script --------------//

