//set up the name of the calendar element's ID
var calElement = 'cal';
var calForm = 'form_add';
var mus_exception_id = 0;

//Determine if getElementById() works
if (document.getElementById) {
	Q = true;
} else {
	Q = false;
}

//      Show calender:
/*function showCal() {

	var cal_cover = document.getElementById('cal_cover');
	if(cal_cover) { cal_cover.style.display='block'; }
        var obj = document.getElementById(calElement);
        obj.style.display = 'block';
}*/

function hideMove(element, scat, val, field, selectID, options) {
//      Pass the value from the DIV to appropriate field:
	if(document.getElementById(field)) {
		var theField = document.getElementById(field);
	} else {
		var theField = document.forms[calForm].elements[field];
	}
	theField.value = val;

	if ( mus_exception_id == 143 ) 
		setTicketTimesByDate('ticket_time', secretRoutesTimes, val);
	if ( mus_exception_id == 142 ) 
		setTicketTimesByDate('ticket_time', guidedTourTimes, val);
	if ( mus_exception_id == 159 ) 
		setTicketTimesByDate('ticket_time', veniceTowerTimes, val);
	if ( mus_exception_id == 42 ) 
		setTicketTimesByDate('ticket_time', borTimes, val);
	

	theField.focus();
	theField.blur();

/* hiding functionality replaced
//      Hide the calender DIV:
	var cal_cover = document.getElementById('cal_cover');
	if(cal_cover) { cal_cover.style.display='none'; }
        var obj = document.getElementById(calElement);
        obj.style.display = 'none';

//      For vacations:
        if (scat == 21)
                populateSelectByDate('price_choice', rooms, val);
*/
	doHideCal(element); //hide the calendar element
}

/*function switchMonth(month) {
        showCal();
}*/

function killCal() {
        alert("IN");
}

function xmlhttpPost(strURL, elem) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
		//	document.body.style.cursor='default';
			updatepage(self.xmlHttpReq.responseText, elem);
        	//} else {
		//	document.body.style.cursor='wait';
		}
    	}
	self.xmlHttpReq.send(strURL);
}


function updatepage(str, elem) {

	if (Q) {
		document.getElementById(calElement).style.visibility='visible';
	}

	//is the page uses layers, hide the layer
	if (document.layers) {
		document.layers[calElement].visibility='visible';
	}

//	Display calendar:
	var cal_cover = document.getElementById('cover_'+elem);
	if(cal_cover) { cal_cover.style.display='block'; }

//	Update date field with request response:
//	document.getElementById(calElement).style.display = "block";
//	document.getElementById(calElement).innerHTML = str;
	document.getElementById(elem).style.display = "block";
	document.getElementById(elem).innerHTML = str;

}

function hideCal(node) {
	//pass the node ID to hide in
	timeoutID  = window.setTimeout("doHideCal('"+node.id+"');", 500); 
}

function doHideCal(elem) {
//	Get the calendar object
	var obj = document.getElementById(elem);

//	Check to see if the div is already hidden
	if(obj && obj.style.display == 'none') { return; }

//      Hide the calender DIV:
       	obj.style.display = 'none';

//	Hide the calendar cover if it exists
	var cal_cover = document.getElementById('cover_'+elem);
	if(cal_cover) { cal_cover.style.display='none'; }

//	if (Q) {document.getElementById(calElement).style.visibility='hidden';}
//	if (document.layers) {document.layers[calElement].visibility='hide';} 

}

function isMouseLeaveOrEnter(e, handler)
{
        if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	if(e.relatedTarget) {
        	var reltg = e.relatedTarget;
	} else {
        	if(e.type == 'mouseout') {
			var reltg = e.toElement;
		} else {
			var reltg = e.fromElement;
		}
	}

        while (reltg && reltg != handler) {
		reltg = reltg.parentNode;
	}

        return (reltg != handler);
}

//used to get the month and year from a field with the xx/xx/xx formatting

function parseCurDate(thisdate) {
	var myDate = new Date();
	//get current year and month
	var year  = ''+myDate.getFullYear();
	var month = myDate.getMonth();
	//add 1 since getMonth() starts at 0, not 1
	month++;
	//pad the month
	if(month < 10) {
		month = '0'+month;
	}
	if(thisdate.length) {
		thisdate.replace(/[^\d\/]/,thisdate);
		if(thisdate.indexOf('/') != -1) {
			var Arr = thisdate.split('/');
			if(Arr[0] && Arr[2]) {
				return '&month='+Arr[0]+'&year=20'+Arr[2]; //make the date complete by adding a 20 on the front
			} else {
				return '&month='+month+'&year='+year; //return current month and year
			}
		} else {
			return '&month='+month+'&year='+year; //return current month and year
		}
	}  else {
		return '&month='+month+'&year='+year; //return current month and year
	}
}

