var curr_date = '';
jQuery(document).ready(function($){	
Xoffset= -400;
Yoffset= 15;
var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all
if (ns4)
skn=document.dek
else if (ns6) {
	if (document.getElementById("dek"))
		skn=document.getElementById("dek").style
} else if (ie4)
skn=document.all.dek.style
if(ns4)document.captureEvents(Event.MOUSEMOVE);
else{
	if (skn) {
		skn.visibility="visible"
		skn.display="none"
	}
}
if (skn) document.onmousemove=get_mouse;

function kill(){
yyy=-1000;
if(ns4){skn.visibility="hidden";}
else if (ns6||ie4)
skn.display="none"
}

function get_mouse(e){
var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
skn.left=x+Xoffset;
var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
skn.top=y+yyy;
}

function DynamicPopup(msg,bak,width){
var content="<TABLE  WIDTH="+width+" BORDER=1 BORDERCOLOR=black CELLPADDING=2 CELLSPACING=0 "+
"BGCOLOR="+bak+"><TD ALIGN=left><FONT COLOR=black SIZE=-2>"+msg+"</FONT></TD></TABLE>";
yyy=Yoffset;
 if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"}
 if(ns6){document.getElementById("dek").innerHTML=content;skn.display=''}
 if(ie4){document.all("dek").innerHTML=content;skn.display=''}
}


	Cufon.replace('#content H2');	
	
	/*$('.rotator') 
	.before('<div id="nav">') 
	.cycle({ 
		fx:     'fade', 
		speed:  1000, 
		timeout: 3000, 
		pager:  '#nav' 
	});*/
	
	$('INPUT[name=Rooms]').blur(function(){
		showSplitDropdown($(this).val());
	});
	$('INPUT[name=Rooms]').keyup(function(){
		showSplitDropdown($(this).val());
	});

	$('INPUT[name=TargetRate], INPUT[name=CheckInDate1], INPUT[name=Days1]').blur(function(){
		checkRates();
	});
	$('SELECT[name=Currency]').change(function(){
		checkRates();
	});

	$('SELECT[name=NeedSpace]').change(function(){
		if($(this).val() == 'Yes, I will need meeting / banquet space') OpenSpaceCalculator();
	});
	
	$('INPUT[name=Days1]').mouseover(function(){
		$('#dek').css({'top':'220px', 'left': '245px'})
		DynamicPopup('<b>Check-in Date</b><br>Here is where you should specify the number of nights the majority of your group will be utilizing the hotel rooms.<br><br>Our system will allow each person in your group to book pre- and post- nights through your customized group website after a hotel is selected.','f5f5f5','350');
	});

	$('INPUT[name=Days1]').mouseout(function(){
		kill();
	});
	
	$('#alternate-dates').click(function(){
		$('#theHideLink').hide();
		$('#DestinationsLongForm').show();
	});
	
	$('.help').mouseover(function(){
		$('#dek').css({'top':'-75px', 'left': '-20px'})
		DynamicPopup('<b>Number of rooms needed per night</b><br>This value should be as accurate as possible. Some hotels require you to use a percentage of your room block.<br><br>If your group ends up using more rooms, then most hotels will honor your discounted group room rate for additional rooms above the blocked amount of rooms.','f5f5f5','350');
	});

	$('.help').mouseout(function(){
		kill();
	});
	$(".calendar").click(function(){
		curr_date = $(this).attr('id');
	})
	$(".calendar").datePicker({createButton:false}).bind(
			// when the link is clicked display the date picker
			'click',
			function()
			{	
				$(this).dpDisplay();
				return false;
				
			}
	).bind(
			// when a date is selected update the SELECTs
			'dateSelected',
			function(e, selectedDate, $td, state)
			{
				updateSelects(selectedDate);
			}
		);
	var updateSelects = function (selectedDate)
	{	var input_id = curr_date.split('_');
		var selectedDate = new Date(selectedDate);
		$('INPUT[name=CheckInDate'+input_id[1]+']').val((selectedDate.getMonth()+1)+'/'+selectedDate.getDate()+'/'+selectedDate.getFullYear());
	}
});
var ie= ((document.all)&&(!document.layers)) ? true : false;
var ns= ((document.layers)&&(!document.getElementById)) ? true : false;
var moz= ((document.getElementById)&&(!document.all)) ? true : false;

