// Multi-Click timeout
var SMC_page_busy = false;
var SMC_page_TimeOutValue = 0;

function SupressMultiClick( timeout ) {
	var nTimeout;
	
	if (timeout == null) {
		nTimeout = 5000;
	}
	else {
		nTimeout = timeout;
	}
	
	if( false == SMC_page_busy ) {
		SMC_page_busy = true;
		SMC_page_TimeOutValue = window.setTimeout( "ClearMultiClickTimeout()", nTimeout );
		return true;
	}
	else {
		return false;
	}
}

function ClearMultiClickTimeout() {
	SMC_page_busy = false;
	clearTimeout( SMC_page_TimeOutValue );
}



function SubmitForm( action )
{
	
	if( !SupressMultiClick( 3000 ) )
	{
		return;
	}
	
	var frm = document.getElementById( "frmEmploymentForm" );
	
	if( Validate() )
	{
		frm.postBack.value = 1;
		frm.action.value = action;
		frm.submit();
	}
	
}



function Validate()
{
	var frm = document.getElementById( "frmEmploymentForm" );
	
	if( isBlank( frm.FirstName.value ) || isEmpty( frm.FirstName.value ) )
	{
		alert( "Please enter your first name" );
		frm.FirstName.focus();
		return false;
	}
	
	if( isBlank( frm.LastName.value ) || isEmpty( frm.LastName.value ) )
	{
		alert( "Please enter your last name" );
		frm.LastName.focus();
		return false;
	}
	
	if( isBlank( frm.LastName.value ) || isEmpty( frm.LastName.value ) )
	{
		alert( "Please enter your last name" );
		frm.LastName.focus();
		return false;
	}
	
	if( isBlank( frm.StreetAddr.value ) || isEmpty( frm.StreetAddr.value ) )
	{
		alert( "Please enter your address" );
		frm.StreetAddr.focus();
		return false;
	}
	
	if( isBlank( frm.Phone.value ) || isEmpty( frm.Phone.value ) )
	{
		alert( "Please enter your phone number" );
		frm.Phone.focus();
		return false;
	}
	
	var tempPhone;
	tempPhone = stripCharsInBag( frm.Phone.value, phoneNumberDelimiters );
	tempPhone = stripCharsInBag( tempPhone, '.' );
	if( !isUSPhoneNumber( tempPhone ) )
	{
		alert( iUSPhone );
		frm.Phone.focus();
		return;
	}
	else
	{
		frm.Phone.value = reformatUSPhone( tempPhone );
	}
	
	
	
	
	
	if( isBlank( frm.Email.value ) || isEmpty( frm.Email.value ) || ( !isEmail( frm.Email.value ) ) )
	{
		alert( "Please enter a valid email address" );
		frm.Email.focus();
		return false;
	}
	
	if( isBlank( frm.City.value ) || isEmpty( frm.City.value ) )
	{
		alert( "Please enter the city you reside in" );
		frm.City.focus();
		return false;
	}
	if( frm.State.selectedIndex == -1 )
	{
		alert( "Please select the state you reside in" );
		frm.State.focus();
		return false;
	}
	
	if( isBlank( frm.ZipCode.value ) || isEmpty( frm.ZipCode.value ) )
	{
		alert( "Please enter your zip code" );
		frm.ZipCode.focus();
		return false;
	}
	
	var zipCode = stripCharsInBag( frm.ZipCode.value, ' -' );

	if( !isZIPCode( zipCode ) || !isInteger( zipCode ) )
	{
		alert( "Please enter a valid zip code" );
		frm.ZipCode.focus();
		return false;
	}
	
	if( zipCode.length == 9 )	// Reformat if 9 digit
	{
		frm.ZipCode.value = zipCode.substring( 0, 5 ) + '-' + zipCode.substring( 5, 9 );
	}
	
	
	
	
	var num = frm.elements.length;
	
	for( var i = 0; i < num; i++ )
	{
	
		if( frm.elements[i].name.indexOf( "rdoQST_" ) >= 0 )
		{
		
			var qstName = frm.elements[i].name;
			
			if ( qstName != undefined && qstName != null )
			{
				var tempSplit = qstName.split( '_' );
				var qstCnt = tempSplit[1];							
			}
			
			var qstHidValid = document.getElementById( ( "HiddenQstValid" + qstCnt ) );
			var qstHidMsg = document.getElementById( ( "HiddenQstMsg" + qstCnt ) )
			var qstTxt = document.getElementById( ( "QSTText_" + qstCnt ) )
			
			var qstValidID;
			var qstRequired;
			var qstShowBox;
			
			var msg = "";
			var txt = "";
			var hasText = false;
			
			if( qstHidValid != undefined && qstHidValid != null )
			{
				
				var temp = qstHidValid.value.split( ',' );
				
				qstValidID = temp[0];
				qstRequired = temp[1];
				qstShowBox = temp[2];
				
			}
			
			if( qstHidMsg != undefined && qstHidMsg != null )
			{
				msg = qstHidMsg.value;
			}
			
			if( qstShowBox != -1 && qstTxt != undefined && qstTxt != null )
			{
				txt = qstTxt.value;
			}
			
			
			if( qstValidID != undefined && qstValidID != null )
			{
				
				if( qstRequired )
				{
					
					if( !document.getElementById( ( "rdoQSTY_" + qstCnt ) ).checked && !document.getElementById( "rdoQSTN_" + qstCnt ).checked )
					{
						alert( "Please answer Question " + qstCnt );
						document.getElementById( ( "rdoQSTY_" + qstCnt ) ).focus();
						return false;
					}
					
				}
				
				
				if( qstShowBox != -1 && qstValidID != "" && document.getElementById( qstValidID ).checked )
				{
					
					if( isBlank( qstTxt.value ) || isEmpty( qstTxt.value ) )
					{
					
						if( msg != "" )
						{
							alert( msg );
							qstTxt.focus();
							return false;
						}
						else
						{
							alert( "Please answer Question " + qstCnt );
							qstTxt.focus();
							return false;
						}
							
					}
					
				}
			
			}
			
		}
		
	}
	
	
	if( frm.rdoAgreeAuthYes != null && !frm.rdoAgreeAuthYes.checked &&
		 frm.rdoAgreeAuthNo != null && !frm.rdoAgreeAuthNo.checked )
		{
			alert( "Please tell us if you agree or disagree with our policies" );
			frm.rdoAgreeAuthYes.focus();
			return false;
		}
	
	
	return true;
	
}



