<!--//
function validateForm(e)
{
	
	var frm = document.forms[e.name];

	var sesTitle = frm.elements['txtSesTitle'].value;//required
	var shortSes = frm.elements['txtSessionLongDesc'].value;//required
	if(frm.elements['txtSynopsis']){//this will not exist if we are using custom questions instead
	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;//required
	var add2 = frm.elements['txtAdd2'].value;
	var city = frm.elements['txtCity'].value;//required
	var state = frm.elements['lstUSState'];//required
	var postal = frm.elements['txtPostal'].value;//required
	var country = frm.elements['lstCountry'];
	
	var phone = frm.elements['txtPhone'].value;//required
	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 = '';
	
	
	//validate topics (if required)
	var topicSelectOption = frm.txtTopicSelectOption.value;
	var topicChkType;
	var bTopicRequired = frm.txtBTopicRequired.value;
	var bTopicSelected = false;
	if(bTopicRequired = 'True'){
		if(topicSelectOption=='single'){
			expTopic = /chkTopic/;
			topicChkType = 'radio';
		}
		for(var f = 0; f<frm.length; f++){
	
			if(frm.elements[f].type == topicChkType)
			{
				//begin topic
				if (frm.elements[f].name.match(expTopic) && frm.elements[f].checked == true){
					bTopicSelected = true;
				
				}
			}
		}
	}
	if(bTopicSelected == false){
		bValid = false;
		document.getElementById('lblTopic').style.background='yellow';
		msg =msg + 'Topic is required. <br>';
	}
	else{
		document.getElementById('lblTopic').style.background='white';
	
	}
	
	
	//validate target audience if required
	var taSelectOption = frm.txtTASelectOption.value;
	var taChkType;
	var bTARequired = frm.txtBTARequired.value;
	var bTASelected = false;
	//alert(taSelectOption+'\n'+bTARequired);
	
	
	
	
	//validate TA(if required)
	var taSelectOption = frm.txtTASelectOption.value;
	var taChkType;
	var bTARequired = frm.txtBTARequired.value;
	var bTASelected = false;
	//alert(taSelectOption + '\n'+bTARequired);
	if(bTARequired = 'True'){
		if(taSelectOption=='single'){
			expTA = /chkTarget/;
			taChkType = 'radio';
		}
		else{
			expTA = /chkTarget\d+/;
			taChkType = 'checkbox';
		}
		//alert(taChkType);
		for(var f = 0; f<frm.length; f++){
	
			if(frm.elements[f].type == taChkType){
				if (frm.elements[f].name.match(expTA) && frm.elements[f].checked == true){
					bTASelected = true;
					//alert(frm.elements[f].name);
				}
			}
		}
		if(bTASelected == false){
			bValid = false;
			document.getElementById('lblTA').style.background='yellow';
			msg =msg + 'Products related to session is required. <br>';
		}
		else{
			document.getElementById('lblTA').style.background='white';
	
		}
	}
	
	
	//end of target audience
	
	

	if(trim(sesTitle)=='')
	{
		bValid = false;
		document.getElementById('lblSesTitle').style.background='yellow';
		msg =msg + 'Session Title is required. <br>';
	}
	else
	{
		document.getElementById('lblSesTitle').style.background='white';
		
	}
	if(trim(shortSes)=='')
	{
		bValid = false;
		document.getElementById('lblShortSes').style.background='yellow';
		msg =msg + 'Short Session Description is required. <br>';
	}
	else
	{
		document.getElementById('lblShortSes').style.background='white';
		
	}
	if(detSes){
	    if(trim(detSes)=='')
	    {
	    //check minimiumn number of words required. if min = 0 then field can be blank
		    if(detSesMinWords > 0)
		    {
			    document.getElementById('lblDetSes').style.background='yellow';
			    bValid = false;
			    msg =msg + 'Detailed Session Description is required. <br>';
		    }
	    }
	    else
	    {
		    document.getElementById('lblDetSes').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(org)=='')
	{
		bValid = false;
		document.getElementById('lblOrganization').style.background='yellow';
		msg =msg + 'Organization is required. <br>';
	}
	else
	{
		document.getElementById('lblOrganization').style.background='white';
		
	}
	if(trim(conTitle)=='')
	{
		bValid = false;
		document.getElementById('lblConTitle').style.background='yellow';
		msg =msg + 'Contact Person\'s Title is required. <br>';
	}
	else
	{
		document.getElementById('lblConTitle').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(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';
		
	}
//if bAdminSpeaker is not checked then
//person should be required to select at least one from the 'additional Speakers'
//listBox
	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 = '<b>The following fields have errors. Please fix before continuing.</b><br><br>' + msg;
		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 topicArray = jsTopics.split(',');
	var tAArray = jsTA.split(',');
	var topic;
	var topicSelectOption = frm.txtTopicSelectOption.value;
	var expTopic;// = /chkTopic\d+/;
	var expTarget = /chkTarget\d+/;
	var topicChkType;
	var taChkType;
	//alert(topicSelectOption);
	if(topicSelectOption=='single'){
		expTopic = /chkTopic/;
		topicChkType = 'radio';
	}
	else{
		expTopic = /chkTopic\d+/;
		topicChkType = 'checkbox';
	}
	
	taChkType = 'checkbox';
	//create an array from jsTopics and jsTA.
	//loop through arrays and check appropriate checkboxes
	
	
	for(var f = 0; f<frm.length; f++)
	{
		if(frm.elements[f].type == topicChkType)
		{
			//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];
					
					if(topicSelectOption=='single'){
						//topicID = 'chkTopic';
						if(frm.elements[f].value == topicID)
					{	
						
						frm.elements[f].checked = true;
						//break;
					}
					else
					{
					
						//frm.elements[f].checked = false;
					}
					}
					else{
						topicID = 'chkTopic'+topicID;
						if(frm.elements[f].name == topicID)
					{	
						
						frm.elements[f].checked = true;
						//break;
					}
					else
					{
					
						//frm.elements[f].checked = false;
					}
					}
					
					
				}
			}
		}
	}
	for(var f = 0; f<frm.length; f++)
	{
		if(frm.elements[f].type == taChkType)
		{
			//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;
					
				}
			}
		}
	}
}
//-->
