if (typeof SMC == 'undefined') {
 SMC = {};
}
el='inter-version-win';
var loader;
document.observe("dom:loaded", function  () {
    SMC.date = new Date();
    var lang = $$("body")[0].getAttribute("lang");
	/* La clase 'clicktohide' permite distiguir los elementos de la zona de la ventana */
	if ($('inter-version')){
	Element.addClassName ('inter-version-win', 'clicktohide');
	$$('#inter-version-win *').each( function(element){
			Element.addClassName (element, 'clicktohide');
		});
	Event.observe('inter-version', 'click', function (e) {	Event.stop(e);  Effect.run( $(el), !Element.visible(el), 20); Event.observe(window.document, 'mousedown', HideWindow , false);  return false;}, false);
	}
	loader = new SMC.Indicator({container: 'container'}); //{container: 'crs'}
    Ajax.Responders.register({
	  onCreate: function() {
	    Ajax.activeRequestCount++;
	    loader.start();
	  },
	  onComplete: function() {
	    Ajax.activeRequestCount--;
	   loader.stop();
	  }
	});
    if($("crs-hotel"))
    new Form.Element.EventObserver("crs-hotel", function(element, value) {new Ajax.Updater('test', '/rooms/thab', {asynchronous:true, evalScripts:false, parameters:'codfb='+$('crs-hotel').options[$('crs-hotel').selectedIndex].value});});

    attachCalendarEvents();

});


function attachCalendarEvents() {
    $$("form .widget_date").each(function(item){
        $(item.id).disabled = false;
        $("trigger_"+item.id ).disabled = false;
         Calendar.setup({
           inputField : item.name,
           ifFormat : "%Y-%m-%d",
           daFormat : "%Y-%m-%d",
           button : item.id,
           range:[SMC.date.getRealYear(),SMC.date.getRealYear()+1]
         });
         Calendar.setup({
             inputField : item.name,
             ifFormat : "%Y-%m-%d",
             daFormat : "%Y-%m-%d",
             button : "trigger_"+item.id,
             range:[SMC.date.getRealYear(),SMC.date.getRealYear()+1]
           });        
         });	
}
function HideWindow(e) {	
  Event.stop(e); ele= Event.element(e) ; var ele_class= Element.classNames(ele);  
if (ele != null && ele_class!='clicktohide' && Element.visible(el)) { 
  Effect.run( $(el), false, 20); 
  Event.stopObserving(window.document, 'mousedown', HideWindow);
 } 
 return false;
 }
 
 
/*---------------- Librerķas basada en Zapatec  Suite ------------------------------------------------*/
Effect = {};
Effect.fade = function(ref, counter) {
	if(ref.OriginalOpacity == null && ref.__zp_opacitySaved == null){
		ref.OpacitySaved = true;
		ref.OriginalOpacity = document.all ? 
			ref.style.filter : ref.style.opacity != null ? 
				ref.style.opacity : ref.style.MozOpacity;
	}

	var md = null;

	var currentOpacity = 
		(!isNaN(parseFloat(ref.OriginalOpacity || 1)) ?
			parseFloat(ref.OriginalOpacity || 1) : (
				(md = ref.OriginalOpacity.match(/alpha\(opacity=(\d+)\)/i)) ?
					parseInt(md[1]) / 100 : 1
			)
		) * counter / 100;

	if (ref.filters) {
		if (!ref.style.filter.match(/alpha/i)) {
			ref.style.filter += ' alpha(opacity=' + (currentOpacity * 100) + ')';
		} else if (ref.filters.length && ref.filters.alpha) {
			ref.style.filter = ref.style.filter.replace(/alpha\(opacity=\d+\)/ig, 'alpha(opacity=' + (Math.floor(currentOpacity * 100)) + ')')
		}
	} else {      
		if(counter > 0 && counter < 100){
			ref.style.opacity = ref.style.MozOpacity = currentOpacity;
		}
	}

	if(counter <= 0){
		ref.style.display = 'none';
		ref.style.filter = ref.style.opacity = ref.style.MozOpacity = ref.OriginalOpacity;
		ref.OriginalOpacity = null;
		ref.OpacitySaved = null;
	}

	if(counter >= 100 && ref.OpacitySaved != null) {
		ref.style.filter = ref.OriginalOpacity;
			ref.style.opacity = ref.style.MozOpacity = ref.OriginalOpacity;
	
		ref.OriginalOpacity = null;
		ref.OpacitySaved = null;
	}
};

