function goSearch() {
  //search=document.forms[0].search.value;
  //aa=aa.toUpperCase();
  document.mainForm.offset.value=0;
  aa=document.getElementById("search").value;
  if (aa.length>0) {
     if(document.mainForm.searchBy.value=="C"){
        // 2010 - document.mainForm.action="wap12nc.php?kp="+aa;
		document.mainForm.action="wap12nc.php?code="+aa;
     } else {
        /* ha scelto by model... */
        document.mainForm.action="search.php";
     }
     document.mainForm.rc_12nc.value=aa;
     document.mainForm.submit();
  }
}

function fLogin(url) {
     document.mainForm.action="login.php";
     document.mainForm.submit();
}

function fExport(url) {
     document.mainForm.action=url;
     document.mainForm.submit();
}

function fAdmin(id) {
	 document.mainForm.user_id.value=id;
     document.mainForm.action="adm-user.php";
     document.mainForm.submit();
}

function fUser() {
     document.mainForm.action="adm-user.php";
     document.mainForm.submit();
}

function fNewsTicker() {
     document.mainForm.action="news_ticker_f.php";
     document.mainForm.submit();
}

function fNewsTickerE(id) {
	 document.mainForm.news_id.value=id;
     document.mainForm.action="news_ticker_f.php";
     document.mainForm.submit();
}

function fTicker(n) {
	// serve per visualizzare o no la barra dei ticker...
	 if (n==0) document.mainForm.TickerText.value='';
     document.mainForm.action="news_ticker_onoff.php";
     document.mainForm.submit();
}

function fContactUs() {
	 document.mainForm.action="adm-contactform.php";
	 lValid = true;
	 if (document.forms[0].company.value.length == 0) {
		 alert("Missing information: Company");
		 document.forms[0].company.focus();
		 lValid = false;
		 return false;
	 }
	 if (document.forms[0].first.value.length == 0) {
		 alert("Missing information: First Name");
		 document.forms[0].first.focus();
		 lValid = false;
		 return false;
	 }
	 if (document.forms[0].last.value.length == 0) {
		 alert("Missing information: Last Name");
		 document.forms[0].last.focus();
		 lValid = false;
		 return false;
	 }
	 if (document.forms[0].email.value.length == 0 ||
		 document.forms[0].email.value.indexOf("@") < 0 ||
		 document.forms[0].email.value.indexOf(".") < 0 ) {
		 alert("Missing/Wrong information: Email");
		 document.forms[0].email.focus();
		 lValid = false;
		 return false;
	 }
	 //
 	 if (document.forms[0].email.value.length > 0) {
		 str = document.forms[0].email.value;
		 message = "Invalid character...";
		 if (!checkInvalidChar(str, message)) {
		    document.forms[0].email.focus();
            lValid = false;
            return false;
		 }
	 }
	 //
 	 if (document.forms[0].country.value == "--") {
		 alert("Missing information: Country");
		 document.forms[0].country.focus();
		 lValid = false;
		 return false;
	 }
	 //
     if (lValid) document.mainForm.submit();
}

function fDelContactUs(n) {
  if (confirm("Are you sure ?")) {
     if (confirm("REALLY ?")) {
		 location.href="adm-contactform.php?act=D&id=" + n;
     }
  }
  return;
}


function fDelNews(n) {
  if (confirm("Are you sure ?")) {
     if (confirm("REALLY ?")) {
		 location.href="news_ticker_f.php?act=D&news_id=" + n;
     }
  }
  return;
}




function checkInvalidChar(str, message)	{
// check email in ContactUs Form!
 var word=/^\?;#<>"!\[\]\{\}/;  // vuol dire che non voglio: ^?;#<>  (!!! ? = \? perchè è riservato!)
 var invalidchar=new RegExp(word);
 var flag2= str.match("[" + invalidchar + "]");
 if(flag2!=null) {
   alert(message + "(" + flag2 + ")");
   return false;
 } else {
   return true;
 }
}




