﻿
function ricercaTesi(iFraseEsatta) {
	// controllo anni
	var a1 = window.document.frmRicercaAvanzata.annoD[window.document.frmRicercaAvanzata.annoD.selectedIndex].value;
	var a2 = window.document.frmRicercaAvanzata.annoA[window.document.frmRicercaAvanzata.annoA.selectedIndex].value;
	a1 = a1.substring(0,4)
	a2 = a2.substring(0,4)
	
	var ok=true;
	
	if (a2 < a1 &&  (ok==true)) {
		ok=false;
		alert("Il periodo finale non può essere inferiore a quello iniziale");
	}
	
	var kVal = Trim(window.document.frmRicercaAvanzata.keyword.value);
	/*if (kVal != '') {
		if ((window.document.frmRicercaAvanzata.keyword.value).length < 3) {
			ok=false;
			alert("Il termine di ricerca deve essere formato da minimo 3 caratteri");
		}
	}*/
	
	if (ok==true) {
	  if (iFraseEsatta==1) {
	  	if (kVal != '') {
		    if (kVal.charAt(0)!='\"' && kVal.charAt(kVal.length)!='\"') {
		      window.document.frmRicercaAvanzata.keyword.value = '\"' + kVal + '\"'
		    }
		  }
	  }
		window.document.frmRicercaAvanzata.submit();
	}
}

function grabEnter() {
  if (navigator.userAgent.indexOf("MSIE") > 0) {
  	if (event.keyCode == 13) {
    		ricercaTesi(0);
    }
  }
}

function Trim(MyString) {
	var NoExit;
	var x;
	var NoExit;
	var MyChar;

	MyString = MyString + "";
	NoExit = true;
	x = MyString.length-1;

	do 
	{
		MyChar = MyString.charCodeAt(x);
		
		if (MyChar != 32)
			NoExit = false
		else
			x = x -1;
	}
	while (NoExit)

	MyString = MyString.substring(0,x+1);
	return (MyString);
}
