/*****************************************************************
 * Company: COODEP.COM
 * Copyright COODEP.COM 2007-2008. All rights reserved.
 * Author: Lucie N. Hutchins
 * Date: 03/27/08
 *****************************************************************/
/* this function validates the content of the registration form */

function validate_regform(frm)
{
     // do not submit the form content if one of the login fields is empty
  if((frm.fn.value=="")||(frm.ln.value=="")||(frm.sj.value=="")||(frm.email.value=="")||(frm.comment.value=="")){
        document.getElementById("lm").innerHTML="<font color=red>Bad Request: You must fill all the required fields (fields with *)</font>";
        // clear from content
        frm.reset();
        frm.fn.focus();
        return false;
  }
    // do not submit the form content if one of the login fields is too long
  if((frm.fn.value.length>50)||(frm.ln.value.length>50)||(frm.sj.value>100)||(frm.email.value.length>50)
      ||(frm.comment.value.length>300)||(frm.company.value.length>50)||(frm.bp.value.length>20)){
        document.getElementById("lm").innerHTML ="<font color=red>Bad Request: One of your input fields is too long</font>";
        // clear from content
        frm.reset();
        frm.fn.focus();
        return false;
  }
  if(email_check(frm.email.value)<=0){  // validate the user's email
       document.getElementById("lm").innerHTML ="<font color=red>Bad email</font>";
        // clear from content
        form.email.value="";
       /* form.comment.value="";*/
        form.email.focus();
        return false;
   }
    return true; 
}
/* this function checks if a given password is not entirely numeric or alphabetic */
function pwd_check(str){
 var digit=/\d/                          //position of the first digit in password
 var digitPos = str.search(digit);
 var Alphabetic =/[a-zA-Z]/             // get position of the first character in password
 var letterPos = str.search(Alphabetic)
 var nonWord  =/\W/                    // match a non-word character
 var nwordPos = str.search(nonWord)    // we only allow password to be alpha-numeric characters

  if ((letterPos==-1)||(digitPos==-1)||(nwordPos !=-1)){
      return 0
  }
  return 1
}
/* This function makes sure the email address has one (@), at least one (.). 
// It also makes sure that there are no spaces, extra '@'s or a (.) just before or after the @. 
// It also makes sure that there is atleast one (.) after the @.
//
 Code from http://www.smartwebby.com/dhtml
*/

function email_check(str) {
   var at="@"
   var dot="."
   var lat=str.indexOf(at)
   var lstr=str.length
   var ldot=str.indexOf(dot)
   if (str.indexOf(at)==-1){
      return 0 
    }
   else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
      return 0
   }
   else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      return 0
   }
   else if (str.indexOf(at,(lat+1))!=-1){
       return 0
   }
   else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      return 0
    }
   else if (str.indexOf(dot,(lat+2))==-1){
      return 0
    }
   else if (str.indexOf(" ")!=-1){
      return 0
     }
     return 1					
 }
 /* this function post the content of the form pointed by the link */

 function formPost(type,userid,prog) {
    if(type == "1"){
       document.getElementById("form1").p.value = 1;
       document.getElementById("form1").ruid.value = userid;
       document.getElementById("form1").action = prog;
       document.getElementById("form1").submit();
     }
     else {
        document.getElementById("form2").t.value = 1;
        document.getElementById("form2").ruid.value = userid;
        document.getElementById("form2").action = prog;
        document.getElementById("form2").submit();
                           
     }
 }
 
