/********************************************************
* NCS Meeting Registration Script
* Revision Date: 07.31.09
********************************************************/
function IsValid(){
   try{
      return (fv() && pvs());
   }catch(e){
      return;
   }
}
function fv(){
	try{
		var el = document.forms[0].elements;
		var success=true;
		if(Trim(el['firstName'].value)==''){success=false;}
		if(Trim(el['lastName'].value)==''){success=false;}
		if(Trim(el['badgeName'].value)==''){success=false;}
		if(Trim(el['address1'].value)==''){success=false;}
		if(Trim(el['city'].value)==''){success=false;}
		/*if(Trim(el['state'].value)==''){success=false;}*/
		if(Trim(el['zip'].value)==''){success=false;}
		if(Trim(el['country'].value)==''){success=false;}
		if(Trim(el['phone'].value)==''){success=false;}
		if(Trim(el['email'].value)==''){success=false;}
		if(!el['addressType'][0].checked&&!el['addressType'][1].checked){
			success = false;
		}
		if(!success){
		   alert("One or more fields in the Registrant Section is incomplete.");
		   return false;
		}
		if(el['c0Count'].selectedIndex==0&&el['c1Count'].selectedIndex==0&&el['c2Count'].selectedIndex==0&&el['c3Count'].selectedIndex==0&&
		   el['c4Count'].selectedIndex==0&&el['c5Count'].selectedIndex==0&&el['c6Count'].selectedIndex==0&&el['c7Count'].selectedIndex==0&&
		   el['c8Count'].selectedIndex==0&&el['c9Count'].selectedIndex==0&&el['c10Count'].selectedIndex==0&&el['c11Count'].selectedIndex==0&&
		   el['c12Count'].selectedIndex==0&&el['c13Count'].selectedIndex==0){success=false;}
		if(!success){
		   alert("Please complete a registration category.");
		   return false;
		}

		if(Trim(el['spouseName'].value)==''&&Trim(el['guestName1'].value)==''&&Trim(el['guestName2'].value)==''){
		   if(el['c8Count'].selectedIndex>0||el['c11Count'].selectedIndex>0){
		      alert("If you are registering a spouse or guest, please include the name(s) of your spouse/guest(s).");
		      return false;
		   }
		}

		if((!el['e0'][0].checked&&!el['e0'][1].checked)||(!el['e0Guest'][0].checked&&!el['e0Guest'][1].checked)){
		   alert("Please complete the Welcome Reception information.");
		   return false;
		}
		if((el['e0Guest'][0].checked&&el['e0Count'].selectedIndex==0)||(el['e0Guest'][1].checked&&el['e0Count'].selectedIndex>0)){
		   alert("Your Welcome Reception guest selections do not match.\nPlease update your selection appropriately.");
		   return false;
		}
		if((!el['e1'][0].checked&&!el['e1'][1].checked)||(!el['e1Guest'][0].checked&&!el['e1Guest'][1].checked)){
		   alert("Please complete the President's Reception information.");
		   return false;
		}
		if((el['e1Guest'][0].checked&&el['e1Count'].selectedIndex==0)||(el['e1Guest'][1].checked&&el['e1Count'].selectedIndex>0)){
		   alert("Your President's Reception guest selections do not match.\nPlease update your selection appropriately.");
		   return false;
		}
		if((!el['e2'][0].checked&&!el['e2'][1].checked)||(!el['e2Guest'][0].checked&&!el['e2Guest'][1].checked)){
		   alert("Please complete the Annual Banquet information.");
		   return false;
		}
		if((el['e2Guest'][0].checked&&el['e2Count'].selectedIndex==0)||(el['e2Guest'][1].checked&&el['e2Count'].selectedIndex>0)){
		   alert("Your Annual Banquet guest selections do not match.\nPlease update your selection appropriately.");
		   return false;
		}

      /*guests match?*/
      if(!GuestMatch(el['e0Count'],el['t0Count'])){
         alert("The number of guests you selected for the Welcome Reception \n"
               +"does not match your Spouse/Guest registration and/or additional evening function ticket purchases.\n\n"
               +"If you are bringing one or more guests, you must either register them or purchase additional tickets accordingly.");
         return false;
      }

      if(!GuestMatch(el['e1Count'],el['t1Count'])){
         alert("The number of guests you selected for the President's Reception \n"
               +"does not match your Spouse/Guest registration and/or additional evening function ticket purchases.\n\n"
               +"If you are bringing one or more guests, you must either register them or purchase additional tickets accordingly.");
         return false;
      }

      if(!GuestMatch(el['e2Count'],el['t2Count'])){
         alert("The number of guests you selected for the Annual Banquet \n"
               +"does not match your Spouse/Guest registration and/or additional evening function ticket purchases.\n\n"
               +"If you are bringing one or more guests, you must either register them or purchase additional tickets accordingly.");
         return false;
      }
		
		if(!el['course0'][0].checked&&!el['course0'][1].checked){
			alert("Please indicate if you will attend the AUA Course or not.");
			return false;
		}
		
		if(!el['course1'][0].checked&&!el['course1'][1].checked){
			alert("Please indicate if you will attend the Industry Sponsored Lunch or not.");
			return false;
		}
		
		if(!el['course2'][0].checked&&!el['course2'][1].checked){
			alert("Please indicate if you will attend the Live Surgery at Northwestern University or not.");
			return false;
		}

		if(!success){alert('A required field is incomplete.\nPlease review your selections for missing information.');}
		return success;
	}catch(e){
	   alert(e);
		return false;
	}
}
function uc(){
	try{
		var el = document.forms[0].elements;
		var x;
		var subtotal=0;
		var total=0;
		var ic = el['ic'].value.split(',');
		for(x=0;x<ic.length;++x){
		   ic[x]=parseInt(ic[x]);
		   el['c'+x.toString()+'Total'].value=FormatCurrency((el['c'+x.toString()+'Count'].selectedIndex*ic[x]));
		   subtotal+=(el['c'+x.toString()+'Count'].selectedIndex*ic[x]);
		}
		el['regTotal'].value=FormatCurrency(subtotal);
		total+=subtotal;
		subtotal=0;

		/*
		var oc = el['oc'].value.split(',');
		for(x=0;x<oc.length;++x){
		   oc[x]=parseInt(oc[x]);
		   el['op'+x.toString()+'Total'].value=FormatCurrency((el['op'+x.toString()+'Count'].selectedIndex*oc[x]));
		   subtotal+=(el['op'+x.toString()+'Count'].selectedIndex*oc[x]);

		}
		el['opTotal'].value=FormatCurrency(subtotal);
		total+=subtotal;
		subtotal=0;
		*/
		
      var tc = el['tc'].value.split(',');
		for(x=0;x<tc.length;++x){
		   tc[x]=parseInt(tc[x]);
		   el['t'+x.toString()+'Total'].value=FormatCurrency((el['t'+x.toString()+'Count'].selectedIndex*tc[x]));
		   subtotal+=(el['t'+x.toString()+'Count'].selectedIndex*tc[x]);
		}
		el['tickTotal'].value=FormatCurrency(subtotal);
		total+=subtotal;
		subtotal=0;

		el['grandTotal'].value=FormatCurrency(total);

		return total;
	}catch(e){
	   alert(e);
		return 0;
	}
}
function GuestMatch(g,t){
   try{
      var el=document.forms[0].elements;
      var gc = g.selectedIndex;
      var tc = t.selectedIndex;
      var sgc = el['c8Count'].selectedIndex + el['c11Count'].selectedIndex;
      if((sgc+tc)>=gc){
         return true;
      }else{
         return false;
      }
   }catch(ex){
      return false;
   }
}

function np(tid){
   try{
		var ok=false;
      if(uc()>0){ok=true;}
		if(ok){sht(tid,true);sp();}else{sht(tid,false);sp();}
   }catch(e){
      return;
   }
}
