// JavaScript Document
/*
	Autore: Sandro Ferretti
	Data:   26/07/2006
	Release:0
	Descrizione: Pagina dei settaggi delle funzioni di tipo javascript
*/

function decision(message , url){
	if(confirm(message)) location.href = url;
	}

//istanzia XMLHttp 
/*function getXMLHttp() {
	var xmlhttp = null;
	if (window.ActiveXObject) {
		if (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	if (!xmlhttp && typeof(XMLHttpRequest) != 'undefined') {
	xmlhttp = new XMLHttpRequest()
	xmlhttp.overrideMimeType('text/xml')
	}
	return xmlhttp
}

function cerca_pagina(criterio){
	
	xmlhttp = getXMLHttp()
	xmlhttp.open("get","htm/cerca.cfm?cerca="+criterio,false);
	xmlhttp.onreadystatechange= function (){elabora_risp()}
	xmlhttp.send();
	
	}
	
function connect_user(user,password){
	
	xmlhttp = getXMLHttp()
	xmlhttp.open("post","Index.cfm",false);
	xmlhttp.send("user="+form.user_ut+"&password="form.password_ut);
	xmlhttp.onreadystatechange= function (){elabora_risp()}
	}*/
	
function formData2QueryString(docForm) {
  var submitContent = '';
  var formElem;
  var lastElemName = '';
  
  for (i = 0; i < docForm.elements.length; i++) {
    
    formElem = docForm.elements[i];
    switch (formElem.type) {
      // Text fields, hidden form elements
      case 'text':
      case 'hidden':
      case 'password':
      case 'textarea':
      case 'select-one':
        submitContent += formElem.name + '=' + escape(formElem.value) + '&'
        break;
        
      // Radio buttons
      case 'radio':
        if (formElem.checked) {
          submitContent += formElem.name + '=' + escape(formElem.value) + '&'
        }
        break;
        
      // Checkboxes
      case 'checkbox':
        if (formElem.checked) {
          // Continuing multiple, same-name checkboxes
          if (formElem.name == lastElemName) {
            // Strip of end ampersand if there is one
            if (submitContent.lastIndexOf('&') == submitContent.length-1) {
              submitContent = submitContent.substr(0, submitContent.length - 1);
            }
            // Append value as comma-delimited string
            submitContent += ',' + escape(formElem.value);
          }
          else {
            submitContent += formElem.name + '=' + escape(formElem.value);
          }
          submitContent += '&';
          lastElemName = formElem.name;
        }
        break;
        
    }
  }
  // Remove trailing separator
  submitContent = submitContent.substr(0, submitContent.length - 1);
  return submitContent;
}
	
/*function elabora_risp(){
	
	if (xmlhttp.readystate == 4){
		document.getElementById('url_pagina').innerHTML = xmlhttp.responseText
		
		}
	}*/
	