/*
function goSales(mm, sm, action, pm) {
//alert("Self= " +"sales_nav.htm?Open&" + mm + "|" + sm);
  self.location.href="sales_nav.htm?Open&" + mm + "|" + sm;
  if (action.length>0) {
     cat=mm;
     prod=sm;
//     document.forms[0].rc_cat.value=cat;
//     document.forms[0].rc_prod.value=prod;
//     document.forms[0].action=action;
//     document.forms[0].submit();
     link=action+"?Open&"+cat+"|"+prod+"||";
//alert("main: "+link);
     parent("main").location.href=link;
  }
}
*/
function fsubmit(thisLink, a_key) {
  document.mainForm.thisLink.value=thisLink;
  document.mainForm.action="wap.php?kp="+a_key;
  if (thisLink=="fam") {
     document.mainForm.offset.value=0;
     document.mainForm.rc_fam.value=a_key;
     document.mainForm.rc_subfam.value="";
     document.mainForm.rc_famclass.value="";
     document.mainForm.rc_12nc.value="";
  } else {
    if (thisLink=="subfam") {document.mainForm.rc_subfam.value=a_key;/*document.mainForm.subfamDesc.value=a_value;*/}
    if (thisLink=="famclass") {document.mainForm.rc_famclass.value=a_key;/*document.mainForm.famclassDesc.value=a_value;*/}
    if (thisLink=="12nc") {
       document.mainForm.rc_12nc.value=a_key;
       document.mainForm.action="wap12nc.php?kp="+a_key;
    }
  }
  document.mainForm.submit();
}
function fsubmit_OLD(thisLink, a_key, a_value) {
  document.mainForm.thisLink.value=thisLink;
  document.mainForm.action="wap.php?kp="+a_key;
  if (thisLink=="fam") {
     document.mainForm.offset.value=0;
     document.mainForm.rc_fam.value=a_key;
     document.mainForm.rc_subfam.value="";
     document.mainForm.rc_famclass.value="";
     document.mainForm.rc_12nc.value="";
  } else {
    if (thisLink=="subfam") {document.mainForm.rc_subfam.value=a_key;/*document.mainForm.subfamDesc.value=a_value;*/}
    if (thisLink=="famclass") {document.mainForm.rc_famclass.value=a_key;/*document.mainForm.famclassDesc.value=a_value;*/}
    if (thisLink=="12nc") {
       document.mainForm.rc_12nc.value=a_key;
       document.mainForm.action="wap12nc.php?kp="+a_key;
    }
  }
  document.mainForm.submit();
}

function delFile(t,f,fn) {
  document.getElementById(f).value=fn;
  t.src=((t.src.indexOf('trash1')>0) ? 'images/trash.gif' : 'images/trash1.gif');
}
function wap12ncEdit(nc12) {
  document.mainForm.action="wap12nc.php?e=1";
  document.mainForm.submit();
}

function wap12ncSave(nc12) {
  document.mainForm.action="wap12nc.php?s=1";
  document.mainForm.submit();
}


function fsubmitSearch(linkKey, rc_mag, rc_fam, prodTitle, rc_subfam, rc_famclass, rc_12nc) {
  document.mainForm.rc_fam.value=rc_fam;
  document.mainForm.rc_subfam.value=rc_subfam;
  document.mainForm.rc_famclass.value=rc_famclass;
  document.mainForm.rc_12nc.value=rc_12nc;
  document.mainForm.action="wap12nc.php";
  document.mainForm.submit();
}



function go(p, stepOffset) {
  // +/- step!
  document.forms[0].offset.value=(p-1)*stepOffset;
  //reloadPage(p);
  reloadPage((p-1)*stepOffset, stepOffset);
}

function fOffset(n) {
  // n = stepOffset ! +/- 20! usata per Prev / Next
  n=parseInt(n,10);
  nrec=document.forms[0].nrec.value;
  offset=document.forms[0].offset.value;  if (offset=='') offset=0;
  offset=parseInt(offset, 10) + n;
  if (offset<0 || offset>nrec) {
     return false;
  } else {
     document.forms[0].offset.value=offset;
     reloadPage(offset, n);
  }
}

function reloadPage(p, stepOffset) {
  if (p==0) document.forms[0].offset.value=0;
  nrec=document.forms[0].nrec.value;
  offset=document.forms[0].offset.value;
  //if (location.pathname=="/search.php") {
  if (location.pathname.lastIndexOf("search.php")>0) {
     document.forms[0].action="search.php";
     document.forms[0].submit();
  } else {
	  // !!!???!!!!!!
     //alert("pagina: "+p);
     //document.forms[0].action="wap.php";
    //  document.forms[0].action=location.pathname;  /* come $_SERVER['PHP_SELF'] */
	i=0;
	while (document.getElementById("page"+i)) {
          oPage=document.getElementById("page"+i);oPage.style.display = "none";
		  i++;
	}
	oPage=document.getElementById("page"+(p/30));oPage.style.display = "inline";
	showPages(nrec, offset, stepOffset, p);
  }
}