Effect.run = function(ref,  show, animSpeed, currVal) {
 	
	if(animSpeed == null)
		animSpeed = 10;

	if(currVal < 0){
		currVal = 0;
	}

	if(currVal > 100){
		currVal = 100;
	}


if(currVal == null) {	
		if(show){
			currVal = 0;
			if(ref.style.display == "none"){
				ref.style.display = '';			
			}
		}
		else {
			currVal = 100;
		}
	}

	currVal += (show ? 1 : -1) * animSpeed;
	
   Effect.fade (ref, currVal); /* Fade Effect */
   
	if (currVal >= 0 && currVal < 100) { 
		setTimeout(function() {
		   Effect.run(ref, show, animSpeed, currVal);
		}, 50);
	}
} 




/* WCH Windowed Controls Hiders */
if (typeof SMC == 'undefined') {
 SMC = {};
}
/// define the Utils namespace
SMC.Utils = {};

SMC.Utils.createWCH = function(element) {
	var f = null;
	element = element || window.self.document.body;
	if (Prototype.Browser.IE) {
		var filter = 'filter:progid:DXImageTransform.Microsoft.alpha(style=0,opacity=0);';
		var id = "WCH" + Math.ceil(Math.random() * 1000) ;
		 new Insertion.Bottom (document.body, 
		 '<iframe id="' + id + '" scroll="no" frameborder="0" ' +
			 'style="z-index:0;position:absolute;visibility:hidden;' + filter +
			 'border:0;top:0;left:0;width:0;height:0;" ' +
			 'src="javascript:false;"></iframe>'
		 );
		f = window.self.document.getElementById(id);
	}
	return f;
};

/**
 * Configure a given WCH object to be displayed on top of the given element.
 * Optionally, a second element can be passed, and in this case it will setup
 * the WCH object to cover both elements.
 *
 * @param f [HTMLIFrame] the WCH object
 * @param el [HTMLElement] the element to cover.
 * @param el2 [HTMLElement, optional] another element to cover.
 */
SMC.Utils.setupWCH_el = function(f, el, el2) {
	if (f) {
		var pos = SMC.Utils.getAbsolutePos(el),
			X1 = pos.x,
			Y1 = pos.y,
			X2 = X1 + el.offsetWidth,
			Y2 = Y1 + el.offsetHeight;
		if (el2) {
			var p2 = SMC.Utils.getAbsolutePos(el2),
				XX1 = p2.x,
				YY1 = p2.y,
				XX2 = XX1 + el2.offsetWidth,
				YY2 = YY1 + el2.offsetHeight;
			if (X1 > XX1)
				X1 = XX1;
			if (Y1 > YY1)
				Y1 = YY1;
			if (X2 < XX2)
				X2 = XX2;
			if (Y2 < YY2)
				Y2 = YY2;
		}
		Zapatec.Utils.setupWCH(f, X1, Y1, X2-X1, Y2-Y1);
	}
};

/**
 * Configure a WCH object to cover a certain part of the screen.
 *
 * @param f [HTMLIFrame] the WCH object.
 * @param x [number] the X coordinate.
 * @param y [number] the Y coordinate.
 * @param w [number] the width of the area.
 * @param h [number] the height of the area.
 */
SMC.Utils.setupWCH = function(f, x, y, w, h) {
	if (f) {
		var s = f.style;
		(typeof x != "undefined") && (s.left = x + "px");
		(typeof y != "undefined") && (s.top = y + "px");
		(typeof w != "undefined") && (s.width = w + "px");
		(typeof h != "undefined") && (s.height = h + "px");
		s.visibility = "inherit";
	}
};

/**
 * Hide a WCH object.
 *
 * @param f [HTMLIFrame] object to hide.
 */
SMC.Utils.hideWCH = function(f) {
	if (f)
		f.style.visibility = "hidden";
};


/**
 * @param el [HTMLElement] reference to the element.
 * @return [object] { x, y } containing the position.
 */
SMC.Utils.getAbsolutePos = function(el, scrollOff) {
	var SL = 0, ST = 0;
	if (!scrollOff) {
		var is_div = /^div$/i.test(el.tagName);
		if (is_div && el.scrollLeft)
			SL = el.scrollLeft;
		if (is_div && el.scrollTop)
			ST = el.scrollTop;
	}
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

/**
 * Destroys the given element (remove it from the DOM tree) if it's not null
 * and it's parent is not null.
 *
 * @param el [HTMLElement] the element to destroy.
 */
SMC.Utils.destroy = function(el) {
	if (el && el.parentNode)
		el.parentNode.removeChild(el);
};

Date.prototype.getRealYear = function() 
{ 
    if(this.getFullYear)
       { return this.getFullYear();}
    else
       { return this.getYear() + 1900; }
};


