document.write('<link href=\"../../css/frankenmuth_booking_form.css\" rel=\"stylesheet\" type=\"text/css\" />\n');
document.write('<div class=\"jrs_clr\"></div>\n');
document.write('<div id=\"jrs_calendar_form\" style=\"overflow:hidden;\">\n');
document.write('<form action=\"http://bookdirect.frankenmuth.org/\" method=\"get\" id=\"widget_booking_form\" name=\"widget_booking_form\" enctype=\"multipart/form-data\" target=\"_blank\" onsubmit=\"check_dates();\"> \n');
document.write('    <input type=\"hidden\" name=\"cloneID\" id=\"cloneID\" value=\"516\" />\n');
document.write('	<input type=\"hidden\" name=\"group_id\" id=\"group_id\" value=\"8105\" />\n');
document.write('    <input type=\"hidden\" name=\"rooms\" value=\"1\" />\n');
document.write('    <input type=\"hidden\" name=\"nights\" id=\"nights\" value=\"1\" />\n');
document.write('    <input type=\"hidden\" name=\"sDay\" id=\"sDay\" value=\"24\" />\n');
document.write('    <input type=\"hidden\" name=\"sMonth\" id=\"sMonth\" value=\"02\" />\n');
document.write('    <input type=\"hidden\" name=\"sYear\" id=\"sYear\" value=\"2012\" />\n');
document.write('		<div id=\"jrs_booking_header\"><img src=\"http://michigan-bookdirect.com/images/bookdirect_images/frankenmuth.org/spacer.gif\" height=\"43\" width=\"1\" border=\"none\" style=\"padding:0px;\" /></div>\n');
document.write('		<div class=\"jrs_clr\"></div>\n');
document.write('		<div id=\"jrs_arrival_input\"><input type=\"text\" name=\"start-date\" id=\"start-date\" class=\"date-pick\" readonly=\"readonly\" value=\"Check-In\" /></div>                \n');
document.write('		<div class=\"jrs_clr\"></div>\n');
document.write('		<div id=\"jrs_departure_input\"><input type=\"text\" name=\"end-date\" id=\"end-date\" class=\"date-pick\" readonly=\"readonly\" value=\"Check-Out\" /></div>\n');
document.write('		<div class=\"jrs_clr\"></div>\n');
document.write('		<div id=\"jrs_lodging_select_div\">\n');
document.write('		                            \n');
document.write('			<select id=\"lodgingID\" name=\"lodgingID\" class=\"jrs_form_select_item\" style=\"width:160px;\">\n');
document.write('				<option value=\"103\" >All Lodging</option>	\n');
document.write('				<option value=\"50\" >Hotels, Motels &amp; Inns</option>	\n');
document.write('				<option value=\"9\" >Resorts, Retreats &amp; Lodges</option>	\n');
document.write('				<option value=\"21\" >Bed &amp; Breakfasts</option>	\n');
document.write('				<option value=\"5\" >Vacation Rentals &amp; Cabins</option>	\n');
document.write('				<option value=\"7\" >RV &amp; Campgrounds</option>	\n');
document.write('						\n');
document.write('		</select>  \n');
document.write('		</div>\n');
document.write('		<div class=\"jrs_clr\"></div>\n');
document.write('		<div id=\"jrs_search_submit\">\n');
document.write('		  <input type=\"image\" align=\"middle\" name=\"Submit\" src=\"http://michigan-bookdirect.com/images/bookdirect_images/frankenmuth.org/search.gif\" style=\"border:none\">\n');
document.write('		</div>\n');
document.write('	</form>\n');
document.write('</div>\n');
document.write('</div>\n');
document.write('\n');
document.write('<style>\n');
document.write('#jrs_calendar_form{\n');
document.write('	width:185px !important;\n');
document.write('	background-image:url(\'http://michigan-bookdirect.com/images/bookdirect_images/frankenmuth.org/formBkg.png\');\n');
document.write('	background-repeat:no-repeat !important;\n');
document.write('	font-family: Arial, Helvetica, Verdana, sans-serif !important;\n');
document.write('	font-size:11px !important;\n');
document.write('	color:#000 !important;\n');
document.write('	height:194px !important;\n');
document.write('	line-height:12px !important;\n');
document.write('	padding:0px;\n');
document.write('	overflow:hidden; !important;\n');
document.write('}\n');
document.write('.date-pick{\n');
document.write('	width:100px !important;\n');
document.write('	padding:1px 0px !important;\n');
document.write('}\n');
document.write('#jrs_booking_header{\n');
document.write('	float:none !important;\n');
document.write('}\n');
document.write('#jrs_booking_sub_header{\n');
document.write('}\n');
document.write('.jrs_form_text{\n');
document.write('	float:none !important;\n');
document.write('	font-weight:500 !important;\n');
document.write('}\n');
document.write('#jrs_adults_div{\n');
document.write('}\n');
document.write('#jrs_kids_div{\n');
document.write('}\n');
document.write('.jrs_clr{\n');
document.write('	clear:both !important;\n');
document.write('}\n');
document.write('#jrs_arrival_input{\n');
document.write('	float:none !important;\n');
document.write('	padding:6px 0px !important;\n');
document.write('	text-align:center !important;\n');
document.write('}\n');
document.write('#jrs_arrival_input img{\n');
document.write('	padding:0px !important;\n');
document.write('}\n');
document.write('#jrs_departure_input{\n');
document.write('	float:none !important;\n');
document.write('	padding:6px 0px !important;\n');
document.write('	text-align:center !important;\n');
document.write('}\n');
document.write('#jrs_departure_input img{\n');
document.write('	padding:0px !important;\n');
document.write('}\n');
document.write('#jrs_lodging_select_div{\n');
document.write('	float:none !important;\n');
document.write('	padding:6px 0px !important;\n');
document.write('	text-align:center !important;\n');
document.write('}\n');
document.write('#jrs_location_dropdown_div{\n');
document.write('	float:none !important;\n');
document.write('	padding:6px 0px !important;\n');
document.write('}\n');
document.write('.ui-datepicker-trigger{\n');
document.write('	display:inline !important;\n');
document.write('	border:none !important;\n');
document.write('	position:relative !important;\n');
document.write('	left:-18px !important;\n');
document.write('	top:4px !important;\n');
document.write('	margin-bottom:0px !important;\n');
document.write('	margin-top:0px !important;\n');
document.write('	vertical-align:top !important;\n');
document.write('}\n');
document.write('.jrs_form_select_item{\n');
document.write('	font-size:10px !important;\n');
document.write('	padding:1px 0px !important;\n');
document.write('}\n');
document.write('#jrs_search_submit{\n');
document.write('	float:none !important;\n');
document.write('	padding:10px 0px !important;\n');
document.write('	text-align:center !important;\n');
document.write('}\n');
document.write('.ui-datepicker{\n');
document.write('	z-index:1000 !important;\n');
document.write('}\n');
document.write('#datepicker_div a, .datepicker_inline a {\n');
document.write('	font-size:11px !important;\n');
document.write('}\n');
document.write('</style>\n');
document.write('<!--[if lte IE 7]>\n');
document.write('<style type=\"text/css\">\n');
document.write('.ui-datepicker-trigger{\n');
document.write('		display:inline !important;\n');
document.write('		border:none !important;\n');
document.write('		position:relative !important;\n');
document.write('		left:-18px !important;\n');
document.write('		top:4px !important;\n');
document.write('		margin-bottom:0px !important;\n');
document.write('		margin-top:0px !important;\n');
document.write('		vertical-align:top !important;\n');
document.write('	}</style>\n');
document.write('<![endif]-->\n');
document.write('\n');

