	var numeros="0123456789";
    var contadordata=0;
	var aberto = false;
	var jan;

	// Verifica se o campo está vazio ...
	function isEmptyObject(sForm,sObject,string){
		var Espaco = " \t\n\r";

		with (sForm){
       		ObjectAux = eval(sObject)
       		if (ObjectAux.value.length==0){
				alert ("O campo "+string+" não foi preenchido!");
				ObjectAux.value = "";
				ObjectAux.focus();
				return 0;
			}
			aux = 0;
			for (i = 0; i < ObjectAux.value.length; i++)
    		{
				var c = ObjectAux.value.charAt(i);
				if (Espaco.indexOf(c) == -1){
					aux = 0;
					break;

				}else{
					aux = aux+1;
				}
			}

			if (aux>=1){
				alert ("O campo "+string+" só contem espaços!");
				ObjectAux.value = "";
				ObjectAux.focus();
				return 0;
			}

 		}
 		return 1;
 	}

	function GetItem2(sForm,sOrigem,sDestino){
		var sel = eval("document."+sForm+"."+sOrigem);
		var sel1 = eval("document."+sForm+"."+sDestino);
 	    if(sel.options.length > 0){
			if (sel.options.selectedIndex != -1){
				for (i=0;i<sel.options.length;i++){
					if (sel.options[i].selected){
			  			sel1.options[sel1.options.length] = new Option(sel.options[i].text,sel.options[i].value);
					}
				}
				for (i=sel.options.length-1;i>=0;i--){
					if (sel.options[i].selected){
						sel.options[i] = null;
					}
				}
			}
		}
 	    if((sDestino.indexOf("_sel")>0) && (sel1.options.length > 0)){
				for (i=sel1.options.length-1;i>=0;i--){
					sel1.options[i].selected = true;
				}
 	    }

 	    if((sOrigem.indexOf("_sel")>0) && (sel.options.length > 0)){
				for (i=sel.options.length-1;i>=0;i--){
					sel.options[i].selected = true;
				}
 	    }
 	}

	function GetAll(sForm, sOrigem, sDestino){
		var sel = eval("document."+sForm+"."+sOrigem);
		var sel1 = eval("document."+sForm+"."+sDestino);
		for (i=sel.options.length-1;i>=0;i--){
			sel.options[i].selected=true;
		}
 	    if(sel.options.length > 0){
			if (sel.options.selectedIndex != -1){
				for (i=0;i<sel.options.length;i++){
					if (sel.options[i].selected){
			  			sel1.options[sel1.options.length] = new Option(sel.options[i].text,sel.options[i].value);
					}
				}
				for (i=sel.options.length-1;i>=0;i--){
					if (sel.options[i].selected){
						sel.options[i] = null;
					}
				}
			}
		}
 	    if((sDestino.indexOf("_sel")>0) && (sel1.options.length > 0)){
				for (i=sel1.options.length-1;i>=0;i--){
					sel1.options[i].selected = true;
				}
 	    }
 	    if((sOrigem.indexOf("_sel")>0) && (sel.options.length > 0)){
				for (i=sel.options.length-1;i>=0;i--){
					sel.options[i].selected = true;
				}
 	    }
	}

	function isPhone(sForm,sObject,string){
		with (eval("document."+sForm+"")){
       			var numeros="0123456789-()+";
        		var campo;
        		var contador=0;

			for (var i=0; i<eval(sObject+".value.length"); i++){
             			campo=eval(sObject+".value.substring(i,i+1)");
			 	if (numeros.indexOf(campo) !=-1)
                 			contador++;
        		}

 	       		if ((contador!=eval(sObject+".value.length")) && (eval(sObject+".value.length")!=0)) {
 	       			alert ("Não foi introduzido um número válido para "+string+" (utilize apenas os caracteres - ( )+ alem dos caracteres numéricos)");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
            		}

		}
		return 1;
	}

	function isInteger(sForm,sObject,string){
		with (sForm){
       	var numeros="0123456789";
        	var campo;
        	var contador=0;

			for (var i=0; i<eval(sObject+".value.length"); i++){
             campo=eval(sObject+".value.substring(i,i+1)");
			 if (numeros.indexOf(campo) !=-1)
                 contador++;
        	}

 	       if ((contador!=eval(sObject+".value.length")) && (eval(sObject+".value.length")!=0)) {
 	       		alert ("Não foi introduzido um número inteiro para o campo "+string+"");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
            	}

		}
		return 1;
	}

	function isIntegerString(sString,string){
    	var numeros="0123456789";
     	var campo;
     	var contador=0;

		for (var i=0; i<sString.length; i++){
          campo=sString.substring(i,i+1);
		 if (numeros.indexOf(campo) !=-1)
              contador++;
     	}

		if ((contador!=sString.length) && (sString.length!=0)) {
			alert ("Não foi introduzido um número inteiro para o campo "+string+"");
			return 0;
		}

		return 1;
	}


	// Verifica se a data é admissivel. Esta função é utilizada para campos com o formato DD-MM-YYYY ...
	function isValidFieldDate(sForm,sObject,string){
		with (sForm){
	       	var numeros="0123456789";
        	var campo;
        	var contador=0;
			var ano;
			var mes;
			var dia;
			var data;
			var daymonth;
			var bissexto;

			ano = eval(sObject+".value.substring(6,10)");
			mes = eval(sObject+".value.substring(3,5)");
			dia = eval(sObject+".value.substring(0,2)");
			data = ano+mes+dia;

			for (var i=0; i<eval(data.length); i++){
			    campo=data.substring(i,i+1);
			    if (numeros.indexOf(campo) !=-1)
			        contador++;
			}

 	       	if ((contador!=8) && (eval(sObject+".value.length")!=0)) {
 	       		alert ("O formato do campo "+string+" não está correcto (dd-mm-yyyy).");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
           	}

			if ((eval(sObject+".value.substring(2,3)")!='-') || (eval(sObject+".value.substring(5,6)")!='-')) {
				alert ("Os separadores (-) para o campo "+string+" não são admissiveis");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
			}


			if (ano%400 == 0){
				bissexto=1;
			}else{
				if (ano%100 == 0){
					bissexto=0;
				}else{
					if (ano%4 == 0){
						bissexto=1;
					}
					else{
						bissexto=0;
					}
				}
			}

			daymonth = new Array(12);
			daymonth[0] = 31;

			if (bissexto==1) {
				daymonth[1] = 29;
			}
			else {
				daymonth[1] = 28;
			}

			daymonth[2] = 31;
			daymonth[3] = 30;
			daymonth[4] = 31;
			daymonth[5] = 30;
			daymonth[6] = 31;
			daymonth[7] = 31;
			daymonth[8] = 30;
			daymonth[9] = 31;
			daymonth[10] = 30;
			daymonth[11] = 31;

			if ((mes<1) || (mes>12)) {
				alert ("O mês da "+string+" não é admissivel!");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
			}

            if ((dia<1) || (dia>daymonth[mes-1])) {
				alert ("O Dia da "+string+" não é admissivel!");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
			}

		}
		return 1;
	}


	// Verifica se a data é >= que a data actual ...
	function isDateGreaterEqualSysdate(sForm,sObject,string){
		var ano;
		var mes;
		var dia;
		var todayDate;
		var UserDate;

		with (sForm){

			ano = eval(sObject+".value.substring(6,10)");
			mes = eval(sObject+".value.substring(3,5)")-1;
			dia = eval(sObject+".value.substring(0,2)");

			todayDate = new Date();
			UserDate  = new Date(ano,mes,dia,23,59,59);

			if (UserDate<todayDate) {
				alert ("A "+string+" tem de ser superior ou igual à data de hoje!");
				eval(sObject+".value=''");
				eval(sObject+".focus()");
				return 0;
			}
		}
		return 1;
	}


	function xy(){
		altura = screen.height/2
		largura = screen.width/2

		window.moveTo(altura+85,largura-90);
	}

	// Abre uma nova janela em que é possível obter o URL de um documento, capitulo ou subcapitulo ...
	function janela(k,largura,altura){
		if ((!aberto)||(jan.closed)){
			jan = window.open(k,'nJanela','scrollbars=yes,width='+largura+',height='+altura);
			aberto = true;
			jan.focus();
		}
	}

	// =======================
	//  Purpose : Show or hide table
	//  Parameters : sChilds - table identifiers (Child1; ... ChildN;|ChildOfChild1|...ChildOfChildN|)
	// =======================
	function controla(sChilds){

		// first we get the Children
		var ids = sChilds.split(";")

		for (i=0;i<ids.length-1;i++){

			var obj = document.getElementById(ids[i]);
			var sAux = obj.style.display
			obj.style.display = (obj.style.display == "none" ) ? "" : "none";

			// if we contract a node
			if ((ids[i].indexOf("Minus")>-1) && (sAux.length==0)){

				// We get the Children of the selected Children
				var idsChilds = sChilds.split("|");

				for (j=1;j<idsChilds.length-1;j++){
					var objChild = document.getElementById(idsChilds[j]);
					sAux1 = objChild.style.display;
					// if minus is visible
					if ((idsChilds[j].indexOf("Minus")>-1) && (sAux.length==0)){
							// minus invisible
							objChild.style.display = "none"
					}else{
						// if object = plus
						if ((idsChilds[j].indexOf("Plus")>-1)){
							// plus visible
							objChild.style.display = ""

						}else{
						 	if (objChild.style.display == "" ){
								objChild.style.display = "none";
							}
						}
					}
				}
			}
		}
	}


