function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function initializeCondition(){
	inputs = document.getElementsByTagName('input');	
	for(i=0; i<inputs.length; i++){
	testid='';
		//if(inputs[i].name.search('question')>-1){
				testid= inputs[i].name+'_condition';
			if(document.getElementById(testid)!=undefined && document.getElementById(testid) !=''){
				conditionDiv = inputs[i].name+'_condition';
				conditionDiv = document.getElementById(conditionDiv);
				if(conditionDiv!='' && conditionDiv != undefined){
					if(inputs[i].checked==true && inputs[i].value=='Yes'){
						if(conditionDiv.className.search('show')<0 && conditionDiv.className.search('hide')<0){
							conditionDiv.className = conditionDiv.className+' show';
						}
					}
					else{
						if(conditionDiv.className.search('hide')<0 && conditionDiv.className.search('show')<0){
							conditionDiv.className = conditionDiv.className+' hide';
						}
					}
				}
			}
			validateConditionalForm();
		}
	//}
}
function formConditionalView(){
	inputs = document.getElementsByTagName('input');	
	
	for(i=0; i<inputs.length; i++){
	testid='';
		//if(inputs[i].name.search('question')>-1){
				testid= inputs[i].name+'_condition';
			if(document.getElementById(testid)!=undefined && document.getElementById(testid) !=''){
				inputs[i].onclick = changeConditionDiv;
			}
		}
	//}
}

function changeConditionDiv(){
	conditionDiv = this.name+'_condition';
	conditionDiv = document.getElementById(conditionDiv);
	if(conditionDiv!='' && conditionDiv != undefined){
		//if(conditionDiv.className.search('hide')>-1 && this.value.substring(0,3)=='Yes'){
		if(this.value.substring(0,3)=='Yes'){	
			conditionDiv.className = conditionDiv.className.replace('hide','show');
		}
		else{
			conditionDiv.className = conditionDiv.className.replace('show','hide');
		}
	}
}
function easeInOut(div){
	if(div.className.search('show')>-1){
		for(i=0; i<500000; i++){
			div.style = 'overflow: hidden; height:'+ i +'px;';
		}
	}
	else{
		for(i=500000; i>0; i--){
			div.style = 'overflow: hidden; height:'+ i +'px;';
		}
	}
	div.style ='';
}
function validateConditionalForm(){

}
function staffingLevel(){
	inputs = document.getElementsByTagName('input');
	for(g=0;g<inputs.length;g++){
		if(inputs[g].value.search('Department')>-1){
			inputs[g].parentNode.className = inputs[g].parentNode.className + ' combineheading';
			inputs[g].className = inputs[g].className +' hide';
		}
	}
}

