<!--//
function validateForm(e)
{
//aliases
    var sessionAlias = document.getElementById('txtSessionAlias').value;
    var speakerAlias = document.getElementById('txtSpeakerAlias').value;
    var sesDescriptionAlias = document.getElementById('txtSessionDescriptonAlias').value;
    var sesFormatAlias = document.getElementById('txtSesFormatAlias').value;
    var sesTypeAlias = document.getElementById('txtSesTypeAlias').value;
    var targetAudienceAlias = document.getElementById('txtTargetAudienceAlias').value;
    var secondarySesTypeAlias = document.getElementById('txtSecondarySesTypeAlias').value;
    var topicAlias = document.getElementById('txtTopicAlias').value;

    var requireCF1 = document.getElementById('txtCF1_Required').value;
    var requireCF2 = document.getElementById('txtCF1_Required').value;
    var requireCF3 = document.getElementById('txtCF1_Required').value;
	
	var frm = document.forms[e.name];
	if(frm.elements['lstLevel']){
	    var level = frm.elements['lstLevel'].options[frm.elements['lstLevel'].selectedIndex].value;
	}
	//require Audience, Role, Topic, secondarySesType
	var topic ='';
	var role ='';
	var audience ='';
	var sesTypeSecondary ='';
	if (document.getElementById('lstLevel')){
	    audience = frm.elements['lstSessionFormat'].options[frm.elements['lstSessionFormat'].selectedIndex].value;
	}
	
	/*if(frm.elements['chkTarget']){
	    role = frm.elements['chkTarget'].options[frm.elements['chkTarget'].selectedIndex].value;
	}*/
	if(document.getElementById('chkTarget')){
	    for (var i = 0; i < document.getElementById('chkTarget').options.length; i++){
	        if(document.getElementById('chkTarget').options[i].selected == true && document.getElementById('chkTarget').options[i].value != ''){
	            role = sesTypeSecondary + document.getElementById('chkTarget').options[i].value + ',';
	        }
	    } 
	   
	}
	/*if(frm.elements['chkTopic']){
	    topic = frm.elements['chkTopic'].options[frm.elements['chkTopic'].selectedIndex].value;
	}*/
	if(document.getElementById('chkTopic')){
	    for (var i = 0; i < document.getElementById('chkTopic').options.length; i++){
	        if(document.getElementById('chkTopic').options[i].selected == true && document.getElementById('chkTopic').options[i].value != ''){
	            topic = sesTypeSecondary + document.getElementById('chkTopic').options[i].value + ',';
	        }
	    } 
	   
	}
	
	//must loop through; could be a multiple select listbox
	if(document.getElementById('lstSecondarySesType')){
	    for (var i = 0; i < document.getElementById('lstSecondarySesType').options.length; i++){
	        if(document.getElementById('lstSecondarySesType').options[i].selected == true && document.getElementById('lstSecondarySesType').options[i].value != ''){
	            sesTypeSecondary = sesTypeSecondary + document.getElementById('lstSecondarySesType').options[i].value + ',';
	        }
	    } 
	   
	}
	
    var sesTitle = frm.elements['txtSesTitle'].value;//required
	var shortSes = frm.elements['txtSessionLongDesc'].value;//required
	if(frm.elements['txtSynopsis']){
	    var detSes = frm.elements['txtSynopsis'].value;//required if detSesMinWords > 0
	}
	var bAdminSpeaker = frm.elements['chkAdminSpeaker'];
	var detSesMinWords = frm.elements['detailedSesMin'].value;//required if minimum > 0
	var shortSesMinWords = frm.elements['shortSesMin'].value;//required if minimum > 0
	
	var salutation = frm.elements['txtContactSalutation'].value;
	var first = frm.elements['txtContactNameFirst'].value;//required
	var mid = frm.elements['txtContactNameMI'].value;
	var last = frm.elements['txtContactNameLast'].value;//required
	var conTitle = frm.elements['txtContactTitle'].value;
	var org = frm.elements['txtOrganization'].value;
	var add1 = frm.elements['txtAdd1'].value;
	var add2 = frm.elements['txtAdd2'].value;
	var city = frm.elements['txtCity'].value;
	var state = frm.elements['lstUSState'];
	var postal = frm.elements['txtPostal'].value;
	var country = frm.elements['lstCountry'];
	
	var phone = frm.elements['txtPhone'].value;
	var ext = frm.elements['txtExt'].value;
	var fax = frm.elements['txtFax'].value;
	var email = frm.elements['txtEmail'].value;//required
	var bio = frm.elements['txtBio'].value;//required
	var additionalSpeakers = frm.elements['lstAdditionalSpeakers'];

   
	//validate required fields
	var bValid = true;
	var msg = '';
   
	if(trim(sesTitle)=='')
	{
		bValid = false;
		document.getElementById('lblSesTitle').style.background='yellow';
		msg =msg + sessionAlias + ' Title is required. <br>';
	}
	else
	{
		document.getElementById('lblSesTitle').style.background='white';
		
	}
	if(shortSesMinWords > 0){
	    if(trim(shortSes)=='')
	    {
		    bValid = false;
		    document.getElementById('lblShortSes').style.background='yellow';
		    msg =msg + 'Short Session Description is required. <br>';
	    }
	    else
	    {
	        //valdate length of short session description
	        var shortSesWordCount_Min = document.getElementById('txtShortSessionWordCount_Min').value;
	        var shortSesWordCount_Max = document.getElementById('txtShortSessionWordCount_Max').value;
	        var shortSesWordCount = countWords_ver4090110(document.getElementById('txtSessionLongDesc').value);
	        //alert(shortSesWordCount);
	        if( parseInt(shortSesWordCount) < parseInt(shortSesWordCount_Min)){
	        bValid = false;
		        document.getElementById('lblShortSes').style.background='yellow';
		        msg =msg + 'Short Session Description is too short. <br>';
	        }
	        if( parseInt(shortSesWordCount) > parseInt(shortSesWordCount_Max)){
	            bValid = false;
		        document.getElementById('lblShortSes').style.background='yellow';
		        msg =msg + 'Short Session Description is too long. <br>';
	        }
	        
		    if(parseInt(shortSesWordCount) >= parseInt(shortSesWordCount_Min) && parseInt(shortSesWordCount) <= parseInt(shortSesWordCount_Max)){
		        document.getElementById('lblShortSes').style.background='white';
		    }
    		//alert(shortSesWordCount_Min); return false;
	    }
	}
	
	
	
	//check minimiumn number of words required. if min = 0 then field can be blank
    if(detSesMinWords > 0){
		if(trim(detSes)==''){
		    document.getElementById('lblDetSes').style.background='yellow';
			bValid = false;
			msg =msg + 'Detailed ' + sesDescriptionAlias + ' is required. <br>';
		}
		else{
		    //valdate length of detailed session description
	        var detSesWordCount_Min = document.getElementById('txtSynopsisWordCount_Min').value;
	        var detSesWordCount_Max = document.getElementById('txtSynopsisWordCount_Max').value;
	        var detSesWordCount = countWords_ver4090110(document.getElementById('txtSynopsis').value);
	        //alert(shortSesWordCount);
	        if( parseInt(detSesWordCount) < parseInt(detSesWordCount_Min)){
	        bValid = false;
		        document.getElementById('lblDetSes').style.background='yellow';
		        msg =msg + 'Detailed Session Description is too short. <br>';
	        }
	        if( parseInt(detSesWordCount) > parseInt(detSesWordCount_Max)){
	            bValid = false;
		        document.getElementById('lblDetSes').style.background='yellow';
		        msg =msg + 'Detailed Session Description is too long. <br>';
	        }
	        
		    if(parseInt(detSesWordCount) >= parseInt(detSesWordCount_Min) && parseInt(detSesWordCount) <= parseInt(detSesWordCount_Max)){
		        document.getElementById('lblDetSes').style.background='white';
		    }
		    //document.getElementById('lblDetSes').style.background='white';
		}
    }
    if(document.getElementById('lstLevel')){
        if(level == 'null'){
            bValid = false;
		    document.getElementById('lstLevel').style.background='yellow';
		    msg = msg + 'Level is required. <br>';
        }
        else{
            document.getElementById('lstLevel').style.background='white';
        }
    }
    if(document.getElementById('lstSessionFormat')){
        audience = document.getElementById('lstSessionFormat');
        if(audience == '0' || audience == ''){
            bValid = false;
		    document.getElementById('lstSessionFormat').style.background='yellow';
		    msg = msg + 'Audience is required. <br>';
        }
        else{
            document.getElementById('lstSessionFormat').style.background='white';
        }
    }
    
    if(document.getElementById('chkTarget')){
        if(role == '0' || role == ''){
            bValid = false;
		    document.getElementById('chkTarget').style.background='yellow';
		    msg = msg + targetAudienceAlias + ' is required. <br>';
        }
        else{
            document.getElementById('chkTarget').style.background='white';
        }
    }
    if(document.getElementById('chkTopic')){
        if(topic == '0' || topic == ''){
            bValid = false;
		    document.getElementById('chkTopic').style.background='yellow';
		    msg = msg + topicAlias + ' is required. <br>';
        }
        else{
            document.getElementById('chkTopic').style.background='white';
        }
    }
    if(document.getElementById('lstSecondarySesType')){
        if(sesTypeSecondary == '0' || sesTypeSecondary == ''){
            bValid = false;
		    document.getElementById('lstSecondarySesType').style.background='yellow';
		    msg = msg + secondarySesTypeAlias + ' is required. <br>';
        }
        else{
            document.getElementById('lstSecondarySesType').style.background='white';
        }
    }
	if(trim(first)=='')
	{
		bValid = false;
		document.getElementById('lblFirst').style.background='yellow';
		msg =msg + 'First Name is required. <br>';
	}
	else
	{
		document.getElementById('lblFirst').style.background='white';
		
	}
	
	
	if(trim(last)=='')
	{
		bValid = false;
		document.getElementById('lblLast').style.background='yellow';
		msg =msg + 'Last Name is required. <br>';
	}
	else
	{
		document.getElementById('lblLast').style.background='white';
		
	}
	if(trim(conTitle)=='')
	{
		bValid = false;
		document.getElementById('lblConTitle').style.background='yellow';
		msg =msg + 'Title is required. <br>';
	}
	else
	{
		document.getElementById('lblConTitle').style.background='white';
		
	}
	if(trim(org)=='')
	{
		bValid = false;
		document.getElementById('lblOrganization').style.background='yellow';
		msg =msg + 'Organization is required. <br>';
	}
	else
	{
		document.getElementById('lblOrganization').style.background='white';
		
	}
	/*if(trim(add1)=='')
	{
		bValid = false;
		document.getElementById('lblAdd1').style.background='yellow';
		msg =msg + 'Address One is required. <br>';
	}
	else
	{
		document.getElementById('lblAdd1').style.background='white';
		
	}
	if(trim(city)=='')
	{
		bValid = false;
		document.getElementById('lblCity').style.background='yellow';
		msg =msg + 'City is required. <br>';
	}
	else
	{
		document.getElementById('lblCity').style.background='white';
		
	}
	*/
	//see if us or canada is selected
	//if so, then a state must also be selected
	if(country.options[country.options.selectedIndex].value == 'US' || country.options[country.options.selectedIndex].value == 'CA')
	{
		if(state.options[state.options.selectedIndex].value == true || state.options[state.options.selectedIndex].value == 'xx')
		{
			bValid = false;
			document.getElementById('lblState').style.background='yellow';
			msg =msg + 'State is required. <br>';
		}
		else
		{
			document.getElementById('lblState').style.background='white';
			
		}
		document.getElementById('lblCountry').style.background='white';
	}
	else
	{
		//state is not required
		document.getElementById('lblState').style.background='white';
		//make sure a country is selected
		if(country.options[country.options.selectedIndex].value == 'xx')
		{
			bValid = false;
			document.getElementById('lblCountry').style.background='yellow';
			msg =msg + 'Country is required. <br>';
		}
		else
		{
			document.getElementById('lblCountry').style.background='white';
		}
		
	}
	/*
	if(trim(postal)=='')
	{
		bValid = false;
		document.getElementById('lblPostal').style.background='yellow';
		msg =msg + 'Postal is required. <br>';
	}
	else
	{
		document.getElementById('lblPostal').style.background='white';
		
	}
	*/
	//validate phone
	/*if(trim(phone)=='')
	{
		bValid = false;
		document.getElementById('lblPhone').style.background='yellow';
		msg =msg + 'Phone is required. <br>';
	}
	else
	{*/
		if(validatePhone('cfpForm',frm.elements['txtPhone'],'no') == false)
		{
			bValid = false;
			document.getElementById('lblPhone').style.background='yellow';
			msg =msg + 'Phone is invalid. <br>';
		}
		else
		{
			document.getElementById('lblPhone').style.background='white';
		}
	//}
	//validate fax
	if(validatePhone('cfpForm',frm.elements['txtFax'],'no') == false)
		{
			bValid = false;
			document.getElementById('lblFax').style.background='yellow';
			msg =msg + 'Fax is invalid. <br>';
		}
		else
		{
			document.getElementById('lblFax').style.background='white';
		}
		
	
	//validate email
	if(trim(email)=='')
	{
		bValid = false;
		document.getElementById('lblEmail').style.background='yellow';
		msg =msg + 'Email is required. <br>';
	}
	else
	{
		//see if email is valid
		if(validateEmail(frm.elements['txtEmail'],'true','no')==false)
		{
			bValid = false;
			document.getElementById('lblEmail').style.background='yellow';
			msg =msg + 'Email is invalid. <br>';
		}
		else
		{
			document.getElementById('lblEmail').style.background='white';
		}
		
	}
	if(trim(bio)=='')
	{
		//if this person is just the adminContact then bio is not required
		if(bAdminSpeaker.checked == true)
		{
			bValid = false;
			document.getElementById('lblBio').style.background='yellow';
			msg =msg + 'Bio is required for all speakers. <br>';
		}
	}
	else
	{
		document.getElementById('lblBio').style.background='white';
		
	}
	var customResponseMsg = '';
	if (requireCF1 == 'True' && document.getElementById('txtCustomCFPResponse1')){
	    var CFResponse1 = document.getElementById('txtCustomCFPResponse1').value;
	    if(trim(CFResponse1)=='')
	    {
		    bValid = false;
		    document.getElementById('txtCustomCFPResponse1').style.background='yellow';
		    customResponseMsg = 'Your response is required to one or more highlighted fields. <br>';
	    }
	    else
	    {
		    document.getElementById('txtCustomCFPResponse1').style.background='white';
    		
	    }
	}
	if (requireCF2 == 'True' && document.getElementById('txtCustomCFPResponse2')){
	    var CFResponse2 = document.getElementById('txtCustomCFPResponse2').value;
	    if(trim(CFResponse2)=='')
	    {
		    bValid = false;
		    document.getElementById('txtCustomCFPResponse2').style.background='yellow';
		    customResponseMsg = 'Your response is required to one or more highlighted fields. <br>';
	    }
	    else
	    {
		    document.getElementById('txtCustomCFPResponse2').style.background='white';
    	}
	}
	if (requireCF3 == 'True' && document.getElementById('txtCustomCFPResponse3')){
	    var CFResponse3 = document.getElementById('txtCustomCFPResponse3').value;
	    if(trim(CFResponse1)=='')
	    {
		    bValid = false;
		    document.getElementById('txtCustomCFPResponse3').style.background='yellow';
		    customResponseMsg = 'Your response is required to one or more highlighted fields. <br>';
	    }
	    else
	    {
		    document.getElementById('txtCustomCFPResponse3').style.background='white';
    		
	    }
	}
	
/*
if bAdminSpeaker is not checked then one of two must be true
1 - person should be required to select at least one from the 'additional Speakers'
2 - speaker is not yet known must be checked
 primaryContactSpeakerCheckbox
    speakerIsNotKnownCheckbox*/
//new validation; Author Jeff Kyle. Date: 9-5-10
var bRequireSpeaker = true;
if (document.getElementById('chkSpeakerIsNotKnown')){
    //var speakerIsNotKnownCheckbox = document.getElementById('chkSpeakerIsNotKnown'); 
    if(document.getElementById('chkSpeakerIsNotKnown').checked == true){
       bRequireSpeaker = false;
    }
}


if (bRequireSpeaker == true){
    if(bAdminSpeaker.checked == false)
	{
		if(additionalSpeakers.options[additionalSpeakers.selectedIndex].value == 0)
		{
			bValid = false;
			//document.getElementById('lbl').style.background='yellow';
			msg =msg + 'The primary contact needs to be designated as a speaker or you need to add  ';
			msg = msg + ' one from the \'Additional Speakers\' list box. <br>';
		}
	}
}
	
	
	if(bValid == false)
	{
		msg = '<strong>The following fields have errors. Please fix before continuing.</strong><br><br>' + msg + customResponseMsg;
		document.getElementById('lblErrMsg').innerHTML = msg;
		return false;
	}
	else
	{
	frm.submit();
	}
	//return;
}