function showSplitDropdown(NumRooms)
{	
	if(parseInt(NumRooms) > 49)
	{
		if(ie)
		{
			document.all['SplitOptions'].style.position = "relative";
			document.all['SplitOptions'].style.visibility="visible";
		}
		if(ns) {document.layers['SplitOptions'].visibility="show";}
		if(moz)
		{
			document.getElementById('SplitOptions').style.position = "relative";	
			document.getElementById('SplitOptions').style.visibility="visible";
		}
	}
	else
	{
		if(ie)
		{
			document.all['SplitOptions'].style.position = "absolute";
			document.all['SplitOptions'].style.visibility="hidden";
		}
		if(ns) {document.layers['SplitOptions'].visibility="hide";}
		if(moz)
		{
			document.getElementById('SplitOptions').style.position = "absolute";	
			document.getElementById('SplitOptions').style.visibility="hidden";
		}
	}
}

var SpaceWin;
function OpenSpaceCalculator()
{	
	SpaceWin=window.open('/Common/Popups/AddSpace.cfm?ShowAsPopup=1', 'Add_Space_Requirement', 'width=360px,height=560px,left=50px,top=50px,resize=1,scrolling=1');	
}

var EventWin;
function OpenEventPopup(ID)
{
	EventWin=window.open('/Common/Popups/CitywideDetail.cfm?eid='+ID, 'CitywideDetail'+ID, 'width=550px,height=375px,left=50px,top=50px,resize=1,scrolling=1');
}


function checkRates()
{
	
	try
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
		  // code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
		  return;
		}
		
		xmlhttp.onreadystatechange=function()
		{
			if(xmlhttp.readyState==4)
			{
				var rText = xmlhttp.responseText;
				
				if (rText != '')
				{
					document.getElementById('RateCheck').innerHTML = '<b>'+rText+'</b>';
				}
				else
				{
					document.getElementById('RateCheck').innerHTML = '';
				}
			}
		}
		var StarRating = document.frmGroup.Rating.options[document.frmGroup.Rating.options.selectedIndex].value;
		var Currency = document.frmGroup.Currency.options[document.frmGroup.Currency.options.selectedIndex].value;
		var Budget = document.frmGroup.TargetRate.value;
		
		var Destination1 = document.frmGroup.Destination1Text.value;
		var CheckInDate1 = document.frmGroup.CheckInDate1.value;
		var Days1 = document.frmGroup.Days1.value;
		
		var Destination2 = document.frmGroup.Destination2Text.value;
		var CheckInDate2 = document.frmGroup.CheckInDate2.value;
		var Days2 = document.frmGroup.Days2.value;
		
		var Destination3 = document.frmGroup.Destination3Text.value;
		var CheckInDate3 = document.frmGroup.CheckInDate3.value;
		var Days3 = document.frmGroup.Days3.value;
		
		var Destination4 = document.frmGroup.Destination4Text.value;
		var CheckInDate4 = document.frmGroup.CheckInDate4.value;
		var Days4 = document.frmGroup.Days4.value;
		
		var Destination5 = document.frmGroup.Destination5Text.value;
		var CheckInDate5 = document.frmGroup.CheckInDate5.value;
		var Days5 = document.frmGroup.Days5.value;
		
		var Destination6 = document.frmGroup.Destination6Text.value;
		var CheckInDate6 = document.frmGroup.CheckInDate6.value;
		var Days6 = document.frmGroup.Days6.value;
		
		var Destination7 = document.frmGroup.Destination7Text.value;
		var CheckInDate7 = document.frmGroup.CheckInDate7.value;
		var Days7 = document.frmGroup.Days7.value;
		
		var Destination8 = document.frmGroup.Destination8Text.value;
		var CheckInDate8 = document.frmGroup.CheckInDate8.value;
		var Days8 = document.frmGroup.Days8.value;
		
		
		if (Destination1 != '')
		{
			xmlhttp.open("GET","/CheckRates.cfm?StarRating="+StarRating+"&Budget="+Budget+"&Currency="+Currency+"&Destination1="+Destination1+"&CheckInDate1="+CheckInDate1+"&Days1="+Days1+"&Destination2="+Destination2+"&CheckInDate2="+CheckInDate2+"&Days2="+Days2+"&Destination3="+Destination3+"&CheckInDate3="+CheckInDate3+"&Days3="+Days3+"&Destination4="+Destination4+"&CheckInDate4="+CheckInDate4+"&Days4="+Days4+"&Destination5="+Destination5+"&CheckInDate5="+CheckInDate5+"&Days5="+Days5+"&Destination6="+Destination6+"&CheckInDate6="+CheckInDate6+"&Days6="+Days6+"&Destination7="+Destination7+"&CheckInDate7="+CheckInDate7+"&Days7="+Days7+"&Destination8="+Destination8+"&CheckInDate8="+CheckInDate8+"&Days8="+Days8,true);
			xmlhttp.send(null);
		}
		else
		{
			document.getElementById('RateCheck').innerHTML = '';
		}
	}
	catch(err)
	{ }		
	
}

