function ProcessCountryChange( iCountryDropDownList )
{
	var date = new Date();

	var countryID = iCountryDropDownList.options[ iCountryDropDownList.selectedIndex ].value;

	if ( SendRequest( "AJAX/ProvinceList.aspx?TS=" + date.getTime() + "&CID=" + countryID, HandleCountryChange ) == false )
	{
		__doPostBack( 'mCountryDropDownList' , '' );
	}
}


function __doPostBack( eventTarget, eventArgument ) 
{
	var form;
	
	if ( window.navigator.appName.toLowerCase().indexOf( "microsoft" ) > -1 ) 
	{
		form = document.mForm;
	}
	else 
	{
		form = document.forms[ "mForm" ];
	}

	form.submit();
}


function HandleCountryChange( iProvinceDropDownListXML, iProvinceDropDownListText )
{
	var provinceDropDownList = document.getElementById( "mProvinceDropDownList" );
	var option;
	var text;
	var value;

	// UPDATE PROVINCE DROP-DOWN LIST
	if ( iProvinceDropDownListText.length > 0 )
	{
		var provinceList = iProvinceDropDownListText.split( "#" );
		
		provinceDropDownList.length = 0;
		provinceDropDownList.options[ provinceDropDownList.length ] = new Option( "Please Select...", "", true, true );
		
		for ( var index = 0; index < provinceList.length; index++ )
		{
			option = provinceList[ index ].split( ";" );
			value = option[ 0 ];
			text = option[ 1 ];
			
			provinceDropDownList.options[ provinceDropDownList.length ] = new Option( value, text, false, false );
		}
	}
	else
	{
		provinceDropDownList.length = 0;
		provinceDropDownList.options[ provinceDropDownList.length ] = new Option( "Please Select...", "", true, true );
	}
	
	// DETERMINE WHICH PROVINCE CONTROL TO DISPLAY
	var provinceSelectionTable = document.getElementById( "mProvinceSelectionTable" );
	var provinceEntryTable = document.getElementById( "mProvinceEntryTable" );
	
	if ( provinceDropDownList.length == 1 )
	{
		provinceSelectionTable.style.visibility = "hidden";
		provinceSelectionTable.style.position = "absolute";
		provinceEntryTable.style.visibility = "visible";
		provinceEntryTable.style.position = "relative";
	}
	else
	{
		provinceSelectionTable.style.visibility = "visible";
		provinceSelectionTable.style.position = "relative";
		provinceEntryTable.style.visibility = "hidden";
		provinceEntryTable.style.position = "absolute";
	}
}


function InitProvinceControls()
{
	var provinceDropDownList = document.getElementById( "mProvinceDropDownList" );
	var provinceSelectionTable = document.getElementById( "mProvinceSelectionTable" );
	var provinceEntryTable = document.getElementById( "mProvinceEntryTable" );
	
	if ( provinceDropDownList.length == 0 )
	{
		provinceSelectionTable.style.visibility = "hidden";
		provinceSelectionTable.style.position = "absolute";
		provinceEntryTable.style.visibility = "visible";
		provinceEntryTable.style.position = "relative";
	}
	else
	{
		provinceSelectionTable.style.visibility = "visible";
		provinceSelectionTable.style.position = "relative";
		provinceEntryTable.style.visibility = "hidden";
		provinceEntryTable.style.position = "absolute";
	}
}


function InitProductControls()
{
	var consultingInfoTable = document.getElementById( "mConsultingInfoTable" );
	var teamInfoTable = document.getElementById( "mTeamInfoTable" );
    var checkBox;
	
	for ( var index = 100; index < 120; index++ )
	{
		checkBox = document.getElementById( "Product" + index );
		
		if ( checkBox != null )
		{
			if ( checkBox.title.indexOf( "Consulting" ) != -1 )
			{
				if ( checkBox.checked )
				{
					consultingInfoTable.style.visibility = "visible";
					consultingInfoTable.style.position = "relative";
				}
				else
				{
					consultingInfoTable.style.visibility = "hidden";
					consultingInfoTable.style.position = "absolute";
				}
			}
			
			if ( checkBox.title.indexOf( "Team" ) != -1 )
			{
				if ( checkBox.checked )
				{
					teamInfoTable.style.visibility = "visible";
					teamInfoTable.style.position = "relative";
				}
				else
				{
					teamInfoTable.style.visibility = "hidden";
					teamInfoTable.style.position = "absolute";
				}
			}
		}
	}
}


