<!--            
// Copyright 1999-2001 Electronic Mind Ltd. All rights reserved
var field_names=new Array("email","E-mail","link","Url/Web address","title","Title","subject","Subject","idnum","ID number","password","Password","password2","Repeat password","st","Search text","address","Address","postcode","Post code","tel","Telephone number");
var alert_message1= "I can not proceed because the form contains errors, as indicated below.\n\n" ;
var alert_message2= "Missing/unselected fields:\n" ;
var alert_message3= "Incorrect/invalid fields:\n" ;
var alert_message4= "Overly large fields:\n" ;
var alert_message9= "Please correct your entry and re-submit the form." ;
var im1= "   Passwords must be between 6 and 20 letters in length.\n" ;
var im2= "   You must select EITHER a particular week day OR certain date(s).\n" ; // no longer used
var im3= "   The start date must be before the end date.\n" ;
var im4= "   The startdate must be entered as well as the end date.\n" ;
var im5= "   You must, at least, select a category or enter some search text.\n" ;
var im6= "   If you enter a link you must also supply a description.\n" ;
var im7= "   The year is not acceptable.\n" ;
var im8= "   A numeric field contains an invalid value. Please enter an integer value.\n" ;
var im9= "   A numeric field contains an invalid value. Please enter a decimal value.\n" ;
var t_error = 0;
var submit_flag=0;
var submit_alert="The form has been submitted. Please wait for a reply" ;

