/*
 * author: G.Sundari Shree
 * Date: 01/21/2011
 */


function validateNewsLetterFormOnSubmit() {
theForm = document.getElementById("newsLetterFormId");

var reason = "";
reason = validateEmail(theForm.email);

if (reason != "") {
    alert(reason);
    return false;
  }else{
    return true;
  }
}

function validateEmail(fld) {

    var error="";
    
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
   
    if (fld.value == "") {
        fld.style.background = '#fbc1a4';
        error = "Enter an email address.\n";
    } else if (!emailFilter.test(tfld)) { //test email for illegal characters
           fld.style.background = '#fbc1a4';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#fbc1a4';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }

  
   return error;
}

function trim(stringToTrim) {
 return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function clickEmailText(str,textbox){

    //alert(str);
    if(str == "Your Email"){
        textbox.value = "";
       // textbox.style.color ='#000';

    }

}

function initEmailText(str,textbox){

    //alert(str);
    if(str == ""){
        textbox.value = "Your Email";
       // textbox.style.color ='#000';

    }

}



function validateNewsLetterTestSubmit() {
theForm = document.getElementById("newsLetterTestFormId");
var reason = "";
reason += validateEmail(theForm.email);

if (reason != "") {
    alert(reason);
    return false;
  }else{
    return true;
  }
}



function validateNewsLetterUploadSubmit() {
theForm = document.getElementById("newsLetterUploadFormId");

var reason = "";
reason += validateSubject(theForm.subject);
reason += validateFile(theForm.file);
if (reason != "") {
    alert(reason);
    return false;
  }else{
    return true;
  }
}

function validateSubject(fld) {

    var error="";

    if (fld.value == "") {
        fld.style.background = '#fbc1a4';
        error = "Enter a subject.\n";
    }

   return error;
}

function validateFile(fld) {

    var error="";

    if (fld.value == "") {
        fld.style.background = '#fbc1a4';
        error = "Browse a file.\n";
    }

   return error;
}


