/***************************************************************************************\
*       ValidationLib                                                                   *
*                                                                                       *
\***************************************************************************************/



	function Validate_TextBox(txtName, lblName, msg)
	{
	    if (document.getElementById(txtName).value == "")
	    {
	        ShowValidationMessage(lblName, msg);
	        document.getElementById(txtName).focus();
	        ChangeTextBoxColor(txtName);
	        return false;
	    }
	    else
	    {
	        ShowValidationMessage(lblName);
	        ChangeTextBoxColor(txtName, "white");
	    }
	    return true;
	
	}
	function ShowValidationMessage(lblName, msg)
	{
	    if (msg == null || msg == "")
	    {
	        var _validationLabel = document.getElementById(lblName);
	        if (_validationLabel.innerHTML != "")
	        {
                _validationLabel.innerHTML = "";
  //              _validationLabel.setAttribute("Visible", "false");
	        }
	    }
	    else
	    {
	        document.getElementById(lblName).innerHTML = "<br /><font color=\"red\">" + msg + "</font><br />";
	//        document.getElementById(lblName).setAttribute("Visible", "true");
	    }
	}
	function Validate_ZipTextBox(txtName, lblName, msg)
	{
	    var zipRegExp = /^\d{5}$|^\d{5}-\d{4}$/;
	    var enteredZip = document.getElementById(txtName).value;
	    var matchArray = enteredZip.match(zipRegExp);
	    if (matchArray == null)
	    {
	        ShowValidationMessage(lblName, msg);
	        document.getElementById(txtName).value = "";
	        document.getElementById(txtName).focus();
	        ChangeTextBoxColor(txtName);
	        return false;		        
	    }
	    else
	    {
	        ShowValidationMessage(lblName);
	        ChangeTextBoxColor(txtName, "white");		    
	    }
	    return true;
	}
	function Validate_EmailTextBox(txtName, lblName, msg)
	{
	    var emailRegExp = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$/;
        var enteredEmail = document.getElementById(txtName).value;
	    var matchArray = enteredEmail.match(emailRegExp);
	    if (matchArray == null)
	    {
	        ShowValidationMessage(lblName, msg);
	        document.getElementById(txtName).value = "";
	        document.getElementById(txtName).focus();
	        ChangeTextBoxColor(txtName);
	        return false;
	    }
	    else
	    {
	        ShowValidationMessage(lblName);
	        ChangeTextBoxColor(txtName, "white");
	    }
	    return true;
	}
	function Validate_StateDropDown(lblName)
	{
	    var state = document.getElementById("state");
	    var stateIndex = state.selectedIndex;
	    if (stateIndex == null)
	        stateIndex = state.options.Count - 1;
	    if (state.options[stateIndex].value == "--")
	    {
	        state.style.backgroundColor = "#FEFF80";
	        state.focus();
		    ShowValidationMessage(lblName, "Please select a valid state.");
		    return false;
	    }
	    else
	    {
	        state.style.backgroundColor = "#FFFFFF";
		    ShowValidationMessage(lblName);
	    }
	    return true;
	}
	function Validate_BirthdayDropDown(lblName)
	{
        var month = document.getElementById("birthMonth");
        var day = document.getElementById("birthDay");
        var year = document.getElementById("birthYear");
        
        var monthIndex = month.selectedIndex;
        var dayIndex = day.selectedIndex;
        var yearIndex = year.selectedIndex;
        
        var message = "";
        
        if (monthIndex == 0)
        {           
	        month.style.backgroundColor = "#FEFF80";
	        month.selectedIndex = 0;
	        monthIndex = 0;
	        message = "Please enter the month of your birthday.";
	        if (dayIndex == 0)
	        {
	            day.style.backgroundColor = "#FEFF80";
	            day.selectedIndex = 0;
	            dayIndex = 0;
	        }
	        else if (yearIndex == 0)
	        {
	            year.style.backgroundColor = "#FEFF80";
	            year.selectedIndex = 0;
	            yearIndex = 0;
	        }
        }	     
        else if (dayIndex == 0)
        {
            month.style.backgroundColor = "#FFFFFF";
	        day.style.backgroundColor = "#FEFF80";
	        day.selectedIndex = 0;
	        dayIndex = 0;
	        message = "Please enter the day of your birthday.";
	        if (monthIndex == 0)
	        {
	            month.style.backgroundColor = "#FEFF80";
	            month.selectedIndex = 0;
	            monthIndex = 0;
	        }
	        else if (yearIndex == 0)
	        {
	            year.style.backgroundColor = "#FEFF80";
	            year.selectedIndex = 0;
	            yearIndex = 0;
	        }
        }   
        else if (yearIndex == 0)
        {
	        day.style.backgroundColor = "#FFFFFF";	            
	        month.style.backgroundColor = "#FFFFFF";	            
	        year.style.backgroundColor = "#FEFF80";
	        message = "Please enter the year of your sebirthday.";     
        }
        else
        {
	        month.style.backgroundColor = "#FFFFFF";
	        day.style.backgroundColor = "#FFFFFF";
	        year.style.backgroundColor = "#FFFFFF";
	        message = "";
        }
        ShowValidationMessage(lblName, message);
	}
	function Validate_DropDownWithOtherDiv(divNameToToggle, listNameToValidate, otherValue, otherTextBoxId)
	{
	    var _toggleDiv = document.getElementById(divNameToToggle);
	    var _list = document.getElementById(listNameToValidate);
	    var _listIndex = _list.selectedIndex;
	    var _otherValue = otherValue;
	    var _otherTextBox = null;
	    if (otherTextBoxId != null)
	        _otherTextBox = document.getElementById(otherTextBoxId);
	    if (_otherValue == null)
	        _otherValue = "Other";
	    
	    if (_listIndex == null)
	        _listIndex = _list.options[_listIndex].count -1;
	        
	    if (_list.options[_listIndex].value == _otherValue)
	        _toggleDiv.style.display = "block";
	    else
	        _toggleDiv.style.display = "none";
	    if (_otherTextBox != null)
	        _otherTextBox.focus();
	
	}
	function Update_TextBoxCharecterCountLabel(txtName, lblName, maxAmountOfChars)
	{
	    var _textBox = document.getElementById(txtName);
	    var _label = document.getElementById(lblName);
	   // alert("we are here " + _textBox.value.length + " - " + maxAmountOfChars + " = " + (maxAmountOfChars - _textBox.value.length));
	    if (_textBox.value.length < 2)
	    {
	        _textBox.style.backgroundColor = "#FFFFFF";	    
	    }
	    else if (_textBox.value.length >= maxAmountOfChars)
	    {
	        _textBox.style.backgroundColor = "#FEFF80";
	        _textBox.value = _textBox.value.substr(0, maxAmountOfChars);
	    }
	    else if (_textBox.value.length >= maxAmountOfChars * 0.90)
	    {
	        _textBox.style.backgroundColor = "#FFFF99";
	    }
	    else if (_textBox.value.length >= maxAmountOfChars * 0.75)
	    {
	        _textBox.style.backgroundColor = "#FFFFCC";
	    }
	    else
	    {
	           // alert("we made it ELSE");
	        _textBox.style.backgroundColor = "#FFFFFF";
	    }
	    
	    _label.innerHTML = (maxAmountOfChars - _textBox.value.length) + " characters left out of " + maxAmountOfChars;
	    
	    
	
	}
	function ChangeTextBoxColor(txtName, color)
	{
	    if (color == null)
	    {
    		document.getElementById(txtName).style.backgroundColor = "#FEFF80";
    	}
    	else
    	{
    	    document.getElementById(txtName).style.backgroundColor = "#FFFFFF";
    	}
	}
