var dbName = new String("Agriturismo/AB.nsf");



function getQueryVar(varName)
{
   var querystring = new String(window.location.href);
   varName = new String(varName);
   var Vend;
   var Vbegin = querystring.indexOf(varName + "=");
   if (Vbegin == -1)
	  return -1;
   else
   {
	  querystring = querystring.substr(Vbegin);
	  Vend = querystring.indexOf("&");
	  if (Vend != -1)
		 querystring = querystring.substr(0, Vend);
	  begin = querystring.indexOf("=");
	  querystring = querystring.substr(begin+1);
	  return querystring;
   }
}
 var vRegione = new Array();

var vProvincia = new Array();
i=0;
vRegione[i]="Abruzzo"; vProvincia[i]="Aquila"; i++;



function Session() {this.Set = Set;this.Get = Get;}function Get(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){var endstr = document.cookie.indexOf (";", j);
if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(j, endstr));}  i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; }return null;}function Set(Name, Value){document.cookie = Name + "=" + escape (Value);}



var m_winInsert=null;
var r_winInsert=null;



function winOpen(thePage)
{
	if ( (m_winInsert==null) || (m_winInsert.closed==true) )
		m_winInsert = window.open(thePage,"map","width=500,height=400,top=100,left=150,resizable=no,scrollbars=no,status=0");
	else
	{ 
		m_winInsert.location.href = thePage;
		m_winInsert.focus();
	}
}



function winOpenReview(thePage)
{
	if ( (r_winInsert==null) || (r_winInsert.closed==true) )
		 r_winInsert = window.open(thePage,"review","width=550,height=520,top=20,left=125,resizable=no,scrollbars=no,status=0");
	else
	{ 
		r_winInsert.location.href = thePage;
		r_winInsert.focus();
	}
}



document._domino_target = "_self";
function _doClick(v, o, t, h) {
  var form = document._DominoForm;
  if (form.onsubmit) {
	 var retVal = form.onsubmit();
	 if (typeof retVal == "boolean" && retVal == false)
	   return false;
  }
  var target = document._domino_target;
  if (o.href != null) {
	if (o.target != null)
	   target = o.target;
  } else {
	if (t != null)
	  target = t;
  }
  form.target = target;
  form.__Click.value = v;
  if (h != null)
	form.action += h;
  form.submit();
  return false;
}



function EnterPressed(parentForm){
parentForm=new String(parentForm);key = window.event.keyCode;
if (key==13)
{var src = new String(window.event.srcElement.parentForm);
eval('document.all.'+src+'.click();');}}



function Extract(str){
var N=new String(str);
var W=new Array();
var nd=true;
while (nd){if (N.search("  ")==-1)
nd=false; else N=new String(N.replace("  ", " "));}
W=N.split(" ");return W;}



function foc() 
{document.getElementById("txtCity").focus()}



function AdjustFieldQuery(Field, FV){
var uS="";var tN=new String(FV);var lQ=new String(tN.toLowerCase());
var AQ=(lQ.search(" and ")!=-1 || lQ.search(" or ")!=-1 || lQ.search(" not ")!=-1  ) ? "A" : "N"; 
var tW=Extract(tN);
if (FV!=""){if (AQ=="N"){tN=''+tW[0]+"*";for (i=1; i<tW.length;i++){tN+= (' or Field '+Field+'='+tW[i]+"*");}
}else{tN=""+tW[0];for (i=1; i<tW.length;i++){if (tW[i]=="and" || tW[i]=="or" || tW[i]=="not" )
{tN+= " "+tW[i];}else tN+= (""+tW[i]+"*");}
} uS+=tN;}return uS;}
function AdjustTotalFieldQuery(Field, FV){
var uS="";var tN=new String(FV);var lQ=new String(tN.toLowerCase());var tW=Extract(tN);
if (FV!=""){tN='"'+tW[0] +"*";for (i=1; i<tW.length;i++){tN+= (' '+tW[i]+ "*" );}tN+='"';uS+=tN;}
return uS;}
function AdjustMultiFieldQuery(Field, FV){
var uS="";var tN=new String(FV);var lQ=new String(tN.toLowerCase());
var AQ=(lQ.search(" and ")!=-1 || lQ.search(" or ")!=-1 || lQ.search(" not ")!=-1  ) ? "A" : "N"; 
var tW=Extract(tN);
if (FV!=""){if (AQ=="N"){tN="";for (j=0; j<Field.length; j++){tN+= ' or Field '+Field[j]+'='+tW[0];
if (j==0)  tN+= "*";for (i=1; i<tW.length;i++){tN+= (' or Field '+Field[j]+'='+tW[i]);if (j==0)  tN+= "*";}}tN=tN.substr(3);}
else{tN="";for (j=0; j<Field.length; j++){oper=new String("");mN=new String("");for (i=0; i<tW.length;i++){ 
if (tW[i]=="and" || tW[i]=="or" || tW[i]=="not" ){oper += tW[i]+" ";}else mN+= (" or Field "+Field[j]+"="+tW[i]+"*");}
mN=mN.substr(3);
if (oper=="and not ") {mN=mN.replace("or","and not");}tN+=mN+" or ";}tN=tN.substr(0, tN.length-3);
}uS+=tN;} return uS;}



