function validate_launch(form){
    if(trim(form.fname.value)==""){
        form.fname.focus();
        alert("Please enter your first name");
        return;
    }
    if(trim(form.lname.value)==""){
        form.lname.focus();
        alert("Please enter your last name");
        return;
    }
    if(trim(form.company.value)==""){
        form.company.focus();
        alert("Please enter your company");
        return;
    }
    if(trim(form.jobTitle.value)==""){
        form.jobTitle.focus();
        alert("Please enter your job title");
        return;
    }
	    if(trim(form.telephone.value)==""){
        form.telephone.focus();
        alert("Please enter your contact telephone number");
        return;
    }
    if(trim(form.email.value)==""){
        form.email.focus();
        alert("Please enter your email");
        return;
    }
    if(!validateEmail(form.email.value,1,1)){
        return;
    }
/*    if(trim(form.country.value)==""){
        form.country.focus();
        alert("Please enter your country");
        return;
    }

    form.fname.value = escape(trim(form.fname.value));
    form.lname.value = escape(trim(form.lname.value));
    form.company.value = escape(trim(form.company.value));
    form.jobTitle.value = escape(trim(form.jobTitle.value));
    form.email.value = escape(trim(form.email.value));
    form.country.value = escape(trim(form.country.value));
*/
    form.fname.value = trim(form.fname.value);
    form.lname.value = trim(form.lname.value);
    form.company.value = trim(form.company.value);
    form.jobTitle.value = trim(form.jobTitle.value);
	form.telephone.value = trim(form.telephone.value);
    form.email.value = trim(form.email.value);
//    form.country.value = trim(form.country.value);
    form.country.value = form.common_country.options[form.common_country.selectedIndex].value;

    form.submit();
}

function validate_audit(form){
    if(trim(form.fname.value)==""){
        form.fname.focus();
        alert("Please enter your first name");
        return;
    }
    if(trim(form.lname.value)==""){
        form.lname.focus();
        alert("Please enter your last name");
        return;
    }
    if(trim(form.company.value)==""){
        form.company.focus();
        alert("Please enter your company");
        return;
    }
    if(trim(form.jobTitle.value)==""){
        form.jobTitle.focus();
        alert("Please enter your job title");
        return;
    }
    if(trim(form.email.value)==""){
        form.email.focus();
        alert("Please enter your email");
        return;
    }
    if(!validateEmail(form.email.value,1,1)){
        return;
    }

/*  form.fname.value = escape(trim(form.fname.value));
    form.lname.value = escape(trim(form.lname.value));
    form.company.value = escape(trim(form.company.value));
    form.jobTitle.value = escape(trim(form.jobTitle.value));
    form.email.value = escape(trim(form.email.value));
    form.country.value = escape(trim(form.country.value));
*/
    form.fname.value = trim(form.fname.value);
    form.lname.value = trim(form.lname.value);
    form.company.value = trim(form.company.value);
    form.jobTitle.value = trim(form.jobTitle.value);
    form.email.value = trim(form.email.value);
//    form.country.value = trim(form.country.value);
    form.country.value = form.common_country.options[form.common_country.selectedIndex].value;

    form.submit();
}

function validate_login(form){
    form.username.value = trim(form.username.value);
    form.password.value = trim(form.password.value);

    if(trim(form.username.value)==""){
        form.username.focus();
        alert("Please enter your Username");
        return;
    }
    if(trim(form.password.value)==""){
        form.password.focus();
        alert("Please enter your Password");
        return;
    }
//    form.login.disabled = true;
    form.submit();
}



function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function validateEmail(addr,man,db) {
    if (addr == '' && man) {
       if (db) alert('email address is mandatory');
       return false;
    }
    if (addr == '') return true;
    var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
    for (i=0; i<invalidChars.length; i++) {
       if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
          if (db) alert('email address contains invalid characters');
          return false;
       }
    }
    for (i=0; i<addr.length; i++) {
       if (addr.charCodeAt(i)>127) {
          if (db) alert("email address contains non ascii characters.");
          return false;
       }
    }

    var atPos = addr.indexOf('@',0);
    if (atPos == -1) {
       if (db) alert('email address must contain an @');
       return false;
    }
    if (atPos == 0) {
       if (db) alert('email address must not start with @');
       return false;
    }
    if (addr.indexOf('@', atPos + 1) > - 1) {
       if (db) alert('email address must contain only one @');
       return false;
    }
    if (addr.indexOf('.', atPos) == -1) {
       if (db) alert('email address must contain a period in the domain name');
       return false;
    }
    if (addr.indexOf('@.',0) != -1) {
       if (db) alert('period must not immediately follow @ in email address');
       return false;
    }
    if (addr.indexOf('.@',0) != -1){
       if (db) alert('period must not immediately precede @ in email address');
       return false;
    }
    if (addr.indexOf('..',0) != -1) {
       if (db) alert('two periods must not be adjacent in email address');
       return false;
    }
    var suffix = addr.substring(addr.lastIndexOf('.')+1);
    if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
       if (db) alert('invalid primary domain in email address');
       return false;
    }
    return true;
}
