// meow.js

// var dayarray=new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi")
// var montharray=new Array("janvier","f&eacute;vrier","mars","avril","mai","juin","juillet","ao&ucirc;t","septembre","octobre","novembre","d&eacute;cembre")
//var dayarray=new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
//var montharray=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
var dayarray=new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado")
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Setiembre","Octubre","Noviembre","Diciembre")
var myContext = null;


function meowOnLoad(context) {
	fixerTaille();
	goforit();
	myContext= context;
    document.onkeydown = toucheEnfoncee;
    window.onresize = doOnWindowResize
    setFooter();
    doShowMsgBox(true);
    
}

function doOnWindowResize(){
	resizeIframe();
	setFooter();
	setMsgBoxPosition();
}

function toucheEnfoncee(e) {

	var touche = correspTouche(e)
	if(touche == 'F2'){ // execute previous Task Unit
		doPF2(myContext);
	}else if (touche == 'F10'){ // toward parameter map
		doPF10(myContext);
	} else if (touche == 'Entree'){ // autoSubmit function
		autoSubmit();
	}
}


function autoSubmitDisabled()
{
	document.getElementById('AJFAutoSubmitDisabledFlag').value="TRUE";
}

function autoSubmitEnabled()
{
	document.getElementById('AJFAutoSubmitDisabledFlag').value="FALSE";
}

function autoSubmit()
{
	if (document.getElementById('AJFAutoSubmitDisabledFlag').value == "FALSE")
	{
	document.getElementById('AJFButton').click();
	}
}

function doPF2(context){
	var elt = document.getElementById('previousUT');
	if (elt.value != ''&& elt.value != 'null'&& elt.value != 'false'){
	 	window.location.href=context+'/_doPF2.do'; //elt.value;	
	}else{
		alert('no previous UT');
	}
}

function doPF7(context){
	var elt = document.getElementById('previous');
	if (elt.value != '' && elt.value == 'true'){
		 window.location.href=context+'/_previous.do';
	}else{
		alert('no previous page');
	}
}

function doPF10(context){
	var elt = document.getElementById('paramJSP');
	if (elt.value != '' && elt.value != 'null'){
	 	window.location.href = context+elt.value;//'/_doPF10.do'; //elt.value;
	}else{
		alert('no param page');
	}
}

function meowPopupOnLoad() {
	fixerTaille();
	chargement();
	//activ_focus();
	//setInterval("activ_focus()",1000)
}



function chargement(){
  document.getElementById('wait').style.visibility='hidden';
}

function getthedate()
{
	var mydate=new Date()
	var year=mydate.getFullYear()
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	var hours=mydate.getHours()
	var amORpm='';
	if (hours>12)
	{
		hours = hours-12;
		amORpm='PM';
	}
	else
	{
		amORpm='AM';
	}
	var minutes=mydate.getMinutes()
	var seconds=mydate.getSeconds()
	if (minutes<=9)
		minutes="0"+minutes
	if (seconds<=9)
		seconds="0"+seconds
//change font size here
	var cdate=dayarray[day]+"  "+daym+" "+montharray[month]+" "+year+" "+hours+":"+minutes+":"+seconds+" "+amORpm
	//VCL
	//document.all.clock.innerHTML=cdate
	document.getElementById('clock').innerHTML=cdate
}

function goforit()
{
		setInterval("getthedate()",1000)
}