function AdvancedSearchHotel(db){
	var R=new String(document.all.Regione.value);
	
	if (R=="" ){
		alert("Impossibile procedere con la ricerca!\nNessun paramentro di ricerca specificato");
		document.all.Regione.focus();
	}
		else{
	
		var Ses=new Session();
		Ses.Set("Sreload", "SI");
		var uS="/"+db+"/Struttura!SearchView&SearchMax=2000&query=";
		var E=false;
	
		/*if (R!=""){ 
			if (E){
				uS+=AdjustTotalFieldQuery("regione", R);
			}
			else{
				E=true;
				uS+=AdjustTotalFieldQuery("regione", R);
			}
		}*/
		uS+=R;
	
		Ses.Set("HITS","");
		uS+="&SearchOrder=1";
		window.location.href=uS+"&Folder=ricerca";
	}
}



var dbName = new String("Agriturismo/AB.nsf");

function AdjustFreeQuery(query)
{
   var urlSearch="";
   var theQuery = new String(query);
   var theWords = new Array();
   var nodouble = true;
   while (nodouble)
   {
	   if (theQuery.search("  ")==-1)
	  {
		   nodouble = false;  
	  }
	   else
	  {
		   theQuery = new String(theQuery.replace("  ", " "));
	  }
   }
   theWords = theQuery.split(" ");
   theQuery = theWords[0];
   for (i=1; i<theWords.length;i++)
		theQuery+= (" and " + theWords[i]);
   urlSearch+=theQuery;
   return urlSearch;
}



function Enterqressed(parentForm){
parentForm=new String(parentForm);key = window.event.keyCode;
if (key==13)
{var src = new String(window.event.srcElement.parentForm);
eval('document.all.'+src+'.click();');}}



function Extract(str){
var N=new String(str);var W=new Array();var nd=true;
while (nd){if (N.search("  ")==-1)
nd=false; else N=new String(N.replace("  ", " "));}
W=N.split(" ");return W;}



function AdjustTotalFieldQueryusc(Field, FV){
var uSC="";var tN=new String(FV);var lQ=new String(tN.toLowerCase());var tW=Extract(tN);
if (FV!=""){tN='Field '+Field+'="'+tW[0] +"*";for (i=1; i<tW.length;i++){tN+= (' '+tW[i]+ "*" );}tN+='"';uSC+=tN;}
return uSC;}



function AdvancedSearchArticolo(db)
{
   var FreeText = new String(document.all.FreeText.value);
   if (FreeText=="")
   {
	  alert("Impossibile procedere con la ricerca! Nessuna parola da ricercare specificata");
	  return 0;
   }
   var Ses = new Session();
   Ses.Set("Sreload", "SI");
   var urlSearch="/"+db+"/Articolo?SearchView&SearchMax=1500&query=";
   var addE = false;
   if (FreeText !="")
   {
	  urlSearch+=AdjustFreeQuery(FreeText);
	  addE = true;
   }

   Ses.Set("HITS","");
   urlSearch+="&SearchOrder=1";

   window.location.href=urlSearch + "&SearchFuzzy=TRUE";
}



function RicercaArticoloKeyPress() 
{
  key = window.event.keyCode;
  if (key==13)
  {
	var src = new String(window.event.srcElement.parentForm);
	if (src == "RicercaArticolo")
	{
		document.all.RicercaArticolo.click();
	}
  }
}

function addPage() {
if ((navigator.appName=="Microsoft Internet Explorer")&&
(parseInt(navigator.appVersion)>=4)) {
window.external.addFavorite
(document.location.href, document.title);
} else {
var msg = "AZ Info: Il tuo browser non supporta lo script '" +
document.location.href + "' ai preferiti!";
if (navigator.appName=="Netscape") msg += " (CTRL-D)";
alert(msg);
}
}