// Suckerfish

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;

// Popup Image

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=780,height=780');");
}

// Popup HTML

function openpopup(popurl) {
var winpops=window.open(popurl,"","width=450,height=300,scrollbars,resizable")
}

// Pre-Filled Search

function ClearSearchBy()
 {
		if (document.getElementById('searchfield').value == 'search allfarm')
			{
			document.getElementById('searchfield').value = '';
			}
		}




function disableAnnFileUpload()
{

  if(document.announce.announcetype[0].checked)
  {
    document.announce.imageButton.disabled=true;
    document.announce.product.disabled=false;
  }
  else
  {
    document.announce.imageButton.disabled=false;
    document.announce.product.disabled=true;
  }
}

function announceOnLoad()
{
  // Perform onload functions here..

  //Call disableAnnFileUpload() function..
  disableAnnFileUpload();
}

function getExt(filename) 
{
  var dot_pos = filename.lastIndexOf(".");

  if(dot_pos == -1)
    return "";

  return filename.substr(dot_pos+1).toLowerCase();
} 


function checkSpeciesSelected()
{
  var ret = true;
  var num_species = document.addproduct.num_species.value;

  
 
  return ret;
}

function isNumeric(sText)

{
  var validChars = "0123456789.";
  var isNumber=true;
  var ch;


  return isNumber;
}

function isSpaces(sText)

{
  var invalidChars = " ";
  var isSpaces=false;
  var ch;


  
  for (i = 0; i < sText.length && isSpaces == false; i++) 
  { 
    ch = sText.charAt(i); 
    if (invalidChars.indexOf(ch) == 0) 
    {
      isSpaces = true;
    }
  }

  return isSpaces;
}


// Check announcement fields..
function checkAnnounce()
{
  var errmsg = "";
  var warnmsg = "";
  var ret = true;

  // Check if it's a product announcement and if a product has been selected..
  if(document.announce.announcetype[0].checked) 
    if (document.announce.product.value == 0)
       errmsg = errmsg + " - You must select a product from the product drop down list.\n";
  if (document.announce.articletitle.value == "")
    errmsg = errmsg + "- You must fill in an article title.\n"; 
  if (document.announce.articletext.value == "")
    errmsg = errmsg + "- You must fill in some article text.\n"; 

  // Warning messages.
  if (document.announce.imageButton.value != "")
    if (getExt(document.announce.imageButton.value) != "gif")
      if (getExt(document.announce.imageButton.value) != "jpg")
        if (getExt(document.announce.imageButton.value) != "jpeg")
          if (getExt(document.announce.imageButton.value) != "png")
            warnmsg = warnmsg + " - The image you are attempting to add is in the wrong format. Please ensure it is a GIF, JPG or PNG image file.\n";
  if (document.announce.product.value == 0)
    if (document.announce.imageButton.value == "")
        warnmsg = warnmsg + "- You have not selected an image.\n"; 

  // If there has been an error, display confirm box..
  if (document.announce.action == "index.php")	// We are not previewing.. 
  {
    if (errmsg != "")				// There has been an error message set..
    {
      ret = alert(errmsg);
      return false;
    }
    if (warnmsg != "")				// There has been an warning message set..
      ret = confirm(warnmsg + "\nAre you sure you want to submit this announcement?");      
  }

  // Return true or false.. 
  return ret;
}

// Check employment fields..
function checkEmployment()
{
  var errmsg = "";
  var warnmsg = "";
  var ret = true;

  // check fields..
  if (document.employment.articletitle.value == "")
    errmsg = errmsg + "- You must fill in the title field.\n"; 
  if (document.employment.articletext.value == "")
    errmsg = errmsg + "- You ust fill in the description field.\n"; 
  if (document.employment.imageButton.value == "")
        errmsg = errmsg + "- You have not selected an attachment.\n"; 
 


  // Warning messages.
  if (document.employment.imageButton.value != "")
    if (getExt(document.employment.imageButton.value) != "doc")
      if (getExt(document.employment.imageButton.value) != "rtf")
        if (getExt(document.employment.imageButton.value) != "pdf")
          if (getExt(document.employment.imageButton.value) != "txt")
            warnmsg = warnmsg + " - The attachment you are about to upload is not a recognized DOC, PDF or TXT file.  It will be marked as 'unspecified'.\n";

  // If there has been an error, display confirm box..
  if (document.employment.action == "index.php?page=employment")	// We are not previewing.. 
  {
    if (errmsg != "")				// There has been an error message set..
    {
      ret = alert(errmsg);
      return false;
    }
    if (warnmsg != "")				// There has been an warning message set..
      ret = confirm(warnmsg + "\nAre you sure you want to submit this employment position?");  
  }

  // Return true or false.. 
  return ret;
}


// Check employment fields..
function checkAddProduct()
{
  var errmsg = "";
  var warnmsg = "";
  var ret = true;

  // Check if it's a product announcement and if a product has been selected..
  if(document.addproduct.prodcat.value == "") 
    errmsg = errmsg + "- You must select a product category from the product category drop down list.\n";
  if (document.addproduct.prodtitle.value == "")
    errmsg = errmsg + "- You must fill in a product title.\n"; 
  if (checkSpeciesSelected() == false)
    errmsg = errmsg + "- You must check at least one associated species.\n";
  if (isNumeric(document.addproduct.prodprice.value) == false)
    errmsg = errmsg + "- The price field can only contain numbers.\n"; 
//  if (isSpaces(document.addproduct.msdsButton.value) == true)
//    errmsg = errmsg + "- The MSDS file you are attempting to upload contains spaces, please rename it and try again.\n"; 

  // Warning messages..
  if (document.addproduct.imageButton.value != "")
    if (getExt(document.addproduct.imageButton.value) != "gif")
      if (getExt(document.addproduct.imageButton.value) != "jpg")
        if (getExt(document.addproduct.imageButton.value) != "jpeg")
          if (getExt(document.addproduct.imageButton.value) != "png")
            warnmsg = warnmsg + " - The image you are attempting to add is in the wrong format. Please ensure it is a GIF, JPG or PNG image file.\n";
  if (document.addproduct.msdsButton.value != "")
    if (getExt(document.addproduct.msdsButton.value) != "doc")
      if (getExt(document.addproduct.msdsButton.value) != "rtf")
        if (getExt(document.addproduct.msdsButton.value) != "pdf")
          if (getExt(document.addproduct.msdsButton.value) != "txt")
            warnmsg = warnmsg + " - The MSDS file you are attempting to upload is not a recognized DOC, PDF or TXT file.  It will be marked as 'unspecified'.\n";

  if (document.addproduct.prodprice.value == "")
    warnmsg = warnmsg + "- You have not entered a product price.\n"; 
  if (document.addproduct.imageButton.value == "")
    if (document.addproduct.img_id.value == "")
    warnmsg = warnmsg + "- You have not selected a product image.\n"; 
  if (document.addproduct.msdsButton.value == "")
    if (document.addproduct.msds_id.value == "")
      warnmsg = warnmsg + "- You have not selected an MSDS file.\n"; 

  // If there has been an error, display confirm box..
  if (document.addproduct.action == "index.php?page=add")	// We are not previewing.. 
  {
    if (errmsg != "")				// There has been an error message set..
    {
      ret = alert(errmsg);
      return false;
    }
    if (warnmsg != "")				// There has been an warning message set..
      ret = confirm(warnmsg + "\nAre you sure you want to submit this product?");      
  }

  // Return true or false.. 
  return ret;
}