function initializeConditionNew(){
	inputs = document.getElementsByTagName('input');	
	for(i=0; i<inputs.length; i++){
	testid='';
			testid= inputs[i].value+'_conditional';
			if(document.getElementById(testid)!=undefined && document.getElementById(testid) !=''){
				conditionDiv = inputs[i].value+'_conditional';
				conditionDiv = document.getElementById(conditionDiv);
				if(conditionDiv!='' && conditionDiv != undefined){
					if(inputs[i].checked==true && inputs[i].value=='Yes'){
						if(conditionDiv.className.search('show')<0 && conditionDiv.className.search('hide')<0){
							conditionDiv.className = conditionDiv.className+' show';
						}
					}
					else{
						if(conditionDiv.className.search('hide')<0 && conditionDiv.className.search('show')<0){
							conditionDiv.className = conditionDiv.className+' hide';
						}
					}
				}
			}
			validateConditionalForm();
		}
}
function formConditionalViewNew(){
	inputs = document.getElementsByTagName('input');	
	
	for(i=0; i<inputs.length; i++){
	testid='';
				testid= inputs[i].value+'_conditional';
			if(document.getElementById(testid)!=undefined && document.getElementById(testid) !=''){
				inputs[i].onclick = changeConditionDivNew;
				initialChangeConditionDivNew(inputs[i]);
			}
		}
}
function initialChangeConditionDivNew(x){
	conditionDiv = x.value+'_conditional';
	conditionDiv = document.getElementById(conditionDiv);
	if(conditionDiv!='' && conditionDiv != undefined){
		if(conditionDiv.className.search('hide')>-1 && (x.value=='Yes' || x.checked===true)){
			conditionDiv.className = conditionDiv.className.replace('hide','show');
		}
		else{
			conditionDiv.className = conditionDiv.className.replace('show','hide');
		}
	}
}
function changeConditionDivNew(){
	conditionDiv = this.value+'_conditional';
	conditionDiv = document.getElementById(conditionDiv);
	if(conditionDiv!='' && conditionDiv != undefined){
		if(conditionDiv.className.search('hide')>-1 && (this.value=='Yes' || this.checked===true)){
			conditionDiv.className = conditionDiv.className.replace('hide','show');
		}
		else{
			conditionDiv.className = conditionDiv.className.replace('show','hide');
		}
	}
}
function annualConferenceRegistration(){
	var elitetotal = document.getElementById('elite_total_input');
	var courtyardtotal = document.getElementById('courtyard_total_input');
	var additionalmealstotal = document.getElementById('additional_meals_total_input');
	var advertisertotal = document.getElementById('advertiser_total_input');
	
	var grandtotal = document.getElementById('grand_total_input');
	
	elitetotal.disabled=true;
	courtyardtotal.disabled=true;
	additionalmealstotal.disabled=true;
	advertisertotal.disabled=true;
	grandtotal.disabled=true;
	
	elitetotal.className='total';
	courtyardtotal.className='total';
	additionalmealstotal.className='total';
	advertisertotal.className='total';
	grandtotal.className='total';
	
	var thisform = document.getElementById('form_76_post');
	
	if(thisform!='' && thisform!=null && thisform!=undefined){
		thisform.onsubmit = submitAnnualConferenceRegistration;
		
		var exhibitorcheck = document.getElementById('type_fov_Exhibitor2279_input');
		var sponsorcheck = document.getElementById('type_fov_Sponsor2280_input');
		var advertisercheck = document.getElementById('type_fov_Advertiser2281_input');
		
		var inputs='';
		var selects='';
		
			inputs = document.getElementById('Exhibitor_conditional').getElementsByTagName('input');
			selects = document.getElementById('Exhibitor_conditional').getElementsByTagName('select');
			
			for(i=0;i<inputs.length;i++){
				inputs[i].onchange=totalUpExhibitorAnnual;
				inputs[i].onclick=totalUpExhibitorAnnual;
				inputs[i].onkeyup=totalUpExhibitorAnnual;
				inputs[i].onkeydown=totalUpExhibitorAnnual;
			}
			for(i=0;i<selects.length;i++){
				selects[i].onchange=totalUpExhibitorAnnual;
			}
			
		
		var sponsoramount = document.getElementById('sponsorship_amount_input');
		
			//sponsoramount.onblur=checkSponsorAmount;
				sponsoramount.onchange=totalUpExhibitorAnnual;
				sponsoramount.onclick=totalUpExhibitorAnnual;
				sponsoramount.onkeyup=totalUpExhibitorAnnual;
				sponsoramount.onkeydown=totalUpExhibitorAnnual;
			
		inputs='';
		selects='';
		
			inputs = document.getElementById('Advertiser_conditional').getElementsByTagName('input');
			selects = document.getElementById('Advertiser_conditional').getElementsByTagName('select');
			
			for(i=0;i<inputs.length;i++){
				inputs[i].onchange=totalUpExhibitorAnnual;
				inputs[i].onclick=totalUpExhibitorAnnual;
				inputs[i].onkeyup=totalUpExhibitorAnnual;
				inputs[i].onkeydown=totalUpExhibitorAnnual;
			}
			for(i=0;i<selects.length;i++){
				selects[i].onchange=totalUpExhibitorAnnual;
			}
	}
	
	checkSponsorEvents();
}
function checkSponsorEvents(){
	var sponsordivs = document.getElementById('Sponsor_conditional').getElementsByTagName('div');
	var sponsordivdesc='';
	var headingtest='';
	for(s=0;s<sponsordivs.length;s++){
	
		if(sponsordivs[s].className.search('sponsorship_event_multicheckbox')>-1){
			var sponsordivdesc = sponsordivs[s].getElementsByTagName('div');
			if(sponsordivdesc.length>0){
				headingtest = sponsordivs[s].innerHTML;
				if(headingtest.search('heading')>-1){
					sponsordivs[s].className+=' heading';
				}
				else{
					sponsordivs[s].className+=' sponsored';	
				}
				
			}
			
		}
	}
	
}
function checkSponsorAmount(){


totalUpExhibitorAnnual();
}
function pastDue(cyear, cmonth, cdate){
	var date=new Date();
	var tdate=date.getDate();
	var tmonth=date.getMonth();
	var tyear=date.getFullYear();
	
	var cdateUTC = Date.UTC(cyear,cmonth,cdate, 0, 0, 0, 0);
	var tdateUTC = Date.UTC(tyear,tmonth,tdate, 0, 0, 0, 0);
	
	var returnval='';
	
	if(cdateUTC<tdateUTC){
		returnval='lt';
	}
	if(cdateUTC==tdateUTC){
		returnval='e';
	}
	if(cdateUTC>tdateUTC){
		returnval='gt';
	}
	
	return returnval;
	
}
function totalUpExhibitorAnnual(){
	var elitetotal = document.getElementById('elite_total_input');
	var courtyardtotal = document.getElementById('courtyard_total_input');
	var additionalmealstotal = document.getElementById('additional_meals_total_input');
	
	var past = pastDue('2011','8','21');
		eliteextra=0;
		courtyardextra=0;
	if(past=='gt'){
		eliteextra=200;
		courtyardextra=100;
	}
	
	var sponsoramount = document.getElementById('sponsorship_amount_input');
	
	sponsoramount.value = sponsoramount.value.replace('\D','');
	var sponsortest = new Number(sponsoramount.value);
	
	var sponsortestresult = isNaN(sponsortest);

	if(sponsortestresult===true){
		sponsoramount.value=0;	
	}
	var eliteprice=0;
	//ELITE EXHIBITS
	var eliteexhibit = document.getElementById('elite_exhibit_input');
	var elitenumdisplays = document.getElementById('elite_number_of_displays_input');
	var eliteled = document.getElementById('elite_large_equipment_display_fov_Yes2362_input');
	
	if(eliteexhibit.checked===true){
		
		if(elitenumdisplays.selectedIndex==0){
			elitenumdisplays.selectedIndex=1;	
		}
		var elitedisplays = new Number(elitenumdisplays.selectedIndex);
		eliteprice=elitedisplays*(1000+eliteextra);
		if(eliteled.checked===true){
			eliteprice+=50;	
		}
	}
	elitetotal.value=eliteprice;
	
	var courtyardprice=0;
	//COURTYARD EXHIBITS
	var courtyardexhibit = document.getElementById('courtyard_exhibit_input');
	var courtyardnumdisplays = document.getElementById('courtyard_number_of_displays_input');
	var courtyardled = document.getElementById('courtyard_large_equipment_display_fov_Yes2364_input');
	var courtyardmailinglabels = document.getElementById('courtyard_mailing_labels_fov_Yes2375_input');
	var courtyardpromostuffed = document.getElementById('courtyard_promotional_materials_stuffed_fov_Yes2371_input');
	
	if(courtyardexhibit.checked===true){
		
		if(courtyardnumdisplays.selectedIndex==0){
			courtyardnumdisplays.selectedIndex=1;	
		}
		var courtyardisplays = new Number(courtyardnumdisplays.selectedIndex);
		courtyardprice=courtyardisplays*(600+courtyardextra);
		if(courtyardled.checked===true){
			courtyardprice+=100;	
		}
		if(courtyardmailinglabels.checked===true){
			courtyardprice+=75;	
		}
		if(courtyardpromostuffed.checked===true){
			courtyardprice+=75;	
		}
	}
	courtyardtotal.value=courtyardprice;
	
	//ADDITIONAL MEALS
	var amprice=0;
	var ameals = document.getElementById('additional_meals_input');
	
	if(ameals.selectedIndex>0){
		amprice = (ameals.selectedIndex-1)*100;	
	}
	else{
		amprice=0;	
	}
	additionalmealstotal.value=amprice;
	
	//ADVERTISING
	var fullpagead = document.getElementById('ad_size_fov_FullPage2313_input');
	var halfpagehorizontalad = document.getElementById('ad_size_fov_12PageHorizontal2314_input');
	var halfpageverticalad = document.getElementById('ad_size_fov_12PageVertical2315_input');
	var quarterpagead = document.getElementById('ad_size_fov_14page2316_input');
	var eighthpagead = document.getElementById('ad_size_fov_18Page2317_input');
	var advertisertotal = document.getElementById('advertiser_total_input');
	var adprice=0;
	
	if(eliteexhibit.checked===true){
		var freequarterad = document.getElementById('elite_ad_choice_fov_Free14PageAd2359_input');
		var fiftydollarcredit = document.getElementById('elite_ad_choice_fov_Creditme50onalargerad2360_input');
		var noad = document.getElementById('elite_ad_choice_fov_NoAd2361_input');
		var advertcheck= document.getElementById('type_fov_Advertiser2281_input');
		var elitediscount=0;
		
		if(fiftydollarcredit.checked===true){
			elitediscount+= -50;
			advertcheck.checked=true;
			document.getElementById('Advertiser_conditional').style.display="block";
		}
		if(freequarterad.checked===true){
			elitediscount+= -50;
			quarterpagead.checked=true;
			advertcheck.checked=true;
			document.getElementById('Advertiser_conditional').style.display="block";
		}
		if(noad===true){
			elitediscount=0;	
			quarterpagead.checked=false;
		}
		adprice+=elitediscount;
	}
	
	if(fullpagead.checked===true){
		adprice+=100;
	}
	if(halfpagehorizontalad.checked===true){
		adprice+=75;
	}
	if(halfpageverticalad.checked===true){
		adprice+=75;
	}
	if(quarterpagead.checked===true){
		adprice+=50;
	}
	if(eighthpagead.checked===true){
		adprice+=30;
	}
	
	if(adprice<0){
			adprice=0;
	}
	
	advertisertotal.value=adprice;

	setGrandTotal();
}
function setGrandTotal(x){
	var elitetotal = document.getElementById('elite_total_input');
	var courtyardtotal = document.getElementById('courtyard_total_input');
	var additionalmealstotal = document.getElementById('additional_meals_total_input');
	var sponsortotal = document.getElementById('sponsorship_amount_input');
	var advertisertotal = document.getElementById('advertiser_total_input');
	
	var grandtotal = document.getElementById('grand_total_input');

	var totalprice=0;
	totalprice += new Number(elitetotal.value);
	totalprice += new Number(courtyardtotal.value);
	totalprice += new Number(additionalmealstotal.value);
	totalprice += new Number(sponsortotal.value);
	totalprice += new Number(advertisertotal.value);

	grandtotal.value=totalprice;
}
function submitAnnualConferenceRegistration(){
	var elitetotal = document.getElementById('elite_total_input');
	var courtyardtotal = document.getElementById('courtyard_total_input');
	var additionalmealstotal = document.getElementById('additional_meals_total_input');
	var advertisertotal = document.getElementById('advertiser_total_input');
	var grandtotal = document.getElementById('grand_total_input');
	
	elitetotal.disabled=false;
	courtyardtotal.disabled=false;
	additionalmealstotal.disabled=false;
	advertisertotal.disabled=false;
	grandtotal.disabled=false;
	
	var fullpagead = document.getElementById('ad_size_fov_FullPage2313_input');
	var halfpagehorizontalad = document.getElementById('ad_size_fov_12PageHorizontal2314_input');
	var halfpageverticalad = document.getElementById('ad_size_fov_12PageVertical2315_input');
	var quarterpagead = document.getElementById('ad_size_fov_14page2316_input');
	var eighthpagead = document.getElementById('ad_size_fov_18Page2317_input');
	
	var sponsoramounttotal = document.getElementById('sponsorship_amount_input');
	var grandtotal = document.getElementById('grand_total_input');
	var eliteexhibit = document.getElementById('elite_exhibit_input');
	var freequarterad = document.getElementById('elite_ad_choice_fov_Free14PageAd2359_input');
	var fiftydollarcredit = document.getElementById('elite_ad_choice_fov_Creditme50onalargerad2360_input');
	var noad = document.getElementById('elite_ad_choice_fov_NoAd2361_input');
	var advertcheck= document.getElementById('type_fov_Advertiser2281_input');
	var admsg='';
	if(eliteexhibit.checked===true && advertcheck.checked===true){
		if(fiftydollarcredit.checked===true){
			if(fullpagead.checked===false && halfpagehorizontalad.checked===false && halfpageverticalad.checked===false && quarterpagead.checked===false){
				admsg='Because you have checked to receive a larger ad at a discounted price you must select at least one ad to place.  If you would like to not have an ad at all please select the "No Ad" option above.';
			}
			if(fullpagead.checked===false && halfpagehorizontalad.checked===false && halfpageverticalad.checked===false && quarterpagead.checked===false && eighthpagead.checked===true){
				admsg='Because you have checked to receive a larger ad at a discounted price you must select at least one ad, 1/4 page or larger.';	
			}
		}
		if(noad.checked===true){
			if(fullpagead.checked===true || halfpagehorizontalad.checked===true || halfpageverticalad.checked===true || quarterpagead.checked===true){
			admsg='You have selected to place an ad and are eligible for a free or discounted ad.  Please return to your elite exhibit information at the top of the page to select your discounted ad type.';
			}
		}
	}
	
	if(admsg.length>0){
		document.getElementById('aderror').innerHTML = admsg;
		returnval=false;
	}
	else{
		returnval=true;
	}
	return returnval;
}
function loadAnnualConferenceRegistration(){
		var registerAsCounty = document.getElementById('registering_as_county2872_input');
		var registerAsNDACoGuest = document.getElementById('registering_as_ndaco_guest2873_input');
		var firsttimeyes = document.getElementById('are_you_a_firsttime_attendee_fov_Yes30_input');
		var firsttimeno = document.getElementById('are_you_a_firsttime_attendee_fov_No31_input');
		var guestyes = document.getElementById('are_you_bringing_a_guest_fov_Yes2436_input');
		var guestno = document.getElementById('are_you_bringing_a_guest_fov_No2437_input');
		
		window.onload=annualConferenceRegistrationType;
		
		registerAsCounty.onclick=annualConferenceRegistrationType;
		registerAsNDACoGuest.onclick=annualConferenceRegistrationType;
		
		firsttimeyes.onclick=annualConferenceRegistrationType;
		firsttimeno.onclick=annualConferenceRegistrationType;
		
		guestyes.onclick=annualConferenceRegistrationType;
		guestno.onclick=annualConferenceRegistrationType;
		
		var thisform = document.getElementById('form_77_post');
	
	if(thisform!='' && thisform!=null && thisform!=undefined){
		thisform.onsubmit = validateAnnualConferenceRegistration;
	}
		
}

