function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
} 

function recordar() {
	var l=screen.availWidth-(420+20);
    window.open("/recordar.cgi","Contrasena","width=420,height=240,directories=no,toolbar=no,resizable=no,menubar=no,scrollbars=no,top=20,left="+l);
}

function enviarDatos() {

    if (document.login2.usuario.value == '') {
        alert("Debe colocar su nombre de usuario.");
        document.login2.usuario.focus();
    }
    else if (document.login2.pass.value == '') {
        alert("Debe colocar su password."); 
        document.login2.pass.focus();
    }
    else if ((document.login2.usuario.value != '') && (document.login2.pass.value != '')) {

		var url = '/index.pl?_c=extranet&_t=Root&_a=getAppHome';
// 		var url = '/index.cgi?static=cuenta_corriente_bioquimico';
		
		document.login2.back.value = url.replace(/&/ig, "*");
        
        temp = hex_sha1(document.login2.pass.value);
        document.login2.password.value = temp

        document.login2.submit();
    }
}

function getLogin(){
	dojo.xhrGet({
		url: "/index.cgi?accion=getPlugin&pluginName=get_login&template=login_plugin_int.tmpl",
		timeout: 8000,
		preventCache:true,
		load: function(response, ioArgs) {
			dojo.byId('loginExtranet').innerHTML = response;

			setLogin();
		},
		error: function(response, err) {
		console.info("HTTP status code: "+ ioArgs.xhr.status+" - err: " + err);
		return response;
		}
	});
}

function enviarDatosLogin() {
	
    if (document.login2.usuario.value == '') {
        alert("Debe colocar su nombre de usuario.");
        document.login2.usuario.focus();
    }
    else if (document.login2.pass.value == '') {
        alert("Debe colocar su password."); 
        document.login2.pass.focus();
    }
    else if ((document.login2.usuario.value != '') && (document.login2.pass.value != '')) {

		var url = '/index.pl?_c=extranet&_t=Root&_a=getAppHome';
// 		var url = '/index.cgi?static=cuenta_corriente_bioquimico';

		document.login2.back.value = url.replace(/&/ig, "*");
        
        temp = hex_sha1(document.login2.pass.value);
        document.login2.password.value = temp

        document.login2.submit();
    }
}

function getLoginPortugues(){
	dojo.xhrGet({
		url: "/index.cgi?accion=getPlugin&pluginName=get_login&template=login_plugin_int_portugues.tmpl",
		timeout: 8000,
		evalJS:true,
		preventCache:true,
		load: function(response, ioArgs) {
			dojo.byId('loginExtranet').innerHTML = response;

			setLoginPortugues();
		},
		error: function(response, err) {
		console.info("HTTP status code: "+ ioArgs.xhr.status+" - err: " + err);
		return response;
		}
	});
}

function getEspecialidades() {
  	var rand = Math.round(100*Math.random()); //  IE CACHE FIX
	new Ajax.Updater('especialidades', '/index.pl', {
					evalScripts:true,
					parameters: '_c=serviceProvider&_a=getService&serviceName=get_catalogue_categories&template=menu_col1.tmpl&_nocache='+rand,
					method: 'get',
					onCreate: function(){
// 							$('LoaderProductsBasket').style.display = 'block';
					},
					onComplete: function(transport) {
// 						$('LoaderProductsBasket').style.display = 'none';
					},
					onFailure: function(){ }
				});
}

function getEspecialidadesPortugues() {
  	var rand = Math.round(100*Math.random()); //  IE CACHE FIX
	new Ajax.Updater('especialidades', '/index.pl', {
					evalScripts:true,
					parameters: '_c=serviceProvider&_a=getService&serviceName=get_catalogue_categories&template=menu_col1_portugues.tmpl&_nocache='+rand,
					method: 'get',
					onCreate: function(){
// 							$('LoaderProductsBasket').style.display = 'block';
					},
					onComplete: function(transport) {
// 						$('LoaderProductsBasket').style.display = 'none';
					},
					onFailure: function(){ }
				});
}

function switchDisplay(idObj){
	var obj = document.getElementById(idObj);

	if(obj.style.display == 'none'){
		obj.style.display = 'block';
	}
	else{
		obj.style.display = 'none';
	}
}

function focusHandler(e){
	if(document.getElementById('usuario').value == defaultLogin){
		document.getElementById('usuario').value = "";
		document.getElementById('usuario').style.color = '#414042';
	}
}

function blurHandler(e){
	if(document.getElementById('usuario').value == ""){
		document.getElementById('usuario').value = defaultLogin;
		document.getElementById('usuario').style.color = '#999';
	}
}

