var req;

function navigate(month,year,c,l,item_uid,item_ref,cutoff,r,initial,timezone_offset,portal,rid,coupon,show) {
	var url = "rezgo_calendar_old.php?month="+month+"&year="+year+"&c="+c+"&l="+l+"&item="+item_uid+"&name="+item_ref+"&cutoff="+cutoff+"&r="+r+"&initial="+initial+"&timezone_offset="+timezone_offset+"&portal="+portal+"&rid="+rid+"&coupon_code="+coupon+"&show="+show;
	//alert(url);
	//document.write(url); return;
	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 rezgo_calendar_request(month,year,transcode,common_id, item_uid,item_ref,timezone_offset,coupon,show,initial,tour_new) {
	var url = "/rezgo_calendar.php?month="+month+"&year="+year+"&transcode="+transcode+"&common_id="+common_id+"&item="+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 ($('rezgo_popup_availability')) {
		obj_popup = $("rezgo_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="/images/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="/images/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();
}