function login(act) {
 if (act=="Login") {
  cookieSet("usr", document.forms[0].elements.User.value, [null, "/"]);
  cookieSet("pwd", document.forms[0].elements.Pass.value, [null, "/"]);
 }
 location.href = "/names.nsf?"+act+"&RedirectTo=" + location.href + "&auto=1";
}

function searchSite(go) {
    var strQuery;

    with (document.forms[0]) {
        var q = elements.Query;
        var qArea = elements.QueryArea;
        var qFrom = elements.QueryFromDate;
        var qTo = elements.QueryToDate;
    }

    if (go) {
        strQuery = "([Language]=" + p.language + ") AND ";

        if (qArea.value != "") {
         switch (qArea.value) {
 case "Rivista":
  strQuery += "([Form]=Document AND [CategoryTitle]=La rivista) AND ";
 break;
 case "Interventi":
  strQuery += "([Form]=Document AND [CategoryTitle]=Interventi) AND ";
 break;
 case "Rassegna":
  strQuery += "([Form]=Document AND [CategoryTitle]=Rassegna stampa) AND ";
 break; 
 case "Blogs":
  strQuery += "([Form]=Blog) AND ";
 break;
 }
        }

        if (qFrom.value != "") {
                strQuery += "([PublishDate]>=" + qFrom.value + ") AND ";
        }

        if (qTo.value != "") {
                strQuery += "([PublishDate]<=" + qTo.value + ") AND ";
        }

        strQuery = p.site + "search?SearchView&SearchOrder=4&SearchMax=0&Query=" + strQuery + q.value;

        location.href = strQuery.replace(/ /gi, "+");
    } else if (q.className == "released") {
        q.className = "selected";
        q.value = "";
    } 
}

function blogopen(url) {
 toLink(url, [0,0,1,1,0,600,500,((p.bw.screen("y")/2)-250),((p.bw.screen("x")/2)-300)]);
}
function blogwrite(docid) {
 toLink(p.site+"Blog_comment?OpenForm&DOCID="+docid, [0,0,0,0,0,450,400,((p.bw.screen("y")/2)-200),((p.bw.screen("x")/2)-225)]);
}

function register(workPath) {
 var tmp;

 switch (typeof(workPath)) {
 case "string":
  tmp = "E?Open&EventDOCID=" + workPath;
 break;
 case "boolean":
  tmp = "R?Open&ProfileDOCID=0D9910FC5A08A8CFC1257185004727FD&Account=" +
  (workPath ? "1" : "2");
 break;
 default:
  tmp = "R?Open&ProfileDOCID=0D9910FC5A08A8CFC1257185004727FD";
 }

 if (tmp) toLink("/ktn/nee/register.nsf/" + tmp, [0,0,0,1,0,500,500,((p.bw.screen("y")/2)-250),((p.bw.screen("x")/2)-250)]);
}

function resizeTitleHolder() {
 var holder = p.bw.getById("titleHolderPrincipal");
 var obj = p.bw.getById("titleContrastPrincipal");

 try {
  if (holder != null && obj != null) {
   holder.style.height = obj.offsetHeight;
  }
 } catch(e) {}
}

function advertisment() {
   try {
      with (document) {
         var box, container, anchor, img;

         box = body.appendChild(buildTag("DIV"));
         box.id = "advertisment";

         container = box.appendChild(buildTag("DIV"));

         anchor = container.appendChild(buildTag("A", null, p.site + "documents/libri?OpenDocument"));
         //anchor = container.appendChild(buildTag("A", null, p.conf + "stores/DocPerUtenti/$FILE/Collana VolumiOK.pdf"));
         //anchor.target = "_blank";

         img = anchor.appendChild(
            buildTag("IMG",
               //p.conf + "stores/DocPerUtenti/$FILE/advertisment" + dt + ".jpg",
               p.conf + "stores/DocPerUtenti/$FILE/advertisment112008.png"));
               //new Function("window.setTimeout('cachedAdvertisment()', 100)")));

         container = box.appendChild(buildTag("DIV"));
         container.style.textAlign = "right";

         anchor = container.appendChild(buildTag("A", "CHIUDI [X]", p.conf + "#"));
         anchor.onclick = new Function("closeAdvertisment(); return false;");

         cachedAdvertisment();
      }
   } catch(e) {}
}

function cachedAdvertisment() {
 var obj = p.bw.getById("advertisment");

 if (obj != null) {
  obj.style.visibility = "visible";
 }
}

function closeAdvertisment() {
 var obj = p.bw.getById("advertisment");

 if (obj != null) {
  obj.style.display = "none";
 }
}

function buildTag(tagName) {
   if (tagName) {
      var tag = document.createElement(tagName);
     
      switch (tagName.toUpperCase()) {
      case "IMG":
         tag.src = arguments[1];

         if (typeof arguments[2] == "function") {
            tag.onload = arguments[2];
         }
      break;
      case "A":
         tag.href = arguments[2];
      case "B":
      case "SPAN":
         if (arguments[1] != null) {
            tag.appendChild(document.createTextNode(arguments[1]));
         }
      break;
      }
     
      return tag;
   } else {
      return document.createTextNode(" ");
   } 
}
