// JavaScript Document
Ajax.Responders.register({
    onCreate: function(){
        document.body.style.cursor = 'wait';
        var top = document.viewport.getScrollOffsets().top;
        $('loading').setStyle({
            'top': top + "px"
        });
        $('loading').show();
    },
    onComplete: function(){
        document.body.style.cursor = 'default';
        $('loading').hide();
    }
});
var showInnMenu = function(){
    $$("#subTriggerInn a:hover").each(
        function(element){
            element.setStyle({
                'color': "#EAD920"
            });
        }
    );
    $("subMenuInn").show();
};
var hideInnMenu = function(){
    $$("#subTriggerInn a:hover").each(
        function(element){
            element.setStyle({
                'color': "#FFFFFF"
            });
        }
    );
    $("subMenuInn").hide();
};
var showMemberMenu = function(){
    $$("#subTriggerMember a:hover").each(
        function(element){
            element.setStyle({
                'color': "#EAD920"
            });
        }
    );
    $("subMenuMember").show();
};
var hideMemberMenu = function(){
    $$("#subTriggerMember a:hover").each(
        function(element){
            element.setStyle({
                'color': "#FFFFFF"
            });
        }
    );
    $("subMenuMember").hide();
};

function updateStates(){
    var country = $('country').value;
    if(country=='United States'){
        $('stateHeader').style.display = 'block';
        $('stateCa').style.display = 'none';
        $('stateMex').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateUs').style.display = 'block';
        $('city').value='';
    }
    else if(country=='Canada'){
        $('stateHeader').style.display = 'block';
        $('stateMex').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateCa').style.display = 'block';
        $('city').value='';
    }
    else if(country=='Mexico'){
        $('stateHeader').style.display = 'block';
        $('stateCa').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateMex').style.display = 'block';
        $('city').value='';
    }
    else if(country=='Australia'){
        $('stateHeader').style.display = 'block';
        $('stateCa').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateMex').style.display = 'none';
        $('stateAu').style.display = 'block';
        $('city').value='';
    }
    else{
        $('stateCa').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateMex').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateHeader').style.display = 'none';
        $('city').value='';
    }
}

function carouselUp(){
    if(carouselPosition<6){
        var obj = $('carouselList');
        var move = new Effect.Move(obj, {
             x: 0,
             y: -61,
             mode: 'relative'
        });
        carouselPosition++;
    }
}

function carouselDown(){
    if (carouselPosition > 0) {
        var obj = $('carouselList');
        var move = new Effect.Move(obj, {
            x: 0,
            y: +61,
            mode: 'relative'
        });
        carouselPosition--;
    }
}

function initIndexPage(){
    initWorld();
    initGoButton();
}

function initGoButton(){
    var element = $('goButton');
    element.onmouseover = function(){
        element.style.opacity='1';
        element.style.cursor='pointer';
    };
    element.onmouseout = function(){
        element.style.opacity='.8';
        element.style.cursor='default';
    }
    element.onclick = function(){
        var country = $('country').value;
        if(country=='United States'){
            var state = $('stateUs').value;
            if(state.length<2){
                alert('Please select a state');
                return false;
            }
        }
        else if(country=='Canada'){
            var state = $('stateCa').value;
            if(state.length<1){
                alert('Please select a province');
                return false;
            }
        }
        else if(country=='Mexico'){
            var state = $('stateMex').value;
            if(state.length<1){
                alert('Please select a state');
                return false;
            }
        }
        else if(country=='Australia'){
            var state = $('stateAu').value;
            if(state.length<1){
                alert('Please select a state');
                return false;
            }
        }
        var city = $('city').value;
        if(city.length<1){
            alert('Please enter a city');
            return false;
        }
       $('postCheckin').value = $('checkin').value;
       $('postCheckout').value = $('checkout').value;
        document.searchForm.submit();
    }
}

function initGoButton2(){
    var element = $('goButton2');
    element.onmouseover = function(){
        element.style.opacity='1';
        element.style.cursor='pointer';
    };
    element.onmouseout = function(){
        element.style.opacity='.8';
        element.style.cursor='default';
    }
    element.onclick = function(){
		$('submitType').value = 'innName';
        document.searchForm.submit();
    }
}