function validate_form(form,submitcount)
{
//      return (true); 
//to test if CGI checks o.k.
//   alert (rf[0]+','+rf[1]+','+rf[2]+','+rf[3]) ;
   if ( submit_flag == 1 && submitcount!=0)
   {
      alert (submit_alert) ;
      return (false);
   }
   // non IE browsers will be cheked by CGI routine to save this file being too big.
   if (navigator.userAgent.toLowerCase().indexOf("msie") == -1) return (true); 


   var reqs=new Array();
   for (var j=0; j <rf.length; j++)
   {
      reqs[j] =rf[j] ;
   }
   
   var message = "";
   var err_message = "";
   var m_f = "";
   var i_f = "";
   var l_f = "";
   var f_val="";
   flen = form.elements.length - 1;
   for (var i = 0; i <= flen; i++)
   {
      //alert (form.elements[i].name+'-'+form.elements[i].type) ;
      // first clean up the text fields and remove unnecessary junk
      f_val=form.elements[i].value ;


      if (f_val!="" && (form.elements[i].type=='text' || form.elements[i].type=='textarea'))
      {
         f_val=clean_up(f_val) ;
         form.elements[i].value=f_val ;
      }

      // next get the fields that are required and check that they have been filled in
      for (var j=0; j <reqs.length; j++)
      {
         if (reqs[j]!="")
         {
            if (form.elements[i].name == reqs[j] && form.elements[i].name != "")
            {
                //check that at least one of the check boxes or radio buttons has been filled in
                if (form.elements[i].type == "radio" || form.elements[i].type == "checkbox")
                {
                  if (form.elements[i].checked == true) reqs[j] = "";
                }
                else
                {
                   if (f_val!="")  reqs[j] = "";
                }
            }
         }
      }
      //now we check to see if any of the fields are not valid
      
      //start with e-mails
      if ( ((form.elements[i].name == "email" ) || (form.elements[i].name == "mailto" ) || (form.elements[i].name == "mailfrom" ))
           && f_val !="")  i_f = i_f + check_email(f_val,form.elements[i].name) ;
      //check url
      if (form.elements[i].name == "link" && f_val !="") i_f = i_f + check_url(f_val) ;
      //check postcode // taken out 
      //if (form.elements[i].name == "postcode" && f_val !="") i_f = i_f + check_postcode(form.elements[i].value) ;
      //check idnum
      if (form.elements[i].name == "idnum" && f_val !="") i_f = i_f + check_idnum(form.elements[i].value) ;
 
      //check passwords have enough letters
      if ((form.elements[i].name == "oldpassword" || form.elements[i].name == "password" || form.elements[i].name == "password2")&& f_val !="") i_f = i_f + check_pwlen(form.elements[i].value) ;

      //then we check the specific fields
      
      // Check that passwords match
      if (form.elements[i].name == "password2" && f_val !="") i_f = i_f + check_pw(form.elements.password.value,form.elements.password2.value) ;

      //And finally we check the specific fields in the "ec" array and perform necesary operations e.g. warning of long fields
      for (var j=0; j <ec.length; j+=3)
      {
        if (form.elements[i].name == ec[j])
        {
            if (ec[j+1] =="0") l_f = l_f + check_max_length(form.elements[i].value,eval(ec[j+2]),ec[j],"") ;
            if (ec[j+1] =="1") // will do this this only once when it gets to startday
            {
               //first check that the dates are valid
               if (f_val !="")
               {
                  i_f = i_f + check_valid_date(form.startday.value,form.startmonth.value,form.startyear.value,'startdate') ;
                  if (form.endday.value !="") i_f = i_f + check_valid_date(form.endday.value,form.endmonth.value,form.endyear.value,'enddate') ;
               }
               //then check that either dates or a week day has been entered
               //if (form.weekday.value !="" && (f_val !="" || form.endday.value !="")) 
               //   i_f = i_f +im2 ;
               //now check that the start date is before the end date
               if (form.startday.value !="" && form.endday.value !="")
               {
                  var xdate1=form.startyear.value ;
                  if (form.startmonth.value <10) xdate1=xdate1+'0' ;
                  xdate1=xdate1+ form.startmonth.value  ;
                  if (form.startday.value <10) xdate1=xdate1+'0' ;
                  xdate1=xdate1+ form.startday.value  ;
                  var xdate2=form.endyear.value ;
                  if (form.endmonth.value <10) xdate2=xdate2+'0' ;
                  xdate2=xdate2+ form.endmonth.value  ;
                  if (form.endday.value <10) xdate2=xdate2+'0' ;
                  xdate2=xdate2+ form.endday.value  ;
                  if (xdate1 > xdate2) i_f = i_f +im3 ;
               }
               //now check that the start date is is entered if the end date is entered
               if (form.startday.value =="" && form.endday.value !="") 
                  i_f = i_f +im4 ;
            }
            if ( (ec[j+1] =="2") && (form.st.value =="" && form.c.value =="") ) i_f = i_f + im5 ;      
            if ( (ec[j+1] =="3") && // non cascading version - just in case they run it with javascript
            ( form.jobA.value !="" || form.jobC.value !="" || form.jobE.value !="" || form.jobG.value !="" || 
              form.jobH.value !="" || form.jobJ.value !="" || form.jobK.value !="" || form.jobL.value !="" || 
              form.jobM.value !="" || form.jobP.value !="" || form.jobR.value !="" )) reqs[2]="";
//            if ( (ec[j+1] =="5") && // non cascading version - just in case they run it with javascript
//            ( form.C.value !="" || form.E.value !="" || form.F.value !="" || form.G.value !="" || 
//              form.H.value !="" || form.I.value !="" || form.K.value !="" || form.L.value !="" || 
//              form.M.value !="" || form.N.value !="" || form.P.value !="" || form.Q.value !="" || 
//              form.R.value !="" || form.S.value !="")) reqs[2]="";
            if ( (ec[j+1] =="6") && 
            ( form.link.value !="" && form.linkdesc.value =="" )) i_f = i_f +im6;
            if ( (ec[j+1] =="7") && ( form.year.value !="" && (form.year.value <"1900" || form.year.value > "2009")) ) i_f = i_f +im7;
            if ( (ec[j+1] =="8") && ( form.elements[i].value !="" && c_integer(form.elements[i].value)=='1') ) i_f = i_f +im8;
            if ( (ec[j+1] =="9") && ( form.elements[i].value !="" && c_float(form.elements[i].value )=='1') ) i_f = i_f +im9;
        }
      }
   }
   // end of main loop (i)


//   alert (reqs[0]+','+reqs[1]+','+reqs[2]+','+reqs[3]) ;

   
   //now see if anything left in the required string
   for (var j=0; j <reqs.length; j++)
   {
      if (reqs[j] != "")  m_f = m_f +name_get(reqs[j]) + "\n" ;
      
   }

   if (m_f != "") message = "_____________________________\n" +message + alert_message2 + m_f + "\n" ;
   if (i_f != "") message = message + alert_message3 + i_f + "\n" ;
   if (l_f != "") message = message + alert_message4 + l_f + "\n" ;
   
   
   
   
   if (message > "")
   {
      alert(alert_message1 + message +"_____________________________\n\n\n" + alert_message9)
      return (false);
   }
   else
   {
//    alert ("ok") ;
    submit_flag = 1 ;
    return (true);
//      form.submit()
   }
}