/* PMML ADDED This */

/************************************************************************************
Cookie Functions
************************************************************************************/

//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name, value, expires, path, domain, secure) {

	document.cookie = name + "=" + escape (value) +
    	((expires) ? "; expires=" + expires.toGMTString() : "") +
    	((path) ? "; path=" + path : "") +
    	((domain) ? "; domain=" + domain : "") +
    	((secure) ? "; secure" : "");
}

// "Internal" function to return the decoded value of a cookie
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
    	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


// *****************************
// Window link for postings
// *****************************
function linkpostings(sfield){

	if (isHTMLMode){
		alert("Please uncheck 'Edit HTML'");
		return;
	}

	if ((!aberto)||(jan.closed)){
		//altura = screen.height/2;
		//largura = screen.width/2;
		altura = 500;
		largura = 700;
		jan = window.open('../postings/linkpostings.jsp?field='+sfield,'nJanela','scrollbars=yes,width='+largura+',height='+altura);
		jan.focus();
		aberto = true;
	}
}


// *****************************
// CALENDAR
// *****************************

function calendar(sfield, basePath){
	openSplashWindow(basePath + '/system/calendar/calendar.jsp?field='+sfield,195,220);
}


// *****************************
// SPLASH WINDOW
// parameter - target object in form : "form.input"
// *****************************
function openSplashWindow(sUrl, width, height){

	var splashWin;
	var nLeft = (window.screen.width - width)/2;
	var nTop = (window.screen.height - height)/2;

	splashWin = window.open(sUrl, '_splash', 'width=' + width + ',height=' + height + 'top=' + nTop + ',left=' + nLeft + ',scrollbars=1,resizable=0');

	splashWin.blur();
	splashWin.resizeTo(width,height);
	splashWin.moveTo(nLeft, nTop);
	splashWin.focus();

	window.onbeforeunload = function() {splashWin.close();};
}