function passClickHandler(e){
	document.getElementById('divPass').style.display = 'none';
	document.getElementById('pass').focus();
}

function passBlurHandler(e){
	if(document.getElementById('pass').value == ""){
		document.getElementById('divPass').style.display = 'block';
	}
}

function setLogin(){
	defaultLogin = "Usuario...";
	document.getElementById('usuario').value = defaultLogin;

	document.getElementById('usuario').onfocus = focusHandler;
	document.getElementById('usuario').onblur = blurHandler;

	document.getElementById('divPass').onclick = passClickHandler;
	document.getElementById('pass').onblur = passBlurHandler;
	document.getElementById('pass').onkeypress = function(){if(document.getElementById('pass').value == ""){document.getElementById('divPass').style.display = 'none';document.getElementById('pass').focus();}};
}

function setLoginPortugues(){
	defaultLogin = "Usuário...";
	document.getElementById('usuario').value = defaultLogin;

	document.getElementById('usuario').onfocus = focusHandler;
	document.getElementById('usuario').onblur = blurHandler;

	document.getElementById('divPass').onclick = passClickHandler;
	document.getElementById('pass').onkeypress = function(){if(document.getElementById('pass').value == ""){document.getElementById('divPass').style.display = 'none';document.getElementById('pass').focus();}};
	document.getElementById('pass').onblur = passBlurHandler;
}

// Explicación extranet Bioquímicos
function showPoppupExplicacionAccesoExtranetBioquimicos() {
  $('explicacion_popup').style.display='block';
}

function closePoppupExplicacionAccesoExtranetBioquimicos() {
  $('explicacion_popup').style.display='none';
}







