function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 
   }


function isValidEmail(str) 
{
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}


function ValidateandSubmitForm(downloadform, URI)
{

flagfname = true;
flaglname = true;
flagorg = true;
flagcontact = true;
flagemail = true;
focusflag = false;

   
   if (IsEmpty(downloadform.filename))
   {
   	document.getElementById("errorMsg").innerHTML = "<b><font color='FF0000'>A file has not been selected for download. Please <a href='downloads.php'><u><font color='FF0000'>click here</font></u></a> to return to the download page.</font></b>"; 
   	return false;
   }
   
  
   if(IsEmpty(downloadform.fname)) 
   { 
     document.getElementById("spanfname").innerHTML = "<b><font color='FF0000'>First Name:</font></b>";
     flagfname = false;
    if (!focusflag){
          downloadform.fname.focus(); 
          focusflag = true; 
          }
     } 
	else
	{
	document.getElementById("spanfname").innerHTML = "First Name:";
	}
  
 if(IsEmpty(downloadform.lname)) 
   { 
      document.getElementById("spanlname").innerHTML = "<b><font color='FF0000'>Last Name:</font></b>";
      flaglname = false; 
     if (!focusflag){
          downloadform.lname.focus(); 
          focusflag = true; 
          }
     } 
else
 {
	document.getElementById("spanlname").innerHTML = "Last Name:";
 }

 if(IsEmpty(downloadform.org)) 
   { 
      document.getElementById("spanorg").innerHTML = "<b><font color='FF0000'>Organization:</font></b>";
      flagorg = false; 
    if (!focusflag){
          downloadform.org.focus(); 
          focusflag = true; 
          }
   }
else
 {
	document.getElementById("spanorg").innerHTML = "Organization:";
 }

 if(IsEmpty(downloadform.contact) || (!IsNumeric(downloadform.contact.value)))
   { 
    document.getElementById("spancontact").innerHTML = "<b><font color='FF0000'>Contact Number:</font></b>";
     flagcontact = false; 
   if (!focusflag){
          downloadform.contact.focus(); 
          focusflag = true; 
          }
   } 
else
 {
 	document.getElementById("spancontact").innerHTML = "Contact Number:";
 }
 
 if(IsEmpty(downloadform.email) || (!isValidEmail(downloadform.email.value))) 
   { 
     document.getElementById("spanemail").innerHTML = "<b><font color='FF0000'>Email Address:</font></b>"; 
      flagemail = false; 
    if (!focusflag){
          downloadform.email.focus(); 
          focusflag = true; 
        }
   } 
else
 {
	document.getElementById("spanemail").innerHTML = "Email Address:";
 }
 

if ((flagfname == false) || (flaglname == false) || (flagorg == false) || (flagcontact == false) || (flagemail == false)) 
{
	document.getElementById("errorMsg").innerHTML = "<b><font color='FF0000'>Please fix the errors in the fields highlighted in red and resubmit the form.</font></b>"; 
	return false;
	
}
else
{
	document.getElementById("errorMsg").innerHTML = ""; 
	
	array = URI.toString().split('=');
	
	downloadform.next_url.value = downloadform.next_url.value + "?file=" + array[1];
	
	return true;
}
}

function EIACOESubmitForm()
{

 document.getElementById("errorMsg").innerHTML = "<b><font color='FF0000'>Incorrect username or password. Please try again or contact Electrosoft if you think you have received this message in error.</font></b>"; 
 return false;

       
}
