// -------------------------------------------------------------
// File     : globals.js
// Author   : F. Nembrini
// Company  : (C) 2011 Quarcom Teleinformatics
// Date     : Agust 03, 2011
// Modified : August 04, 2011
// Aim      : Manage SSTMP scripts
// -------------------------------------------------------------

// ################################################### Novita ###################################################
function showDetNovita(id, type)
{
  var winNov = window.open("novita_dett.php?id=" + id + "&type=" + type + "","News","width=650,height=500,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetNovita()

// ################################################### Prodotti ###################################################
function showDetProd(id)
{
  var winDP = window.open("prod_det.php?id=" + id + "","Product","width=650,height=500,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDetProd()


// ################################################### Attachments ###################################################
function attachDocManifestazione(id)
{
  var winAttach = window.open("attach_doc_manif.php?id=" + id + "","AddAttachment","width=500,height=300,scrollbars=1,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End attachDocManifestazione()

// ################################################### Foto ###################################################
function showFotoDet(id,width,height)
{
  var winFot = window.open("regione_foto_dett.php?id=" + id + "","Fotogallery","width="+ width +",height="+ height +",scrollbars=0,resizable=1,menubar=0,status=0,location=0,alwaysRaised=0");
} // End showFotoDet()


// ################################################### Credits ###################################################
function showCredits()
{
  var winCredits = window.open("credits.html","Credits","width=353,height=72,scrollbars=0,resizable=1,menubar=0,location=0,alwaysRaised=0,status=0,statusbar=0");
} // End showCredits()

// ################################################### Disclaimer ###################################################
function showDisclaimer(lang)
{
  var winDisc = window.open("disclaimer.php?lang=" + lang + "","Disclaimer","width=650,height=450,scrollbars=0,resizable=1,menubar=0,location=0,alwaysRaised=0");
} // End showDisclaimer()

// ################################################### Links ###################################################
function openLink(lnk)
{
  var winLink = window.open(lnk,"Link");
  return false;
} // End openLink()

// ################################################### Form ###################################################

var checkArray = new Array(false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
var isChecked = false;

function checkIt(index)
{
  if(checkArray[index])
  {
    checkArray[index] = false;
  }
  else
  {
    checkArray[index] = true;
  }
} // End checkIt()


function registerForm(form,m,s)
{
  var error = true;
  var msg   = "";
  
  msg = "Please complete mandatory fields.";
  
  form.email.setAttribute("class", "fvalid");
  form.phone.setAttribute("class", "fvalid");
  form.country.setAttribute("class", "fvalid");
  form.city.setAttribute("class", "fvalid");
  form.zip.setAttribute("class", "fvalid3");
  form.address.setAttribute("class", "fvalid");
  form.institution.setAttribute("class", "fvalid");
  form.lastname.setAttribute("class", "fvalid");
  form.firstname.setAttribute("class", "fvalid");
  form.title.setAttribute("class", "fvalid2");
  
  if(form.title.value.length != 0 && form.firstname.value.length != 0 && form.lastname.value.length != 0 && form.institution.value.length != 0  && form.address.value.length != 0 && form.zip.value.length != 0 && form.city.value.length != 0 && form.country.value.length != 0 && form.phone.value.length != 0 && form.email.value.length != 0)
  {
    if(form.email.value.indexOf("@") == -1  || form.email.value.indexOf(".") == -1)
    {
      form.email.setAttribute("class", "ferror");
      form.email.focus();
      error = true;
      alert("E-mail syntax not valid!");
    }
    else
    {
      error = false;
    }
  }
  else
  {
    if(form.email.value.length == 0)
    {
      form.email.setAttribute("class", "ferror");
      form.email.focus();
    }
    
    if(form.phone.value.length == 0)
    {
      form.phone.setAttribute("class", "ferror");
      form.phone.focus();
    }
    
    if(form.country.value.length == 0)
    {
      form.country.setAttribute("class", "ferror");
      form.country.focus();
    }
    
    if(form.city.value.length == 0)
    {
      form.city.setAttribute("class", "ferror");
      form.city.focus();
    }
    
    if(form.zip.value.length == 0)
    {
      form.zip.setAttribute("class", "ferror3");
      form.zip.focus();
    }

    if(form.address.value.length == 0)
    {
      form.address.setAttribute("class", "ferror");
      form.address.focus();
    }

    if(form.institution.value.length == 0)
    {
      form.institution.setAttribute("class", "ferror");
      form.institution.focus();
    }

    
    if(form.lastname.value.length == 0)
    {
      form.lastname.setAttribute("class", "ferror");
      form.lastname.focus();
    }
    
    if(form.firstname.value.length == 0)
    {
      form.firstname.setAttribute("class", "ferror");
      form.firstname.focus();
    }

    if(form.title.value.length == 0)
    {
      form.title.setAttribute("class", "ferror2");
      form.title.focus();
    }
    
    alert(msg);
	error = true;
  }
  
  if(!error)
  {
    form.action = "index.php?snd=1&m=" + m + "&s=" + s + "";
	form.method = "post";
	form.submit();
  }
} // end registerForm()


function memberForm(form,m,s)
{
  var error = true;
  var msg   = "";
  
  msg = "Please complete mandatory fields.";
  
  form.email.setAttribute("class", "fvalid");
  form.phone.setAttribute("class", "fvalid");
  form.country.setAttribute("class", "fvalid");
  form.city.setAttribute("class", "fvalid");
  form.zip.setAttribute("class", "fvalid3");
  form.address.setAttribute("class", "fvalid");
  form.bd_day.setAttribute("class", "fvalid4");
  form.bd_month.setAttribute("class", "fvalid4");
  form.bd_year.setAttribute("class", "fvalid4");
  form.lastname.setAttribute("class", "fvalid");
  form.firstname.setAttribute("class", "fvalid");
  form.title.setAttribute("class", "fvalid2");
  
// && form.bd_day.value.length != 0  && form.bd_month.value.length != 0 && form.bd_year.value.length != 0
  if(form.title.value.length != 0 && form.firstname.value.length != 0 && form.lastname.value.length != 0  && form.address.value.length != 0 && form.zip.value.length != 0 && form.city.value.length != 0 && form.country.value.length != 0 && form.phone.value.length != 0 && form.email.value.length != 0)
  {
    if(form.email.value.indexOf("@") == -1  || form.email.value.indexOf(".") == -1)
    {
      form.email.setAttribute("class", "ferror");
      form.email.focus();
      error = true;
      alert("E-mail syntax not valid!");
    }
    else
    {
      error = false;
    }
  }
  else
  {
    if(form.email.value.length == 0)
    {
      form.email.setAttribute("class", "ferror");
      form.email.focus();
    }
    
    if(form.phone.value.length == 0)
    {
      form.phone.setAttribute("class", "ferror");
      form.phone.focus();
    }
    
    if(form.country.value.length == 0)
    {
      form.country.setAttribute("class", "ferror");
      form.country.focus();
    }
    
    if(form.city.value.length == 0)
    {
      form.city.setAttribute("class", "ferror");
      form.city.focus();
    }
    
    if(form.zip.value.length == 0)
    {
      form.zip.setAttribute("class", "ferror3");
      form.zip.focus();
    }

    if(form.address.value.length == 0)
    {
      form.address.setAttribute("class", "ferror");
      form.address.focus();
    }
    
    /*
    if(form.bd_year.value.length == 0)
    {
      form.bd_year.setAttribute("class", "ferror4");
      form.bd_year.focus();
    }
    
     if(form.bd_month.value.length == 0)
    {
      form.bd_month.setAttribute("class", "ferror4");
      form.bd_month.focus();
    }
    
    if(form.bd_day.value.length == 0)
    {
      form.bd_day.setAttribute("class", "ferror4");
      form.bd_day.focus();
    }
    */
    if(form.lastname.value.length == 0)
    {
      form.lastname.setAttribute("class", "ferror");
      form.lastname.focus();
    }
    
    if(form.firstname.value.length == 0)
    {
      form.firstname.setAttribute("class", "ferror");
      form.firstname.focus();
    }

    if(form.title.value.length == 0)
    {
      form.title.setAttribute("class", "ferror2");
      form.title.focus();
    }
    
    alert(msg);
	error = true;
  }
  
  if(!error)
  {
    form.action = "index.php?snd=1&m=" + m + "&s=" + s + "";
    // form.action = "membership_form.php?snd=1";
	form.method = "post";
	form.submit();
  }
} // end memberForm()


function checkMail(form,m,s)
{
  var error = true;
  
  if(form.email.value.length != 0)
  {
    error = false; 
    if(form.email.value.indexOf("@") == -1  || form.email.value.indexOf(".") == -1)
    {
      error = true;
      alert("E-mail syntax not valid!");
    }
    else
    {
      error = false;
    }
  }
  else
  {
    error = true;
    alert("Please insert e-mail address!");
  }
  
  if(!error)
  {
    form.action = "index.php?m=" + m + "&s=" + s + "";  
    form.method = "post";
	form.submit();
  }
} // end checkMail()

// ################################################### Sorting ###################################################
function sortBy(column)
{
  form = document.forms['rslist'];
  
  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['rslist'];
  form.rows.value = rows;
  form.submit();
}

function highLightRow(el, cl_name)
{
  el.className = cl_name;
}