CarouselPlacasHome = Class.create(Abstract, {
	initialize: function (scroller, slides, controls, options) {
		this.scrolling	= false;
		this.scroller	= $(scroller);
		this.slides		= slides;
		this.controls	= controls;

		this.options    = Object.extend({
            duration:           0.8,
            auto:               true,
            frequency:          5,
            visibleSlides:      1,
            controlClassName:   'carousel-control',
            jumperClassName:    'carousel-jumper',
            disabledClassName:  'carousel-disabled',
            selectedClassName:  'carousel-selected',
            circular:           true,
            wheel:              true,
            effect:             'fade',
            transition:         'spring'
        }, options || {});
        
        if (this.options.effect == 'fade') {
            this.options.circular = true;
        }

		this.slides.each(function(slide, index) {
			slide._index = index;
        });

		if (this.controls) {
            this.controls.invoke('observe', 'click', this.click.bind(this));
        }
        
        if (this.options.wheel) {            
            this.scroller.observe('mousewheel', this.wheel.bindAsEventListener(this)).observe('DOMMouseScroll', this.wheel.bindAsEventListener(this));;
        }

        if (this.options.auto) {
            this.start();
        }

		if (this.options.initial) {
			var initialIndex = this.slides.indexOf($(this.options.initial));
			if (initialIndex > (this.options.visibleSlides - 1) && this.options.visibleSlides > 1) {               
				if (initialIndex > this.slides.length - (this.options.visibleSlides + 1)) {
					initialIndex = this.slides.length - this.options.visibleSlides;
				}
			}
            this.moveTo(this.slides[initialIndex]);
		}
	},

	click: function (event) {
		this.stop();

		var element = event.findElement('a');

		if (!element.hasClassName(this.options.disabledClassName)) {
			if (element.hasClassName(this.options.controlClassName)) {
				eval("this." + element.rel + "()");
            } else if (element.hasClassName(this.options.jumperClassName)) {
                this.moveTo(element.rel);
                if (this.options.selectedClassName) {
                    this.controls.invoke('removeClassName', this.options.selectedClassName);
                    element.addClassName(this.options.selectedClassName);
                }
            }
        }

		this.deactivateControls();

		event.stop();
    },

	moveTo: function (element) {
		if (this.options.beforeMove && (typeof this.options.beforeMove == 'function')) {
			this.options.beforeMove();
        }

		this.previous = this.current ? this.current : this.slides[0];
		this.current  = $(element);

		var scrollerOffset = this.scroller.cumulativeOffset();
		var elementOffset  = this.current.cumulativeOffset();

		if (this.scrolling) {
			this.scrolling.cancel();
		}

        switch (this.options.effect) {
            case 'fade':               
                this.scrolling = new Effect.Opacity(this.scroller, {
                    from:   1.0,
                    to:     0.1,
                    duration: this.options.duration,
                    afterFinish: (function () {
                        this.scroller.scrollLeft = elementOffset[0] - scrollerOffset[0];
                        this.scroller.scrollTop  = elementOffset[1] - scrollerOffset[1];

                        new Effect.Opacity(this.scroller, {
                            from: 0.3,
                            to: 1.0,
                            duration: this.options.duration,
                            afterFinish: (function () {
                                if (this.controls) {
                                    this.activateControls();
                                }
                                if (this.options.afterMove && (typeof this.options.afterMove == 'function')) {
                                    this.options.afterMove();
                                }
                            }).bind(this)
                        });
                    }
                ).bind(this)});
            break;
            case 'scroll':
            default:
                var transition;
                switch (this.options.transition) {
                    case 'spring':
                        transition = Effect.Transitions.spring;
                        break;
                    case 'sinoidal':
                    default:
                        transition = Effect.Transitions.sinoidal;
                        break;
                }

                this.scrolling = new Effect.SmoothScroll(this.scroller, {
                    duration: this.options.duration,
                    x: (elementOffset[0] - scrollerOffset[0]),
                    y: (elementOffset[1] - scrollerOffset[1]),
                    transition: transition,
                    afterFinish: (function () {
                        if (this.controls) {
                            this.activateControls();
                        }
                        if (this.options.afterMove && (typeof this.options.afterMove == 'function')) {
                            this.options.afterMove();
                        }                        
                        this.scrolling = false;
                    }).bind(this)});
            break;
        }

		return false;
	},

	prev: function () {
		if (this.current) {
			var currentIndex = this.current._index;
			var prevIndex = (currentIndex == 0) ? (this.options.circular ? this.slides.length - 1 : 0) : currentIndex - 1;
        } else {
            var prevIndex = (this.options.circular ? this.slides.length - 1 : 0);
        }

		if (prevIndex == (this.slides.length - 1) && this.options.circular && this.options.effect != 'fade') {
			this.scroller.scrollLeft =  (this.slides.length - 1) * this.slides.first().getWidth();
			this.scroller.scrollTop =  (this.slides.length - 1) * this.slides.first().getHeight();
			prevIndex = this.slides.length - 2;
        }

		this.moveTo(this.slides[prevIndex]);
	},

	next: function () {
		if (this.current) {
			var currentIndex = this.current._index;
			var nextIndex = (this.slides.length - 1 == currentIndex) ? (this.options.circular ? 0 : currentIndex) : currentIndex + 1;
        } else {
            var nextIndex = 1;
        }

		if (nextIndex == 0 && this.options.circular && this.options.effect != 'fade') {
			this.scroller.scrollLeft = 0;
			this.scroller.scrollTop  = 0;
			nextIndex = 1;
        }

		if (nextIndex > this.slides.length - (this.options.visibleSlides + 1)) {
			nextIndex = this.slides.length - this.options.visibleSlides;
		}		

		this.moveTo(this.slides[nextIndex]);
	},

	first: function () {
		this.moveTo(this.slides[0]);
    },

	last: function () {
		this.moveTo(this.slides[this.slides.length - 1]);
    },

	toggle: function () {
		if (this.previous) {
			this.moveTo(this.slides[this.previous._index]);
        } else {
            return false;
        }
    },

	stop: function () {
		if (this.timer) {
			clearTimeout(this.timer);
		}
	},

	start: function () { 
        this.periodicallyUpdate();
    },

	pause: function () {
		this.stop();
		this.activateControls();
    },

	resume: function (event) {
		if (event) {
			var related = event.relatedTarget || event.toElement;
			if (!related || (!this.slides.include(related) && !this.slides.any(function (slide) { return related.descendantOf(slide); }))) {
				this.start();
            }
        } else {
            this.start();
        }
    },

	periodicallyUpdate: function () {
		if (this.timer != null) {
			clearTimeout(this.timer);
			this.next();
        }
		this.timer = setTimeout(this.periodicallyUpdate.bind(this), this.options.frequency * 1000);
    },
    
    wheel: function (event) {
        event.cancelBubble = true;
        event.stop();
        
		var delta = 0;
		if (!event) {
            event = window.event;
        }
		if (event.wheelDelta) {
			delta = event.wheelDelta / 120; 
		} else if (event.detail) { 
            delta = -event.detail / 3;	
        }        
       
        if (!this.scrolling) {
            this.deactivateControls();
            if (delta > 0) {
                this.prev();
            } else {
                this.next();
            }            
        }
        
		return Math.round(delta); //Safari Round
    },

	deactivateControls: function () {
		this.controls.invoke('addClassName', this.options.disabledClassName);
    },

	activateControls: function () {
		this.controls.invoke('removeClassName', this.options.disabledClassName);
    }
});


