/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function submit_contractor(form) {
    propersys_id = $('contractor_propersys_id').value;
    email = $('contractor_email').value;
    company = $('contractor_company').value;
    company_no = $('contractor_company_no').value;
    if(form.substr(0, 4)!='edit'){
        same_emails = $('same_emails').value;
        cctypes = 0;
        form_elm = document.getElementById(form);
        for (var i=0; i < form_elm.elements.length; i++) {
            if ((form_elm.elements[i].type == 'checkbox') &&
                (form_elm.elements[i].checked) &&
                (form_elm.elements[i].id == 'contractor[contractor_type_ids][]')) {
                cctypes = cctypes + 1;
            }

            if (same_emails) {
                $('contractor_director_email').value = email;
                $('contractor_po_email').value = email;
            }
            $('contractor_main_office_email').value = email;
        };
        if (cctypes == 0){
            alert('Please select at least one service.')
            return false
        }
        if (cctypes > 5){
            alert('Please choose from up to 5 services, no more than 5.')
            return false
        }
    }
    
    if (company == "") {
        alert('You must include a Company name.')
        return false
    }
    if (company_no == "") {
        alert('You must include a Company Reg. No.')
        return false
    }
    if (propersys_id == "") {
        alert('You must include a propersys id.')
        return false
    }
    $(form).submit();
    
}

function submit_signup(form) {
    email = $('contractor_email').value;
    company = $('contractor_company').value;
    company_no = $('contractor_company_no').value;
    t_c = $('contractor_has_tc').checked;
    cctypes = 0;
    form_elm = document.getElementById(form);
    for (var i=0; i < form_elm.elements.length; i++) {
        if ((form_elm.elements[i].type == 'checkbox') &&
            (form_elm.elements[i].checked) &&
            (form_elm.elements[i].id == 'contractor[contractor_type_ids][]')) {
            cctypes = cctypes + 1;
        }
    };
    if (cctypes == 0){
        alert('Please select at least one service.')
        return false
    }
    if (cctypes > 5){
        alert('Please choose from up to 5 services, no more than 5.')
        return false
    }
    if (company.length < 1) {
        alert('You must include a Company name.')
        return false
    }
    if (company_no.length < 1) {
        alert('You must include a Company Reg. No.')
        return false
    }
    if (!echeck(email)) {
        return false
    }
    if (!t_c ) {
        alert('You must agree the Term & Conditions')
        return false
    }
    $(form).submit();
}
