//Flemings Steakhouse local page specific js

var localPage = true;

Event.observe(window, 'load',
      initAllLocal
    );
	
Event.observe(window, 'unload',
      resetFieldsLocal
    );

function initAllLocal() {
	if($('date')) {
		var picker = new Control.DatePicker('date', {icon: '/img/calendar.png'});
    }
}

function resetFieldsLocal() {
	if($('date')) {
		$('guests').selectedIndex = 0;	    
	    $('date').value = "Select a Date";
    }	
};

function slideDownFade(slideId, fadeId) {
	
	//Parse Date data from Date Picker
	var month = "";
	var day = "";
	var year = "";
			
	if($('date').value != "Select a Date") {
		var resDate = $('date').value;
		var sepResDate = resDate;
		var vars = sepResDate.split("-");
		
		month = vars[0];
		day = vars[1];
		year = vars[2];
	}
	else {
		var now = new Date();
		month = now.getMonth() + 1;
		day = now.getDate();
		year = now.getYear();
	}
		
	if($(slideId).style.display == "none"){			
		var locID = "";
		var migrationState = "";
		
		if(document.body.getAttribute('id')) {
			locID = document.body.getAttribute('id')
		}
		else {
			locID = $('location-select').value;
			if(locID) {
			    $('private-dining-wrap').morph('width:382px;', { duration: 0.8 });
			    $('availability-container').morph('width:382px;', { duration: 0.8 });
			}
			else {
			    alert("Please select a Fleming's location for your reservation.");
			    return false;
			}
			
		}
		
		// Determine database migration state 1 - pre, 2 - post
		//migrationState = locID.substring(5);
		//locID = locID.substring(0,4);		
		
		//set reservation URL		
		var ReservePage = "";
		if($('ReservePage'))
		{
			ReservePage = $('ReservePage').value;
		}
		else
		{
		    ReservePage = "reserve";
		}
		
		 
	    var newiframe = document.createElement('iframe');
	    newiframe.id = "availability-iframe";
	    newiframe.style.border = "0px";
	    newiframe.setAttribute('frameBorder', '0');
	    //if(migrationState == "1") {
	    newiframe.src = "https://reservations.flemingssteakhouse.com/" + ReservePage + ".asp?siteid=" + locID + "&PartySize=" + $('guests').value + "&Month=" + month + "&Day=" + day + "&Year=" + year + "&Time=" + $('time').value + "&noclose=x";		
	    //} else if(migrationState == "2") {
	    //    newiframe.src = "https://reservations.flemingssteakhouse.com/" + ReservePage + "2.asp?siteid=" + locID + "&PartySize=" + $('guests').value + "&Month=" + month + "&Day=" + day + "&Year=" + year + "&Time=" + $('time').value + "&noclose=x";
	    //} else {
		//    alert("Please select a Fleming's location for your reservation.");
		//    return false;
		//}
	    //newiframe.src = "reservations.html" + "?date=" + $('date').value + "&time=" + $('time').value + "&guests=" + $('guests').value;
	    newiframe.style.display = "none";
	    $('availability-container').appendChild(newiframe);
		
	    Effect.Fade(fadeId);
	    //added to fade coupons
	    if($('coupon-left')) {
		    $('coupon-left').style.backgroundColor = "#ffffff";
		    $('coupon-right').style.backgroundColor = "#ffffff";
		    Effect.Fade('coupon-left');
		    Effect.Fade('coupon-right');
	    }
	    //added to fade drop-downs on promo page
	    if($('location-select')) {
	        $('location-select').style.visibility = "hidden";
	        $('guests').style.visibility = "hidden";
	        $('time').style.visibility = "hidden";
	    }
	    Effect.Fade('footer');
	    Effect.Appear('availability-iframe', { duration: 0.5, delay: 1.2 });
	    //fade instead of slide
	    //Effect.Appear(slideId, { duration: 0.5, delay: 0.5 });
	    Effect.toggle(slideId,'slide'); 
    }else{
	    var locID = "";
	    if(document.body.getAttribute('id')) {
		    locID = document.body.getAttribute('id')
	    }
	    else {
		    locID = $('location-select').value;
		    $('availability-container').morph('width:382px;', { duration: 1.0 });
	    }
	    Effect.Fade('availability-iframe', { duration: 0.5 });		
	    setTimeout(function(){$('availability-container').removeChild($('availability-iframe'))}, 600);		
	    setTimeout(function(){
		    var newiframe = document.createElement('iframe');
		    newiframe.id = "availability-iframe";
		    newiframe.style.border = "0px";
		    newiframe.setAttribute('frameBorder', 'no');		    
	        newiframe.src = "https://reservations.flemingssteakhouse.com/" + ReservePage + ".asp?siteid=" + locID + "&PartySize=" + $('guests').value + "&Month=" + month + "&Day=" + day + "&Year=" + year + "&Time=" + $('time').value + "&noclose=x";			        
		    //newiframe.src = "reservations.html" + "?date=" + $('date').value + "&time=" + $('time').value + "&guests=" + $('guests').value;
		    newiframe.style.display = "none";
		    $('availability-container').appendChild(newiframe);

		    Effect.Appear('availability-iframe', { duration: 0.5, delay: 0.5 });
	    }, 700);	    
	}	
	return false;
}

function slideUpFade(slideId, fadeId) {
	if(!($(slideId).style.display == "none")){
	
		setTimeout(function(){$('availability-container').removeChild($('availability-iframe'))}, 1000);
		
		if(!(document.body.getAttribute('id'))) {
			$('availability-container').morph('width:304px;', {duration: 1.0 });
		}
		
		//re-appear coupons
		if($('coupon-left')) {
			Effect.Appear('coupon-left');
			Effect.Appear('coupon-right');
			$('coupon-left').style.backgroundColor = "";
		    $('coupon-right').style.backgroundColor = "";
		}
		//added to re-appear drop-downs on promo page
	    if($('location-select')) {	    
	        setTimeout( function() {
	            $('location-select').style.visibility = "visible";
	            $('guests').style.visibility = "visible";
	            $('time').style.visibility = "visible";
	            }, 1700);
	    }
		Effect.Appear(fadeId);
		Effect.Fade('availability-iframe', { duration: 0.5 });
		//fade instead of slide
		//Effect.Fade(slideId, { duration: 0.5, delay: 0.5 });
		Effect.toggle(slideId,'slide', { duration: 1.0, delay: 0.8 });
		Effect.Appear('footer');
	}
	return false;
	
}

// Database migration patch - jump to location instead of Reserve
function goToLoc(loc) {
	if($('wine-menus')) {
		window.location = "/locations/" + loc;
	} else {
		window.location = "/locations/" + loc;	
	}
}