function validateBidForm(){
     var country = $('country').value;
        if(country=='United States'){
            var state = $('stateUs').value;
            if(state.length<2){
                alert('Please select a state');
                return false;
            }
        }
        else if(country=='Canada'){
            var state = $('stateCa').value;
            if(state.length<1){
                alert('Please select a province');
                return false;
            }
        }
        else if(country=='Mexico'){
            var state = $('stateMex').value;
            if(state.length<1){
                alert('Please select a province');
                return false;
            }
        }
        var city = $('city').value;
        if(city.length<1){
            alert('Please enter a city');
            return false;
        }
        var checkin = $('checkin').value;
        if(checkin.length<1){
            alert('Please choose a check in date');
            return false;
        }
        var checkout = $('checkout').value;
        if(checkout.length<1){
            alert('Please choose a check out date');
            return false;
        }
        $('postCheckin').value = checkin;
        $('postCheckout').value = checkout;
        var amount = $('amount').value;
        if(amount.length<2){
            alert('Please enter an amount');
            return false;
        }
        var numberOfGuests = $('numberOfGuests').value;
        if(numberOfGuests<1){
            alert('Please select the number of guests');
            return false;
        }
        document.bidForm.submit();
}

function validateFeaturedDeals(){
 	document.featuredDealsForm.submit();
}

function featuredDealsCountrySelect(){
	var country = $('country').value;
    if(country=='United States'){
        $('stateHeader').style.display = 'block';
        $('stateCa').style.display = 'none';
        $('stateMex').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateUs').style.display = 'block';
        $('city').value='All';
    }
    else if(country=='Canada'){
        $('stateHeader').style.display = 'block';
        $('stateMex').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateCa').style.display = 'block';
        $('city').value='All';
    }
    else if(country=='Mexico'){
        $('stateHeader').style.display = 'block';
        $('stateCa').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateMex').style.display = 'block';
        $('city').value='All';
    }
    else if(country=='Australia'){
        $('stateHeader').style.display = 'block';
        $('stateCa').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateMex').style.display = 'none';
        $('stateAu').style.display = 'block';
        $('city').value='All';
    }
    else{
        $('stateCa').style.display = 'none';
        $('stateUs').style.display = 'none';
        $('stateMex').style.display = 'none';
        $('stateAu').style.display = 'none';
        $('stateHeader').style.display = 'none';
        $('city').value='All';
    }
}

function initCountry(country){
    var regex = new RegExp('\\b'+ 'hoverAction' + '\\b');
    var elements = $('hoverBlock').getElementsByTagName("div");
    for (var i = 0; i < elements.length; i++) {
        if (regex.test(elements[i].className)) {
            elements[i].onmouseover = function(){
                this.style.backgroundColor = '#a3b6c6'
                var id = this.id;
                var tempArray = id.split('_');
                var index = tempArray[1];
                //var locationName = tempArray[2];
                var movie = getFlashMovieObject(country+"Movie");
                movie.sendHoverToFlash(index);

            };
            elements[i].onmouseout = function(){
                this.style.backgroundColor = '';
                var id = this.id;
                var tempArray = id.split('_');
                var index = tempArray[1];
                //var locationName = tempArray[2];
                var movie = getFlashMovieObject(country+"Movie");
                movie.sendHoverOutToFlash(index);
            };
        };
    };
}

function initWorld(){
    for (var j = 0; j < 2; j++) {
        if(j==0){
            var element='hoverBlock';
        }
        else{
            var element='hoverBlock2';
        }
        var regex = new RegExp('\\b' + 'hoverAction' + '\\b');
        var elements = $(element).getElementsByTagName("div");
        for (var i = 0; i < elements.length; i++) {
            if (regex.test(elements[i].className)) {
                elements[i].onmouseover = function(){
                    this.style.backgroundColor = '#a3b6c6'
                    var id = this.id;
                    var tempArray = id.split('_');
                    var index = tempArray[1];
                    //var locationName = tempArray[2];
                    var movie = getFlashMovieObject("worldMovie");
                    movie.sendHoverToFlash(index);

                };
                elements[i].onmouseout = function(){
                    this.style.backgroundColor = '';
                    var id = this.id;
                    var tempArray = id.split('_');
                    var index = tempArray[1];
                    //var locationName = tempArray[2];
                    var movie = getFlashMovieObject("worldMovie");
                    movie.sendHoverOutToFlash(index);
                };
            }
        }
    }
}