function ShowQuestionInput( id, show, showBox )
{
	
	if( show == "no" && showBox == 0 )
	{
		document.getElementById( id ).style.display = "block";
	}
	else if( show == "yes" && showBox == 1 )
	{
		document.getElementById( id ).style.display = "block";
	}
	else
	{
		document.getElementById( id ).style.display = "none";
	}
	
}



function AvailableEnabled( chkID, inpID, isClick )
{
	if( !isClick )
	{
		if( document.getElementById( chkID ).checked )
			document.getElementById( inpID ).style.backgroundColor = "#FCFCFC"
		else
			document.getElementById( inpID ).style.backgroundColor = "#EEE"	
	}
	else
	{
		if( document.getElementById( chkID ).checked == false )
		{
			document.getElementById( inpID ).style.backgroundColor = "#FCFCFC"
			document.getElementById( chkID ).checked = true;
		}
	}
	
}



function ReselectValues()
{

	var frm = document.getElementById( "frmEmploymentForm" );		
	
	
	
	
	var num = frm.elements.length;
	
	for( var i = 0; i < num; i++ )
	{
	
		if( frm.elements[i].name.indexOf( "rdoQST_" ) >= 0 )
		{
		
			var qstName = frm.elements[i].name;
			var qstCnt = qstName.substr( ( qstName.length - 1 ), ( qstName.length ) );
			
			var qstHidValid = document.getElementById( ( "HiddenQstValid" + qstCnt ) );
			var qstBox = document.getElementById( ( "QSTBox_" + qstCnt ) );
			
			var qstValidID;
			var qstRequired;
			var qstShowBox;
			
			if( qstHidValid != undefined && qstHidValid != null )
			{
				
				var temp = qstHidValid.value.split( ',' );
				
				qstValidID = temp[0];
				qstRequired = temp[1];
				qstShowBox = temp[2];
				
			}
			
			
			if( qstShowBox != -1 && document.getElementById( qstValidID ).checked )
			{
				
				if( qstBox.style.display != "block" )
				{
					qstBox.style.display = "block";
				}
			
			}
			
		}
		
	}
	
	
	
		if( frm.chkAvailMon.checked )
			document.getElementById( 'AvailMon' ).style.backgroundColor = '#FCFCFC'
		if( frm.chkAvailTue.checked )
			document.getElementById( 'AvailTue' ).style.backgroundColor = '#FCFCFC'
		if( frm.chkAvailWed.checked )
			document.getElementById( 'AvailWed' ).style.backgroundColor = '#FCFCFC'
		if( frm.chkAvailThu.checked )
			document.getElementById( 'AvailThu' ).style.backgroundColor = '#FCFCFC'
		if( frm.chkAvailFri.checked )
			document.getElementById( 'AvailFri' ).style.backgroundColor = '#FCFCFC'
		if( frm.chkAvailSat.checked )
			document.getElementById( 'AvailSat' ).style.backgroundColor = '#FCFCFC'
		if( frm.chkAvailSun.checked )
			document.getElementById( 'AvailSun' ).style.backgroundColor = '#FCFCFC'
			
	
	
}



