if (window.ActiveXObject) {
	var srvrConnect=new ActiveXObject('Microsoft.XMLHTTP');
} else if (window.XMLHttpRequest) {
	var srvrConnect=new XMLHttpRequest();
}

var selDate=new Date();
var oldDate=0;
var oldBck='#666699';

function sel(dy,mo,yr){
	if (dy) {
		if (document.getElementById('shortDesc').value !=""){
			msg='You have not yet saved your entries. If you continue without clicking the save button, you will lose the information you have entered. Click OK to continue, or Cancel to go back and save your entries.';
			if (confirm(msg)!=true) return;
		}
		document.getElementById('longDesc').value='';
		document.getElementById('shortDesc').value='';
		document.getElementById('startTime').value='';
		document.getElementById('endTime').value='';
		document.getElementById('location').value='';
		document.getElementById('id').value='';
		document.getElementById('eventDate').value='';
		if (oldDate!=0) document.getElementById(oldDate).style.backgroundColor=oldBck;
		srvrConnect.open('post','admin/_processCal.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('action=get&eventDate='+mo+'/'+dy+'/'+yr);
		document.getElementById('prevInfoHolder').innerHTML=srvrConnect.responseText;
		oldBck=document.getElementById(dy).style.backgroundColor;
		document.getElementById(dy).style.backgroundColor='#cccccc'
		oldDate=dy;
	}
}

function nextMo(mo,yr){
	if (document.getElementById('shortDesc').value !=""){
		msg='You have not yet saved your entries. If you continue without clicking the save button, you will lose the information you have entered. Click OK to continue, or Cancel to go back and save your entries.';
		if (confirm(msg)!=true) return;
	}
	mo=mo<12?mo+1:1;
	if (mo==1) yr=yr+1;
  oldDate=0;
  oldBck='#666699';
	document.getElementById('longDesc').value='';
	document.getElementById('shortDesc').value='';
	document.getElementById('startTime').value='';
	document.getElementById('endTime').value='';
	document.getElementById('location').value='';
	document.getElementById('id').value='';
	document.getElementById('eventDate').value='';
		srvrConnect.open('post','admin/_processCal.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('action=gen&mo=' + mo + '&yr=' + yr);
		document.getElementById('calHolder').innerHTML=srvrConnect.responseText;
//	drawCal(mo,yr);
}

function prevMo(mo,yr){
	if (document.getElementById('shortDesc').value !=""){
		msg='You have not yet saved your entries. If you continue without clicking the save button, you will lose the information you have entered. Click OK to continue, or Cancel to go back and save your entries.';
		if (confirm(msg)!=true) return;
	}
	mo=mo>1?mo-1:12;
	if (mo==12) yr=yr-1;
  oldDate=0;
  oldBck='#666699';
		document.getElementById('longDesc').value='';
		document.getElementById('shortDesc').value='';
		document.getElementById('startTime').value='';
		document.getElementById('endTime').value='';
		document.getElementById('location').value='';
		document.getElementById('id').value='';
		document.getElementById('eventDate').value='';
		srvrConnect.open('post','admin/_processCal.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('action=gen&mo=' + mo + '&yr=' + yr);
		document.getElementById('calHolder').innerHTML=srvrConnect.responseText;
//	drawCal(mo,yr);
}

function pullQuote(obj,dat){
	document.getElementById('pullQuote').className='pullQuoteOff';
	var calWidth=(document.getElementById('calDiv2').offsetWidth);
	if (obj.offsetLeft<calWidth/2){
		document.getElementById('pq1').style.display='none';
		document.getElementById('pq1').style.visibility='hidden';
		document.getElementById('pq2').style.display='none';
		document.getElementById('pq3').style.display='block';
		document.getElementById('pq3').style.visibility='visible';
		document.getElementById('pq4').style.display='block';
		document.getElementById('pullQuote').style.top=(obj.offsetTop+53)+'px';
		document.getElementById('pullQuote').style.left=Math.max((obj.offsetLeft-93),-60)+'px';
	} else {
		document.getElementById('pq1').style.display='block';
		document.getElementById('pq1').style.visibility='visible';
		document.getElementById('pq2').style.display='block';
		document.getElementById('pq3').style.display='none';
		document.getElementById('pq3').style.display='none';
		document.getElementById('pq3').style.visibility='hidden';
		document.getElementById('pq4').style.display='none';
		document.getElementById('pullQuote').style.top=(obj.offsetTop+53)+'px';
		document.getElementById('pullQuote').style.left=(obj.offsetLeft-220)+'px';
	}
	calTimr=setTimeout(function(){pullQuote2(obj,dat)},5);
	obj.onmouseout=function(){clearTimeout(calTimr)};
}
	function pullQuote2(obj,dat){
		document.getElementById('quoteContent').innerHTML='<div align="center"><img src="images/wait-indicator.gif" /></div>';
		document.getElementById('pullQuote').className='pullQuoteOn';
		//setTimeout(function (){pullQuote3(dat)},50);	
		setTimeout(function (){pullQuote3(obj.getAttribute('sessID'))},5);	
	}
	function pullQuote3(dat){
		srvrConnect.open('post','_processAjax.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		//srvrConnect.send('act=6&dat='+dat);
		srvrConnect.send('act=7&sid='+dat);
		document.getElementById('quoteContent').innerHTML=srvrConnect.responseText;
	}
	function clearQuote(){
		document.getElementById('pullQuote').className='pullQuoteOff';
		if (typeof(calTimr)!='undefined') clearTimeout(calTimr);
	}
function edit(lineIdx){
	document.getElementById('longDesc').value=document.getElementById('longDesc' + lineIdx).value;
	document.getElementById('shortDesc').value=document.getElementById('shortDesc' + lineIdx).value;
	document.getElementById('startTime').value=document.getElementById('startTime' + lineIdx).value;
	document.getElementById('endTime').value=document.getElementById('endTime' + lineIdx).value;
	document.getElementById('location').value=document.getElementById('location' + lineIdx).value;
	document.getElementById('id').value=document.getElementById('id' + lineIdx).value;
	document.getElementById('eventDate').value=document.getElementById('eventDate' + lineIdx).value;
	document.getElementById('startTime').focus();
}

function del(id){
	if (confirm('You have chosen to delete this event. Are you sure you wish to continue')){
		srvrConnect.open('post','admin/_processCal.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('action=del&id='+id);
		document.getElementById('prevInfoHolder').innerHTML=srvrConnect.responseText;
		document.getElementById('longDesc').value='';
		document.getElementById('shortDesc').value='';
		document.getElementById('startTime').value='';
		document.getElementById('endTime').value='';
		document.getElementById('location').value='';
		document.getElementById('id').value='';
	} else {
		return;
	}
}
function save(id){
	if (document.getElementById('shortDesc').value==''){
		alert('You must enter a Short Description. This field is required.');
		document.getElementById('shortDesc').focus();
		return;
	}
		srvrConnect.open('post','admin/_processCal.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var strData = 'longDesc=' + document.getElementById('longDesc').value.replace(/\&/g,'|||')
				+ '&shortDesc=' + document.getElementById('shortDesc').value.replace(/\&/g,'|||')
				+ '&startTime=' + document.getElementById('startTime').value
				+ '&endTime=' + document.getElementById('endTime').value
				+ '&location=' + document.getElementById('location').value
				+ '&id=' + document.getElementById('id').value
				+ '&specDay=' + document.getElementById('specDay').value
				+ '&eventDate=' + document.getElementById('eventDate').value;
		srvrConnect.send('action=edit&' + strData);
		document.getElementById('prevInfoHolder').innerHTML=srvrConnect.responseText;
		document.getElementById('longDesc').value='';
		document.getElementById('shortDesc').value='';
		document.getElementById('startTime').value='';
		document.getElementById('endTime').value='';
		document.getElementById('location').value='';
		document.getElementById('id').value='';
		document.getElementById('shortDesc').focus();
}

function setDayType(evDate,dayType){
		srvrConnect.open('post','admin/_processCal.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('action=chg&eventDate=' + evDate + '&dayType=' + dayType);
		document.getElementById('prevInfoHolder').innerHTML=srvrConnect.responseText;
		switch(dayType) {
			case '0':
				oldBck='#666699';
				break;
			case '1': 
				oldBck='#9999cc';
				break;
			case '2':
				oldBck='#669966';
				break;
			case '3':
				oldBck='#996666';
				break;
		}
}

function valTime(obj,val){
	val=val.replace(/[^\d\.:AaPp]/g,'');
	val=val.replace(/\.+/g,'.');
	val=val.replace(/[aA]+[\.]?/g,' AM');
	val=val.replace(/[pP]+[\.]?/g,' PM');
	val=val.replace(/\./g,':');
	val=val.substring(val.search(/\d/),val.length);
	if (val.search(/M/)!=-1) val=val.substring(0,val.search(/M/)+1);
	if (parseInt(val)>23) {
		alert('Invalid Entry. Try Again.');
		obj.value='';
		obj.focus();
		return;
	}
	if (parseInt(val)>11 && !(parseInt(val)==12&&val.search(/AM/)!=-1)) {
		val=val.replace(/ AM| PM/,'');
		val=val+' PM';
		hrs=new RegExp(parseInt(val).toString());
		newHr=parseInt(val)!=12?(parseInt(val)-12).toString():'12';
		val=val.replace(hrs,newHr);
	} else {
		if (val.search(/ AM| PM/)==-1 && val!='') val=val+' AM';
		if (parseInt(val)==0) val=val.replace(/0+/,'12');
	}
	
	obj.value=val;	
}

/*--------------------------- CONSUMER SIDE JS ---------------------------------*/
var grStep=8, mL=0, w=100, expTimer;
function expCal(obj){
	obj.blur();
	if (obj.innerHTML=='Expand Calendar'){
		with (document.getElementById('calDiv').style){
			 position='absolute';
			 left='-5%';
			 width='110%'; 
			 zIndex='1000';
		}
		document.getElementById('calScreen').style.display='block';
		document.getElementById('calExpBtn').style.color='white';
		obj.innerHTML='Contract Calendar';
		document.getElementById('cal').className='calTableDS';
	} else {
		with (document.getElementById('calDiv').style){
			 position='relative';
			 left='0%';
			 width='100%'; 
			 zIndex='650';
		}
		document.getElementById('calScreen').style.display='none';
		document.getElementById('pullQuote').style.display='none';
		document.getElementById('calExpBtn').style.color='blue';
		obj.innerHTML='Expand Calendar';
		document.getElementById('cal').className='calTable';
	}
}
function showCal(){
	//document.getElementById('topDiv').style.display='none';
	var scr=document.createElement('div');
	scr.className='calScreen';
	scr.id='calScreen';
	scr.onclick=closeCal;
	var calDiv=document.createElement('div');
	calDiv.id='calDiv';
	calDiv.className='calDiv';
	document.body.appendChild(scr);	
	document.body.appendChild(calDiv);
		srvrConnect.open('post','module_Calendar.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;

}
	function closeCal(){
		document.getElementById('calScreen').parentNode.removeChild(document.getElementById('calScreen'));
		document.getElementById('calDiv').parentNode.removeChild(document.getElementById('calDiv'));
		//document.getElementById('topDiv').style.display='block';
	}
function updateCal(j,y){
		document.body.style.cursor='wait';
		document.getElementById('monthCell').className='wait';
		setTimeout(function() {updateCal2(j,y)},10);
}
function updateCal2(j,y){
		srvrConnect.open('get','_processAjax.cfm?r='+Math.random()+'&act=5&j='+j+'&y='+y,0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;
		document.body.style.cursor='auto';
		document.getElementById('monthCell').className=null;
		//if (document.getElementById('calScreen') && document.getElementById('calScreen').style.display=='block') document.getElementById('cal').className='calTableDS';
}
function updateCalCat(obj){
		document.body.style.cursor='wait';
		document.getElementById('monthCell').className='wait';
		setTimeout(function() {updateCalCat2(obj.value)},10);
}
function updateCalCat2(cat){
		srvrConnect.open('get','_processAjax.cfm?r='+Math.random()+'&act=5&cat='+cat,0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;
		document.body.style.cursor='auto';
		document.getElementById('monthCell').className=null;
		//if (document.getElementById('calScreen').style.display=='block') document.getElementById('cal').className='calTableDS';
}
function updateCalFac(obj){
		document.body.style.cursor='wait';
		document.getElementById('monthCell').className='wait';
		setTimeout(function() {updateCalFac2(obj.value)},10);
}
function updateCalFac2(fac){
		srvrConnect.open('get','_processAjax.cfm?r='+Math.random()+'&act=5&fac='+fac,0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;
		document.body.style.cursor='auto';
		document.getElementById('monthCell').className=null;
		//if (document.getElementById('calScreen').style.display=='block') document.getElementById('cal').className='calTableDS';
}
function updateCalVoucher(obj){
		document.body.style.cursor='wait';
		document.getElementById('monthCell').className='wait';
		setTimeout(function() {updateCalVoucher2(obj)},10);
}
function updateCalVoucher2(vouch){
		srvrConnect.open('get','_processAjax.cfm?r='+Math.random()+'&act=5&vouch='+vouch,0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;
		document.body.style.cursor='auto';
		document.getElementById('monthCell').className=null;
		//if (document.getElementById('calScreen').style.display=='block') document.getElementById('cal').className='calTableDS';
}
var maxPass=0
function chooseFlight(yr,mo,dy,h,m,desc,spots,price){
	//document.getElementById('openTicket').checked=false;
	maxPass=spots;
	var selDate=new Date(yr,mo-1,dy,h,m);
	var html='<b>Selected Flight</b><br /><br />'
	html=html+'<b>Date: </b>' + selDate +'<br />';
	if (document.getElementById('facName') && document.getElementById('facName').selectedIndex){
		html=html+'<b>Location: </b>' + document.getElementById('facName')[document.getElementById('facName').selectedIndex].text + '<br />';
	}
	html=html+'<b>Flight: </b>' + document.getElementById('cat')[document.getElementById('cat').selectedIndex].text + '<br />';
	if (desc!='') html=html+'<b>Description: </b>' + desc ;
	html=html+'<br /><b><em>You may reserve up to ' + spots + ' spaces @ '+price+' per person.</em></b>';
	document.getElementById('selectionHolder').style.display='block';
	document.getElementById('selectionBox').innerHTML=html;
	document.getElementById('selectedDate').value=(mo)+'/'+dy+'/'+yr;
	document.getElementById('pricePerPerson').value=price;
	
}

/*--------------------CAL ADMIN JS ------------------*/
function updateAdminCal(j,y){
		document.body.style.cursor='wait';
		document.getElementById('monthCell').className='wait';
		setTimeout(function() {updateAdminCal2(j,y)},10);
}
function updateAdminCal2(j,y){
		srvrConnect.open('get','admin/_processAdminAjax.cfm?r='+Math.random()+'&act=7&j='+j+'&y='+y,0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;
		document.body.style.cursor='auto';
		document.getElementById('monthCell').className=null;
		//if (document.getElementById('calScreen') && document.getElementById('calScreen').style.display=='block') document.getElementById('cal').className='calTableDS';
}
function updateAdminCalCat(obj){
		document.body.style.cursor='wait';
		document.getElementById('monthCell').className='wait';
		setTimeout(function() {updateAdminCalCat2(obj.value)},10);
}
function updateAdminCalCat2(cat){
		srvrConnect.open('get','admin/_processAdminAjax.cfm?r='+Math.random()+'&act=7&cat='+cat,0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send();
		document.getElementById('calDiv').innerHTML=srvrConnect.responseText;
		document.body.style.cursor='auto';
		document.getElementById('monthCell').className=null;
		//if (document.getElementById('calScreen').style.display=='block') document.getElementById('cal').className='calTableDS';
}

