if (document.all) var srvrConnect=new ActiveXObject("Microsoft.XMLHTTP");

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 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;	
}


