

	function popup_calendar(el) {
		var p = findPosn(el);
		var le = p[0] + document.getElementById(el).scrollWidth - 10;
		var to = p[1] - 2;
		document.getElementById('calendar').style.top = to + 'px';
		document.getElementById('calendar').style.left = le + 'px';
		changeOpac(1, "calendar")
		opacity("calendar", 0, 95, 300);
		sndCal(el, 0, 0);
	}
	
	
	/* 	This is a more advanced version of the above script - it features the following functionality:
			el 						this is the element id to pass the value to
			fixed_scroll			"fixed" or "scroll" - this is to set whether the calendar scrolls with the page or not
			daterange				makes only a selected range of dates selectable:
									"futureonly"		only dates in the future
									"pastonly"			only dates in the past
									"futurepresent"		today, along with all dates in the future
									"pastpresent"		today, along with all dates in the past
									"thismonthonly"		this month range only
									"alldates"			or anything else will allow selection of all dates
									
			highlightselectedday	"true" or "false" - grabs the currently selected day from the specified text field, and highlights it on the calendar
			highlighttoday			"true" or "false" - highlights today's date on the calendar
	
	*/
	function popup_calendar_2(el, fixed_scroll, daterange, highlightselectedday, highlighttoday) {
		
		if (fixed_scroll == 'fixed') { 		document.getElementById("calendar").style.position = 'fixed'; 		} 
			else {							document.getElementById("calendar").style.position = 'absolute'; 	}

		try { var selectedday = document.getElementById(el).value; } catch(er) { }
			
		var p = findPosn(el);
		var le = p[0] + document.getElementById(el).scrollWidth - 10;
		var to = p[1] - 2;
		document.getElementById('calendar').style.top = to + 'px';
		document.getElementById('calendar').style.left = le + 'px';
		changeOpac(1, "calendar")
		opacity("calendar", 0, 95, 300);
		
		sndCal2(el, 0, 0, daterange, highlightselectedday, selectedday, highlighttoday);
	}




	function popdown_calendar() {
		if (document.getElementById("calendar").style.display !== "none") {
			opacity("calendar", 95, 0, 300);
			window.setTimeout('document.getElementById("calendar").style.display = "none";', 350);
			window.setTimeout('document.getElementById("calendar_inside").innerHTML = \'<span style="font-family:arial; color:#aaaaaa;">Loading...</span>\'', 350);
		}
	}



	function findPosn(obj) {
		var curleft = curtop = 0;
		obj = document.getElementById(obj);
		if (obj.offsetParent) {	
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}



	function calendar_selector(el, dayer, monther, yearer) {
		var sel_me = dayer + " " + monther + " " + yearer;
		el = document.getElementById(el);
		el.value = sel_me;
		popdown_calendar();
	}


 

/* --- AJAX ---------------------------------------------------------------------------------------------------------------------------------------------------- */

	function createRequestObject_calendar() {
	    var ro;
	    var browser = navigator.appName;
	    if(browser == "Microsoft Internet Explorer"){
	        ro = new ActiveXObject("Microsoft.XMLHTTP");
	    }else{
	        ro = new XMLHttpRequest();
	    }
	    return ro;
	}
	
	var cal_ajax = createRequestObject_calendar();
	
	
	
	function sndCal(el, mon, yea) {
	    cal_ajax.open('get', 'ajax/calendar/calendar_popup.php?el='+el+'&mon='+mon+'&yea='+yea);
	    cal_ajax.onreadystatechange = handleResponseCal;
	    cal_ajax.send(null);
	}
	
	function sndCal2(el, mon, yea, daterange, highlightselectedday, selectedday, highlighttoday) {				// this is modified - see "popup_calendar_2()";
	    cal_ajax.open('get', 'ajax/calendar/calendar_popup.php?el='+el+'&mon='+mon+'&yea='+yea+'&dr='+daterange+'&hsd='+highlightselectedday+'&sd='+selectedday+'&ht='+highlighttoday);
	    cal_ajax.onreadystatechange = handleResponseCal;
	    cal_ajax.send(null);
	}
	
	
	
	function handleResponseCal() {
	    if(cal_ajax.readyState == 4){
	        var response = cal_ajax.responseText;
	        document.getElementById("calendar_inside").innerHTML = response;
	    }
	}
