$(document).ready(function(){
	var displayDate = $.datepicker.formatDate('mm/dd/yy', new Date())
//Promo Cupon sidebar.
	//Click Get Coupon
	$('#myGetCoupon').click(function() {
		//Valores del formulario
		var str = $("#getCoupon").serialize();
		// ajax
			$.ajax({
				type: "POST",
				url: "/coupon/cuponform.asp?Adults="+$('#Adultos').val()+"&Kids="+$('#Kids').val(),
				async: false,
				data: $('#Adultos').val()+"&Kids="+$('#Kids').val(),
				beforeSend: function(){ $('.loading').show();},
				success: function(msg) {
				$('#couponBox').html(msg);
				$('.loading').delay(500).slideUp(300, function(){
					$("#Fecha").datepicker({															
						showOn: "both",
						buttonImage: "/images/coupon/calendar.png",
						buttonImageOnly: true,
						formatDate: 'mm/dd/yy',
						minDate:0
					});
					$("#Arribo").datepicker({
						  showOn: "both",
						  buttonImage: "/images/coupon/calendar.png",
						  buttonImageOnly: true,
						  formatDate: 'mm/dd/yy',
						  onSelect:function(theDate) {
						  $("#Salida").datepicker('option','minDate',new Date(theDate));
					  }
					});
					$("#Salida").datepicker({
						  showOn: "both",
						  buttonImage: "/images/coupon/calendar.png",
						  formatDate: 'mm/dd/yy',
						  buttonImageOnly: true,
						  onSelect:function(theDate) {
							$("#Arribo").datepicker('option','maxDate',new Date(theDate))
						}
					});
					$.colorbox({
					inline:true,
					href:"#cuponWrapper",
					opacity:0.6,
					innerWidth:527,
					innerHeight:478,
					onOpen: function(){
						$("#cuponWrapper, #couponBox").show();
						$("#Fecha,#Arribo,#Salida").val(displayDate)
					}, //make sure results show in the modal window
				   onClosed: function(){ $("#couponBox,#couponBox2,#couponBox3,#couponBox4").empty(); $("#cuponWrapper,#couponBox").hide(); }
				});//colorbox
				  }); //loading
				}//successe
			});//end ajax
		return false;
	}); // end click
}); // end of doc ready
/**
 * jQuery.ajax mid - CROSS DOMAIN AJAX 
 * ---
 * @author James Padolsey (http://james.padolsey.com)
 * @version 0.11
 * @updated 12-JAN-10
 * ---
 * Note: Read the README!
 * ---
 * @info http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
 */

jQuery.ajax = (function(_ajax){
    
    var protocol = location.protocol,
        hostname = location.hostname,
        exRegex = RegExp(protocol + '//' + hostname),
        YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
        query = 'select * from html where url="{URL}" and xpath="*"';
    
    function isExternal(url) {
        return !exRegex.test(url) && /:\/\//.test(url);
    }
    
    return function(o) {
        
        var url = o.url;
        
        if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
            
            // Manipulate options so that JSONP-x request is made to YQL
            
            o.url = YQL;
            o.dataType = 'json';
            
            o.data = {
                q: query.replace(
                    '{URL}',
                    url + (o.data ?
                        (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
                    : '')
                ),
                format: 'xml'
            };
            
            // Since it's a JSONP request
            // complete === success
            if (!o.success && o.complete) {
                o.success = o.complete;
                delete o.complete;
            }
            
            o.success = (function(_success){
                return function(data) {
                    
                    if (_success) {
                        // Fake XHR callback.
                        _success.call(this, {
                            responseText: data.results[0]
                                // YQL screws with <script>s
                                // Get rid of them
                                .replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
                        }, 'success');
                    }
                    
                };
            })(o.success);
            
        }
        
        return _ajax.apply(this, arguments);
        
    };
    
})(jQuery.ajax);

$(window).ready(function(){
jQuery('#coupon').delay(2000).slideDown(500);
});
