//by Cristian [actualizado 31/10/2006]
//Soporte XHTML Strict + Popup + IE 7 fix * eolas + bug W2000 sobre fp8 + call Function
var brwIE = false;
if(navigator.appName == "Microsoft Internet Explorer"){
	brwIE = true;
}
var brwFF = false;
var NAV = navigator.userAgent.toLowerCase().split(".").join("");
if(NAV.indexOf('firefox')>-1){	
	bwVersion=NAV.substr((NAV.lastIndexOf("/")+1),3);	
	if(bwVersion<102){
		var brwFF = true;
	}	
}else if(NAV.indexOf('opera')>-1){	
	var brwFF = true;
}
// 
activado = false;
function obtenerXY(a, offset) {
	altoInput = a.offsetHeight;
	anchoInput = a.offsetWidth;
	var p = offset ? offset.slice(0) : [0, 0];
	while (a) {
		var tn = a.tagName.toLowerCase();		
		p[0] += a.offsetLeft;
		p[1] += a.offsetTop;
		if (tn == "body") {
			break;
		}
		a = a.offsetParent;		
	}
	p[0] -= 0;
	p[1] += altoInput+1;
	
	if(self.pageYOffset){		
		scrolTop = self.pageYOffset;
		scrolLeft = self.pageXOffset;
		altoWin = self.innerHeight-19;
		anchoWin = self.innerWidth-19;		
	}else if (document.documentElement && document.documentElement.scrollTop){
		scrolTop = document.documentElement.scrollTop;
		scrolLeft = document.documentElement.scrollLeft;
		altoWin = document.documentElement.clientHeight;
		anchoWin = document.documentElement.clientWidth;
	}else if (document.body){
		scrolTop = document.body.scrollTop;
		scrolLeft = document.body.scrollLeft;
		altoWin = document.body.clientHeight;
		anchoWin = document.body.clientWidth;
	}	
	if ((p[0]-scrolLeft)>(anchoWin-document.getElementById('devCal').offsetWidth)) {
		p[0] = p[0]-158+anchoInput;
	}
	if ((p[1]-scrolTop)>(altoWin-document.getElementById('devCal').offsetHeight)) {
		p[1] = p[1]-170-altoInput;
	}
	return p;
}
Motor=false;
function CalendarioV(rol, input1, input2, fechaInicial, idioma, semana, func) {
	_calGlobalFunction = func;
	Objinput1 = eval(input1);
	Objinput2 = eval(input2);
	if (activado) {
		pasaDate(Objinput1.value);
	} else {		
		rol ? pasaVars(fechaInicial, Objinput2.value, idioma, semana) : pasaVars(Objinput2.value, '', idioma, semana);
		var coordenadas = obtenerXY(input1, (0, 0));		
		var divC = document.getElementById('devCal').style;		
		with (divC) {
			visibility = 'visible';
			left = coordenadas[0]+'px';
			top = coordenadas[1]+'px';
			focus();
			visibility = 'hidden';
			visibility = 'visible';
		}
		activado = true;
	}
}
function Calendario(input1, fechaInicial, idioma, semana) {
	Objinput1 = eval(input1);
	if (activado) {
		pasaDate(Objinput1.value);
	} else {
		limitaSemana='';
		if(semana){
			limitaSemana=semana;
		}
		if (brwFF) {
			htmObj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="158" height="168" id="flashCal">';
			htmObj += '<param name="movie" value="calendarioFlash/calendario.swf" /><param name="quality" value="high" /><param name="swliveconnect" value="true" />';
			htmObj += '<embed src="calendarioFlash/calendario.swf" swliveconnect="true" flashvars="fechaInicial='+Calendario.arguments[1]+'&idioma='+Calendario.arguments[2]+'&diasDisabled='+limitaSemana+'&limite=0&act=1" quality="high" width="158" height="168" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="flashCal" name="flashCal" /></object>';
			document.getElementById('devCal').innerHTML = htmObj;
		} else {
			with(document['flashCal']){
				SetVariable("_root.fechaInicial", fechaInicial);
				SetVariable("_root.limite", 0);
				SetVariable("_root.idioma", Calendario.arguments[2]);
				SetVariable("_root.diasDisabled", limitaSemana);
				SetVariable("_root.act", 1);
			}
		}
		var coordenadas = obtenerXY(input1, (0, 0));
		var divC = document.getElementById('devCal').style;
		with (divC) {
			visibility = 'visible';
			left = coordenadas[0]+'px';
			top = coordenadas[1]+'px';
			focus();
			visibility = 'hidden';
			visibility = 'visible';
		}
		activado = true;
	}	
}
function pasaDate() {
	Objinput1.value = pasaDate.arguments[0];
	var divC = document.getElementById('devCal').style;
	with (divC) {
		visibility = 'hidden';
		left = -200+'px';
		top = -200+'px';
	}
	activado = false;
	if(typeof _calGlobalFunction=="string"){
		eval(_calGlobalFunction);
	}
	_calGlobalFunction = null;
}
function pasaVars() {
	if (brwFF) {	
		htmObj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="158" height="168" id="flashCal">';
		htmObj += '<param name="movie" value="calendarioFlash/calendario.swf" /><param name="quality" value="high" /><param name="swliveconnect" value="true" />';
		htmObj += '<embed src="calendarioFlash/calendario.swf" swliveconnect="true" flashvars="fechaInicial='+pasaVars.arguments[0]+'&fechaLimite='+pasaVars.arguments[1]+'&idioma='+pasaVars.arguments[2]+'&diasDisabled='+pasaVars.arguments[3]+'&limite=1&act=1" quality="high" width="158" height="168" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="flashCal" name="flashCal" /></object>';
		document.getElementById('devCal').innerHTML = htmObj;
	} else {		
		with(document['flashCal']){
			SetVariable("_root.fechaInicial", pasaVars.arguments[0]);		
			SetVariable("_root.fechaLimite", pasaVars.arguments[1]);
			SetVariable("_root.idioma", pasaVars.arguments[2]);
			SetVariable("_root.diasDisabled", pasaVars.arguments[3]);
			SetVariable("_root.limite", 1);
			SetVariable("_root.act", 1);			
		}		
	}
}
function writeFlash() {
	document.write('<div id="devCal" style="visibility:hidden; top:-200px; left:-200px; position:absolute; width:158px; height:168px; z-index:999;">');
	document.write('<object data="calendarioFlash/calendario.swf" type="application/x-shockwave-flash" width="158" height="168" id="flashCal">');
	document.write('<param name="movie" value="calendarioFlash/calendario.swf" /><param name="quality" value="high" /><param name="swliveconnect" value="true" /><param name="flashVars" value="'+brwIE+'" />');
	document.write('</object></div>');
}
document.onmousedown = function() {
	if (activado) {
		var divC = document.getElementById('devCal').style;
		with (divC) {
			visibility = 'hidden';
			left = -200+'px';
			top = -200+'px';
		}
		activado = false;		
	}
};
/**/
function writeFlashObject() {
	document.write('<div id="devCal" style="visibility:hidden; top:-200px; left:-200px; position:absolute; width:158px; height:168px; z-index:999;"></div>');
}
if(typeof FlashObject=="undefined"){
	writeFlash();	
}else{	
	writeFlashObject();
	var fo = new FlashObject("calendarioFlash/calendario.swf", "flashCal", "158", "168", "6.0.0.0", "", true);
	fo.addVariable("_isIE", brwIE);
	fo.write("devCal");				
}
//Popup
Pop_width = 154;
Pop_height = 164;
function CalendarioVPopup(rol, input1, input2, fechaInicial, idioma, semana) {
	Pop_left=(screen.width/2)-(Pop_width/2); 
	Pop_top=(screen.height/2)-(Pop_height/2); 
	var parametros='rol='+rol+'&input1='+input1+'&input2='+input2+'&fechaInicial='+fechaInicial+'&idioma='+idioma+'&semana='+semana;
	popUpCal = window.open('calendarioFlash/CalendarioPopup.asp?'+parametros,'calendario','width='+Pop_width+',height='+Pop_height+',top='+Pop_top+',left='+Pop_left+',toolbars=no,status=no,scrollbars=no,resizable=no');
	popUpCal.focus();	
}
function CalendarioPopup(input1, fechaInicial, idioma, semana) {
	Pop_left=(screen.width/2)-(Pop_width/2); 
	Pop_top=(screen.height/2)-(Pop_height/2); 
	var parametros='input1='+input1+'&fechaInicial='+fechaInicial+'&idioma='+idioma+'&semana='+semana;
	popUpCal = window.open('calendarioFlash/CalendarioPopup.asp?'+parametros,'calendario','width='+Pop_width+',height='+Pop_height+',top='+Pop_top+',left='+Pop_left+',toolbars=no,status=no,scrollbars=no,resizable=no');
	popUpCal.focus();	
}