$(document).ready(function() {

    $('#start-date').datepicker({
		minDate: 0, 
        maxDate: '+1Y',
		numberOfMonths: 1,
        hideglitched: false,
        showOn: 'both', 
        buttonImage: 'http://michigan-bookdirect.com/images/bookdirect_images/frankenmuth.org/cal.gif', 
        buttonImageOnly: true,   	
        onSelect: DatePicked
    });
    $('#end-date').datepicker({
		minDate: 1, 
        maxDate: '+1Y',
		numberOfMonths: 1,
        hideglitched: false,
        showOn: 'both', 
        buttonImage: 'http://michigan-bookdirect.com/images/bookdirect_images/frankenmuth.org/cal.gif', 
        buttonImageOnly: true,      	
        onSelect: DatePicked      
    });    
    
    $("#nights").change(DatePicked);
}); 


// JavaScript Document
function format_date(ms) {
    var thedate;
    thedate = new Date(ms);
    return (thedate.getMonth() + 1) + '/' + zeropad(thedate.getDate(),2) + '/' + thedate.getFullYear();  // Jan = 0
}

function zeropad (num, zeros) {
    var retval = '';
    var numstr = num.toString();
    for (var i=numstr.length; i < zeros; i++) {
        retval += '0';
    }
    retval += numstr;
    return retval;
}