//this function will reset state and country if form is being posted back from live2.asp
function updateTopicsTA()
{

	var frm = document.forms['cfpForm'];
	var jsTopics = frm.txtJSSelTopics.value;
	var jsTA = frm.txtJSSelTA.value;
	//var jsTopics = document.getElementById('txtJSSelTopics').value;
	//var jsTA = document.getElementById('txtJSSelTA').value;
	//jsTopics = jsTopics.replace('','');
	//jsTA = jsTA.replace('','');
	var topicArray = jsTopics.split(',');
	var tAArray = jsTA.split(',');
	var topic;
	//create an array from jsTopics and jsTA.
	//loop through arrays and check appropriate checkboxes
	var expTopic = /chkTopic\d+/;
	var expTarget = /chkTarget\d+/;
	for(var f = 0; f<frm.length; f++)
	{
		if(frm.elements[f].type == 'checkbox')
		{
			//begin topic
			if (frm.elements[f].name.match(expTopic))
			{
				//loop through array and see if this checkbox needs to be selected
				for(var tLoop = 0; tLoop < topicArray.length; tLoop++)
				{
					topicID = topicArray[tLoop];
					topicID = 'chkTopic'+topicID;
					//alert(topicID);
					if(frm.elements[f].name == topicID)
					{	
						
						frm.elements[f].checked = true;
						//break;
					}
					else
					{
					
						//frm.elements[f].checked = false;
					}
				}
			}
			//end of topics
			//begin ta
			if (frm.elements[f].name.match(expTarget))
			{
			//loop through array and see if this checkbox needs to be selected
				for(var taLoop = 0; taLoop < tAArray.length; taLoop++)
				{
					taID = tAArray[taLoop];
					taID = 'chkTarget'+taID;
					//alert(topicID);
					if(frm.elements[f].name == taID)
					{	
						
						frm.elements[f].checked = true;
						//break;
					}
					else
					{
					
						//frm.elements[f].checked = false;
					}
				}
			}
			//end ta
		}
	}					
						
}