function clickNorthAmerica(){
    $('hoverBlock').style.display='none';
    $('hoverBlock2').style.display='block';
    var movie = getFlashMovieObject("worldMovie");
    movie.sendNAToFlash();
}

function clickNAFromFlash(){
    $('hoverBlock').style.display='none';
    $('hoverBlock2').style.display='block';
}

function backToWorldFromFlash(){
    $('hoverBlock2').style.display='none';
    $('hoverBlock').style.display='block';
}

function flashHoverElement(index,element){
    $('hover_'+index+'_'+element).style.backgroundColor = '#a3b6c6';
}

function flashHoverOutElement(index,element){
    $('hover_'+index+'_'+element).style.backgroundColor = '';
}

function getFlashMovieObject(movieName){
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1){
        if (document.embeds && document.embeds[movieName]) {
            return document.embeds[movieName];
        }
    }
    else{
        return document.getElementById(movieName);
    }
}

function hover(element){
	$(element).style.cursor='pointer';
}

function hoverElement(element){
	element.style.cursor='pointer';
}

function redirect(location){
	var location = baseUrl + '/' + location;
	window.location = location;
}

function redirectUrl(url){
	window.location = url;
}

function toggleSection(sectionName){
	var element=$(sectionName);
	Effect.toggle(element, 'blind', {duration:1.5});
}

function showBio(num){
    var element = $('bio'+num);
    if (element.style.display=='none'){
        element.show();
        $('bio'+num+'Head').update('Hide');
    }
    else{
        element.hide();
        $('bio'+num+'Head').update('Biography');
    }
}

function toggleMap(){
	if($('mapButton').value == 'Show Map'){
		$('mapButton').value = 'Hide Map';
	}
	else{
		$('mapButton').value = 'Show Map';
	}
	Effect.toggle('gmap', 'blind', {duration:.5});
}

var map = null;
var loadCounter=1;
function loadMap(lat, lon, name, address, city, state, from){
  	if(GBrowserIsCompatible()){
		var map = new GMap2(document.getElementById("map"));
		var center = new GLatLng(lat, lon);
		map.setCenter(center, 13);
		var directionsPanel = document.getElementById("innDirections");
  		var directions = new GDirections(map, directionsPanel);
  		directions.load(from+" to "+address+" , "+city+" , "+state);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var marker = new GMarker(center, {title:name});
		map.addOverlay(marker);
	}
}

function reLoadMap(lat, lon, address, city, state, from){
	if(from.length<1){
		var from=$('directionsFrom').value;
		if(from.length<1){
			alert('Please enter an address');
			return false;
		}
	}
	var map = new GMap2(document.getElementById("map"));
	var center = new GLatLng(lat, lon);
	map.setCenter(center, 13);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	var marker = new GMarker(center, {title:name});
	map.addOverlay(marker);
	var directionsPanel =$("innDirections");
	Effect.toggle(directionsPanel, 'blind', {
		duration:1,
		afterFinish:function(){
			directionsPanel.innerHTML='';
			var directions = new GDirections(map, directionsPanel);
			directions.load(from+" to "+address+" , "+city+" , "+state);
			Effect.toggle(directionsPanel, 'blind', {
				duration:1}
			);
		}
	});
}

function loadMapAjax(type, lat, lon, zoomLevel, value, markerCount){
    if (markerCount > 0 && markerCount<500) {
        $('message').innerHTML = "Please wait while we load " + markerCount + " inns onto the map <img align='middle' src='" + baseUrl + "/public/images/design2/spinner.gif' />";
    }
    var zoomLevel = parseInt(zoomLevel);
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        var center = new GLatLng(lat, lon);
        map.setCenter(center, zoomLevel);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
		if (markerCount < 500) {
			var url = baseUrl + "/ajax/getmapmarkers";
			var requestObject = new Object();
			requestObject.type = type;
			requestObject.value = value;
			var jsonRequest = JSON.stringify(requestObject);
			new Ajax.Request(url, {
				method: 'post',
				parameters: 'request=' + escape(jsonRequest),
				onSuccess: function(transport){
					var responseObject = JSON.parse(transport.responseText);
					for (i = 0; i < responseObject.marker.length; i++) {
						addMarker(responseObject.marker[i]);
					}
					$('message').hide();
					Effect.toggle('gmap', 'blind', {
						duration: 1.5
					});
				}
			});
		}
    }
}