function ProcessProductChange( iCheckBox )
{
	var productID = iCheckBox.value;
	var consultingInfoTable = document.getElementById( "mConsultingInfoTable" );
	var teamInfoTable = document.getElementById( "mTeamInfoTable" );
	var consultationSubjectTextBox = document.getElementById( "mConsultationSubjectTextBox" );
	var phoneTextBox = document.getElementById( "mPhoneTextBox" );
	var bestTimeTextBox = document.getElementById( "mBestTimeTextBox" ); 
	var trainingDatabaseTextBox = document.getElementById( "mTrainingDatabaseTextBox" ); 

	if ( iCheckBox.title.indexOf( "Consulting" ) != -1 )
	{
		if ( iCheckBox.checked )
		{
			consultingInfoTable.style.visibility = "visible";
			consultingInfoTable.style.position = "relative";
		}
		else
		{
			consultingInfoTable.style.visibility = "hidden";
			consultingInfoTable.style.position = "absolute";
			consultationSubjectTextBox.value = "";
			phoneTextBox.value = "";
			bestTimeTextBox.value = "";
		}
	}
	
	if ( iCheckBox.title.indexOf( "Team" ) != -1 )
	{
		if ( iCheckBox.checked )
		{
			teamInfoTable.style.visibility = "visible";
			teamInfoTable.style.position = "relative";
		}
		else
		{
			teamInfoTable.style.visibility = "hidden";
			teamInfoTable.style.position = "absolute";
			trainingDatabaseTextBox.value = "";
		}
	}
}


function ValidateRegistration( iForm )
{
	var consultingInfoTable = document.getElementById( "mConsultingInfoTable" );
	var teamInfoTable = document.getElementById( "mTeamInfoTable" );
	var consultationSubjectTextBox = document.getElementById( "mConsultationSubjectTextBox" );
	var phoneTextBox = document.getElementById( "mPhoneTextBox" );
	var bestTimeTextBox = document.getElementById( "mBestTimeTextBox" ); 
	var trainingDatabaseTextBox = document.getElementById( "mTrainingDatabaseTextBox" ); 
	var consultationSubjectEntryMarker = document.getElementById( "mConsultationSubjectEntryMarker" );
	var phoneEntryMarker = document.getElementById( "mPhoneEntryMarker" );
	var bestTimeEntryMarker = document.getElementById( "mBestTimeEntryMarker" ); 
	var trainingDatabaseEntryMarker = document.getElementById( "mTrainingDatabaseEntryMarker" ); 

	consultationSubjectEntryMarker.innerHTML = "";
	phoneEntryMarker.innerHTML = "";
	bestTimeEntryMarker.innerHTML = "";
	trainingDatabaseEntryMarker.innerHTML = "";
	
	var errorArray = new Array();
	
	if ( consultingInfoTable.style.visibility == "visible" )
	{
		consultationSubjectTextBox.value = Trim( consultationSubjectTextBox.value );
		phoneTextBox.value = Trim( phoneTextBox.value );
		bestTimeTextBox.value = Trim( bestTimeTextBox.value );
		
		if ( consultationSubjectTextBox.value == "" )
		{
			errorArray[ errorArray.length ] = "<li>\"Purpose of Consultation\" is required and cannot be blank.</li>";
			consultationSubjectEntryMarker.innerHTML = "!! ";
		}
		
		if ( phoneTextBox.value == "" )
		{
			errorArray[ errorArray.length ] = "<li>\"Phone\" is required and cannot be blank.</li>";
			phoneEntryMarker.innerHTML = "!! ";
		}
		
		if ( bestTimeTextBox.value == "" )
		{
			errorArray[ errorArray.length ] = "<li>\"Best Time to Call\" is required and cannot be blank.</li>";
			bestTimeEntryMarker.innerHTML = "!! ";
		}
	}
	
	if ( teamInfoTable.style.visibility == "visible" )
	{
		trainingDatabaseTextBox.value = Trim( trainingDatabaseTextBox.value );
		
		if ( trainingDatabaseTextBox.value == "" )
		{
			errorArray[ errorArray.length ] = "<li>\"Training Database\" is required and cannot be blank.</li>";
			trainingDatabaseEntryMarker.innerHTML = "!! ";
		}
	}
	
	if ( errorArray.length > 0 )
	{
		var messageDiv = document.getElementById( "mMessageDiv" );
		var errorPrefix = "<p class=\"Error\">The following " +  errorArray.length + " error(s) occurred while processing your submission:</p>"
		var errorMessage = "";
		
		for ( var index = 0; index < errorArray.length; index++ )
		{
			errorMessage += errorArray[ index ];
		}
		
		messageDiv.innerHTML = errorPrefix + "<ul class=\"Error\">" + errorMessage + "</ul>";	
		
		return false;
	}
	else
	{
		return true;
	}
}


function Trim( iString )
{
	return iString.replace( /^[\s]+|[\s]+$/g, "" );
}