function updateListBoxes()
{

	var frm = document.forms.cfpForm;
	var jSState = document.getElementById('txtJSState');
	var jSCountry = document.getElementById('txtJSCountry');
	var listState = frm.lstUSState;
	var listCountry = frm.lstCountry;
	var jSNumSpeakers = document.getElementById('txtJSNumSpeakers');
	var listNumSpeaker = frm.lstAdditionalSpeakers;
	//check value of additional speakers
	for(var a = 0;a<listNumSpeaker.length;a++)
			{
				if(listNumSpeaker.options[a].value == jSNumSpeakers.value)
				{
					listNumSpeaker.options[a].selected = true;
					
				}
			}
			
	//check state value
	if (!(jSState == ''))
	{
		if(jSState.value == 'xx')
			listState.options[0].selected = true;
		else
		{
			for(var i = 0;i<listState.length;i++)
			{
				if(listState.options[i].value == jSState.value)
				{
					listState.options[i].selected = true;
					
				}
			}
		}
	}
	//added 2-21-06 by jk
	//disables state list box if country is not 'US' or 'CA'
	if(jSCountry.value == 'US' || jSCountry.value == 'CA'){
					listState.disabled = false;
				}
				else{
					listState.disabled = true;
				}
	//check country value
	if (!(jSCountry == ''))
	{
		if(jSCountry.value == 'xx')
			listCountry.options[0].selected = true;
		else
		{
			for(var j = 0; j < listCountry.length;j++)
			{
				if(listCountry.options[j].value == jSCountry.value)
				{
					listCountry.options[j].selected = true;
					
				}
			}
		}
	}
}