// VALIDATION FUNCTIONS ////////////////////////////////////////////////////////


function check_email(mytext,myname)
{
   t_error=0;
   at_pos=mytext.indexOf('@',0) ;
   if (at_pos < 3) t_error=1;
   dot_pos= mytext.indexOf('.',at_pos) ;
   dot_pos2= mytext.lastIndexOf('.',at_pos) ;
   if (dot_pos == -1) t_error=1;
   if (mytext.length-dot_pos2<2 || mytext.length-at_pos<6) t_error=1;
   if (t_error ==0) t_error=validchars(mytext,'-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz')
   //for (var j=0;j<mytext.length;j++)
   //{
   //   var c=mytext.substring(j,j+1)
   //   if (!((c>="A" && c<="Z")||(c>="a" && c<="z")||(c>="0" && c<="9")||(c=="@")||(c==".")||(c=="_")||(c=="-")||(c=="[")||(c=="]"))) t_error=1;
   //}
//   if (t_error ==1) return (name_get('email') + "\n"); else return("") ;
   if (t_error ==1) return (name_get(myname) + "\n"); else return("") ;
}   

function check_url(mytext)
{
   t_error=0;
   mytext = mytext.toLowerCase();
   www_pos=mytext.indexOf('www',0) ;
   dot_pos=mytext.indexOf('.',www_pos) ;
   dot_pos2= mytext.lastIndexOf ('.', www_pos) ;
   if (dot_pos == -1) t_error = 1;
   if (mytext.length-dot_pos2 <2 || mytext.length-www_pos <6) t_error = 1;
   if (t_error ==0) t_error=validchars(mytext,'-./0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]_abcdefghijklmnopqrstuvwxyz~\?=')

   //for (var j=0;j<mytext.length;j++)
   //{
   //   var c = mytext.substring(j,j+1)
   //   if (!((c>="A" && c<="Z")||(c>="a" && c<="z")||(c>="0" && c<="9")||(c==":")||(c=="\\")||(c=="/")||(c==".")||(c=="_")||(c=="-")||(c=="[")||(c=="]"))) t_error=1;
   //}
   if (t_error ==1) return (name_get('url') + "\n"); else return("") ;
} 

function check_idnum(mytext)
{
   t_error=0;
   t_error=c_integer(mytext) ;
   if (mytext.length !=7) t_error = 1;
   if (t_error ==1) return (name_get('idnum') + "\n"); else return("") ;
}  

function check_filename(mytext)
{
   t_error=validchars(mytext,'-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\\_abcdefghijklmnopqrstuvwxyz')
   if (t_error ==1) return (name_get('filename') + "\n"); else return("") ;
}  


function check_postcode(mytext)
{
   mytext = mytext.toUpperCase();
   t_error=validchars(mytext,' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
   if (mytext.length<6 || mytext.length>8)t_error=1;
   var s_pos1=mytext.indexOf(' ',0) ;
   var s_pos2=mytext.indexOf(' ',s_pos1+1) ;
   if ((s_pos2>0)||s_pos1<2||s_pos1>4)t_error=1;// can only have one space character at the second or thirs position

//   alert (mytext);
   if (t_error==1) return(name_get('postcode')+"\n");else return("");
}  

function check_max_length(mytext,maxsize,fieldname,ac)
{
   t_error=0;
   if (mytext.length>maxsize)
      if (ac!="") mytext=mytext.substring(0,maxsize);else t_error=1;
   if (t_error==1) return (name_get(fieldname)+"\n");else return("");
}


function check_pw(pw1,pw2)
{
   if (pw1 !="" && pw1 !=pw2) return (name_get('password2') + "\n"); else return("") ;
}


function check_pwlen(mytext)
{
   t_error=0;
   if (mytext.length <6 || mytext.length >20) t_error = 1;
   if (t_error ==1) return (im1); else return("") ;
}  


function check_valid_date(day,month,year,fieldname)
{
   t_error=0;
   if (month < 1 || month > 12) t_error = 1;
   if (day < 1 || day > 31) t_error = 1;
   if ((month==4 || month==6 || month==9 || month==11) && day==31) t_error = 1;
   if (month == 2)
   { 
      if (day>29) t_error = 1;
      if (day==29 && !(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))) t_error = 1;
   }
   if (t_error ==1) return (name_get(fieldname) + "\n"); else return("") ;
}

