function Validate(frm){
	var returnValue = false;
	if( frm.user.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
			alert("Please enter your User Name.");
    	frm.user.focus();
	} else if( frm.pass.value.replace(/(^\s+)|(\s+$)/g, '').length < 2 ){
    	alert("Please enter a your Password.");
    	frm.pass.focus();
  } else {
  		returnValue = true;
  }
  return returnValue;
}

function ValidateEmail(frm){
    var returnValue = false;
    if (!ValidEmail(frm.email_address.value)){
        alert("Please enter a valid email address.");
        frm.email_address.focus();
    } else {
        returnValue = true;
    }
    return returnValue;
}

function ValidEmail(strValue){
    var valid = true;
    var regExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    var regExp2 = /(\s+)|(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;

    if ( (strValue.search(regExp)) == -1 || strValue.search(regExp2) != -1)
            valid = false;

    return valid;
}

function show_it(what) {
    if(document.getElementById(what) != null) {
        element = document.getElementById(what).style;
        element.display = "block";
        //document.getElementById(what).style.display='block';
    }
}

function hide_it(what) {
    if(document.getElementById(what) != null) {
        document.getElementById(what).style.display='none';
    }
}


function submit_form() {
    if (check_form()==false || checkdates()==false) {
        return false;
    }
}

function submit_rfp_form() {
    if (check_form()==false || checkrfpdates()==false) {
        return false;
    }
}
function check_form(){
    var thisform = document.rfp;
    var form_ok = false;
    if (thisform.group_name.value == ""){
        alert("The Group Name Cannot be blank");
        thisform.group_name.focus();
    } else if (thisform.prefix.value =="" && pref==1){
        alert("Please select a prefix.");
        thisform.prefix.focus();
    } else if (thisform.first_name.value ==""){
         alert("The First Name Field Cannot be blank");
         thisform.first_name.focus();
    } else if (thisform.last_name.value ==""){
         alert("The Last Name Field Cannot be blank");
         thisform.last_name.focus();
    } else if ( !ValidEmail(thisform.email.value) ) {
        alert("Please enter a valid email address");
        thisform.email.focus();
    } else {
         form_ok = true;
    }
    return form_ok;
}


function checkdates()
{
    //var reg     = /\d{4}\-\d{2}\-\d{2}/;
    var reg     = /\d{2}\/\d{2}\/\d{4}/;

    var start = document.daterange.startdate.value;
    var end = document.daterange.enddate.value;
    //startdate   = frm.startdate.value;
    //enddate     = frm.enddate.value;
    var startdet = start.split('/');
    var enddet = end.split('/');

    if (start!='') {
        if (!reg.test(start)) {
            alert("Start Date format is wrong");
            return false;
        }
    }
    if (end!='') {
        if (!reg.test(end)) {
            alert("End Date format is wrong");
            return false;
        }
    }

    if (end!='' && start!='') {
        if (end < start) {
            alert("End date is before Start date");
            return false;
        }
    }

    today = new Date();
    day = today.getDate();
    if (day < 10) {
        day = "0"+day;
    }

    month = today.getMonth() + 1;
    if(month < 10) {
        month = "0"+month;
    }

    year = today.getFullYear();
    //today = year+"-"+month+"-"+day;
    today = month+"/"+day+"/"+year;
    if ((startdet[2] == year || enddet[2] == year) && (startdet[2] <= year || enddet[2] <= year)) {
        if(start > today || end > today) {
            alert("Date is after today");
            return false;
        }
    }
    //return true;
}
function checkrfpdates()
{
    //var reg     = /\d{4}\-\d{2}\-\d{2}/;
    var reg     = /\d{2}\/\d{2}\/\d{4}/;

    var start = document.rfp.startdate.value;
    var end = document.rfp.enddate.value;
    //startdate   = frm.startdate.value;
    //enddate     = frm.enddate.value;
    var startdet = start.split('/');
    var enddet = end.split('/');

    if (start!='') {
        if (!reg.test(start)) {
            alert("Start Date format is wrong");
            return false;
        }
    }
    if (end!='') {
        if (!reg.test(end)) {
            alert("End Date format is wrong");
            return false;
        }
    }

    if (end!='' && start!='') {
        if (end < start) {
            alert("End date is before Start date");
            return false;
        }
    }

    today = new Date();
    day = today.getDate();
    if (day < 10) {
        day = "0"+day;
    }

    month = today.getMonth() + 1;
    if(month < 10) {
        month = "0"+month;
    }

    year = today.getFullYear();
    //today = year+"-"+month+"-"+day;
    today = month+"/"+day+"/"+year;
    if ((startdet[2] == year || enddet[2] == year) && (startdet[2] <= year || enddet[2] <= year)) {
        if(start <= today || end <= today) {
            alert("Date is before or on today. Please Choose a later date.");
            return false;
        }
    }
    //return true;
}
function check_user_form(){
        var thisform = document.signup;
        var form_ok = false;
    if (thisform.username.value =="") {
         alert("Please enter Username for the user");
         thisform.username.focus();
    } else if (thisform.password.value =="") {
         alert("Please enter Password for the user");
         thisform.password.focus();
    } else if (thisform.fname.value =="") {
         alert("The First Name Field Cannot be blank");
         thisform.fname.focus();
    } else if (thisform.lname.value =="") {
         alert("The Last Name Field Cannot be blank");
         thisform.lname.focus();
    } else if (thisform.phone.value =="") {
         alert("Please enter Phone Number for the user");
         thisform.phone.focus();
    } else if ( !ValidEmail(thisform.email.value) ) {
        alert("Please enter a valid email address");
        thisform.email.focus();
    } else {
         form_ok = true;
    }
    return form_ok;
}


