

lochash = "reject_anchor";

SEL=10;
CHK=20;
RAD=30;
EML=40;
FIL=50;
TXT=60;
INP=70;
REQ=110;
OPT=120;

// Validation specifications (length, type, required/optional)
fields = new Array();
fields["wanted_flag"] = [1 , RAD, REQ];
fields["title"] = [50 , INP, REQ];
fields["price"] = [30 , INP, REQ];
fields["currency_code"] = [ 3, SEL, REQ];
fields["town"] = [ 50, INP, REQ];
fields["country_id"] = [ 3, SEL, REQ];
fields["highlight_id"] = [ 2, RAD, REQ];
fields["payment_type_id"] = [ 2, SEL, OPT];
fields["client_comments"] = [ 100, INP, OPT]; 
fields["description"] = [ 2500, TXT, REQ];
fields["item_condition"] = [ 500, TXT, REQ];
fields["display_name"] = [ 100, INP, REQ];
fields["display_email"] = [ 100, EML, REQ];
fields["display_address"] = [ 500, TXT, OPT]; 
fields["display_comments"] = [ 500, TXT, OPT]; 
fields["contact_company"] = [ 100, INP, REQ]; 
fields["contact_address"] = [ 255, INP, REQ]; 
fields["contact_phone"] = [ 100, INP, REQ]; 
fields["contact_email"] = [ 100 , INP, REQ];
fields["contact_fax"] = [ 100 , INP, OPT];
fields["contact_fullname"] = [ INP , TXT, REQ];
fields["purchase_order_num"] = [ 100, TXT, OPT];
fields["signature_flag"] = [ 1 , CHK, REQ];
fields["where_heard_id"] = [ 2 , SEL, REQ];
fields["optin_flag"] = [ 1 , RAD, REQ];
fields["terms_flag"] = [ 1 , RAD, REQ];

function checkForm()
{
    // disabling client-side validation till I can test cross-browser
    return true;
    if(radioValue('highlight_id') != 0)
    {
        fields['payment_type_id'][2] = REQ;
    }
    
    // validate (and format text)
    reject = new Array();
    body = "";
    for(name in fields)
    {
        //alert(name);
        valid = fields[name];
        
        mylabel = document.getElementById(name+"_label");
        if(mylabel.className.indexOf('rejected')!=-1)
        {
            mylabel.className = mylabel.className.replace("rejected","");
        }
        
        switch (valid[1])
        {
            
            case SEL:
                if(selectValue(name) == "" && valid[2]==REQ)
                {
                    
                    reject.push(name);
                    break;
                }
                else 
                    break;
            case CHK:
                if(checkboxValue(name) == false && valid[2]==REQ)
                {
                    reject.push(name);
                    break; 
                }
                else 
                    break;
            case RAD:
                if(radioValue(name) == null && valid[2]==REQ)
                {
                    reject.push(name);
                    break;
                }
                else 
                    break;
            case TXT:
                value = trim(textValue(name));
                if(value.length == 0 && valid[2]==REQ)
                { 
                    reject.push(name);
                    break;
                }
                if(value.length > valid[0])
                {
                    value = value.substr(0,valid[0]);
                    setTextValue(name,value);
                    reject.push(name);
                    break; 
                }
                break;
            case INP:
                value = trim(inputValue(name))
                if(value.length == 0 && valid[2]==REQ)
                {
                    reject.push(name);
                    break;
                }
                else
                    break;
                
            case EML:
                if(validEmail(inputValue(name)))
                {
                    break;
                }
                else
                {
                    reject.push(name);
                    break;
                }
        }
    
    }
    
    // special condition
    if(radioValue('terms_flag') != 1)
    {
        reject.push('terms_flag');
    }
    if(reject.length > 0)
    {
        for(i = 0;i < reject.length; ++i)
        {
            mylabel = document.getElementById(reject[i]+"_label");
            mylabel.className = mylabel.className + " rejected";
        }
        document.getElementById('reject_message').style.display = 'block';
        if(lochash == "reject_anchor")
        {
            lochash = "reject_anchor1";
            location.hash = "reject_anchor1";
        }
        else
        {
            lochash = "reject_anchor";
            location.hash = "reject_anchor";
        }
        return false;
    }
    else
    {
        return true;
    }



}