// *****************************************
//  FUNCAO PARA VERIFICACAO DE EMAIL VALIDO
// *****************************************
function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address.
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	/* The following string represents the range of characters allowed in a
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]";
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+';
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid
	if (user.match(userPat)==null) {
		// user is not valid
		//alert("The username doesn't seem to be valid.");
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.");
		return false;
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding
	   the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.");
	   return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!";
	   //alert(errStr);
	   return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

// *****************************************
//  FUNCAO PARA LIMPAR ESPACOS ANTES E DEPOIS DE STRING
// *****************************************
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return "";
	}

	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);

	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
}//End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";

	if(v_length < 0){
		return "";
	}

	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While

	return strTemp;
}//End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return "";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While

	return strTemp;
}//End Function

// *****************************************
//  FUNCAO PARA CORRIGIR STRING COM CHARS VALIDOS
// *****************************************
function correctName(sSource) {
	var validChars = "0123456789 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàáâãÀÁÂÃèéêÈÉÊìíîÌÍÎòóôõÒÓÔÕùúûÙÚÛçÇ.,:;-_!?+*#$%€()=«»&";
	var i, currChar, sReturn = "";

	for (i=0; i < sSource.length; i++) {
		currChar = sSource.charAt(i);
		if (validChars.indexOf(currChar) >= 0) sReturn += currChar;
	}
	return sReturn;
}//End Function
	
function correctNameWithBR(sSource) {
	var validChars = "0123456789 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàáâãÀÁÂÃèéêÈÉÊìíîÌÍÎòóôõÒÓÔÕùúûÙÚÛçÇ.,:;-_!?+*#$%€()=«»&";
	var i, currChar, sReturn = "";

	i=-1
	while (i < sSource.length) {
		++i;
		currChar = sSource.charAt(i);
		if (validChars.indexOf(currChar) >= 0) sReturn += currChar;
		else if (sSource.substring(i,i+4)=='<br>') {
			sReturn += "<br>"; i += 3;
		}
	}
	return sReturn;
}//End Function