function showPages(nrec, offset, stepOffset, p)
{
	// può essere standard e riutilizzarlo così com'è !!?!?
	 offset=parseInt(offset,10);
	 stepOffset=parseInt(stepOffset,10);  if(stepOffset<0) stepOffset=stepOffset*-1;
	 p=parseInt(p,10);
	 navRow="";
     if(nrec>stepOffset)
     {
     //navRow+="<hr noshade size=\"1\">\n";
	 navRow+="<hr style='height:1px; color:#f2f2f2;'>\n";
     navRow+="<input type=\"hidden\" name=\"nrec\" value=\"" + nrec + "\">\n";
     navRow+="<span class=\"track\">";
     navRow+= nrec + "&nbsp;Item(s)";
        navRow+="&nbsp;&nbsp;&nbsp;&nbsp;" + (Math.abs(offset/stepOffset)*stepOffset+1) + "-" + ((Math.abs(offset/stepOffset)+1)*stepOffset) + "&nbsp;&nbsp;\n";
        pages="";
        prevpages="";
        nextpages="";
        if(offset>0) prevpages="<a href=\"#\" onClick=\"fOffset(-" + stepOffset + ");\">&laquo; Prev </a>";
        if((parseInt(offset,10)+parseInt(stepOffset,10))<nrec) nextpages=" <a href=\"#\" onClick=\"fOffset(" + stepOffset + ");\">Next &raquo;</a>";
        for( ij=1; ij<Math.abs((nrec-1)/stepOffset)+1; ij++){
           pages=pages + "&nbsp;|&nbsp;<a href=\"#\" onClick=\"go(" + ij + ", " + stepOffset + ");\">";
           if( (Math.abs(offset/stepOffset))+1==ij) {
             pages=pages + "<font color=\"#FF9900\"><b>" + ij + "</b></font>";
			 // (si può fare... )pages=pages + "<font style='#ffffff; background-color:#FF9900;'><b>" + ij + "</b></font>";
           } else {
             pages=pages+ij;
           }
           pages=pages + "</a>";
        }
        navRow=navRow + prevpages + pages + nextpages;
        navRow+="</span><br>\n\n\n";
     }
	 if(document.getElementById("pagination")) document.getElementById("pagination").innerHTML = navRow;
}






function fsch(sch) {
// NOT IN USE !
/*
  document.forms[0].rc_sch.value=sch;
  document.forms[0].submit();

//self.location.href="aSalesWAP2?Open&F20|8019|AGB 595/WP    gas deep fat fryer|W60|W03|851259501000|" + sch;
*/
}
function fback() {
//  document.forms[0].rc_prod.value=prod;
//  document.forms[0].rc_range.value=range;
//  document.forms[0].action="aSalesNRS1";
//  document.forms[0].submit();
//parent.frames['main'].location.href="aSalesWAP1?Open&F20|8019|AGB 595/WP    gas deep fat fryer|W60||W03|";
parent.frames['main'].location.href="aSalesWAP0?Open&F20|8019|AGB 595/WP    gas deep fat fryer|W60|W03|";
}


function print12nc() {
  document.getElementById("hlink").style.display="none";
  document.getElementById("phPage1").style.display="inline";
  document.getElementById("phPage2").style.display="inline";
  document.getElementById("phPage3").style.display="inline";
  document.getElementById("page1").style.display="inline";
  document.getElementById("page2").style.display="inline";
  document.getElementById("page3").style.display="inline";
  window.print();
}

function showDiv(n)
{
// visualizza le cartelline ! che bello!
  objh1=document.getElementById("hpage1");
  objh2=document.getElementById("hpage2");
  objh3=document.getElementById("hpage3");
  obj1=document.getElementById("page1");
  obj2=document.getElementById("page2");
  obj3=document.getElementById("page3");
  if (n==1) {
    objh1.style.display = "inline";
    objh2.style.display = "none";
    objh3.style.display = "none";
    obj1.style.display = "inline";
    obj2.style.display = "none";
    obj3.style.display = "none";
  }
  if (n==2) {
    objh1.style.display = "none";
    objh2.style.display = "inline";
    objh3.style.display = "none";
    obj1.style.display = "none";
    obj2.style.display = "inline";
    obj3.style.display = "none";
  }
  if (n==3) {
    objh1.style.display = "none";
    objh2.style.display = "none";
    objh3.style.display = "inline";
    obj1.style.display = "none";
    obj2.style.display = "none";
    obj3.style.display = "inline";
  }
}


