// copyright Ivo Truxa, truXoft.com

var msie = (navigator.userAgent.indexOf("MSIE")!=-1);

function submitFda()
{
 if (document.fda.domestic[0].checked && (document.fda.Country.value==234 || document.fda.Country.value==235 || document.fda.Country.value==175 || document.fda.Country.value== 243)){alert("You are trying to use the 'Foreign Facility' registration for a facility with a USA address.\nPlease correct your choice above and select either the 'Domestic Facility' registration above or use your address outside the USA"); return false;}
 if (document.fda.domestic[1].checked && document.fda.Country.value!=234 && document.fda.Country.value!=235 && document.fda.Country.value!=175 && document.fda.Country.value!=243){alert("You are trying to use the 'Domestic Facility' registration for a facility with an address outside the USA.\nPlease correct your choice above and select either the 'Foreign Facility' registration above or use your address inside the USA"); return false;}
 if (document.fda.Name.value.length < 2) {alert("Please enter the\nFACILITY NAME\nin Facility Information"); return false;}
 if (document.fda.Address.value.length < 2) {alert("Please enter the\nADDRESS\nin Facility Information"); return false;}
 if (document.fda.City.value.length < 2) {alert("Please enter the\nCITY\nin Facility Information"); return false;}
// if (document.fda.State.value.length < 2) {alert("Please enter the\nSTATE\nin Facility Information"); return false;}
 if (document.fda.Country.selectedIndex==0) {alert("Please select the\nCOUNTRY\nin Facility Information"); return false;}
 if (document.fda.Phone.value.length < 8) {alert("Please enter the full\nPHONE NUMBER\nin Facility Information\n(including country and local area codes!)"); return false;}
 if (document.fda.Fax.value.length < 8) {alert("Please enter the full\nFAX NUMBER\nin Facility Information\n(including country and local area codes!)"); return false;}
 if (document.fda.emgName.value.length < 5) {alert("Please enter the\nINDIVIDUAL'S NAME\nin Emergency Contact Information"); return false;}
 if (document.fda.agnName.value.length < 5) {alert("Please enter the\nINDIVIDUAL'S NAME\nin 'Owner, Operator, or Agent in Charge' Contact Information"); return false;}
 if (document.fda.emgPhone.value.length < 8 && document.fda.emgHomePhn.value.length < 8 && document.fda.emgCellPhn.value.length < 8) {alert("Please enter a\nPHONE NUMBER\nin Emergency Contact Information\n(including country and local area codes!)"); return false;}
 var corpOk = false;
 var humanChecked = false;
 for (var i=0; i<document.fda.corpType.length; i++) 
   if (document.fda.corpType[i].checked) 
    {
     corpOk=true;
     if (i>0 && i<10) humanChecked = true;
    }
// if (!corpOk) {alert("Please select an\nESTABLISHMENT TYPE"); return false;}
 if (document.fda.corpType[0].checked)
 {
  var warhOk = false;
  for (var i=0; i<document.fda.warehouse.length; i++) if (document.fda.warehouse[i].checked) warhOk = true;
  if (!warhOk) {alert("Please select a\nWAREHOUSE / HOLDING FACILITY TYPE"); return false;}
 }
 if (humanChecked || 1) // || 1 - changed to make mandatory allways
 {
  var humanOk = false;
  for (var i=0; i<document.fda.catHuman.length; i++) if (document.fda.catHuman[i].checked) humanOk=true;
  if (!humanOk) {alert("Please select PRODUCT CATEGORIES of\nFOOD FOR HUMAN CONSUMPTION"); return false;}
 }
 if (document.fda.corpType[10].checked)
 {
  var animOk = false;
  for (var i=0; i<document.fda.catAnim.length; i++) if (document.fda.catAnim[i].checked) animOk=true;
  if (!animOk) {alert("Please select PRODUCT CATEGORIES of\nFOOD FOR ANIMAL CONSUMPTION"); return false;}
 }
}

function showCat() 
{
 var hum = 
  (
   document.fda.corpType[1].checked ||
   document.fda.corpType[2].checked ||
   document.fda.corpType[3].checked ||
   document.fda.corpType[4].checked ||
   document.fda.corpType[5].checked ||
   document.fda.corpType[6].checked ||
   document.fda.corpType[7].checked ||
   document.fda.corpType[8].checked ||
   document.fda.corpType[9].checked
  ) ? 'block' : 'none';
/*
 if (msie){
  warehouseOpt.style.display = (document.fda.corpType[0].checked) ? 'block' : 'none';
  catAnim.style.display = (document.fda.corpType[10].checked) ? 'block' : 'none';
  catHum.style.display = hum;
 }else{
  document.getElementById('warehouseOpt').style['display'] = (document.fda.corpType[0].checked) ? 'block' : 'none';
  document.getElementById('catAnim').style['display'] = (document.fda.corpType[10].checked) ? 'block' : 'none';
  document.getElementById('catHum').style['display'] = hum;
 }
*/
}

