    function Validate(f) 
    {   
    
        var ary1 = new Array('Password','Main Site Name','Main Site Url','Email Address','Check Payable To','Address Line 1','City','Zip/Postal Code','State', 'Security Code'); 
        var ary2 = new Array(f.password.value, f.site_name.value, f.site_url.value, f.email.value, f.name_payout.value, f.address_line1.value, f.city.value, f.zip.value,f.state.value, f.tempest_key.value);
        var ary3 = new Array('password','site_name', 'site_url', 'email', 'name_payout', 'address_line1', 'city', 'zip','state', 'tempest_key');
        
    
        //check if all fields are filled
        for(i=0; i<ary2.length; i++) {
            var check1=IsEmpty(ary2[i]);
            if(!check1) {
                alert("The field '"+ ary1[i]+ "' can not be empty." );
                return false;
            }
        }
        
        
        //check if we have a valid email
        var flag=valid_email(ary2[3],ary1[3]);
        if (!flag) 
        {
            alert("invalid email");
            return false;
        }
        
            
        //check that one country has been selected
        var flag=isSelected(f.country);
        if (!flag) 
        {
            alert("Please select a country from the list");
            document.data_form.country.focus();
            return false;
        }
        
        
        //check if we have a valid zip for USA & Canada
        var flag=valid_zip(ary2[7],ary1[7]);
        if (!flag) 
        {
            alert("invalid zip");
            return false;
        }
        
        
        //check that we have a valid password
        var flag=valid_pwd(ary2[0],ary1[0]);
        if (!flag) 
        {
            alert("invalid password");
            return false;
        }
        
        
        //check that webmaster has agreed to terms & conditions
        var flag=f.checkbox_terms.checked;
        if (!flag)
        {
            alert("You must read & agree to the \n Terms & Conditions to continue.");
            f.checkbox_terms.focus();
            return false;
        }
    
        return true;
    }
    
    
    
    function valid_email(val, desc) {
        re=/^[0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,4}$/i;
    
        spaces = / /gi;
        val = val.replace(spaces, "");
        
        if(re.test(val)) 
        {
            return true;
        } 
        else 
        {
            alert("Invalid '"+ desc + "'.\n");
            document.data_form.email.select();
            document.data_form.email.focus();
            return false;
        }
    }
    
    
    
    function valid_pwd(val, desc) 
    {
        re=/^[a-z0-9A-Z]{4,15}$/;
        if(re.test(val)) {
            return true;
        } else {
            alert("Invalid '"+ desc + "',\nShould only contain alphanumeric characters.\nMin 4, max 15"); 
            document.data_form.password.select();
            document.data_form.password.focus();
            return false;
        }
    }
    
    
    
    function valid_zip(val,desc)
    {
        //check for United States
        if (document.data_form.country.options[document.data_form.country.selectedIndex].value == "840")
        {
            if (val.length != 5 && val.length != 9 )
            {
                alert("Invalid '"+ desc + "'.\n");
                document.data_form.zip.select();
                document.data_form.zip.focus();
                return false;
            }
            else
            {
                return true;
            }
        }
        
        //check for Canada
        if (document.data_form.country.options[document.data_form.country.selectedIndex].value == "124")
        {
            regexp=/^([a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}[\s]*[-]*[\.]*[0-9]{1}[a-zA-Z]{1}[0-9]{1}){1}$/i;
            if(regexp.test(val))
            {
                return true;
            }
            else
            {
                alert("Invalid '"+ desc + "'.\n");
                document.data_form.zip.select();
                document.data_form.zip.focus();
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    
    
    
    function IsEmpty(field) 
    {
        if(field=='') 
        {
            return false;
        } 
        else 
        {   
            return true;
        }
    }
    
    
    
    function isSelected(fieldObject)
    {
        if (!fieldObject.options[fieldObject.selectedIndex].value) { return false; }
        else { return true;}
    }
    
    function check_inst()
    {
        var inst_index = window.document.data_form.inst_mess.selectedIndex;
        var inst = window.document.data_form.inst_mess.options[inst_index].value;
        
        if (inst == "NONE")
            window.document.data_form.inst_info.disabled = true;
        else
            window.document.data_form.inst_info.disabled = false;
    
    }