function check_valid_year(year,fieldname,minyear,maxyear)
{
   t_error=0;
   if (!c_integer(year)) t_error = 1;
   if (t_error == 0) if (year<minyear ||  year>maxyear ) t_error = 1;
   if (t_error ==1) return (name_get(fieldname) + "\n"); else return("") ;
}

//function check_prof_search(mytext1,mytext2)
//{
//   t_error=0;
//   if (mytext1.length <1 && mytext2.length <1) t_error = 1;
//   if (t_error ==1) return (im5); else return("") ;
//}  



// AUXILARY FUNCTIONS //////////////////////////////////////////////////////////

function name_get(fieldname)
{
   for (var j=0;j<field_names.length;j=j+2)if (fieldname==field_names[j]) return ('   '+field_names[j+1]); 
   // now we can repeat above for fields that are called different names in diferent places e.g. category
   for (var j=0;j<en.length;j=j+2)if (fieldname==en[j]) return ('   '+en[j+1]);
   //if all else fails return the fieldname itself
   return ('   '+fieldname);
}

function validchars(mytext,charset)
{
   var t_res="" ;
   for (var j=0;j<mytext.length;j++) if (charset.indexOf(mytext.substring(j,j+1),0)==-1) t_res=1;
   return(t_res) ;
}

//  str = ' !"#$%&' + "'" + '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
//function c_alpha(mytext){return validchars(mytext,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')}
//function c_alphanum(mytext){return validchars(mytext,'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')}
function c_integer(mytext){return validchars(mytext,'0123456789')}
function c_float(mytext){return validchars(mytext,'0123456789.')}
//function c_currency(mytext){return validchars(mytext,'0123456789,.£$')}




// FORM CLEANING UP FUNCTIONS //////////////////////////////////////////////////


function clean_up(mytext)
{
   var t_text="" ;
   var t_end=0 ;
   var t_len=0 ;

   //trim leading spaces
   mytext.substring(0,1)
   while(mytext.substring(0,1)==' ')mytext=mytext.substring(1,mytext.length);
   //trim trailing  spaces
   while(''+mytext.charAt(mytext.length-1)==' ')mytext=mytext.substring(0,mytext.length-1);

   //remove HTML tags
   var t_start=mytext.indexOf("<",0);
   while(t_start>-1)
   {
      t_end =mytext.indexOf(">",t_start);
      if (t_end==-1) t_end=mytext.length;
      mytext=mytext.substring(0,t_start)+mytext.substring(t_end+1,mytext.length) ;
      t_start=mytext.indexOf("<",t_end);
   }
   
   //remove profanity
   //string will be in another file and the array sorting will be done once
   //this needs to be modified to cope with things such as "essex"; possible in second string containing words which can be part of another.
   var pt="sex,babes,shit,fuck off,fuck,damn,porno,cum,cunt,prick,pecker,";
    +"asshole,pedophile,man-boy,man/boy,dong,twat,";
   censored_string ="xxxxxxxxxxxxxxxxxxxxxxxx";
   t_start=pt.indexOf(",",0);
   while(t_start>-1)
   {
      t_end =pt.indexOf(",",t_start+1);
      if (t_end==-1) t_end=pt.length;
      t_len=t_end-t_start-1;
      t_text=pt.substring(t_start+1,t_end);
      var pt_in =mytext.indexOf(t_text,0);
      while (pt_in>-1 && t_text!="")
      {
         mytext=mytext.substring(0,pt_in)+censored_string.substring(0,t_len)+mytext.substring(pt_in+t_len,mytext.length);
         pt_in =mytext.indexOf(t_text,0);
      }
      t_start=pt.indexOf(",",t_end);
   }
   //alert ("="+mytext+"=") ;
   return(mytext) ;
}   

//##########################################################################################
//##########################################################################################

function ascii(mychar)
{
   var charset = ' !"#$%&' + "'" + '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
   var x=charset.indexOf(mychar,0);
   if (x!=-1) return(x+32); else return(0);
}
//-->