function checkDate(dt)
{
  if (dt.value!="") ValidateForm(dt);
}

function openRich(id,f)
{
  document.forms[0].fAction.value=f;
  document.forms[0].nId.value=id;
  fSubmit();
}

function writeRich(id)
{
  // e->E, i->I rispettivamente:
  // (e) modalita' di editing senza submit, con (E)
  // (i) modalita' di creazione senza submit, con (I)
  f=document.forms[0].fAction.value;
  document.forms[0].fAction.value=f.toUpperCase();
  document.forms[0].nId.value=id;
  fSubmit();
}

function fPrint(){
  window.print();
}
	
function fSubmit(){
  document.forms[0].submit();
}
	
function fDelete() {
  if (confirm("Are you sure ?")) {
     if (confirm("REALLY ?")) {
        document.forms[0].action="delDocument";
        document.forms[0].submit();
     }
  }
  return;
}


function swap_close(n){
  document.getElementById("close_img").src=(n==1) ? "images/close_on.gif":"images/close_off.gif";
}


function swap_rr(n,a,i){
  if (a=="E") document.getElementById("img_rre"+i).src=(n==1) ? "images/edit3.gif":"images/b_blank.gif";
  if (a=="D") document.getElementById("img_rrd"+i).src=(n==1) ? "images/trash6.gif":"images/b_empty.gif";
  if (a=="C") document.getElementById("img_rrn").src=(n==1) ? "images/new1.gif":"images/b_blank.gif";
}



// thanks to alliance.com
function keySort(dropdownlist,caseSensitive)
{
  // check the keypressBuffer attribute is defined on the dropdownlist 
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) dropdownlist.keypressBuffer = ''; 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) optionText = optionText.toLowerCase();
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since we have selected our own value 
    }
  }
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key;
  return true; // give default behavior
}




function feedAnag() {
  var i=0; var f=""; var newText=""; var newValue="";
  var doc=document.forms[0];
  var iMag=doc.iMagF.value;
  var aList1 = doc.jsMag.value.split("@");

  var i = doc.xdar0ag.selectedIndex;
  var f = doc.xdar0ag.options[i].text;
  var position = doc.xdar0ag;

  if (f.length>0) {
     // le cancella tutte... tranne la 1°
     max=position.length;
     for (i=1;i<max;i++) {   position.options.remove(1);   }
	 // cerca tutti gli elementi della 2° lista e li aggiunge alla 2° combobox...
     for (i=0;i<aList1.length;i++) {
       thisIMag=aList1[i].split("||")[0];
       if (thisIMag==iMag) {
          newText = aList1[i].split("||")[1];
          newValue = aList1[i];
          position.options[position.length] = new Option(newText, newValue, true, true)
       }
     }
  }
  position.options[0].selected=true;
}





/*---------------------------------------------
var preloadFlag = false;
function preloadImages() {
  if (document.images) {
     company_over = newImage("images/company-over.gif");
     products_over = newImage("images/products-over.gif");
     clients_over = newImage("images/clients-over.gif");
     support_over = newImage("images/support-over.gif");
     news_over = newImage("images/news-over.gif");
     preloadFlag = true;
  }
}

function newImage(arg) {
  // per far il roll.over dei menu grafici...
  if (document.images) {
     rslt = new Image();
     rslt.src = arg;
     return rslt;
  }
}

function changeImages() {
  if (document.images && (preloadFlag == true)) {
     for (var i=0; i<changeImages.arguments.length; i+=2) {
	 document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
     }
  }
}


// ... nella pagina...
<BODY ONLOAD="preloadImages();">

  <A HREF="#"
     ONMOUSEOVER="changeImages('company', 'images/company-over.gif'); return true;"
     ONMOUSEOUT="changeImages('company', 'images/company.gif'); return true;">
  <IMG NAME="company" SRC="images/company.gif" BORDER=0 ALT="company">
  </A>

//  /roll-over
---------------------------------------------- */
