function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
}

String.prototype.trim = function() {
	var x=this;
	//x=x.replace(/^\s*(.*)/, "$1");
	//x=x.replace(/(.*?)\s*$/, "$1");
	var trimExp = /^\s+|\s+$/g;
    x=x.replace(trimExp, "");
	return x;
}

function ControllaEMail(EMail)
{
    //var re = new RegExp("^\\w+[\\w-\\.]*\\@(\\w+((-\\w+)|(\\w*))\\.)+[a-zA-Z]{2,3}$");
    /* Nuova re per consentire di inserire due o più caratteri "-" nella mail. modifica in data 24/02/2004.*/
    
    //var re = new RegExp("^\\w+[\\w-\\.]*\\@(\\w+((-\\w+)*|(\\w*))\\.)+[a-zA-Z]{2,4}$");
     // nuova gestione per verificare che sia possibile l'inserimento del simbolo - anche all'inizio dell'indirizzo
     // Cesare Barazzetta 10/04/2006
     var re  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	    

     return re.test(EMail);
}

function validateUSDate( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only
	    valid dates with 2 digit month, 2 digit day,
	    4 digit year. Date separator can be ., -, or /.
	    Uses combination of regular expressions and
	    string parsing to validate date.
	    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
	
	PARAMETERS:
	   strValue - String to be tested for validity
	
	RETURNS:
	   True if valid, otherwise false.
	
	REMARKS:
	   Avoids some of the limitations of the Date.parse()
	   method such as the date separator character.
	*************************************************/
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	var aRet = new Array(1);

	//check to see if in correct format
	if(!objRegExp.test(strValue)){
		aRet[0] = false;
		aRet[1] = "Formato non corretto.";
		return aRet;
	} else {
		var strSeparator = strValue.substring(2,3) //find date separator
		var arrayDate = strValue.split(strSeparator); //split date into month, day, year
		//create a lookup for months not equal to Feb.
		var arrayLookup = { "01" : 31,"03" : 31, "04" : 30,"05" : 31,"06" : 30,"07" : 31,
		                    "08" : 31,"09" : 30,"10" : 31,"11" : 30,"12" : 31}

		//check for year
		var intYear = parseInt(arrayDate[2],10);
		if(intYear < 1900 || intYear > 2049) {
			aRet[0] = false;
			aRet[1] = "L'anno deve essere compreso tra 1900 e 2050.";
			return aRet;
		}
		
		var intDay = parseInt(arrayDate[1],10);
		//check if month value and day value agree
		aRet[1] = "Data non valida";
		if(arrayLookup[arrayDate[0]] != null) {
			if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0){
				aRet[0] = true; //found in lookup table, good date
				aRet[1] = "";
				return aRet;
			}
		}
		
		//check for February
		var intMonth = parseInt(arrayDate[0],10);
		if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0){
				aRet[0] = true; //Feb. had valid number of days
				aRet[1] = "";
				return aRet;
		}
	}
	aRet[0] = false;
	return aRet; //any other values, bad date
}


