// -------------------------------------------------------------
// File     : globals.js
// Author   : F. Nembrini
// Company  : (C)2003 Quarcom Teleinformatics
// Date     : March 03, 2003
// Modified : 
// Aim      : Manage win popups
// -------------------------------------------------------------

function showDetBook(id)
{
  var winBook = window.open("libri_dett.php?id=" + id + "","Libro","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetBook()

function showAuthBook(id)
{
  var winAuthBook = window.open("autori_libri.php?id=" + id + "","AutoreLibro","width=780,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showAuthBook()

function showDetAuth(id)
{
  var winAuth = window.open("autori_dett.php?id=" + id + "","Autore","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetAuth()

function showBookAuth(id)
{
  var winBookAuth = window.open("libri_autori.php?id=" + id + "","LibriAutore","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showBookAuth()

function showGallery_tmb(id, w, h)
{
  var winGall = window.open("../php/imgGallery_page_tmb.php?id=" + id + "","GalleryI_tmb","width=" + w + ",height=" + h + ",scrollbars=0,resizable=0,menubar=0,location=0,alwaysRaised=0");
  winMod.resizeTo(w,h);
} // End showGallery_tmb()

function showDetRec(id)
{
  var winRec = window.open("eco_dett.php?id=" + id + "","Recensione","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetRec()

function showDetSpec(id)
{
  var winSpec = window.open("speciali_dett.php?id=" + id + "","Speciali","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetSpec()

function showSpecAuth(id)
{
  var winSpec = window.open("speciali_dett_auth.php?id=" + id + "","Speciali","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showSpecAuth()

function showDetEvent(id)
{
  var winEvent = window.open("eventi_dett.php?id=" + id + "","Eventi","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetEvent()


function sortBy(column)
{
  form = document.forms[0];
  
  if(form.sorting.value == "ASC")
    form.sorting.value = "DESC";
  else
    form.sorting.value = "ASC";
  
  form.order_by.value = column;
  form.submit();
}

function setRowsPage(rows)
{
  form = document.forms[0];
  form.rows.value = rows;
  form.submit();
}

function showInfoPP()
{
  var winPP = window.open("info_pp.html","Info","width=780,height=590,scrollbars=0,resizable=0,menubar=0,location=0,alwaysRaised=0");
} // End showInfoPP()


var counter = 0;

function rotImgHome()
{  
  var argv = rotImgHome.arguments;
  var argc = argv.length;
  var tmout = 10000;
  var strArgv = "";
  var cnt = 0;
  
  document.images["home_txt"].src = "http://www.edizionicasagrande.com/php/home_txt.php?id=" + argv[counter] + "";
  counter = (counter+1) % argc;
  
  for(var i=0; i < argc; i++)
  {
     if(cnt < argc -1)
       strArgv +=  argv[i] + ",";
     else
       strArgv +=  argv[i];
     
     cnt++;
  }
  
  setTimeout("rotImgHome(" + strArgv + ")", tmout);
} // End rotImgHome()


function pressAttach(id)
{
  var winPressAttach = window.open("press_attachments.php?id=" + id + "","PressAttach","width=600,height=200,scrollbars=1,resizable=0,menubar=0,location=0,alwaysRaised=0");
} // End pressAttach()


/* Shopping cart funtions */

function addBook(id)
{
  var winSC = window.open("shopping_cart.php?action=add_item&id=" + id + "&qty=1","ShoppingCart","width=700,height=500,scrollbars=1,resizable=1,status=0,statusbar=0,menubar=0,location=0,alwaysRaised=0");
} // End addBook()

function delBook(id)
{
  if(confirm("Eliminare questo libro dal carrello?"))
  {
   // document.location.href = "shopping_cart.php?action=remove_item&id=" + id + "";
   document.location.href = "index.php?m=7&s=8&action=remove_item&id=" + id + "";
  }
} // End delBook()

function updateQty(item)
{
 itemId = item.name;
 newQty = item.options[item.selectedIndex].text;
 document.location.href = "index.php?m=7&s=8&action=update_item&id="+itemId+"&qty="+newQty;
} // end updateQty()

function checkOrder(form)
{
  var error = false;
  
  if(form.nome.value.length == 0 || form.cognome.value.length == 0 || form.indirizzo.value.length == 0 || form.cap.value.length == 0 || form.citta.value.length == 0 || form.nazione.options[form.nazione.options.selectedIndex].value == "" || form.email.value.length == 0 || form.tel.value.length == 0)
  {
    error = true;
    alert("Completare i campi obbligatori p.f.");
    form.nome.focus();
  }
  else
  {
    if(form.email.value.indexOf("@") == -1 || form.email.value.indexOf(".") == -1)
    {
      error = true;
      alert("Il formato dell'e-mail non e' valido!");
    }
  }
  
  if(!error)
  {
    form.method  = "post";
    form.enctype = "multipart/form-data";
    form.action  = "shopping_order.php?id=" + form.id.value +"";
    form.submit();
  }
} // End checkOrder()

function showCart()
{
  var winSC = window.open("shopping_cart.php","ShoppingCart","width=700,height=500,scrollbars=1,resizable=1,status=0,statusbar=0,menubar=0,location=0,alwaysRaised=0");
} // End showCart()


/* Customer management */

function showReg(id)
{
  var winSR = window.open("shopping_subscribe.php?c=1","SR","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showReg()

function showMod(id)
{
  var winSR = window.open("shopping_modify.php?c=2","SM","width=700,height=650,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showMod()

function subscribeCust(form)
{
  var error = false;
  
  if(form.nome.value.length == 0 || form.cognome.value.length == 0 || form.indirizzo.value.length == 0 || form.cap.value.length == 0 || form.citta.value.length == 0 || form.nazione.options[form.nazione.options.selectedIndex].value == "" || form.email.value.length == 0 || form.pwd1.value.length == 0 || form.pwd2.value.length == 0 || form.tel.value.length == 0)
  {
    error = true;
    alert("Completare i campi obbligatori p.f.");
    form.nome.focus();
  }
  else
  {
    if(form.email.value.indexOf("@") == -1 || form.email.value.indexOf(".") == -1)
    {
      error = true;
      alert("Il formato dell'e-mail non e' valido!");
    }
    
    if(form.pwd1.value != form.pwd2.value)
    {
      error = true;
      alert("Le password non coincidono!");
    }
  }
  
  if(!error)
  {
    form.method  = "post";
    form.enctype = "multipart/form-data";
    form.action  = "index.php?m=7&s=2&sub=1";
    form.submit();
  }
} // End subscribeCust()

function modifyCust(form)
{
  var error = false;
  
  if(form.nome.value.length == 0 || form.cognome.value.length == 0 || form.indirizzo.value.length == 0 || form.cap.value.length == 0 || form.citta.value.length == 0 || form.nazione.options[form.nazione.options.selectedIndex].value == "" || form.email.value.length == 0 || form.tel.value.length == 0)
  {
    error = true;
    alert("Completare i campi obbligatori p.f.");
    form.nome.focus();
  }
  else
  {
    if(form.email.value.indexOf("@") == -1 || form.email.value.indexOf(".") == -1)
    {
      error = true;
      alert("Il formato dell'e-mail non e' valido!");
    }
    
    if(form.pwd1.value.length != 0 || form.pwd2.value.length != 0)
    {
      if(form.pwd1.value != form.pwd2.value)
      {
        error = true;
        alert("Le password non coincidono!");
      }
    }
  }
  
  if(!error)
  {
    form.method  = "post";
    form.enctype = "multipart/form-data";
    form.action  = "index.php?m=7&s=4&upd=1";
    form.submit();
  }
} // End modifyCust()

function setDlvAdd(form,num)
{
  var state;
  
  if(num==1)
  {
    form.dlv.value = 1;
    state = true;
    form.reset();
  }
  else if(num==2)
  {
    form.dlv.value = 2;
    state = false;
  }
  
  form.dlv_name.disabled = state;
  form.dlv_lastname.disabled = state;
  form.dlv_address.disabled = state;
  form.dlv_zip.disabled = state;
  form.dlv_city.disabled = state;
  form.dlv_country.disabled = state;  
} // end setDlvAdd()


function checkDlv(form)
{
  var error = 0;
  
  if(form.dlv.value == 2)
  {
    form.first_name.value = form.dlv_name.value;
    form.last_name.value  = form.dlv_lastname.value;
    form.address1.value   = form.dlv_address.value;
    form.city.value       = form.dlv_city.value;
    form.zip.value        = form.dlv_zip.value;
    form.country.value    = form.dlv_country.value;
 
    if(form.dlv_name.value == "" || form.dlv_lastname.value == "" || form.dlv_address.value == "" || form.dlv_city.value == "" || form.dlv_zip.value == "" || form.dlv_country.value == "")
      error = 1;
    
    form.custom.value = "sid=" + form.dlv_sid.value + "&cid=" + form.c_id.value + "&nm=" + form.dlv_nm.value + "&c_fnam=" + form.dlv_name.value + "&c_lnam=" + form.dlv_lastname.value + "&c_addr=" + form.dlv_address.value + "&c_city=" + form.dlv_city.value + "&c_zip=" + form.dlv_zip.value + "&c_cou=" + form.dlv_country.value + "";
  }
  /*
  else
  {
    form.custom.value = "sid=" + form.dlv_sid.value + "&nm=" + form.dlv_nm.value + "&c_fnam=" + form.first_name.value + "&c_lnam=" + form.last_name.value + "&c_addr=" + form.address1.value + "&c_city=" + form.city.value + "&c_zip=" + form.zip.value + "&c_cou=" + form.country.value + "";
  }
  */
  form.custom.value += "&c_otype=" + form.o_type.value + "";

  if(!error)
  { form.submit(); }
  else
  {  alert("Completare i campi obbligatori"); }
} // end checkDlv()

function makeOrder()
{
  window.opener.document.location.href = "index.php?m=7&s=1&c=1";
  self.close();
} // end makeOrder()

function makeOrder2()
{
  document.location.href = "index.php?m=7&s=1&c=1";
} // end makeOrder2()


function checkOrderType(form)
{
  if(form.order_type.value == 0)
   form.o_type.value = 0;
  else
   form.o_type.value = 1;
} // checkOrderType()


function checkPwdForg(form,m,s)
{
  var error = true;
  var msg;
  
  msg = "Completate i campi obbligatori (grassetto) per favore";

  if(form.email.value.length != 0 && form.code.value.length != 0 )
  {
	error = false;	
  }
  else
  {
    alert(msg);
	error = true;
  }
  
  if(!error)
  {
    form.action = "index.php?snd=1&m=" + m + "&s=" + s + "";
	form.method = "post";
	form.submit();
  }
} // end checkPwdForg()