function addMarker(data){
	var point = new GLatLng(data.lat,data.lon);
	map.addOverlay(createMarkerDetail(point,data));
}

function createMarkerDetail(point,data){
	var marker = new GMarker(point, {title:data.name});
  	marker.value = data.innId;
  	GEvent.addListener(marker, "click", function() {
   	 	var myHtml = "<a href='"+baseUrl+"/detail/inn/innId/"+data.innId+"'>"+data.name+"</a>"+"<br/>"+data.address+"<br/>"+data.city;
    	map.openInfoWindowHtml(point, myHtml);
  	});
  	return marker;
}

function toggleDirections(){
	Effect.toggle('innDirectionsBox', 'blind', {duration:1.5});
}
function showGuestBox(){
	var numberOfRooms=$('numberOfRooms').value;
	if(numberOfRooms==0){
		$('numberOfGuests').style.display='none';
	}
	else{
		var html='';
		for(var i=1;i<=numberOfRooms;i++){
			html=html+"Room "+i+": Number of Guests <select id='numberOfGuests_"+i+"' name='numberOfGuests_"+i+"'>";
			for(var j=1;j<=6;j++){
				html=html+"<option value='"+j+"'>"+j+"</option>";
			}
			html=html+"</select><br/>";
		}
		$('numberOfGuests').innerHTML=html;
		$('numberOfGuests').style.display='block';
	}
}

function getLatLon() {
	var geocoder = new GClientGeocoder();
	var street = $('address').value;
	var city = $('city').value;
	var country = $('country').value;
	var state = '';
	var zip = $('zip').value;
	if(country == '' || country == 'United States'){
		state = $('stateUs').value;
	}
	else{
		if(country == 'Canada'){
			state = $('stateCa').value;
		}
		else{
			if(country == 'Mexico'){
				state = $('stateMex').value;
			}
			else{
				if(country == 'Australia'){
					state = $('stateAu').value;
				}
			}
		}
	}
	var address = street+' '+city+' '+state+' '+zip+' '+country;
  	geocoder.getLatLng(
		address,
    	function(point) {
      		if (!point) {
        		alert(address + " was not found. Please verify the address and try again or manually enter and save your latitude and longitude");
      		} 
			else {
        		$('latitude').value = point.lat();
				$('longitude').value = point.lng();
      		}
    	}
  	);
}




function checkInnAvailability(){
	if(validateDatesForSearch()){
	    $("advise").hide();
		Effect.Fade('instructions',{duration:0.25});
		Effect.Fade('availableRooms',{duration:0.25});
		Effect.Fade('reservationDetail',{duration:0.25});
		var url=baseUrl+'/ajax/innavailability';
        var requestObject = new Object();
        requestObject.action = 'new';
        requestObject.innId = innId;
        requestObject.checkin = $('checkin').value;
        requestObject.checkout = $('checkout').value;
        var jsonRequest = JSON.stringify(requestObject);
		new Ajax.Updater('availableRooms',url,{
			method: 'post',
		   	parameters: 'request='+escape(jsonRequest),
		   	evalScripts:true,
		   	onSuccess:function(transport){
			  	Effect.Appear('instructions',{duration:0.5});
			  	Effect.Appear('availableRooms',{duration:0.5});
			  	Effect.Appear('reservationDetail',{duration:0.5});
			}
		});
		var url=baseUrl+'/ajax/updatereservationbox';
		new Ajax.Updater('reservationDetail', url, {
			method: 'post',
			parameters: {action:'clearBox'},
			evalScripts:true
		});
	}
	else{
	    $("advise").show();
	}
}

function validateDatesForSearch(){
	var startDate=$('checkin').value;
	if(startDate.length<1){
		$('advise').innerHTML="<div style='color:red'>No Check In Date</div>";
		return false;
	}
	var endDate=$('checkout').value;
	if(endDate.length<1){
		$('advise').innerHTML="<div style='color:red'>No Check Out Date</div>";
		return false;
	}
	$('advise').innerHTML = '&nbsp;';
	return true;
}

function setNumberOfGuests(roomId){
	$('advise').addClassName('spinner');
	var numberOfGuests=$('numberOfGuests_'+roomId).value;
	var url=baseUrl+'/ajax/setnumberofguests';
	new Ajax.Request(url,{
		method:'post',
		parameters: {roomId : roomId, numberOfGuests: numberOfGuests},
		onSuccess:function(){
			$('advise').removeClassName('spinner');
		}
	});
}