var USStateDelimiter = "|";
var USStates = "AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PA|PR|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY"

function PopulateLists()
{
	
	var frm = document.getElementById( "frmEmploymentForm" );
	var opt;

	for( j = 1; j <= 4; j++ )
	{
	
		var selectList = document.getElementById( ( 'EduYears' + j ) );
		
		for( i = 0; i <= 5; i++ )
		{
		
			if( i == 0 )
			{
				opt = new Option( " ", " " );
			}
			else if( i == 5 )
			{
				opt = new Option( "4+", "4+" );
			}
			else
			{
				opt = new Option( i, i );
			}
				
			selectList.options[i] = opt;
			
		}
		
	}
	
	
	var s = USStates.split( USStateDelimiter );
	s.sort();
	
	for( j = 0; j < s.length; j++ )
	{
	
		opt = new Option( s[j], s[j] );
		frm.State.options[j] = opt;
		
		
		opt = new Option( s[j], s[j] );
		frm.EmpState1.options[j] = opt;
		
		opt = new Option( s[j], s[j] );
		frm.EmpState2.options[j] = opt;
		
		opt = new Option( s[j], s[j] );
		frm.EmpState3.options[j] = opt;
		
		opt = new Option( s[j], s[j] );
		frm.RefState1.options[j] = opt;
		
		opt = new Option( s[j], s[j] );
		frm.RefState2.options[j] = opt;
		
		opt = new Option( s[j], s[j] );
		frm.RefState3.options[j] = opt;
		
		opt = new Option( s[j], s[j] );
		frm.RefState4.options[j] = opt;
		
	
	}
	


	if( frm.selectedVals != null && frm.selectedVals.value != "" )
	{
	
		var temp = frm.selectedVals.value.split( ',' );
		
		for( i = 0; i < temp.length; i+=2 )
		{
			document.getElementById( temp[i] ).selectedIndex = temp[(i+1)];
		}
		
	}
	
}


function AgeUnder16Check()
{
	
	
	
	return true;

}



function PrintView( val )
{

	if( val == 'show' )
	{
		document.getElementById( "FormView" ).style.display = "none";
		document.getElementById( "PrintView" ).style.display = "block";
	}
	else
	{
		document.getElementById( "FormView" ).style.display = "block";
		document.getElementById( "PrintView" ).style.display = "none";
	}
}	


function AddSelectedVals( id )
{

	var frm = document.getElementById( "frmEmploymentForm" );
	var index = document.getElementById( id ).selectedIndex;
	var temp = frm.selectedVals.value.split( ',' );
	
	if( frm.selectedVals != null && frm.selectedVals.value != "" )
	{
	
		for( i = 0; i < temp.length; i+=2 )
		{
			if( temp[i] == id )
			{
				temp[(i+1)] = index;
				frm.selectedVals.value = temp;
				return;
			}
		}
		
	}
	else
	{
		temp += ( id + "," + index );
		frm.selectedVals.value = temp;
		return;
	}
	
	temp += ( "," + id + "," + index );
	frm.selectedVals.value = temp;
	
}
