// Support Functions
   function strip(filter,str){
      var i,curChar;
      var retStr = '';
      var len = str.length;
      for(i=0; i<len; i++){
         curChar = str.charAt(i);
         if(filter.indexOf(curChar)<0) 
           //not in filter, keep it
            retStr += curChar;
      }
      return retStr;
   }
   function reformat(str){
      var arg;
      var pos = 0;
      var retStr = '';
      var len = reformat.arguments.length;
      for(var i=1; i<len; i++){
         arg = reformat.arguments[i];
         if(i%2==1)
            retStr += arg;
         else{
            retStr += str.substring(pos, pos + arg);
            pos += arg;
         }
      }
      return retStr;
   }
   //End Support Functions


  //Validation Rules
   function notEmpty(str){
      if(strip(" \n\r\t",str).length ==0)
         return false;
      else
         return true;
   }
   function validateInteger(str){
      str = strip(' \n\r\t',str);
      //remove leading zeros, if any
      while(str.length > 1 && str.substring(0,1) == '0'){
         str = str.substring(1,str.length);
      }
      var val = parseInt(str);
      if(isNaN(val))
         return false;
      else
         return true;
   }
   
   function validateFloat(str){
      str = strip(' \n\r\t',str);
      //remove leading zeros, if any
      while(str.length > 1 && str.substring(0,1) == '0'){
         str = str.substring(1,str.length);
      }
      var val = parseFloat(str);
      if(isNaN(val))
         return false;
      else
         return true;
   }



 function validateCC(str,type){
      str = strip("-./_\n\r\t\\",str);
      if(type=="1")
         if(str.charAt(0)!="4")
            return false;
      if(type=="2")
         if(str.charAt(0)!="5")
            return false;
      if(type=="3")
         if(str.charAt(0)!="6")
            return false;
      if(type=="4")
         if(str.charAt(0)!="3")
            return false;
      if(validateInteger(str) && 
         ((str.length==15&&type=="4") || 
         str.length==16))
         return true;
      else
         return false;
   }


  function validateDate(str){
      var dateVar = new Date(str);
      if(isNaN(dateVar.valueOf()) || 
         (dateVar.valueOf() ==0))
         return false;
      else
         return true;
   }
   

  function validateEMail(str){
      str = strip(" \n\r\t",str);
      if(str.indexOf("@") > -1 && str.indexOf(".") > -1)
         return true;
      else
         return false;
   }
   
  function validateWords(str){   
       if(countWords(form.comments.value) ==4)
     		return true;
     	else
     		return false;
   }

  
   
   //End Validation Rules
   
  
  //Formatting functions
     
     function formatCC(str,type){
        str = strip("-./_\n\r\t\\",str);
        switch(type){
           case "1": 
              return reformat(str,"",4,"-",4,"-",4,"-",4);
              break;
           case "2": 
              return reformat(str,"",4,"-",4,"-",4,"-",4);
              break;
           case "3": 
              return reformat(str,"",4,"-",4,"-",4,"-",4);
              break;
           case "4":
              return reformat(str,"",4,"-",6,"-",5);
        }
     }
     function formatDate(str,style){
        var dateVar = new Date(str);
        var year = dateVar.getYear();
        if(year<10)
           year += 2000;
        if(year<100)
           year += 1900;
        switch(style){
           case "MM/DD/YY":
	      return (dateVar.getMonth() + 1) + "/" + 
	         dateVar.getDate() + "/" + year;
	      break;
           case "DD/MM/YY":
              return dateVar.getDate() + "/" + 
                (dateVar.getMonth() + 1) + "/" + year;
              break;
           case "Month Day, Year":
              return getMonthName(dateVar) + " " + 
                dateVar.getDate() + ", " + year;
              break;
           case "Day, Month Day, Year":
              return getDayName(dateVar) + ", " + 
                getMonthName(dateVar) + " " + 
                dateVar.getDate() + ", " + year;
              break;
           default:
              return (dateVar.getMonth() + 1) + "/" + 
                dateVar.getDate() + "/" + year;
              break;
        }
     }
     //End Formatting Functions
