
function openpopup(popurl){
	newW = window.open(popurl,"","width=500,height=438,")
	if((document.window != null) && (!newW.opener))
		newW.opener = document.window;
	//window.close ();
	newW.focus ();
}

function openpopup_2(popurl){
	newW = window.open(popurl,"","width=800,height=600,toolbar,location,status,scrollbars,resizable,")
	if((document.window != null) && (!newW.opener))
		newW.opener = document.window;
	//window.close ();
	newW.focus ();
}

function checkEmailAddress(field) {

// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!
var good;
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
   good = true
} else {
   //field.focus()
   //field.select()
   good = false
   }
	return good;
}

function extLink(SITE,EXT_SITE,URL){
  var message = "";
  message = "Attenzione!\n\nState abbandonando il sito "+SITE+".";
  message+= "\n\nLe informazioni contenute nel nuovo sito prescelto ("+EXT_SITE+") possono non essere conformi al";
  message+= "\nD. Lgs. 219/06 che regola la pubblicita\' sui medicinali per uso umano e le opinioni espresse non riflettono";
  message+= "\nnecessariamente le posizioni dell'azienda, ne\' sono da essa avallate.";
  if (confirm(message)){
	  window.open(URL, 'externalLink');
  }
}

function validateRegForm_1(OBJ,OP) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href = "/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if( (OBJ.BUSINESS_NAME.value).length <= 0 )
    	errors += "Ragione Sociale Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.LINE_1_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.SECTOR_NAME.value).length <= 0 )
    	errors += "Citta' Obbligatorio!\n";
    if( (OBJ.LOCALITY_CODE.value).length <= 0 )
    	errors += "Provincia Obbligatorio!\n";
    if( (OBJ.POSTAL_CODE.value).length <= 0 )
    	errors += "C.A.P. Obbligatorio!\n";
    else if( isNaN(OBJ.POSTAL_CODE.value) )
    	errors += "C.A.P. Non valido!\n";
    if( (OBJ.PROFESSION.value).length <= 0 )
    	errors += "Professione Obbligatorio!\n";
    if( (OBJ.LOCALITY_ALBO_CODE.value).length <= 0 )
    	errors += "Prov. Iscrizione Albo Obbligatorio!\n";
    if( (OBJ.NUM_ALBO_TEXT.value).length <= 0 )
    	errors += "Numero Iscrizione Albo Obbligatorio!\n";
    if( (OBJ.SPECIALIZZATION.value).length <= 0 )
    	errors += "Specializzazione Obbligatorio!\n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    //CE04153446
    //if( (OBJ.PHONE_NUMBER.value).length <= 0 )
    //	errors += "Num. Tel. Obbligatorio!\n";
    else if( isNaN(OBJ.PHONE_NUMBER.value) )
    	errors += "Num. Tel. Non valido!\n";
    if( (OBJ.USERNAME.value).length <= 0 )
    	errors += "Username Obbligatorio!\n";
    if( (OBJ.PASSWORD.value).length <= 0 )
    	errors += "Password Obbligatorio!\n";
    if( (OBJ.RETYPE.value).length <= 0 )
    	errors += "Conferma Password Obbligatorio!\n";
    if( OBJ.PASSWORD.value != OBJ.RETYPE.value )
    	errors += "Password e Conferma Password devono coincidere!\n";
    if( !OBJ.OVERALL_CONSENT.checked )
    	errors += "Trattamento Dati Personali Obbligatorio!\n";
	//CE04153446
	//if(!(OBJ.EMAIL_CONSENT[0].checked) && !(OBJ.EMAIL_CONSENT[1].checked))
	if( !(OBJ.EMAIL_CONSENT[0].checked) )
		errors += "Consenso all'utilizzo della email obbligatorio!\n";
    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function validateRegForm_2(OBJ,OP) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href = "/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if ((OBJ.BUSINESS_NAME.value.length <= 0))
		 errors += "Testata Giornalistica Obbligatoria!\n";
    if(!OBJ.PROFESSION.checked)
    	errors += "Occorre dichiarare di essere giornalista!\n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    if( (OBJ.PHONE_NUMBER.value).length <= 0 )
    	errors += "Num. Tel. Obbligatorio!\n";
    else if( isNaN(OBJ.PHONE_NUMBER.value) )
    	errors += "Num. Tel. Non valido!\n";
    if( (OBJ.PASSWORD.value).length <= 0 )
    	errors += "Password Obbligatorio!\n";
    if( (OBJ.RETYPE.value).length <= 0 )
    	errors += "Conferma Password Obbligatorio!\n";
    if( OBJ.PASSWORD.value != OBJ.RETYPE.value )
    	errors += "Password e Conferma Password devono coincidere!\n";
    if( !OBJ.OVERALL_CONSENT.checked )
    	errors += "Trattamento Dati Personali Obbligatorio!\n";
	if(!(OBJ.EMAIL_CONSENT[0].checked) && !(OBJ.EMAIL_CONSENT[1].checked))
		errors += "Consenso all'utilizzo della email obbligatorio!\n";
    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}