function validateUSDateMessage(field) {

var v = field.value, objRegExp = /^\d{2}(\/)\d{2}\1(\d{2}|\d{4})$/;
var msg1 = 'Inserire la data nel seguente formato:';
msg1 += '\n\n\tgg/mm/aaaa';
msg2 = 'Data non valida. Inserire una data corretta.';
if (!objRegExp.test(v)) {
alert(msg1);
field.focus();
field.select();
return false;
} else {
var strSeparator = v.substring(2,3);
var arrayDate = v.split(strSeparator);
var arrayLookup = {
'01': 31 , '03': 31 , '04': 30 , '05': 31 , '06': 30 , '07': 31 ,
'08': 31 , '09': 30 , '10': 31 , '11': 30 , '12': 31
};
var intDay = arrayDate[0];
if (arrayLookup[arrayDate[1]]) {
if (intDay <= arrayLookup[arrayDate[1]] && intDay != 0) return true;
}
if (arrayDate[1] == '02') {
var intYear = arrayDate[2];
if (((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) 
&& intDay !=0)
return true;
}
}
alert(msg2);
field.focus();
field.select();
return false;
}
function confrontaOggi( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only
	    valid dates with 2 digit month, 2 digit day,
	    4 digit year. Date separator can be ., -, or /.
	    Uses combination of regular expressions and
	    string parsing to validate date.
	    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
	
	PARAMETERS:
	   strValue - String to be tested for validity
	
	RETURNS:
	   =0 se coincidono
	   <0 se la data è minore di quella odierna
	   >0 se la data è maggiore di quella odierna
	
	REMARKS:
	   Avoids some of the limitations of the Date.parse()
	   method such as the date separator character.
	*************************************************/

	var iRet = 0;
	
	var strSeparator = strValue.substring(2,3) //find date separator
	var arrayDate = strValue.split(strSeparator); //split date into month, day, year
	var oggi = new Date();
	oggi = Date.UTC(oggi.getFullYear(), oggi.getMonth(), oggi.getDate());
	var dtConfronta = Date.UTC(parseInt(arrayDate[2], 10), parseInt(arrayDate[1], 10) - 1, 
									parseInt(arrayDate[0], 10));
	
	if (dtConfronta > oggi)
		iRet = 1
	else if (dtConfronta < oggi)
		iRet = -1;
	
	return iRet;
}

function FillChar(str, lenTotale, direzione, chrRiempimento){
	var strRiempimento = "";

	for (var count = 0; count < lenTotale; count++)
		strRiempimento += chrRiempimento;

	if (direzione.toLowerCase() == "d") {
		str += strRiempimento;
		str = str.substr(0, lenTotale);
	} else {
		str = strRiempimento + str;
		str = str.substr((str.length)-lenTotale);
	}
	return str;
}

function CreaComboJS_Mese(nomeObj){
	//torna l'oggetto select
	var doc = document;
	var obj, opt, testo;
	var arrMesi = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno",
							"Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
	
	obj = doc.createElement("select");	
	obj.id = nomeObj;
	obj.name = nomeObj;
	obj.className = "PortletText1";

	opt = doc.createElement("option");
	opt.value = "NULL";
	opt.setAttribute("attNullo", 1);
	testo = doc.createTextNode("");
	opt.appendChild(testo);
	obj.appendChild(opt);

	for(var count = 1; count < 13; count++){	
		opt = doc.createElement("option");
		opt.value = count;
		opt.setAttribute("attNullo", 0);
		testo = doc.createTextNode(arrMesi[count-1]);
		opt.appendChild(testo);
		obj.appendChild(opt);
	}
	
	return obj;
}

function InterrompiEvento(ev){
	if (ev.cancelable != null) {
	    ev.preventDefault();
	} else {
	    ev.cancelBubble = true;
	    ev.returnValue = false;
	}
}

function validateInteger( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only
	    valid integer number.
	
	PARAMETERS:
	   strValue - String to be tested for validity
	
	RETURNS:
	   True if valid, otherwise false.
	******************************************************************************/
	//var objRegExp  = /(^-?\d\d*$)/;
	var objRegExp  = /(^\d\d*$)/;
	
	//check for integer characters
	return objRegExp.test(strValue);
}

function getPositionNumber(c, position) {
    var result;
    position = parseInt(position, 10);
    switch(c) {
        case "0":
            result = (position == 0) ? 0 : 1; break;
        case "1":
            result = (position == 0) ? 1 : 0; break;
        case "2":
            result = (position == 0) ? 2 : 5; break;
        case "3":
            result = (position == 0) ? 3 : 7; break;
        case "4":
            result = (position == 0) ? 4 : 9; break;
        case "5":
            result = (position == 0) ? 5 : 13; break;
        case "6":
            result = (position == 0) ? 6 : 15; break;
        case "7":
            result = (position == 0) ? 7 : 17; break;
        case "8":
            result = (position == 0) ? 8 : 19; break;
        case "9":
            result = (position == 0) ? 9 : 21; break;
        case "A":
            result = (position == 0) ? 0 : 1; break;
        case "B":
            result = (position == 0) ? 1 : 0; break;
        case "C":
            result = (position == 0) ? 2 : 5; break;
        case "D":
            result = (position == 0) ? 3 : 7; break;
        case "E":
            result = (position == 0) ? 4 : 9; break;
        case "F":
            result = (position == 0) ? 5 : 13; break;
        case "G":
            result = (position == 0) ? 6 : 15; break;
        case "H":
            result = (position == 0) ? 7 : 17; break;
        case "I":
            result = (position == 0) ? 8 : 19; break;
        case "J":
            result = (position == 0) ? 9 : 21; break;
        case "K":
            result = (position == 0) ? 10 : 2; break;
        case "L":
            result = (position == 0) ? 11 : 4; break;
        case "M":
            result = (position == 0) ? 12 : 18; break;
        case "N":
            result = (position == 0) ? 13 : 20; break;
        case "O":
            result = (position == 0) ? 14 : 11; break;
        case "P":
            result = (position == 0) ? 15 : 3; break;
        case "Q":
            result = (position == 0) ? 16 : 6; break;
        case "R":
            result = (position == 0) ? 17 : 8; break;
        case "S":
            result = (position == 0) ? 18 : 12; break;
        case "T":
            result = (position == 0) ? 19 : 14; break;
        case "U":
            result = (position == 0) ? 20 : 16; break;
        case "V":
            result = (position == 0) ? 21 : 10; break;
        case "W":
            result = (position == 0) ? 22 : 22; break;
        case "X":
            result = (position == 0) ? 23 : 25; break;
        case "Y":
            result = (position == 0) ? 24 : 24; break;
        case "Z":
            result = (position == 0) ? 25 : 23; break;
      }
	return result;
}

function swapImgRestorePortale() { 
  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 findObjPortale(n, d) { 
  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=findObjPortale(n,d.layers[i].document);
  if(!x && d.getElementById) 
  	x=d.getElementById(n); 
  return x;
}

function swapImagePortale() { 
  var i,j=0,x,a=swapImagePortale.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   if ((x=findObjPortale(a[i]))!=null)
   {document.MM_sr[j++]=x; 
   if(!x.oSrc) x.oSrc=x.src; 
   x.src=a[i+2];}
}
//apre la pagina di stampa
function apri(){
window.open('/pls/portal/url/page/sil/stampapagina','Stampa','height=500,width=750,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=yes,location=no');
return;
}
//apre la pagina di stampa per le ricerche
function apriRicerca(){
window.open('/pls/portal/url/page/sil/stamparicerca','Stampa','height=500,width=750,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=yes,location=no');
return;
}
// permette di inviare un contatto
// verifica se il contatto è già stato inviato
// invia il contatto
// gestisce DWContatti
function invioContatto(tipo_contatto,scheda_impresa,scheda_lavoratore,id_professione){  
   
    var TIPO_CONTATTO=tipo_contatto;
    var SCHEDA_IMPRESA=scheda_impresa;
    var SCHEDA_LAVORATORE=scheda_lavoratore;
    var ID_PROFESSIONE=id_professione;
    if (tipo_contatto =="" || scheda_impresa=="" ||scheda_lavoratore==""){
    	alert("Non è stato possibile inviare il contatto\nParametri insufficenti\nIndicare tipo_contatto,scheda_impresa e scheda_lavoratore");
    	return;
    }
    var url="/ask4job/popContatto.jsp?ID_PROFESSIONE="+ID_PROFESSIONE+"&TIPO_CONTATTO="+TIPO_CONTATTO+"&SCHEDA_IMPRESA="+SCHEDA_IMPRESA+"&SCHEDA_LAVORATORE="+SCHEDA_LAVORATORE;
	var message="Confermi l'invio del contatto?";
	windowWidth = 400;
	windowHeight = 102;
	
	NS_window = "screenX=" + (window.screenX + ((window.outerWidth - windowWidth) / 2)) + 
				",screenY=" + (window.screenY + ((window.outerHeight - windowHeight) / 2)) + 
				",statusbar=no,menubar=no,scrollbar=no,width=400,height=140,toolbar=no,width=" + windowWidth + ",height=" + windowHeight ;			
	IE_window = "left=" + (((screen.availWidth - windowWidth) / 2)) + 
				",top=" + (((screen.availHeight - windowHeight) / 2)) + 
				",statusbar=no,menubar=no,scrollbar=no,width=400,height=140,toolbar=no,width=" + windowWidth + ",height=" + windowHeight ;

     if (confirm(message)){
     	var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
	    var IE = (navigator.appName == "Microsoft Internet Explorer");
		if (!(Nav4 || IE)) return ;
     	if (Nav4) 
        	window.open(url,"Contatto",NS_window);
   		else
   			 window.open(url,"Contatto",IE_window);
    	
     }
     return;
}
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