function DatePicked() {
	var departure = $("#start-date");
	var arrival = $("#end-date");
	var nights = $("#nights");
	var oneDay = 1000*60*60*24;
	var triggeringElement = $(this);
	
	var departureDate = departure.datepicker("getDate");
	
	var minArrivalDate = new Date();
	if (departureDate != null) {
		var minArrivalDate = new Date(departureDate.getTime() + (oneDay));
	} else {
		minArrivalDate.setDate(minArrivalDate.getDate());
	}
	arrival.datepicker('option', 'minDate', minArrivalDate);
	
	var arrivalDate = arrival.datepicker("getDate");
	
	if (departureDate != null && arrivalDate != null && triggeringElement.attr("id") != "nights") {
		var difference = Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay);
		nights.val(difference);
	} else if (departureDate != null && triggeringElement.attr("id") == "nights") {
		var nightsEntered = parseInt(nights.val());
		if (nightsEntered >= 2) {
			var newArrivalDate = new Date();
			newArrivalDate.setDate(departureDate.getDate() + nightsEntered);
			arrival.datepicker("setDate", newArrivalDate);
		} else {
			alert("You must select 1 or more nights.");
		}
	}
	
	set_date_fields();
}

function DatePicked_LA_conf(){
	var departure = $("#start-date");
	var arrival = $("#end-date");
	var nights = $("#nights");
	var oneDay = 1000*60*60*24;
	var triggeringElement = $(this);
	
	var departureDate = departure.datepicker("getDate");
	
	var minArrivalDate = new Date();
	if (departureDate != null) {
		minArrivalDate = departureDate;
		minArrivalDate.setDate(minArrivalDate.getDate()+1);
	} else {
		minArrivalDate.setDate(minArrivalDate.getDate());
	}
	
	if(departureDate.getDate()>arrival.datepicker("getDate").getDate()) arrival.datepicker('setDate', minArrivalDate);
	
	var arrivalDate = arrival.datepicker("getDate");
	
	if (departureDate != null && arrivalDate != null && triggeringElement.attr("id") != "nights") {
		var difference = Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay);
		nights.val(difference);
	} else if (departureDate != null && triggeringElement.attr("id") == "nights") {
		var nightsEntered = parseInt(nights.val());
		if (nightsEntered >= 2) {
			var newArrivalDate = new Date();
			newArrivalDate.setDate(departureDate.getDate() + nightsEntered);
			arrival.datepicker("setDate", newArrivalDate);
		} else {
			alert("You must select 1 or more nights.");
		}
	}
	
	set_date_fields();
}
		
function set_arrival (chosenvalue) {
    update_hiddens('arrival', chosenvalue); 
}
function set_departure (chosenvalue) {
    update_hiddens('departure', chosenvalue); 
}

function set_date_fields() {
    var arrival, departure;
    var now = new Date();
    var one_day=1000*60*60*24;							
    
	arrival = new Date(document.getElementById('start-date').value);
	
    document.getElementById('sDay').value = arrival.getDate();
    if(document.getElementById('sDay').value.length==1){
    	document.getElementById('sDay').value = '0'+document.getElementById('sDay').value;
    }    
    document.getElementById('sMonth').value = arrival.getMonth() + 1;  // Jan = 0
    if(document.getElementById('sMonth').value.length==1){
    	document.getElementById('sMonth').value = '0'+document.getElementById('sMonth').value;
    }
    document.getElementById('sYear').value = arrival.getFullYear();	

}



function check_submit(){
	if(document.getElementById('group_id').value == ''){
    	alert('Please enter a city.');
        return false;
    }
    else{
    	return true;
    }
}

function check_dates(){
	if(document.getElementById('start-date').value == 'Check-In' || document.getElementById('end-date').value == 'Check-Out'){
    	document.getElementById('start-date').value = '02/24/2012';
        document.getElementById('end-date').value = '02/25/2012';
    }
}

function submit_asp(site_url){
	check_dates();
	form_data = $('#jrs_calendar_form :input').serialize();
	window.open(site_url+'redirect_booking.php?'+form_data);
}
;