function validatePrfForm_1(OBJ,OP,UID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if( (OBJ.BUSINESS_NAME.value).length <= 0 )
    	errors += "Ragione Sociale Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.LINE_1_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.SECTOR_NAME.value).length <= 0 )
    	errors += "Citta' Obbligatorio!\n";
    if( (OBJ.LOCALITY_CODE.value).length <= 0 )
    	errors += "Provincia Obbligatorio!\n";
    if( (OBJ.POSTAL_CODE.value).length <= 0 )
    	errors += "C.A.P. Obbligatorio!\n";
    else if( isNaN(OBJ.POSTAL_CODE.value) )
    	errors += "C.A.P. Non valido!\n";
    if( (OBJ.PROFESSION.value).length <= 0 )
    	errors += "Professione Obbligatorio!\n";
    if( (OBJ.LOCALITY_ALBO_CODE.value).length <= 0 )
    	errors += "Prov. Iscrizione Albo Obbligatorio!\n";
    if( (OBJ.NUM_ALBO_TEXT.value).length <= 0 )
    	errors += "Numero Albo Obbligatorio!\n";
    if( (OBJ.SPECIALIZZATION.value).length <= 0 )
    	errors += "Specializzazione Obbligatorio!\n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    //CE04153446
    //if( (OBJ.PHONE_NUMBER.value).length <= 0 )
    //	errors += "Num. Tel. Obbligatorio!\n";
    else if( isNaN(OBJ.PHONE_NUMBER.value) )
    	errors += "Num. Tel. Non valido!\n";
    if( (OBJ.USERNAME.value).length <= 0 )
    	errors += "Username Obbligatorio!\n";
    if( OBJ.PASSWORD.value != OBJ.RETYPE.value )
    	errors += "Nuova Password e Conferma Password devono coincidere!\n";
	//CE04153446
	//if(!(OBJ.EMAIL_CONSENT[0].checked) && !(OBJ.EMAIL_CONSENT[1].checked))
	if( !(OBJ.EMAIL_CONSENT[0].checked) )
		errors += "Consenso all'utilizzo della email obbligatorio!\n";
    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function validatePrfForm_2(OBJ,OP, UID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href = "/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if(!OBJ.PROFESSION.checked)
    	errors += "Occorre dichiarare di essere giornalista!\n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    if( (OBJ.PHONE_NUMBER.value).length <= 0 )
    	errors += "Num. Tel. Obbligatorio!\n";
    else if( isNaN(OBJ.PHONE_NUMBER.value) )
    	errors += "Num. Tel. Non valido!\n";
    if( OBJ.PASSWORD.value != OBJ.RETYPE.value )
    	errors += "Password e Conferma Password devono coincidere!\n";
	if(!(OBJ.EMAIL_CONSENT[0].checked) && !(OBJ.EMAIL_CONSENT[1].checked))
		errors += "Consenso all'utilizzo della email obbligatorio!\n";
    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function validateINFOPRIVACYFORM(OBJ){
    var errors = "";
	if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if( (OBJ.EMAIL.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    if( (OBJ.PHONE.value).length <= 0 )
    	errors += "Num. Tel. Obbligatorio!\n";
    else if( isNaN(OBJ.PHONE.value) )
    	errors += "Num. Tel. Non valido!\n";
	if( (OBJ.REQUEST.value).length <= 0 )
    	errors += "Oggetto della richiesta Obbligatorio!\n";
    if( errors.length > 0 ){
    	alert(errors);
		return false;
	} else {
		return true;
	}
}

function validateMatForm_1(OBJ,OP,UID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if( (OBJ.BUSINESS_NAME.value).length <= 0 )
    	errors += "Ragione Sociale Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.LINE_1_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.SECTOR_NAME.value).length <= 0 )
    	errors += "Citta' Obbligatorio!\n";
    if( (OBJ.POSTAL_CODE.value).length <= 0 )
    	errors += "C.A.P. Obbligatorio!\n";
    else if( isNaN(OBJ.POSTAL_CODE.value) )
    	errors += "C.A.P. Non valido!\n";
    if( (OBJ.OSPITAL.value).length <= 0 )
    	errors += "Ospedale Obbligatorio!\n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    if( (OBJ.OBJECT_TEXT.value).length <= 0 )
    	errors += "Oggetto Richiesta Obbligatorio!\n";
    if( (OBJ.CONTENT_TEXT.value).length <= 0 )
    	errors += "Scopo Richiesta Obbligatorio!\n";

    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}


function validateMatForm_2(OBJ,OP,UID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if( (OBJ.BUSINESS_NAME.value).length <= 0 )
    	errors += "Testata Giornalistica Obbligatoria! \n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    if( (OBJ.OBJECT_TEXT.value).length <= 0 )
    	errors += "Oggetto Richiesta Obbligatorio!\n";
    if( (OBJ.CONTENT_TEXT.value).length <= 0 )
    	errors += "Scopo Richiesta Obbligatorio!\n";

    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function validateVisForm_1(OBJ,OP,UID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.FIRST_NAME.value).length <= 0 )
    	errors += "Nome Obbligatorio!\n";
    if( (OBJ.LAST_NAME.value).length <= 0 )
    	errors += "Cognome Obbligatorio!\n";
    if( (OBJ.BUSINESS_NAME.value).length <= 0 )
    	errors += "Ragione Sociale Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.LINE_1_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo Societa' di Lavoro Obbligatorio!\n";
    if( (OBJ.SECTOR_NAME.value).length <= 0 )
    	errors += "Citta' Obbligatorio!\n";
    if( (OBJ.POSTAL_CODE.value).length <= 0 )
    	errors += "C.A.P. Obbligatorio!\n";
    else if( isNaN(OBJ.POSTAL_CODE.value) )
    	errors += "C.A.P. Non valido!\n";
    if( (OBJ.OSPITAL.value).length <= 0 )
    	errors += "Ospedale Obbligatorio!\n";
    if( (OBJ.EMAIL_ADRS_TEXT.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.EMAIL_ADRS_TEXT) )
    	errors += "Indirizzo E-Mail Non Valido!\n";
    if( (OBJ.CONTENT_TEXT.value).length <= 0 )
    	errors += "Motivo Richiesta Obbligatorio!\n";

    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function validateRmdPswdForm_1(OBJ,OP) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else {
    var errors = "";
    if( (OBJ.email.value).length <= 0 )
    	errors += "Indirizzo E-Mail Obbligatorio!\n";
    else if( !checkEmailAddress(OBJ.email) )
    	errors += "Indirizzo E-Mail Non Valido!\n";

    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function validateQuestForm_1(OBJ,OP,UID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  }
}

function validateQuestForm_2(OBJ,OP,UID,ARR) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else {
  	errors = "";
    for( i = 0; i < ARR.length; i++ ) {
    	check = false;
    	for( j = 0; j < eval("OBJ.R_"+ARR[i]+".length"); j++ ) {
    		if( !check && eval("OBJ.R_"+ARR[i]+"["+j+"].checked == true") )
    			check = true;
    	}
    	if( !check ) {
    		errors += "Question number " + (i+1) + " has no answer!\n";
    	}
    }

    if( errors.length > 0 )
    	alert(errors);
    else
    	OBJ.submit();
  }
}

function executeQuest(OBJ,S_ID,QUEST_ID,DONE) {
  if( DONE == "TRUE" ) {
    // Read-only mode
  } else {
    // Arcade mode
    OBJ.QUEST_ID.value = QUEST_ID;
    OBJ.submit();
  }
}

function validateJobForm_1(OBJ,OP,UID,JID) {
  if( OP == "CANCEL" ) {
    if( confirm("Abbandonare l'operazione?") )
    	location.href="/home.jsp?page=-1";
  } else if( OP == "UPDATE" ) {
    var errors = "";

    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") ) {
      OBJ.action="modify-job.do?JOB_ID="+JID+"&USER_ID="+UID;
      OBJ.submit();
    }
  } else {
    var errors = "";
    if( (OBJ.job_description.value).length <= 0 )
    	errors += "Nome del Job Obbligatorio!\n";
    if( (OBJ.job_criteria.value).length <= 0 )
    	errors += "Criterio di Ricerca Non Valido!\n";

    if( errors.length > 0 )
    	alert(errors);
    else if( confirm("Confermare l'operazione?") )
    	OBJ.submit();
  }
}

function deleteJobConfirm(S_ID, J_ID , U_ID) {
  if(confirm("Delete selected Job?")) {
  	location.href = "delete-job.do;jsessionid="+S_ID+"?JOB_ID="+J_ID+"&USER_ID="+U_ID;
  }
}
