//<!--

var v_parola ="";
var link;

/****************************************************************/

//Verifica che sia una stringa vuota

/****************************************************************/

var whitespace = " \t\n\r";

function isEmpty(s)
 {   
  return ((s == null) || (s.length == 0))
 }

/****************************************************************/


//Verifica che sia una stringa vuota o costituita solo di spazi bianchi

/****************************************************************/

function isWhitespace (s)

{   var i;


    if (isEmpty(s)) return true;


    for (i = 0; i < s.length; i++)
    {   
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }


    return true;
}


/****************************************************************/

// CanSubmit= ForceEntry(txtProva,"il campo Prova") --> Forza il riempimento del campo Prova

/****************************************************************/

function ForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);

	if (isWhitespace(strField)) {
		alert("Introdurre i dati per " + FieldName);
		objField.focus();
		objField.select();
		return false;

	}


 return true;

}
		

/****************************************************************/

//mostra la stringa di errore e assegna il focus

/****************************************************************/

function PromptErrorMsg(Field,strError)
{
	alert("Immettere una data valida per  " + strError + ".");
	Field.focus();
}





	/****************************************************************/

	// CanSubmit= ForceLength(txtProva,"il campo Prova") --> 
	  //  Forza il riempimento del campo Prova con un valore della lunghezza desiderata

	/****************************************************************/



	function ForceLength(objField, nLength, strWarning)
	{
		var strField = new String(objField.value);

		if (strField.length > nLength) {
		alert(strWarning);
		return false;
	} else
		return true;
	}	



     function storeCaret (textEl) {
       if (textEl.createTextRange) 
         textEl.caretPos = document.selection.createRange().duplicate();
     }

     function insertAtCaret (textEl, text) {
       if (textEl.createTextRange && textEl.caretPos) {
         var caretPos = textEl.caretPos;
         caretPos.text =
           caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
             text + ' ' : text;
       }
       else
         textEl.value  = text;
     }
     


function testo(parola)
{
    v_parola = parola;
}




function verifica_tokens(theForm)

{
 ritorno=true;

var token = new String;

var tokens = theForm.p_frase.value;

var tokens_array = tokens.split(" ");

for (var loop=0; loop < tokens_array.length; loop++)
{
    token=(tokens_array[loop]);
 
    if ( (token.toUpperCase()!='"') && (token.toUpperCase()!=',') && (token.toUpperCase()!='AND') &&  (token.toUpperCase()!='OR') && (token.toUpperCase()!='NOT') && (token.toUpperCase()!='NEAR') && (token.toUpperCase()!=' ') && (token.toUpperCase()!='  ') && (token.toUpperCase()!='   ') ) 

     {

     if ((token.length>0) && (token.length<4))

      {


       alert('Attenzione! \n\nOgni parola della frase di ricerca deve contenere almeno 4 caratteri.');

       ritorno=false;

       return ritorno;
      
      }

     }

}



 return ritorno;

}




function disableForm(theform) {

for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}

}




function Form_Validator(theForm)
{


 CanSubmit=true;

     CanSubmit=ForceEntry(theForm.p_frase,"il campo Frase di ricerca.");		 

  
var str= theForm.p_frase.value;
 
 
 if (str.indexOf('"')==-1) {	
	if (CanSubmit == true)  CanSubmit=verifica_tokens(theForm);	
 }

	if (CanSubmit == true)
		 {
              if ( theForm.p_frase.value.length < 3) 
                   {
                   alert("Immettere nel campo Frase di ricerca una stringa di almeno 3 caratteri.")		 
            		   CanSubmit=false                   
                    };

                 };



		if (CanSubmit == true)
		 {
			CanSubmit=ForceLength(theForm.p_frase,50,"Il campo Frase di ricerca non puņ superare i 50 caratteri.");		 
                 };


		if (CanSubmit == true) 
     {

      urlString="http://www.webdiocesi.chiesacattolica.it/pls/cci_dioc_new/gp_cerca_cci.risultati_dioc?"; 
      urlString=urlString + "id_sessione="; 
      urlString=urlString + "&pwd_sessione="; 
      urlString=urlString + "&pagina=0"; 
      urlString=urlString + "&lingua=ita"; 
      urlString=urlString + "&tipo_ricerca=diocesi"; 
      urlString=urlString + "&p_frase=" + theForm.p_frase.value; 
     
     

      disableForm(theForm);


//      document.location.href=urlString;
return true;


      return false;
     }
    else
    return false;


}