function checkStatusSpeakerIsNotKnown(e){
    var item = e.id;
    var additionalSpeakerList = document.getElementById('lstAdditionalSpeakers');
    var primaryContactSpeakerCheckbox = document.getElementById('chkAdminSpeaker');
    var speakerIsNotKnownCheckbox = document.getElementById('chkSpeakerIsNotKnown');
    var speakerBioTextbox = document.getElementById('txtBio');
    var bioCounterTextbox = document.getElementById('txtBioCounter');
    var bioPanel = document.getElementById('divBio');
    if(item == 'chkSpeakerIsNotKnown' && e.checked == true){
        //disable speaker controls
        //session will be linked to Contact (people record) rather than speaker record
        additionalSpeakerList.options[0].selected = true;
        additionalSpeakerList.disabled = true;
        primaryContactSpeakerCheckbox.checked = false;
        primaryContactSpeakerCheckbox.disabled = true;
        speakerBioTextbox.value = '';
        speakerBioTextbox.disabled = true;
        bioCounterTextbox.value = '0';
        bioCounterTextbox.disabled = true;
        bioPanel.style.display = 'none';
        return;
    }
    else{
        //enable speaker controls
        //require selection from speaker controls
        additionalSpeakerList.disabled = false;
        primaryContactSpeakerCheckbox.disabled = false;
        speakerBioTextbox.disabled = false;
        bioCounterTextbox.value = '0';
        bioCounterTextbox.disabled = false;
        bioPanel.style.display = 'block';
        return;
    }
}

//-->

