<!--
function trim(strText) { 
    while (strText.substring(0,1) == ' ') {
        strText = strText.substring(1, strText.length);
    }
    while (strText.substring(strText.length-1,strText.length) == ' ') {
        strText = strText.substring(0, strText.length-1);
    }
   return strText;
} 

function complete (aElement, aWindow) {
    for (var i=0; i < aWindow.required.length; i++) {
		if (aWindow.required[i][0] == aElement.name) {
			if(aElement.name=="vatno"){
				alert("We can only accept loads from companies with a VAT registration")
			}
			else{
				alert('Please complete the "' + aWindow.required[i][1] + '" field')
			}
			aElement.focus();
			return false;
		}
    }
}

function checkForm(aWindow) {
	//second form on page as login is forms[0]
    var e = trim(aWindow.document.forms[1].elements['email'].value.toString().toLowerCase());
    if(aWindow.document.forms[1].elements['terms_yes']){
		var f = aWindow.document.forms[1].elements['terms_yes'].checked;
	}
	else{
		f = true
	}
    var charStrg = 'abcdefghijklmnopqrstuvwxyz';
    var atPos = e.indexOf('@');
    var email = false;

    if (atPos > -1) {
        if (charStrg.lastIndexOf(e.substr(e.length-1, 1)) > -1 
	    && charStrg.lastIndexOf(e.substr(e.length-2, 1)) > -1 ) {
            if ((e.lastIndexOf('.') - atPos) > 1 ) {
                email = true;
            }
        }
    }
    
    if ( email == false ) {
        alert('Please enter a valid email address');
        aWindow.document.forms[1]['email'].focus();
        return false;
    }

    if ( !f ) {
        alert('Please read our terms and conditions');
        aWindow.document.forms[1]['terms_yes'].focus();
        email = false;
        return false;
    }
    
    if ( email == true ) {
        for (var i=0; i < aWindow.required.length; i++ ) {
            var aElement = eval('aWindow.document.forms[1][\'' + aWindow.required[i][0] + '\']');
            if ( aElement.type == 'text' && aElement.value == '' ) {
                return complete(aElement, aWindow);
            }
            if ( aElement.type == 'select-one' && aElement.selectedIndex == 0 ) {
                return complete(aElement, aWindow);
            }
            if ( aElement.type == 'textarea' && aElement.value == '' ) {
                return complete(aElement, aWindow);
            }
        }
    } 
    
    return email;
}

//-->