function validateNumberOfGuests(){
	$('advise').addClassName('spinner');
	var url=baseUrl+'/ajax/validatenumberofguests';
	new Ajax.Request(url,{method:'get',
    		onSuccess: function(transport){
			if(transport.responseText=='valid'){
				var location=baseUrl+'/booking/step1';
				window.location=location;
			}
			else{
				$('advise').removeClassName('spinner');
				$('message').innerHTML='Please choose the number of guests in each room';
			}
    		}
  	});
}

function iframeValidateNumberOfGuests(){
	$('advise').addClassName('spinner');
	var url=baseUrl+'/ajax/validatenumberofguests';
	new Ajax.Request(url,{method:'get',
    		onSuccess: function(transport){
			if(transport.responseText=='valid'){
				var location=baseUrl+'/booking/step1';
				window.location=location;
			}
			else{
				$('advise').removeClassName('spinner');
				$('message').innerHTML='Please choose the number of guests in each room';
			}
    		}
  	});
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function dragDropAvailability(){
	Droppables.add('reservationDetail',{
		accept: 'availableItem',
		onDrop: function(element){
			$('advise').addClassName('spinner');
			var url=baseUrl+'/ajax/updatereservationbox';
			new Ajax.Updater('reservationDetail', url, {
				method: 'post',
				parameters: {action:'addRoom', roomId:element.id},
				evalScripts:true,
				onSuccess:function(){
					$('advise').removeClassName('spinner');
					element.style.display='none';
				}
			});
		}
	});

	Droppables.add('availableRooms',{
		accept: 'reservation',
		onDrop: function(element){
			$('advise').addClassName('spinner');
			var url=baseUrl+'/ajax/updatereservationbox';
			new Ajax.Updater('reservationDetail', url, {
				method: 'post',
				parameters: {action:'removeRoom', roomId:element.id},
				evalScripts:true,
				onSuccess:function(){
					var url=baseUrl+'/ajax/innavailability';
					var requestObject = new Object();
			        requestObject.action = 'update';
			        var jsonRequest = JSON.stringify(requestObject);
					new Ajax.Updater('availableRooms', url, {
						method: 'post',
						parameters: 'request='+escape(jsonRequest),
						evalScripts:true,
						onSuccess:function(){
							$('advise').removeClassName('spinner');
						}
					});
				}
			});
		}
	});
}

function iframeDragDropAvailability(){
	Droppables.add('reservationDetail',{
		accept: 'availableItem',
		onDrop: function(element){
			$('advise').addClassName('spinner');
			var url=baseUrl+'/ajax/iframeupdatereservationbox';
			new Ajax.Updater('reservationDetail', url, {
				method: 'post',
				parameters: {action:'addRoom', roomId:element.id},
				evalScripts:true,
				onSuccess:function(){
					$('advise').removeClassName('spinner');
					element.style.display='none';
				}
			});
		}
	});

	Droppables.add('availableRooms',{
		accept: 'reservation',
		onDrop: function(element){
			$('advise').addClassName('spinner');
			var url=baseUrl+'/ajax/iframeupdatereservationbox';
			new Ajax.Updater('reservationDetail', url, {
				method: 'post',
				parameters: {action:'removeRoom', roomId:element.id},
				evalScripts:true,
				onSuccess:function(){
					var url=baseUrl+'/ajax/iframeinnavailability';
					var requestObject = new Object();
			        requestObject.action = 'update';
			        var jsonRequest = JSON.stringify(requestObject);
					new Ajax.Updater('availableRooms', url, {
						method: 'post',
						parameters: 'request='+escape(jsonRequest),
						evalScripts:true,
						onSuccess:function(){
							$('advise').removeClassName('spinner');
						}
					});
				}
			});
		}
	});
}

function clickDot(section,id){
	var text_element=$(section+"_text");
	text_element.innerHTML=reviewText[id];
	for(var i=1;i<=5;i++){
		var element=$(section+"_"+i);
		if(i<=id){
			element.innerHTML="<img src='"+dotSelected+"' />";
		}
		else{
			element.innerHTML="<img src='"+dotBlank+"' />";
		}
	}
	scores[section]=id;
}

function validateReviewSubmit(){
	if(scores['overall']<1){
		alert('Please select an overall score');
		return false;
	}
	else if(scores['room']<1){
		alert('Please select a room score');
		return false;
	}
	else if(scores['service']<1){
		alert('Please select a service score');
		return false;
	}
	else if(scores['value']<1){
		alert('Please select a value score');
		return false;
	}
	else if(scores['cleanliness']<1){
		alert('Please select a cleanliness score');
		return false;
	}
	else if(scores['meals']<1){
		alert('Please select a meals score');
		return false;
	}
	$('Overall').value=scores['Overall'];
	$('Room').value=scores['Room'];
	$('Service').value=scores['Service'];
	$('Value').value=scores['Value'];
	$('Cleanliness').value=scores['Cleanliness'];
	$('Food').value=scores['Food'];
	return true;
}

function createDragDropSelectionBox(baseUrl){
	Droppables.add('selectionBox',{
			accept: 'availableSelection',
			onDrop: function(element){
				var selectionArray=element.id.split("_");
				var selection=selectionArray[1];
				document.body.style.cursor='wait';
				var url=baseUrl+"/search/ajaxupdateselections/function/add/selection/"+selection;
				new Ajax.Updater('selectionBox', url, { method: 'get', evalScripts:true, onSuccess:function(){
					element.style.display='none';
						document.body.style.cursor='default';
					} });
			}});

	Droppables.add('availableBox',{
		accept: 'selectedSelection',
		onDrop: function(element){
			var selectionArray=element.id.split("_");
			var selection=selectionArray[1];
			document.body.style.cursor='wait';
			var url=baseUrl+"/search/ajaxupdateselections/function/remove/selection/"+selection;
			new Ajax.Updater('selectionBox', url, { method: 'get', evalScripts:true, onSuccess:function(){
				element.style.display='none';
				var availableElement=$('available_'+selection);
				availableElement.style.display='block';
					document.body.style.cursor='default';
				} });
		}});
}

function addFavorite(innId){
	var url=baseUrl+"/ajax/addfavorite/innId/"+innId;
	new Ajax.Request(url,{
		method:'get',
		onSuccess: function(transport){
			if(transport.responseText=='fail'){
				var proceed=confirm('You must be logged in to use this feature, proceed to log in?');
				if(proceed){
					var location=baseUrl+'/member/member/function/addFavorite/innId/'+innId;
					window.location=location;
				}
			}
			else{
				alert(transport.responseText);
			}
		}
	});
}

function addFavoriteRecipe(recipeId){
	new Effect.Highlight('favoriteFlash_'+recipeId,{startcolor:'#FFFF66', endcolor:'#FFFFFF', restoreColor:"#FFFFFF",
	duration: 1, afterFinish:function(){
		var url=baseUrl+"/ajax/addfavoriterecipe/recipeId/"+recipeId;
			new Ajax.Request(url,{
				method:'get',
				onSuccess: function(transport){
					if(transport.responseText=='fail'){
						var proceed=confirm('You must be logged in to use this feature, proceed to log in?');
						if(proceed){
							var location=baseUrl+'/member/member/function/addFavoriteRecipe/recipeId/'+recipeId;
							window.location=location;
						}
					}
					else{
						alert(transport.responseText);
					}
				}
			});
	 }});
}

function reportContent(baseUrl,reviewId){
	alert('Thanks for your report');
	var url=baseUrl+'/review/report/reviewId/'+reviewId;
	new Ajax.Request(url,{method:'get'});
}

function showGuestBookPhotoUpload(){
	Effect.Fade('guestbookVideoUpload',{
	    duration:0.5,
	    afterFinish: function(){
            Effect.Appear('guestbookPhotoUpload',{
                duration:0.5
            });
        }
	});
}

function showGuestBookVideoUpload(){
	Effect.Fade('guestbookPhotoUpload',{
	    duration:0.5,
	    afterFinish:function(){
		  Effect.Appear('guestbookVideoUpload',{
		      duration:0.5
		  });
		}
	});
}

function clickBilling(input){
	if(input=='Yes'){
		$('bFirstName').value=$('pFirstName').value;
		$('bLastName').value=$('pLastName').value;
		$('bAddress').value=$('pAddress').value;
		$('bCity').value=$('pCity').value;
		$('bState').value=$('pState').value;
		$('bZip').value=$('pZip').value;
	}
}

function toggleAvailability(name_item){
    $("more_" + name_item).toggle();
    $("less_" + name_item).toggle();
	Effect.toggle($(name_item), 'blind', {duration:0.5});
}

function showCBMessage(){
	var text = "We're sorry, this member has not yet upgraded their membership to ";
	text+="accept online bookings.  Only our Preferred Members are able to offer ";
	text+="online bookings. Are you the owner of this property? Stop missing customers; ";
	text+="find out now how all the benefits of TheBedandBreakfastList can be yours for ";
	text+="less than a $1 a day!";
	alert(text);
}

function showCBMessage1(innId){
	var url=baseUrl+'/ajax/hitreservation/innId/'+innId;
	new Ajax.Request(url,{method:'get'});
	var text = "We're sorry, this member has not yet upgraded their membership to ";
	text+="accept online bookings.  Only our Preferred Members are able to offer ";
	text+="online bookings. Are you the owner of this property? Stop missing customers; ";
	text+="find out now how all the benefits of TheBedandBreakfastList can be yours for ";
	text+="less than a $1 a day!";
	alert(text);
}

function showCBMessage2(innId, bookingStyle){
	var url=baseUrl+'/ajax/hitreservation/innId/'+innId;
	new Ajax.Request(url,{method:'get'});
	if(bookingStyle.length>1 && bookingStyle!='Internal Booking Engine'){
		var method = bookingStyle;
	}
	else{
		var method = 'email';
	}
	var text = "This innkeeper requests that you contact them via ";
	text+=method+" for availability and booking information. ";
	text+="This information can be found to the left under the photo of the inn. Thank you.";
	alert(text);
}

function showCBOwnerMessage(){
	var text="You must be a preferred member to access this section of the website. Join now for only 41 cents per day ";
	text+="and start taking advantage of all the benefits that Spiral Notebook\u2122 Real-Time booking calendar offers. ";
	text+="Stop losing customers to your competitors who do offer Real-Time booking. Join now by clicking the ";
	text+="'Preferred Member' tab. ";
	alert(text);
}

function showCBOwnerMessage2(){
	var text="You must enter your Authorize.net credentials before you can enter availability ";
	text+="and start to accept reservations ";
	alert(text);
}

function submitFormCC(){
	var text="I understand that I am placing a firm order to reserve a room ";
	text+="at this selected hospitality property (inn, hotel, bed and breakfast, ";
	text+="hostel, lodge, resort, vacation rental property or other facility ";
	text+="servicing guests for overnight sleeping accommodations). ";
	text+="I understand that the $4.99 booking fee charged to me by ";
	text+="Innovative Web Enterprises, llc is not refundable under any circumstances. ";
	text+="I have read the Terms and Conditions for the use of this site and the ";
	text+="Privacy Policy and I agree to adhere to the terms as written. I understand that ";
	text+="cancellation policies, refunds and terms of booking at the hospitality ";
	text+="properties vary individually and that I have investigated and agree to the ";
	text+="various policies of the hospitality property which I am about to book. ";
	if (confirm(text)) {
		return true;
	}
	return false;
}

function validateDealSearch(){
     var country = $('country').value;
        if(country=='United States'){
            var state = $('stateUs').value;
            if(state.length<2){
                alert('Please select a state');
                return false;
            }
        }
        else if(country=='Canada'){
            var state = $('stateCa').value;
            if(state.length<1){
                alert('Please select a province');
                return false;
            }
        }
        else if(country=='Mexico'){
            var state = $('stateMex').value;
            if(state.length<1){
                alert('Please select a state');
                return false;
            }
        }
        else if(country=='Australia'){
            var state = $('stateAu').value;
            if(state.length<1){
                alert('Please select a state');
                return false;
            }
        }
        var city = $('city').value;
        if(city.length<1){
            alert('Please enter a city');
            return false;
        }
        var startDate = $('startDate').value;
        if(startDate.length<1){
            alert('Please select a start date');
            return false;
        }
        var endDate = $('endDate').value;
        if(endDate.length<1){
            alert('Please select an end date');
            return false;
        }
        $('postStartDate').value = startDate;
        $('postEndDate').value = endDate;
        return true;
}

function showWhyJoinCostCalculator(){
	window.open(baseUrl+'/footer/whyjoincostcalculator');
}

function showConverter(){
	var location = baseUrl + '/detail/converter';
	window.open(location,'converter','width=300,height=300,resizeable=1,toolbar=1,location=0,directories=0');
}

function popRegisterToBid(){
    var confirmation=confirm("Bid-A-Bed is only available to Registered Members of The Bed and Breakfast List. Proceed to register for your free membership? ");
    if(confirmation){
        document.location=baseUrl+'/member/member';
    }
    else{
        return false;
    }
}

function popLoginMessage(){
    var confirmation=confirm("You must be a registered member of The Bed and Breakfast List. Proceed to register for your free membership or log in to your existing membership? ");
    if(confirmation){
        return true;
    }
    else{
        return false;
    }
}

function messageCounter(){
	var count = $('message').value.length;
	$('messageQuantity').innerHTML = 3000 - count;
}

function showBillingAgreement(){
	var amount = $('amount').value;
	if(amount=='0'){
		$('billingAgreement').hide();
		$('billingAgreement2').hide();
		$('text1').show();
		$('text2').show();
	}
	else{
		$('billingAgreement').show();
		$('billingAgreement2').show();
		$('text1').hide();
		$('text2').hide();
	}
}

function goInnKeeper(innId){
	var confirmation = confirm("Welcome to TheBedAndBreakfastList, you will now be directed to register and confirm your identity. You will need to first register as a new user then you will be able to log in and edit your data. Proceed?");
	if(confirmation){
		document.location=baseUrl+'/inn/register/innId/'+innId;
	}
	else{
		return false;
	}
}

function flashHeaderText(){
	//$('headerText').style.backgroundColor = '#517DAC';
	//$('headerText').style.color = '#ffffff';
	Effect.Pulsate('headerText', {
		pulses:15, duration:10, afterFinish:function(){
			//$('headerText').style.backgroundColor = '#ffffff';
			//$('headerText').style.color = '#7E8832';
		}
	});
}

function redirectToAgreement(){
	//inn/pay.tpl
	var period = $('period').value;
	if(period == 'monthly'){
		var file = $('monthlyAgreement').value;
		var location = baseUrl+'/public/files/'+file;
		window.open(location,'Agreement','width=800,height=1200');
	}
	else{
		var file = $('annualAgreement').value;
		var location = baseUrl+'/public/files/'+file;
		window.open(location,'Agreement','width=800,height=1200');
	}
}

function setBookingStyle(){
	var bookingStyle = $('bookingStyle').value;
	if(bookingStyle == 'External Booking Engine'){
		$('bookingUrl').show();
	}
	else{
		$('bookingUrl').hide();
	}
}

function bookingRedirect(url){
	window.open(url,'newWindow','width=800,height=800');
}

function iframeCheckInnAvailability(){
	if(validateDatesForSearch()){
	    $("advise").hide();
		Effect.Fade('availableRooms',{duration:0.25});
		Effect.Fade('reservationDetail',{duration:0.25});
		var url=baseUrl+'/ajax/iframeinnavailability';
        var requestObject = new Object();
        requestObject.action = 'new';
        requestObject.innId = innId;
        requestObject.checkin = $('checkin').value;
        requestObject.checkout = $('checkout').value;
        var jsonRequest = JSON.stringify(requestObject);
		new Ajax.Updater('availableRooms',url,{
			method: 'post',
		   	parameters: 'request='+escape(jsonRequest),
		   	evalScripts:true,
		   	onSuccess:function(transport){
			  	Effect.Appear('availableRooms',{duration:0.5});
			  	Effect.Appear('reservationDetail',{duration:0.5});
			}
		});
		var url=baseUrl+'/ajax/iframeupdatereservationbox';
		new Ajax.Updater('reservationDetail', url, {
			method: 'post',
			parameters: {action:'clearBox'},
			evalScripts:true
		});
	}
	else{
	    $("advise").show();
	}
}

function showAvailabilityCalendar(){
	$('checkin').value = '';
	$('checkout').value = '';
	Dialog.info(
		{
			url: baseUrl + "/availability/availabilitycalendar/innId/" + innId, 
			options: {
				method: 'get',
				evalScripts: true
			}
		}, 
		{
			className: "dialog", 
			width:725, 
			height:600
		}
	);
}

function setCheckIn(month, day, year){
	$('checkin').value = month + '/' + day + '/' + year;
}

function setCheckOut(month, day, year){
	$('checkout').value = month + '/' + day + '/' + year;
}


/*-----------------Social Links-----------------------------*/
function fbs_click() { //face book
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function GetThisMyspace(T,C,U, L){
    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)+ '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    window.open(targetUrl);
}


