function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
	}
	function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
		}
	return null;
	}
	function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" +
		expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

	function salvacookieLibri()
	{
	    //alert ('libri!');
	    SetCookie("tipo","libri");
	    return true;
	}
	function salvacookieArticoli()
	{
	    //alert ('articoli!');
	    SetCookie("tipo","articoli");
	    return true;
	}
	function checkParam() {
	
	 
		var formName = document.formVincData;		
		var validDate = checkDate();
		if (!validDate) {
			return false;
		}
		if (!checkPrePostData()) {
			return false;
		}
	
		if (document.getElementById('text').value == "" && formName.data.value == "") {
			return false;
		}
		
		return true;		
	}
	
	function checkDate(){
		var formName = document.formVincData;		
		var dFrom = getFromDate(formName);
		
		if(dFrom!="" && dFrom != "//" && !isDate(dFrom)){
			alert("La data "+dFrom+" non e' corretta");			
			return false;
		}
		if (dFrom == "//") {
			dFrom = "";
		}
		
		var dTo = "";		
			
		dTo = getToDate(formName);
		if(dTo!="" && dTo != "//" && !isDate(dTo)){
			alert("La data "+dTo+" non e' corretta");			
			return false;
		}			
		if (dTo == "//") {
			dTo = "";
		}				
		var finalString = dFrom; // giorno singolo		
		if(dTo != ""){			
			finalString= dFrom + "-" + dTo; 
		}
	
		formName.data.value= finalString; 
		return true;
	}

	function checkPrePostData() {
		var formName = document.formVincData;		
		var fromDate;
		var selIndex;
		var fromDay, fromMonth, fromYear;
		var toDay, toMonth, toYear;
	
		//alert("@ formName: "+formName);
	
		selIndex = formName.fromDay.selectedIndex;
		fromDay = formName.fromDay.options[selIndex].value;
		selIndex = formName.fromMonth.selectedIndex;
		fromMonth = formName.fromMonth.options[selIndex].value;
		selIndex = formName.fromYear.selectedIndex;
		fromYear = formName.fromYear.options[selIndex].value;

		var iFromDate = parseFloat(fromYear + fromMonth + fromDay);
		if (isNaN(iFromDate)) {
			iFromDate = 0;
		}
		selIndex = formName.toDay.selectedIndex;
		toDay = formName.toDay.options[selIndex].value;
		selIndex = formName.toMonth.selectedIndex;
		toMonth = formName.toMonth.options[selIndex].value;
		selIndex = formName.toYear.selectedIndex;
		toYear = formName.toYear.options[selIndex].value;
		
		var iToDate = parseFloat(toYear +  toMonth + toDay);
		if (isNaN(iToDate)) {
			iToDate = 0;
		}
		
		if (iFromDate > 0 && iToDate > 0 &&  iFromDate > iToDate)  {
			alert("Data di fine ricerca antacedente a quella inizio");
			return false;
		}
		return true;
	}

// metodi getFromDate e getToDate servono sia al menu che alla pg vincoli --ls
	function getFromDate(formName){
		var fromDate;
		var selIndex;
		var fromDay, fromMonth, fromYear;
	
		//alert("@ formName: "+formName);
	
		selIndex = formName.fromDay.selectedIndex;
		fromDay = formName.fromDay.options[selIndex].value;
		selIndex = formName.fromMonth.selectedIndex;
		fromMonth = formName.fromMonth.options[selIndex].value;
		selIndex = formName.fromYear.selectedIndex;
		fromYear = formName.fromYear.options[selIndex].value;

		fromDate = fromDay + "/" + fromMonth + "/" + fromYear ; //+ " 00:00";
		
	
//		alert("@ returning from date: "+fromDate);
		return fromDate;
	}


	function getToDate(formName){
		var toDate;
		var selIndex;
		var toDay, toMonth, toYear;
	
		selIndex = formName.toDay.selectedIndex;
		toDay = formName.toDay.options[selIndex].value;
		selIndex = formName.toMonth.selectedIndex;
		toMonth = formName.toMonth.options[selIndex].value;
		selIndex = formName.toYear.selectedIndex;
		toYear = formName.toYear.options[selIndex].value;
	
		toDate = toDay + "/" + toMonth + "/" + toYear ; // + " 23:59";
	
		//alert("@ returning to date: "+toDate);
		return toDate;
	}


	/**********************************************************************/ 
	/*Function name :isDate(s) */ 
	/*Usage of this function :To check s is a valid format */ 
	/*Input parameter required:s=input string in dd/mm/yyyy format */ 
	/*Return value :if is a valid date return 1 */ 
	/* else return 0 */ 
	/**********************************************************************/ 

	function isDate(s) {

		var na=s.split("/"); 		
		var ret=true; 
	
		if ((na.length!=3)) { 
			ret=false; 
		} else {			
					
			var dayS  =na[0];
			var monthS=na[1]; 			
			var yearS =na[2];
			 
			if (((ret) && (yearS<1000)||yearS.length>4)) 
				ret=false; 

			if (ret) { 
				var v=new Date(monthS+"/"+dayS+"/"+yearS); 
				if (v.getMonth()!=monthS-1) 
					ret=false; 
			} 
		} 
		return ret; 
	} 
function printpage() 
{
  if (window.print) 
  {
    window.print();
  } 
  else 
  {
    alert('Funzione non supportata dal browser.');
  }
}

function pdfWindow()
{
    alert ('pdf window');
    return true;
}