function keyCheck(code, obj,entier,decimal,negatif)
{
// Le code 45 est pour le signe -
// Le code 46 est pour le point
// Les codes entre 48 et 57 sont les chiffres


	var str=obj.value;
	var indice = str.indexOf(".");
	if(code==45)
	{
		if (str.length > 0 || negatif == "N")
			return false;
	}

	if(code==46)
	{
		if (indice >= 0 || decimal == 0)
			return false;
	}

	if((code<48 || code >58) && (code != 46) && (code != 45))
		return false;

	if(code != 46 && code != 45)
	{
		if(indice >= 0)
		{
			var sbstr = str.substring(indice+1,str.length);
			if(sbstr.length > decimal - 1)
				return false;
		}
		else
		{
			var debut = 0;
			if (str.substring(0,1) == "-")
				debut = 1;
			var sbstr = str.substring(debut,str.length);
			if(sbstr.length > entier - 1)
				return false;
		}
	}

	return true;
}

	function getWindowHeight() {
		var windowHeight=0;
		if (typeof(window.innerHeight)=='number') {
			windowHeight=window.innerHeight;
		}
		else {
			if (document.documentElement&&
				document.documentElement.clientHeight) {
				windowHeight=
					document.documentElement.clientHeight;
			}
			else {
				if (document.body&&document.body.clientHeight) {
					windowHeight=document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}
	
	function getWindowWidth() {
		var windowWidth=0;
		if (typeof(window.innerWidth)=='number') {
			windowWidth=window.innerWidth;
		}
		else {
			if (document.documentElement&&
				document.documentElement.clientWidth) {
				windowWidth=
					document.documentElement.clientWidth;
			}
			else {
				if (document.body&&document.body.clientWidth) {
					windowWidth=document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	}


function setFooter() {
	var windowHeight=getWindowHeight();
	if (windowHeight>0) {
	var contentHeight=document.getElementById('content').offsetHeight;
	var footerElement=document.getElementById('pie');

	var footerHeight=footerElement.offsetHeight;

	if (windowHeight-(contentHeight+footerHeight)>=0) {
		footerElement.style.position='absolute';
		footerElement.style.bottom=0;
		footerElement.style.width="100%";
		document.body.style.overflowY='hidden';
	}
	else {
		footerElement.style.position='static';
		document.body.style.overflowY='auto';
	}
    }
}
/*
 *    Message box. This script is used to Message Taglib
 */
var pvInit; // position verticale de départ
var pvEnd;  // position verticale maximale
var pvIndex;

var phInit;
var phEnd;
var phIndex;

var dh=2; //deplacement horizontal
var dv=2;// déplacement vertical
var delai=20;// délai du timer
var isDisplayed=false;
var isTimeoutEnabled=true;
var isVerticalMove=true;


/**
 * Call from doShowMsgBox() and window.onresize()
 * to set the MsgBox position.
 */
function setMsgBoxPosition(){
	//VCL
	var msgBoxWidth = document.getElementById('myMessageBox').offsetWidth;
	var msgBoxHeight = document.getElementById('myMessageBox').offsetHeight;
	//var msgBoxWidth = document.all.myMessageBox.offsetWidth;
	//var msgBoxHeight = document.all.myMessageBox.offsetHeight;
	if(document.getElementById('shortcuts')!=null){
	//if(document.all.shortcuts!=null){
	//Página con menú horizontal
		if(screen.width>=1024){//Se tiene en cuenta la resolución de pantalla
			//var tam=document.all.shortcuts.offsetWidth+30;
			if(navigator.appName=="Netscape"){
				var tam=document.getElementById('shortcuts').offsetWidth+100;
			}
			else{
		 		var tam=document.getElementById('shortcuts').offsetWidth+30;
		 	}
		}
	}else{
	//Página sin menú horizontal(login...)
		if(screen.width>=1024){//Se tiene en cuenta la resolución de pantalla
			//var tam=document.all.header.offsetHeight;
			var tam=document.getElementById('header').offsetHeight;
		}
	}
	if( isVerticalMove ){
		//var headerHeight = document.all.header.offsetHeight;
		var headerHeight = document.getElementById('header').offsetHeight;
		pvInit = headerHeight - msgBoxHeight + 25;
		var mTop = headerHeight + 20+39;
		//var mLeft = document.all.shortcuts.offsetWidth+30;
		var mLeft=tam;
		//document.all.myMessageBox.style.top = pvInit;
		document.getElementById('myMessageBox').style.top = pvInit;
		//Página sin menú horizontal(login...)
		//if(document.all.shortcuts==null){
		if(document.getElementById('shortcuts')==null){
			if(screen.width<1024){//Se tiene en cuenta la resolución de pantalla
				//document.all.myMessageBox.style.left=msgBoxWidth+175;
				document.getElementById('myMessageBox').style.left=msgBoxWidth+175;
				
			}
			else{
				//document.all.myMessageBox.style.left=mLeft+msgBoxWidth+300;
				document.getElementById('myMessageBox').style.left=mLeft+msgBoxWidth+300;
				
			}
		//Página con menú horizontal	
		}else{
			if(screen.width<1024){//Se tiene en cuenta la resolución de pantalla
				//document.all.myMessageBox.style.left=msgBoxWidth-563;
				document.getElementById('myMessageBox').style.left=msgBoxWidth-563;
				pvInit =-200;
				
			}
			else{
				//document.all.myMessageBox.style.left=mLeft-msgBoxWidth-6;
				if(navigator.appName=="Netscape"){
					document.getElementById('myMessageBox').style.left=mLeft-msgBoxWidth+60;
				}
				else{
					document.getElementById('myMessageBox').style.left=mLeft-msgBoxWidth-6;
				}
				
			}
		}
		pvIndex=pvInit;
		//Resolucion pequeña con barra de navegación
		//if((document.all.shortcuts!=null)&&(screen.width<1024)){
		if((document.getElementById('shortcuts')!=null)&&(screen.width<1024)){
			pvEnd=0;
		}
		else
			pvEnd=mTop+44;
	}else{
		//horizontal mode
		//var mTop = document.all.myMessageBoxButton.offsetTop+61;
		var mTop = document.getElementById('myMessageBoxButton').offsetTop+61;
		var mLeft = getWindowWidth()+4;
		phInit=getWindowWidth();
		phIndex=phInit;
		phEnd=getWindowWidth()-msgBoxWidth-2;
		//document.all.myMessageBox.style.top=mTop;
		document.getElementById('myMessageBox').style.top=mTop;
		//document.all.myMessageBox.style.left=getWindowWidth();
		document.getElementById('myMessageBox').style.left=getWindowWidth();

	}
}

function doShowMsgBox(withTimeoutEnabled){
	isTimeoutEnabled= !(withTimeoutEnabled!=null && withTimeoutEnabled==false);


	if( isDisplayed ){
		timer=setInterval(exeHide, delai);			
	}else{
			setMsgBoxPosition();
		timer=setInterval(exeShow, delai);	
	}
	isDisplayed = !isDisplayed; 
}

function exeShow() {
	var ex=document.getElementById('myMessageBox');
	ex.style.visibility='visible';
	//document.all.myMsgBoxFooter.innerHTML="";
	document.getElementById('myMsgBoxFooter').innerHTML="";

	if (isVerticalMove){
	  if (pvIndex < pvEnd){
		ex.style.top=(pvIndex+=dv)+"px";
	  }else{
	  	//document.all.myMsgBoxFooter.innerHTML="<IMG src=\""+myContext+"/images/situacion/helpUp.gif\" onclick=\"javascript:doShowMsgBox(false);\" />";
	  	document.getElementById('myMsgBoxFooter').innerHTML="<IMG src=\""+myContext+"/images/situacion/helpUp.gif\" onclick=\"javascript:doShowMsgBox(false);\" />";
		window.onload='';
		clearInterval(timer);
		if( isTimeoutEnabled==null || isTimeoutEnabled ){
			window.setTimeout(doShowMsgBox, 3000);
		}
	  }
	}else{
	//horizontal move
	  if (phIndex > phEnd){
		ex.style.left=(phIndex-=dh)+"px";
	  }else{
		window.onload='';
		clearInterval(timer);
		if( isTimeoutEnabled==null || isTimeoutEnabled ){
			window.setTimeout(doShowMsgBox, 3000);
		}
	  }
	}
}

function exeHide() {
	var ex=document.getElementById('myMessageBox');
	//document.all.myMsgBoxFooter.innerHTML="";
	document.getElementById('myMsgBoxFooter').innerHTML="";
	if ( isVerticalMove ){
  	  if (pvIndex > pvInit){
		ex.style.top=(pvIndex-=dv)+"px";
	  }else{
		//document.all.myMsgBoxFooter.innerHTML="<IMG src=\""+myContext+"/images/situacion/helpDown.gif\" onclick=\"javascript:doShowMsgBox(false);\" />";
		document.getElementById('myMsgBoxFooter').innerHTML="<IMG src=\""+myContext+"/images/situacion/helpDown.gif\" onclick=\"javascript:doShowMsgBox(false);\" />";
		window.onload='';
		clearInterval(timer);
		
	  }
	}else{
	//HORIZONTAL
	  if (phIndex < phInit){
		ex.style.left=(phIndex+=dh)+"px";
	  }else{
		window.onload='';
		clearInterval(timer);
	  }
	}
}

