
function ToggleSelectOther( htmlName, testValue )
{
	var selectValue = document.getElementById( htmlName ).value;

	if ( document.getElementById( htmlName + "Other" ) )
	{
		document.getElementById( htmlName + "Other" ).style.display = ( selectValue == testValue ) ? "block" : "none";
	}
}

function LeftPad( contentToSize, padLength, padChar )
{
	var paddedString = contentToSize.toString();

	for( i = contentToSize.length + 1; i <= padLength; i++ )
	{
		paddedString = padChar + paddedString;
	}

	return paddedString;
}


function GetJsDate( dateName )
{
	var year = '0000';
	var month = '00';
	var day = '00';

	if ( document.getElementById( dateName + "_year" ) )
	{
		if ( document.getElementById( dateName + "_year" ).value == '-' )
		{
			return '0000-00-00';
		}

		year = LeftPad( document.getElementById( dateName + "_year" ).value, 4, '0' );
	}

	if ( document.getElementById( dateName + "_month" ) )
	{
		if ( document.getElementById( dateName + "_month" ).value == '-' )
		{
			return '0000-00-00';
		}

		month = LeftPad( document.getElementById( dateName + "_month" ).value, 2, '0' );
	}

	if ( document.getElementById( dateName + "_day" ) )
	{
		if ( document.getElementById( dateName + "_day" ).value == '-' )
		{
			return '0000-00-00';
		}

		day = LeftPad( document.getElementById( dateName + "_day" ).value, 2, '0' );
	}

	var returnVal = year + "-" + month + "-" + day;

	return returnVal;
}

function NotEqualTo( value, compareTo )
{
	return ( value != compareTo );
}

function NotEmpty( value )
{
	return ( value != "" );
}

// Used in some places to display the word count remaining.
var lastWordCount = 0;

function MinWords( value, minWords )
{
	CountWords( value );
	return ( lastWordCount >= minWords );
}

function MaxWords( value, maxWords )
{
	CountWords( value );
	return ( lastWordCount <= maxWords );
}

function CountWords( value )
{
	var y = value;
	var r = 0;

	a = y.replace(/\s/g,' ');
	a = a.split(' ');

	for (z=0; z<a.length; z++)
	{
		if ( a[z].length > 0 )
		{
			r++;
		}
	}

	lastWordCount = r;
}

function CheckDateRange( value, min, max )
{
    if( max != 0 && value > max )
    {
        return false;
    }

    if( min != 0 && value < min )
    {
        return false;
    }

    return true;
}

function ValidEmail( value )
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if( !value.match( reg ) )
	{
		return false;
	}
	
	return true;
	
}

function SameAsField( value, field )
{
	var fieldValue = document.getElementById[ field ].value;
	
	if( value != fieldValue )
	{
		return false;
	}
	
	return true;
	
}