function valida_pass(theForm){			
							
		if(theForm.v_password.value.replace(/\s*/g,'') == '' || theForm.v_password.value.length < 8 ){
			alert("La vecchia Password e' obbligatoria, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.v_password.focus()
			return false
			}	
			
		if(theForm.n_password.value.replace(/\s*/g,'') == '' || theForm.n_password.value.length < 8 ){
			alert("La nuova Password e' obbligatoria, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.n_password.focus()
			return false
			}
			
		if(theForm.c_n_password.value.replace(/\s*/g,'') == '' || theForm.c_n_password.value.length < 8 ){
			alert("Il Conferma Password e' obbligatorio, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.c_n_password.focus()
			return false
			}
		
		if(theForm.n_password.value.replace(/\s*/g,'') != theForm.c_n_password.value.replace(/\s*/g,'')  ){
			alert("La Password deve essere uguale a quella del 'Conferma Password'!")
			theForm.c_n_password.focus()
			return false
			}
	}
	
function valida_pass2(theForm){			
							
		if(theForm.n_password.value.replace(/\s*/g,'') == '' || theForm.n_password.value.length < 8 ){
			alert("La nuova Password e' obbligatoria, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.n_password.focus()
			return false
			}
			
		if(theForm.c_n_password.value.replace(/\s*/g,'') == '' || theForm.c_n_password.value.length < 8 ){
			alert("Il Conferma Password e' obbligatorio, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.c_n_password.focus()
			return false
			}
		
		if(theForm.n_password.value.replace(/\s*/g,'') != theForm.c_n_password.value.replace(/\s*/g,'')  ){
			alert("La Password deve essere uguale a quella del 'Conferma Password'!")
			theForm.c_n_password.focus()
			return false
			}
	}

function valida_cerca(theForm){
	
	if(theForm.cerca.value.replace(/\s*/g,'') == ''){
			alert("Il criterio di ricerca e' obbligatorio!")
			theForm.cerca.focus()
			return false
			}
		}	
function valida_utenza(theForm){
	
	if(theForm.user_ut.value.replace(/\s*/g,'') == ''){
			alert("La User e' obbligatoria!")
			theForm.user_ut.focus()
			return false
			}
			
	if(theForm.password_ut.value.replace(/\s*/g,'') == '' ){
			alert("La Password e' obbligatoria!")
			theForm.password_ut.focus()
			return false
			}
	}
	
function valida_contenuto(theForm){
	
		if((theForm.titolo.value.replace(/\s*/g,'') == '')||(theForm.titolo.value.length > 1000)){
			alert("Attenzione il campo Titolo e' Obbligatorio e non superiore a 1000 caratteri!");
			theForm.titolo.focus();
			return false;
			}
	
		if(theForm.abstract.value.replace(/\s*/g,'') == ''){
			alert("Attenzione il campo Abstract e' Obbligatorio !");
			theForm.abstract.focus();
			return false;
			}
		
		if(theForm.testo.value.replace(/\s*/g,'') == '<DIV>&nbsp;</DIV>' || theForm.testo.value.replace(/\s*/g,'') == '<P>&nbsp;</P>' ){
			alert("Attenzione il campo testo e' obbligatorio")
			return false;
			}
	}
	
function valida_utente(theForm){
	
		if(theForm.user_ut.value.replace(/\s*/g,'') == '' || theForm.user_ut.length > 100){
			alert("Il nome User e' obbligatorio!")
			theForm.user_ut.focus()
			return false
			}
			
		if(theForm.password_ut.value.replace(/\s*/g,'') == '' || theForm.password_ut.value.length < 8 || theForm.user_ut.length > 100){
			alert("La Password e' obbligatorio, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.password_ut.focus()
			return false
			}
			
		if((theForm.email_ut.value.replace(/\s+$|^\s+/g,"") == '')||(theForm.email_ut.value.length > 500)){
		        alert("Il Campo Email e' obbligatorio e non puo' contenere piu' di 500 caratteri!");
				theForm.email_ut.focus();
				return (false);
		}else{
				var x = theForm.email_ut.value.replace(/\s+$|^\s+/g,"");
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (filter.test(x)) {}
			
				else {
						alert("Attenzione il formato e-mail non e' corretto");
						theForm.email_ut.focus();
						return (false);}
		
	    }
	}
	
function valida_utente_mod(theForm){
	
		if(theForm.user_ut_mod.value.replace(/\s*/g,'') == '' || theForm.user_ut_mod.length > 100){
			alert("Il nome User e' obbligatorio!")
			theForm.user_ut_mod.focus()
			return false
			}
			
		if(theForm.password_ut_mod.value.replace(/\s*/g,'') == '' || theForm.password_ut_mod.value.length < 8 || theForm.user_ut_mod.length > 100){
			alert("La Password e' obbligatorio, deve essere almeno di 8 Caratteri e non superiore di 100!")
			theForm.password_ut_mod.focus()
			return false
			}
			
		if((theForm.email_ut_mod.value.replace(/\s+$|^\s+/g,"") == '')||(theForm.email_ut_mod.value.length > 500)){
		        alert("Il Campo Email e' obbligatorio e non puo' contenere piu' di 500 caratteri!");
				theForm.email_ut_mod.focus();
				return (false);
		}else{
				var x = theForm.email_ut_mod.value.replace(/\s+$|^\s+/g,"");
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (filter.test(x)) {}
			
				else {
						alert("Attenzione il formato e-mail non e' corretto");
						theForm.email_ut_mod.focus();
						return (false);}
		
	    }
	}
	
function valida_ins_alleg(theForm){
		
			if((theForm.titolo_alleg.value.replace(/\s+$|^\s+/g,"") == '')||(theForm.titolo_alleg.value.length > 1000)){
				alert("Attenzione il Campo Titolo e' obbligatorio e non puo' contenere piu' di 1000 caratteri!")
				theForm.titolo_alleg.focus();
				return false;
			}
			
					
			if((theForm.allegato.value.replace(/\s+$|^\s+/g,"") == '')||(theForm.allegato.value.length > 1000)){
				alert("Attenzione il Campo Allegato e' obbligatorio e non puo' contenere piu' di 1000 caratteri!")
				theForm.allegato.focus();
				return false;
			}

	}
	
function valida_ins_link(theForm){
	
			if((theForm.titolo_link.value.replace(/\s+$|^\s+/g,"") == '')||(theForm.titolo_link.value.length > 1000)){
				alert("Attenzione il Campo Titolo e' obbligatorio e non puo' contenere piu' di 1000 caratteri!")
				theForm.titolo_link.focus();
				return false;
			}
			
					
			if((theForm.testo.value.replace(/\s+$|^\s+/g,"") == 'http://')||(theForm.testo.value.length > 1000)){
				alert("Attenzione il Campo Descrizione e' obbligatorio e non puo' contenere piu' di 1000 caratteri!")
				theForm.testo.focus();
				return false;
			}
					
			if((theForm.testo.value.replace(/\s+$|^\s+/g,"") == '')||(theForm.testo.value.length > 1000)){
				alert("Attenzione il Campo Descrizione e' obbligatorio e non puo' contenere piu' di 1000 caratteri!")
				theForm.testo.focus();
				return false;
			}

	}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}