

        function len(str)
        {
            return String(str).length;
        }
        
        function instr(strSearch, charSearchFor)
        {
            var str = new String();
            str = strSearch;
            return str.lastIndexOf(charSearchFor);
        }

        function mid(str, start, length)
        {
                if (start < 0 || length < 0) return "";
                var iEnd, iLen = String(str).length;
                if (start + length > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + length;

                return String(str).substring(start,iEnd);
        }

        function right(str, n)
        {
            if (n <= 0)     // Invalid bound, return blank string
               return "";
            else if (n > String(str).length)   // Invalid bound, return
               return str;                     // entire string
            else 
            { // Valid bound, return appropriate substring
               var iLen = String(str).length;
               return String(str).substring(iLen, iLen - n);
            }
        }

        function left(str, n)
        {
            if (n <= 0)     // Invalid bound, return blank string
                    return "";
            else if (n > String(str).length)   // Invalid bound, return
                    return str;                // entire string
            else // Valid bound, return appropriate substring
                    return String(str).substring(0,n);
        }


        function trim(str)
        {
            return rtrim(ltrim(str));
        }

        function rtrim(str)
        {
                var whitespace = new String(" \t\n\r");
                var s = new String(str);
                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
                {
                    var i = s.length - 1;       // Get length of string
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;
                    s = s.substring(0, i+1);
                }
                return s;
        }
       function ltrim(str)
        {
            var whitespace = new String(" \t\n\r");
            var s = new String(str);
            if (whitespace.indexOf(s.charAt(0)) != -1) 
            {
                var j=0, i = s.length;
                while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                    j++;
                s = s.substring(j, i);
            }
            return s;
        }
       function strcmp(str1, str2)
       {
         return (str1==str2);
       }
      
      function findDotNetElement(elemName)
       {
            var start, str;
            Obj = getElementsByClassName('*')
            for(var i=0; i<Obj.length;i++)
            {
                if (Obj[i].type=='textarea' || Obj[i].type=='text' || Obj[i].type=='password' || Obj[i].type=='file')
                {
                    start = instr(Obj[i].name.toString(), ('$' + elemName).toString());
                    if (start >= 0)
                    {
                        return Obj[i];
                    }
                }
            }
            
            for(var i=0; i<Obj.length;i++)
            {
                if (Obj[i].type=='textarea' || Obj[i].type=='text' || Obj[i].type=='password' || Obj[i].type=='file')
                    if (Obj[i].name.toString()==elemName) return Obj[i];
            }
            return null;
       }
       function areNotSimilar(DNelem1, DNelem2)
       {
            var elem1 = findDotNetElement(DNelem1);
            var elem2 = findDotNetElement(DNelem2);
            return strcmp(elem1.value==elem2.value);
       }
               
       function getElementsByClassName(strTagName, strClassName)
       {
            var arrElements = (strTagName == "*" && document.all)? document.all : document.getElementsByTagName(strTagName);
            var arrReturnElements = new Array();
            if (strClassName)
            {
                strClassName = strClassName.replace(/\-/g, "\\-");
                var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
                var oElement;
                for(var i=0; i<arrElements.length; i++)
                {
                    oElement = arrElements[i];      
                    if(oRegExp.test(oElement.className))
                    {
                        arrReturnElements.push(oElement);
                    }   
                }
            }
            else
            {
                var oElement;
                for(var i=0; i<arrElements.length; i++)
                {
                    oElement = arrElements[i];      
                    arrReturnElements.push(oElement);
                }
            }            
            
            return (arrReturnElements)
        }
        function validateAll(className)
        {
            var docObj;
            Obj = getElementsByClassName('*',className)
            for(var i=0; i<Obj.length;i++)
            {
                if (Obj[i].type=='textarea' && Obj[i].className==className && Obj[i].value=="") return Obj[i];
                if (Obj[i].type=='text' && Obj[i].className==className && Obj[i].value=="") return Obj[i];
                if (Obj[i].type=='password' && Obj[i].className==className&& Obj[i].value=="") return Obj[i];
                if (Obj[i].type=='hidden' && Obj[i].className==className && Obj[i].value=="") return Obj[i];
                if (Obj[i].type=='select-one' && Obj[i].className==className && Obj[i].value=="") return Obj[i];
                if (Obj[i].type=='select-multiple' && Obj[i].className==className && Obj[i].value=="") return Obj[i];
                if (Obj[i].type=='radio' && Obj[i].className==className && Obj[i].checked==false) return Obj[i];
                if (Obj[i].type=='checkbox' && Obj[i].className==className && Obj[i].checked==false) return Obj[i];
            }
            return null;
        }
        function Alert(msg)
        {
            alert("Firsthips alert\n-------------------------------------------------------------------------\n\n" + msg);            
        }

        function checkPostCode(toCheck) 
        {
          // Permitted letters depend upon their position in the postcode.
          var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
          var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
          var alpha3 = "[abcdefghjkstuw]";                                // Character 3
          var alpha4 = "[abehmnprvwxy]";                                  // Character 4
          var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
      

          // Array holds the regular expressions for the valid postcodes
          var pcexp = new Array ();

          // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
          pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
          
          // Expression for postcodes: ANA NAA
          pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

          // Expression for postcodes: AANA  NAA
          pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
          
          // Exception for the special postcode GIR 0AA
          pcexp.push (/^(GIR)(\s*)(0AA)$/i);
          
          // Standard BFPO numbers
          pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
          
          // c/o BFPO numbers
          pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

          // Load up the string to check
          var postCode = toCheck;

          // Assume we're not going to find a valid postcode
          var valid = false;
          
          // Check the string against the types of post codes
          for ( var i=0; i<pcexp.length; i++) {
            if (pcexp[i].test(postCode)) {
            
              // The post code is valid - split the post code into component parts
              pcexp[i].exec(postCode);
              
              // Copy it back into the original string, converting it to uppercase and
              // inserting a space between the inward and outward codes
              postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
              
              // If it is a BFPO c/o type postcode, tidy up the "c/o" part
              postCode = postCode.replace (/C\/O\s*/,"c/o ");
              
              // Load new postcode back into the form element
              valid = true;
              
              // Remember that we have found that the code is valid and break from loop
              break;
            }
          }
          
          // Return with either the reformatted valid postcode or the original invalid 
          // postcode
          if (valid) {return postCode;} else return false;
        }
        
        //***********************************************
         function emailCheck(emailStr) 
         {
          var emailPat=/^(.+)@(.+)$/
          var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
          var validChars="\[^\\s" + specialChars + "\]"
          var quotedUser="(\"[^\"]*\")"
          var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
          var atom=validChars + '+'
          var word="(" + atom + "|" + quotedUser + ")"
          var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
          var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
          var matchArray=emailStr.match(emailPat)
          if (matchArray==null) 
          {
            Alert("Invalid email address entered, please check use of @ and .");
            return false;
          }
          
          var user=matchArray[1]
          var domain=matchArray[2]
          
          if (user.match(userPat)==null) 
          {
            Alert("The email address you have entered is not valid, please check the first part of it");
            return false;
          }
          var IPArray=domain.match(ipDomainPat)
          if (IPArray!=null) {
             // this is an IP address
            for (var i=1;i<=4;i++) {
              if (IPArray[i]>255) 
              {
                Alert("The email address you have entered is not valid, please check Destination IP");
                return false;
              }
             }
             return true;
          }
          var domainArray=domain.match(domainPat)
          if (domainArray==null) 
          {
            Alert("The email address you have entered is not valid, please check the domain name");
            return false;
          }
          var atomPat=new RegExp(atom,"g")
          var domArr=domain.match(atomPat)
          var len=domArr.length
          if (domArr[domArr.length-1].length<2 || 
             domArr[domArr.length-1].length>6) 
             {
                Alert("The email address you have entered is not valid,\nthe last part of the address must not have more than a six-letter domain");
                return false;
            }
          if (len<2) 
          {
            var errStr="The email address you have entered is not valid, this address is missing a hostname!"
            Alert(errStr);
            return false;
          }
         return true;
         }
        function ApplyStuff()
        {
            var Obj = getElementsByClassName("*", "*");
            for(var i=0; i<Obj.length; i++)
            {
                if(Obj[i].type=='textarea' || Obj[i].type=='text' || Obj[i].type=='password' || Obj[i].type=='select-one' || Obj[i].type=='select-multiple')
                {
                    Obj[i].onchange=onEventChange;
                }   
                else if(Obj[i].type=='checkbox' || Obj[i].type=='radio')
                {
                    Obj[i].onclick=onEventChange;
                }
            }
            
            
        }
        function doApplyValidate()
        {
            return(doValidate('G'));
        }
        function onEventChange()
        {
            var Obj = getElementsByClassName("*", "XP");
            for(var i=0; i<Obj.length; i++)
            {
                start = instr(Obj[i].name.toString(), ('$Apply').toString());
                if (start >= 0)
                {
                    Obj[i].disabled=false;
                    Obj[i].onclick=doApplyValidate;
                }
            }
        }
       function checkTextAreaMaxLength(elemName, maxlength)
       {
            var str = new String();
            var obj = findDotNetElement(elemName);
            if (obj!=null)
            {
                str = obj.value.toString();
                if (str.length > maxlength)
                    return false;
            }
            return true;
       }
       function disableButton(buttonID) 
       {
            document.getElementById(buttonID).value='Please wait...';
            document.getElementById(buttonID).disabled=true;
       }    
        
        function voidValidate(obj, flag)
        {
            if (flag==false)
                document.getElementById(obj.id).form.submit();
            window.setTimeout("disableButton('" + obj.id + "')", 0);
            return true;
        }
        
        //this works against ALL checkboxes on the page
        function isCheckboxClicked()
        {
          for (i=0,n=document.forms[0].elements.length;i<n;i++)
          {
             if (document.forms[0].elements[i].type=="checkbox" !=-1)
             {
                if (document.forms[0].elements[i].checked==true)
                {
                    return true;
                }
             }
          }
          return false;
        } 
        
        
        function ValidateUKTelephone(strValue)
        {
            var objRegExp = /^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/;
            return objRegExp.test(strValue);
        }

       // function ValidateURL(strValue)
       // {
       //     var objRegExp = /^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|gov|net|org|biz|info|name|us|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/;
       //     return objRegExp.test(strValue);
       // }
   
        
        
        
        
        
        //-->