   // -------------------------------------------------------
   // Function to verify a date input field
   // Arguments:
   //    1. reference to the date-entry field
   //    2. error message (if passed empty, uses default)
   //    3. date display format (defaults to 'dd MMM yyyy')
   // Called as onChange="return validDate(this,'Duh!','0')"
   // Function converts date to a standard database format
   //    or selects invalid entry and prompts the user.
   // If year does not include century, and year < 10 (n),
   //    converts the century to 2K+
   // -------------------------------------------------------
   function validDate(dateField, errMsg, fmt) {
      var ds = dateField.value;
      // bail if the date parameter is empty
      if (ds == "")
         return true;

      // declare local variables
      var n = 10;   // the Y2K offset in years
      var today = new Date();
      var err = 0;  // error flag
      var month = "";
      var d;
      var m;
      var y;
      var p1 = 0;
      var p2 = 0;
      var dd = 0;
      var mm = 0;
      var yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();

      var e = errMsg;
      if (errMsg == "") {
         // default error message if second parameter is empty
         e = "Invalid date! Please re-enter using a standard format...";
      }

      // strip leading and trailing spaces
      while (ds.charAt(0) == " ") {
            ds = ds.substring(1,ds.length);
            dateField.value = ds;
      }
      while (ds.charAt(ds.length-1) == " ") {
            ds = ds.substring(0,ds.length-1);
            dateField.value = ds;
      }

      // handle common data-entry shortcuts
      if (ds == "t" || ds == "today" || ds == "0") {
            dd = today.getDate();
            mm = today.getMonth() + 1;
            ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length < 3 && isNum(ds)) {
         // try as a date in the current month and year
         if (parseInt(ds) < 32) {
            dd = ds;
            mm = today.getMonth() + 1;
            ds = mm + "/" + dd + "/" + yy;
         }
      }
      else if (ds.length == 3 && monthToNum(ds) > 0) {
         // assume it's a month string, set date as 1st
         dd = 1;
         mm = monthToNum(ds);
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length == 4 && isNum(ds)) {
         if (parseInt(ds) > 1231) {
            // assume it's a year [yyyy], set date to 1st January
            dd = 1;
            mm = 1;
            yy = ds;
            ds = mm + "/" + dd + "/" + yy;
         } else {
            // assume it's a month and day [mmdd], set year as current
            dd = ds.substring(2);
            mm = ds.substring(0,2);
            ds = mm + "/" + dd + "/" + yy;
         }
      }
      else if (ds.length>4 && ds.length<7 && monthToNum(ds.substring(0,3))>0 && ds.indexOf(" ",0)>0) {
         // assume it's a month and day (mmm d[d]), set year as current
         p1 = ds.indexOf(" ");   // position of space
         dd = ds.substring(p1+1,ds.length);
         mm = monthToNum(ds.substring(0,3));
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf("/",0)>0 && ds.indexOf("/",0)==ds.lastIndexOf("/")) {
         // assume it's a month and day (mm/dd), set year as current
         p1 = ds.indexOf("/");   // position of slash
         mm = ds.substring(0,p1);
         dd = ds.substring(p1+1,p1+3);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf(" ",0)>0 && ds.indexOf(" ",0)==ds.lastIndexOf(" ")) {
         // assume it's a month and day (mm dd), set year as current
         p1 = ds.indexOf(" ");   // position of space
         mm = ds.substring(0,p1);
         dd = ds.substring(p1+1,p1+3);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }
      else if (ds.length>2 && ds.length<6 && ds.indexOf("-",0)>0 && ds.indexOf("-",0)==ds.lastIndexOf("-")) {
         // assume it's a day and month (dd-mm), set year as current
         p1 = ds.indexOf("-");   // position of dash
         dd = ds.substring(0,p1);
         mm = ds.substring(p1+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }

      if (ds.indexOf("-",0)>0 && ds.indexOf("-",0)<3) {
         // test for DD-MMM-YYYY standard format
         if (ds.length == 11 && ds.indexOf("-",0) == 2 && ds.lastIndexOf("-") == 6) {
            dd = ds.substring(0,2);
            mm = monthToNum(ds.substring(3,6));
            yy = ds.substring(7,11);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (isNum(mm+dd+yy)) {
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         // test for DD-MMM-YY abbreviated format
         else if (ds.length == 9 && ds.indexOf("-",0) == 2 && ds.lastIndexOf("-") == 6) {
            dd = ds.substring(0,2);
            mm = monthToNum(ds.substring(3,6));
            yy = (parseInt(ds.substring(7,9))<n) ? ("20" + ds.substring(7,9)) : ("19" + ds.substring(7,9));
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (isNum(mm+dd+yy)) {
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
         // test for DD-MM-YY[YY] format
         else {
            p1 = ds.indexOf("-");   // position of first dash
            dd = ds.substring(0,p1);
            p2 = ds.lastIndexOf("-");   // position of last dash
            mm = ds.substring(p1+1,p2);
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (mm.charAt(0) == "0") mm = mm.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (dd==0 || mm==0) {
                  mm = 0;
                  dd = 0;
                  yy = 0;
            }
            else {
               if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
               while (yy.substring(0,1)=="0") {
                  yy = yy.substring(1,yy.length);  // remove leading zeroes
               }
               if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
               if (isNum(mm+dd+yy)) {
                  if (yy > 0 && yy < 100) {
                     yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
                  }
                  ds = mm + "/" + dd + "/" + yy;
               }
               else {
                     mm = 0;
                     dd = 0;
                     yy = 0;
               }
            }
         }
      }

      // test for MMDDYY patterned formats
      else if (ds.length == 6 && isNum(ds)) {
         dd = ds.substring(2,4);
         mm = ds.substring(0,2);
         yy = ds.substring(4,6);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.charAt(0) == "0") yy = yy.substring(1,2);
         if (yy == "0" || yy == "00") yy = "2000";
         if (yy > 0 && yy < 100) {
            yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
         }
         ds = mm + "/" + dd + "/" + yy;
      }

      // test for MMDDYYYY patterned formats
      else if (ds.length == 8  && isNum(ds)) {
         dd = ds.substring(2,4);
         mm = ds.substring(0,2);
         yy = ds.substring(4,8);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         ds = mm + "/" + dd + "/" + yy;
      }

      // convert year 2K+ for MM/DD/YY[YY] pattern formats
      else if (ds.indexOf("/",0) > 0 && (ds.length-ds.lastIndexOf("/")) < 6) {
         p1 = ds.indexOf("/");   // position of first slash
         mm = ds.substring(0,p1);
         p2 = ds.lastIndexOf("/");   // position of last slash
         dd = ds.substring(p1+1,p2);
         yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0") {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
         if (isNum(mm+dd+yy)) {
            if (yy > 0 && yy < 100) {
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
            ds = mm + "/" + dd + "/" + yy;
         }
         else {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }

      // convert year 2K+ for MM.DD.YY[YY] pattern formats
      else if (ds.indexOf(".",0) > 0 && (ds.length-ds.lastIndexOf(".")) < 6) {
         p1 = ds.indexOf(".");   // position of first dot
         mm = ds.substring(0,p1);
         p2 = ds.lastIndexOf(".");   // position of last dot
         dd = ds.substring(p1+1,p2);
         yy = ds.substring(p2+1,ds.length);
         if (dd.charAt(0) == "0") dd = dd.substring(1,2);
         if (mm.charAt(0) == "0") mm = mm.substring(1,2);
         if (yy.length > 4) yy = yy.substring(0,4);
         if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
         while (yy.substring(0,1)=="0") {
            yy = yy.substring(1,yy.length);  // remove leading zeroes
         }
         if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
         if (isNum(mm+dd+yy)) {
            if (yy > 0 && yy < 100) {
               yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
            }
            ds = mm + "/" + dd + "/" + yy;
         }
         else {
               mm = 0;
               dd = 0;
               yy = 0;
         }
      }

      // validate the standard space-delimited formats
      else if (ds.indexOf(" ",0)>0 && (ds.length-ds.lastIndexOf(" "))<6) {
         if (ds.indexOf(",",0) > 0) {
            // validate 'mmm[...] dd, yy[yy]' type formats
            p1 = ds.indexOf(" ");   // position of first space
            mm = monthToNum(ds.substring(0,3));
            dd = ds.substring(p1+1,ds.indexOf(",",0));
            p2 = ds.lastIndexOf(" ");   // position of last space
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1)=="0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }

         else if (monthToNum(ds.substring(ds.indexOf(" ")+1,ds.indexOf(" ")+4))>0) {
            // validate 'dd mmm[...] yy[yy]' type formats
            p1 = ds.indexOf(" ");   // position of first space
            dd = ds.substring(0,p1);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            p2 = ds.lastIndexOf(" ");   // position of last space
            mm = monthToNum(ds.substring(p1+1,p1+4));   // extract 3 bytes for month
            yy = ds.substring(p2+1,ds.length);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1) == "0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }

         // validate 'MM DD YY[YY]' formats
         else {
            p1 = ds.indexOf(" ");   // position of first space
            mm = ds.substring(0,p1);
            p2 = ds.lastIndexOf(" ");   // position of last space
            dd = ds.substring(p1+1,p2);
            yy = ds.substring(p2+1,ds.length);
            if (dd.charAt(0) == "0") dd = dd.substring(1,2);
            if (mm.charAt(0) == "0") mm = mm.substring(1,2);
            if (yy.length > 4) yy = yy.substring(0,4);
            if (yy == "0" || yy == "00" || yy == "000") yy = "2000";
            while (yy.substring(0,1)=="0") {
               yy = yy.substring(1,yy.length);  // remove leading zeroes
            }
            if (yy == "") yy = (today.getYear() < 1900) ? today.getYear() + 1900 : today.getYear();
            if (isNum(mm+dd+yy)) {
               if (yy > 0 && yy < 100) {
                  yy = (yy < n) ? (2000 + parseInt(yy)) : (1900 + parseInt(yy));
               }
               ds = mm + "/" + dd + "/" + yy;
            }
            else {
               mm = 0;
               dd = 0;
               yy = 0;
            }
         }
      }

      // attempt to parse any other dates with valid IETF formats
      if (dd==0 && mm==0 && yy==0) {
         d = new Date(Date.parse(ds));
         dd = d.getDate();
         mm = (d.getMonth() + 1);
         // Netscape returns last 2 digits of years 1900-1999,
         // and the full year (4 char) string for dates > 2000 or < 1900;
         // IE returns 1900 minus the current year in all cases,
         // <duh> except IE3, when the year is earlier than 1970 </duh>
         if (d.getYear() > 2000) {
            yy = d.getYear();  // Netscape
         }
         else if (d.getYear() < 1900 && d.getYear() > 200) {
            yy = d.getYear();  // Netscape, date prior to 1900
         }
         else {
            yy = d.getYear() + 1900;
         }
         if (dd == 31 && mm == 12 && yy == 1969) {
            // IE's start-epoch date
            mm = 0;
            dd = 0;
            yy = 0;
         }
         ds = mm + "/" + dd + "/" + yy;
      }

      // verify the date components
      if (parseInt(dd)>0 && parseInt(mm)>0 && parseInt(yy)+1>0) {
         if (mm < 1 || mm > 12) err = 1;
         if (dd < 1 || dd > 31) err = 1;
         if (yy < 1000 || yy > 9999) err = 1;

         // check the months with 30 days
         if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
            if (dd == 31) {
               dd = 1;  // flick it forward a day
               mm = mm + 1;
            }
         }
         // check February and leap years
         if (mm == 2) {
            if (dd > 29) err = 1;
            if (dd == 29 && ((yy/4) != parseInt(yy/4))) {
               dd = 1;  // flick it forward a day
               mm = 3;
            }
         }
      }

      // finally, test whether the input string can be Date.parsed
      d = new Date(Date.parse(ds));
      if (!d.getDate()) err = 1;

      if (err==1 || dd==0 || mm==0) {
         alert(e);
         dateField.select();
         dateField.focus();
         return false;
      }

      // we have a valid IETF date, so convert it to
      // the specified standard format for database entry
      if (parseInt(dd)<10 && (fmt < 4 || fmt > 6))
         dd = "0" + dd;   // add leading zero to days 1-9

      // convert month numeric to string
      if (mm == 1)
         month = "Jan";
      else if (mm == 2)
         month = "Feb";
      else if (mm == 3)
         month = "Mar";
      else if (mm == 4)
         month = "Apr";
      else if (mm == 5)
         month = "May";
      else if (mm == 6)
         month = "Jun";
      else if (mm == 7)
         month = "Jul";
      else if (mm == 8)
         month = "Aug";
      else if (mm == 9)
         month = "Sep";
      else if (mm == 10)
         month = "Oct";
      else if (mm == 11)
         month = "Nov";
      else if (mm == 12)
         month = "Dec";
      else month == "";
      // add leading zero to months 1-9 for mm formats
      if (fmt > 6 && mm < 10) mm = "0" + mm;

      // trim for yy formats
      if ((yy>99) && (fmt==0 || fmt==2 || fmt==5 || fmt==7 || fmt==9)) {
         yy = yy - (parseInt(yy/100)*100);
         if (yy < 10) yy = "0" + yy;
      }

      // re-test the date components
      if (dd==0 || dd=="" || month=="" || mm==0 || mm=="" || yy=="") {
         alert(e);
         dateField.select();
         dateField.focus();
         return false;
      }

      // redraw the date input field per format parameter:
      /*  0 = "dd mmm yy"     e.g. 27 Jan 99
          1 = "dd mmm yyyy"   e.g. 27 Jan 1999
          2 = "dd-mmm-yy"     e.g. 05-Aug-98
          3 = "dd-mmm-yyyy"   e.g. 05-Aug-1998
          4 = "mmm d, yyyy"   e.g. Aug 5, 1999
          5 = "m/d/yy"        e.g. 8/5/98
          6 = "m/d/yyyy"      e.g. 8/5/1998
          7 = "mm/dd/yy"      e.g. 09/21/56
          8 = "mm/dd/yyyy"    e.g. 08/05/1998
          9 = "mm dd yy"      e.g. 08 15 98
          10 = "mm dd yyyy"   e.g. 21 09 1956  */

      if (fmt == 1)
         dateField.value = dd + " " + month + " " + yy;
      else if (fmt == 2)
         dateField.value = dd + "-" + month + "-" + yy;
      else if (fmt == 3)
         dateField.value = dd + "-" + month + "-" + yy;
      else if (fmt == 4)
         dateField.value = month + " " + dd + ", " + yy;
      else if (fmt == 5)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 6)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 7)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 8)
         dateField.value = mm + "/" + dd + "/" + yy;
      else if (fmt == 9)
         dateField.value = mm + " " + dd + " " + yy;
      else if (fmt == 10)
         dateField.value = mm + " " + dd + " " + yy;
      else
         dateField.value = dd + " " + month + " " + yy;

      return true;
   }

   // Internal function to test whether argument is a number
   function isNum(arg) {
      if (arg == "")
         return false;
      for (i=0; i<arg.length; i++) {
         if (arg.charAt(i) < "0" || arg.charAt(i) > "9") {
            return false;
         }
      }
      return true;
   }

   // Internal function to convert a month string to numeric 1-12
   function monthToNum(monthStr) {
      if (monthStr=="")
         return false;
      var m = monthStr;
      if (monthStr.length>3)
         var m = monthStr.substring(0,2);
      if (m=="jan" || m=="Jan" || m=="JAN")
         return 1;
      else if (m=="feb" || m=="Feb" || m=="FEB")
         return 2;
      else if (m=="mar" || m=="Mar" || m=="MAR")
         return 3;
      else if (m=="apr" || m=="Apr" || m=="APR")
         return 4;
      else if (m=="may" || m=="May" || m=="MAY")
         return 5;
      else if (m=="jun" || m=="Jun" || m=="JUN")
         return 6;
      else if (m=="jul" || m=="Jul" || m=="JUL")
         return 7;
      else if (m=="aug" || m=="Aug" || m=="AUG")
         return 8;
      else if (m=="sep" || m=="Sep" || m=="SEP")
         return 9;
      else if (m=="oct" || m=="Oct" || m=="OCT")
         return 10;
      else if (m=="nov" || m=="Nov" || m=="NOV")
         return 11;
      else if (m=="dec" || m=="Dec" || m=="DEC")
         return 12;
      else
         return 0;
   }

function isValid (str,what)
{

if (str == "")
	{
	window.alert("Invalid "+what);
	return 2;
	}
test=str.toLowerCase();
for (i = 0; i < str.length;i++)
	{
	if ( (test.charCodeAt(i) < 97) || (test.charCodeAt(i) > 122))
		if (test.charCodeAt(i) != 32 & test.charCodeAt(i) !=44 & test.charCodeAt(i) !=46)
			{
			window.alert("Invalid "+what);
			return 2;
			}
	}
return 0;
}

function prepare (str)
{
nuova="'";
for (i = 0; i < str.length;i++)
	{
	nuova = nuova + str.charAt(i)
	if (str.charAt(i)=="'")
		nuova = nuova + "'";
	}
// nuova=str.replace("'","''"); FUNZIONA BENISSIMO.
nuova=nuova+"'";
return (nuova);
}

function helpw(page) {
if (page.substr(0,9) == "help_city")	{
	if (isValid(document.F1.state.value,"state")==0)
		page = page + "&stato='" + document.F1.state.value + "'";
	else 
		return;
	}
if (page.substr(0,10) == "help_place")	{
	if (isValid(document.F1.state.value,"state")==0)
		page = page + "&stato='" + document.F1.state.value + "'";
	else
		return;
	if (isValid(document.F1.city.value,"city")==0)
		page = page + "&citta='" + document.F1.city.value + "'";
	else
		return;
	}
msg = open (page,"nuova","toolbar=no,directories=no,menubar=no,scrollbars=yes,height=480,width=640");
msg.focus();
return false;
}

function makeQuery(dove)
{
tit=document.F1.id_tit.value;
t1=document.F1.id_tour.value;
t2=document.F1.id_tour2.value;
fstate=document.F1.state.value;
fcity=document.F1.city.value;
fplace=document.F1.place.value;
d1=document.F1.dateF.value;
d2=document.F1.dateT.value;
ex=document.F1.ET.checked;
sk=document.F1.NS.checked;
comm = 'select data,performance.show,citta,stato,posto from performance';
if ((tit != '') && (eval(tit)!=document.undefined))
	{
	comm = comm + ",canzoni where (canzoni.show=performance.show and id_titolo=" + tit + ") and posto<> 'nowhere'";
	if (sk == true)
		comm = comm + " and numero <> 0 "
	}
else
	comm = comm + " where posto<>'nowhere'";
if ((t1 != '') && (eval(t1)!=document.undefined))
	if (( t2!= '') && (eval(t2)!=document.undefined))
		comm = comm + " and (tour_id >=" + t1 + " and tour_id <=" + t2 +")";
	else
		comm = comm + " and tour_id =" + t1;
if (fstate != '')
		comm = comm + " and stato ="+prepare(fstate);
if (fcity != '')
		comm = comm + " and citta ="+prepare(fcity);
if (fplace != '')
		comm = comm + " and posto ="+prepare(fplace);
if ((d1 != '')  && (eval(document.F1.dateF)!=document.undefined))
	if (( d2!= '') && (eval(document.F1.dateT)!=document.undefined))
		comm = comm + " and (data >=#" + d1 + "# and data <=#" + d2 +"#)";
	else
		comm = comm + " and data =#" + d1 +"#";
if (ex == true)
	comm = comm + " and tour_id > 1 ";
dove.value=comm;
//page = "results.asp?sqlstr=" + comm;
//msg = open (page,"nuova","toolbar=no,directories=no,menubar=no,scrollbars=yes,height=480,width=640");
//msg.focus();
//parent.result.location.href=page;
}

function makeQuery_st(dove)
{

tit=document.F1.id_tit.value;
vr=document.F1.VER.value;
fstate=document.F1.state.value;
fcity=document.F1.city.value;
fplace=document.F1.place.value;
d1=document.F1.dateF.value;
d2=document.F1.dateT.value;

comm = 'select data,performance.show,citta,stato,posto,tour_name from performance, tour';
if ((tit != '') && (eval(tit)!=document.undefined)) {
	comm = comm + ",canzoni where (canzoni.show=performance.show and id_titolo=" + tit + ") and (tour.tour_id = performance.tour_id) and posto<> 'nowhore'";
	if ((vr != '') && (eval(vr)!=document.undefined)) 
			comm = comm + " and take ="+vr;
	}
else
	comm = comm + " where posto<>'nowhere' and (tour.tour_id = performance.tour_id)";
if (fstate != '')
		comm = comm + " and stato ="+prepare(fstate);
if (fcity != '')
		comm = comm + " and citta ="+prepare(fcity);
if (fplace != '')
		comm = comm + " and posto ="+prepare(fplace);
if ((d1 != '')  && (eval(document.F1.dateF)!=document.undefined))
	if (( d2!= '') && (eval(document.F1.dateT)!=document.undefined))
		comm = comm + " and (data >=#" + d1 + "# and data <=#" + d2 +"#)";
	else
		comm = comm + " and data =#" + d1 +"#";
dove.value=comm;
}

function makeQuery_bt(dove)
{
tit=document.F1.id_tit.value;
t1=document.F1.id_tour.value;
t2=document.F1.id_tour2.value;
fstate=document.F1.state.value;
fcity=document.F1.city.value;
fplace=document.F1.place.value;
d1=document.F1.dateF.value;
d2=document.F1.dateT.value;
ex=document.F1.ET.checked;
sk=document.F1.NS.checked;
vr=document.F1.VER.value;
pr=document.F1.id_prod.value;
td=document.F1.title.value;
sup=document.F1.supp.options[document.F1.supp.options.selectedIndex].value

zeppas = ""
zeppap = ""
listatabs = ""
slist = "select codice, titolo, n_dischi, supp_ext, matrice, cmp_produttore.casa from "
flist = "dischi,cmp_supporto,cmp_produttore"
comm =  " where dischi.casa = cmp_produttore.id_casa and formato = supp_id "
if (sk == true)
	comm = comm + " and dischi.legale=true";
else
	comm = comm + " and dischi.legale=false";

if ((tit != '') && (eval(tit)!=document.undefined))
	{
	listatabs = listatabs + "dischi,canz_dischi"
	linktab = "(canz_dischi.compare_su=dischi.codice or canz_dischi.compare_su=dischi.copy_of)"
	zeppas = zeppas + " and canz_dischi.id_song=" + tit;
	//comm = comm + " or (canz_dischi.id_song = 9999 and canz_dischi.id_perf in (select x.show from canzoni x where x.id_titolo= " + tit + " and x.numero<>0)))";


	if ((vr != '') && (eval(vr)!=document.undefined))
		zeppas = zeppas + " and take ="+vr;
	}
if ((t1 != '') && (eval(t1)!=document.undefined))
	if (( t2!= '') && (eval(t2)!=document.undefined))
		zeppap= zeppap + " and (tour_id >=" + t1 + " and tour_id <=" + t2 +")";
	else
		zeppap = zeppap + " and tour_id =" + t1;
if (fstate != '')
		zeppap = zeppap + " and stato ="+prepare(fstate);
if (fcity != '')
		zeppap = zeppap + " and citta ="+prepare(fcity);
if (fplace != '')
		zeppap = zeppap + " and posto ="+prepare(fplace);
if ((d1 != '')  && (eval(document.F1.dateF)!=document.undefined))
	if (( d2!= '') && (eval(document.F1.dateT)!=document.undefined))
		zeppap = zeppap + " and (data >=#" + d1 + "# and data <=#" + d2 +"#)";
	else
		zeppap = zeppap + " and data =#" + d1 +"#";
if (ex == true)
	zeppap = zeppap + " and tour_id > 1 ";
if (pr != '')
		comm = comm + " and dischi.casa ="+pr;
if (td != '')
		comm = comm + " and titolo like '%"+td+"%'";
if ((sup != '') && (sup != '0'))
		comm = comm + " and formato ="+sup;
if (zeppap != "") 
	{
	listatabs = "dischi,canz_dischi,performance"
	linktab = "(canz_dischi.compare_su=dischi.codice or canz_dischi.compare_su=dischi.copy_of) and canz_dischi.id_perf=performance.show "
	zeppas = zeppas + zeppap
	}
if (zeppas != "") 
	{
	comm = comm + " and codice in (select codice from " + listatabs + " where " + linktab + zeppas + ")"
	}
if (pr != '')
	comm = comm + " order by matrice "
else
	comm = comm + " order by titolo "
dove.value=slist + flist + comm;
//window.alert(comm);
}