function slctAll()
{
 for (var i=0; i<document.fda.length; i++)  
   if (document.fda.elements[i].name.search('x') == 0)
     document.fda.elements[i].checked = document.fda.xAll.checked;
}

function countrySel(obj)
{
 for (var i in obj.options) 
  {      
   eval("obj.options[i] = document.fda.Country.options[i]")
   if (i==0) obj.options[i].selected=true
  }
}

function show_props(obj, objName) {   
  var result = ""   
  for (var i in obj) {result+=objName+"."+i+" = "+obj[i]+"<br>\n"}   
  return result
 }
 

function hide(obj,val,nr)
{
 if (agOK)
   for (var i=2; i<=nr; i++) 
     if (msie)
          eval(obj+i+".style.visibility=\""+val+"\"")
     else eval(obj+i+"['style'].visibility=\""+val+"\"");
}

function anim(chgPic)
{
 if (agOK)
   {
    sz = new Array(0,9,6,8,8)
    var nr = 1+Math.floor(3.99*Math.random())
    var tm = 500+Math.ceil(1200*Math.random())
    hide('t'+nr,'visible',sz[nr])
    setTimeout("hide('t"+nr+"','hidden',"+sz[nr]+")",tm)
    if (!chgPic) setTimeout("slideShow()",tm)
    setTimeout("anim("+(chgPic+1)%4+")",tm+1)
   }
}


function slideShow()
{
 if (agOK && document.images)
   {
    var nr = Math.floor((pcnm.length-0.01)*Math.random())
    if (msie)
      {
       chgImg(im1,nr,1)
       chgImg(im2,(nr+7)%pcnm.length,0.8)
       chgImg(im3,(nr+14)%pcnm.length,0.67)
      }
    else chgImg(document.pic1,nr,1)
   }
}


function popup(url)
{
 window.open(url,'Info','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=460').focus();
 self.name = "mainWin";
}

function selPay(type)
{
 if (msie) switch(type) {
  case 'cc' : cc.style.display='block'; tt.style.display='none';  ck.style.display='none';  break;
  case 'tt' : cc.style.display='none';  tt.style.display='block'; ck.style.display='none';  break;
  case 'ck' : cc.style.display='none';  tt.style.display='none';  ck.style.display='block'; break;
 }
 else switch(type) {
  case 'cc' : document.getElementById('cc').style['display']='block'; document.getElementById('tt').style['display']='none';  document.getElementById('ck').style['display']='none';  break;
  case 'tt' : document.getElementById('cc').style['display']='none';  document.getElementById('tt').style['display']='block'; document.getElementById('ck').style['display']='none';  break;
  case 'ck' : document.getElementById('cc').style['display']='none';  document.getElementById('tt').style['display']='none';  document.getElementById('ck').style['display']='block'; break;
 }
}

function verifyCC()
{
 var terms = false;
 if (!document.fda.terms[0].checked) {alert("You have to read and agree with the Terms of the Registration"); return false;}
 if (document.fda.payType[0].checked) {
   if (document.fda.pay_cctype.value == '') {alert("Please select CC type"); return false;}
   if (document.fda.pay_fname.value.length < 1) {alert("Please enter your\nFIRST NAME"); return false;}
   if (document.fda.pay_lname.value.length < 1) {alert("Please enter your\nLAST NAME"); return false;}
   if (document.fda.pay_ccnum.value.length < 12) {alert("Please enter the\nCREDIT CARD NUMBER"); return false;}
 }
 return true;
}


function validNewUser(affil)
{
 if (document.fda.Name.value.length < 2) {alert("Please enter your\nNAME"); return false;}
 if (document.fda.Phone.value.length < 8) {alert("Please enter your full\nPHONE NUMBER\n(including country and local area codes!)"); return false;}
 if (document.fda.Email.value.length < 7) {alert("Please enter your valid \nEMAIL ADDRESS"); return false;}
 if (affil){
   if (document.fda.Address.value.length < 2) {alert("Please enter the\nADDRESS\nin Facility Information"); return false;}
   if (document.fda.City.value.length < 2) {alert("Please enter the\nCITY\nin Facility Information"); return false;}
   if (document.fda.Country.selectedIndex==0) {alert("Please select the\nCOUNTRY\nin Facility Information"); return false;}
   if (!document.fda.terms[0].checked) {alert("You have to read and agree with the Affiliate Contract"); return false;}
 }
 return true;
}


function sendPwd(text1,text2)
{
 if (document.fda.login.value) {
   if (confirm(text1)) {
     document.fda.sendPass.value=1; 
     document.fda.submit();
   }
 }else {alert(text2);}
 return false;
}

function slctAll(){
  for (var i=0; i < document.fda.length; i++)  
    if (document.fda.elements[i].name.search('x') != -1)
      document.fda.elements[i].checked = document.fda.chkAll.checked;
}

function chkSlct(){
  for (var i=0; i < document.fda.length; i++)  
    if (document.fda.elements[i].name.search('x') != -1)
      if (document.fda.elements[i].checked) return true;
 return false;
}