function validateAnnualConferenceRegistration(){

	var errmsg='';
	var firsttimeyes = document.getElementById('are_you_a_firsttime_attendee_fov_Yes30_input');
	var firsttimeno = document.getElementById('are_you_a_firsttime_attendee_fov_No31_input');
	
	var thisform = document.getElementById('form_77_post');

	if(firsttimeyes.checked==true && getCheckedValue(thisform.elements['first_time_attendee_days'])==''){
		errmsg='Please select days.';
	}
	if(firsttimeno.checked==true && getCheckedValue(thisform.elements['days'])==''){
		errmsg='Please select days.';
	}
	
	
	if(errmsg.length>0){
		var msg=document.getElementById('form_77_msg');
		msg.className='msg taoCMSerror';
		msg.innerHTML = errmsg;
		window.scrollTo(0,0);
		returnval=false;
	}
	else{
		returnval=true;
	}
	return returnval;
}


function annualConferenceRegistrationType(){
		var firsttimeyes = document.getElementById('are_you_a_firsttime_attendee_fov_Yes30_input');
		var firsttimeno = document.getElementById('are_you_a_firsttime_attendee_fov_No31_input');
		
		var firsttimedays = document.getElementById('firsttimedays');
		var nonfirsttimedays = document.getElementById('nonfirsttimedays');
		
		if(firsttimeyes.checked==true){
			firsttimedays.style.display="block";
			nonfirsttimedays.style.display="none";
		}
		if (firsttimeno.checked==true){
			firsttimedays.style.display="none";
			nonfirsttimedays.style.display="block";
		}
		
		var guestyes = document.getElementById('are_you_bringing_a_guest_fov_Yes2436_input');
		var guestno = document.getElementById('are_you_bringing_a_guest_fov_No2437_input');
		
		var guestfields = document.getElementById('guestfields');
		
		if(guestyes.checked==true){
			guestfields.style.display="";
		}
		else{
			guestfields.style.display="none";
		}

		var registerAsCounty = document.getElementById('registering_as_county2872_input');
		var registerAsNDACoGuest = document.getElementById('registering_as_ndaco_guest2873_input');
		
		var countyfields = document.getElementById('countyinputs');
		var companyfields = document.getElementById('companyinputs');
		
		if (registerAsCounty.checked==true){
			countyfields.style.display="block";
			companyfields.style.display="none";
		} else {
			countyfields.style.display="none";
			companyfields.style.display="block";
		}
			
	
}
