
//REMOVE ADULT REGISTRATION
function removedaily(){
				document.ipmc.dayM.checked=false;
				document.ipmc.dayT.checked=false;
				document.ipmc.dayW.checked=false;
				document.ipmc.dayTh.checked=false;
				document.ipmc.dayM.disabled=true;
				document.ipmc.dayT.disabled=true;
				document.ipmc.dayW.disabled=true;
				document.ipmc.dayTh.disabled=true;

    document.ipmc.price[0].checked=false;
    document.ipmc.price[1].checked=false;
    document.ipmc.price[2].checked=false;
				document.ipmc.qtyD.value=0;
				document.ipmc.qtyDC1.value=0;
				document.ipmc.qtyDC2.value=0;
				document.ipmc.qtyDC3.value=0;
    document.ipmc.qtyD.disabled=true;
				document.ipmc.qtyDC1.disabled=true;
				document.ipmc.qtyDC2.disabled=true;
				document.ipmc.qtyDC3.disabled=true;
}

function removefull(){
    document.ipmc.price[3].checked=false;
    document.ipmc.price[4].checked=false;
    document.ipmc.price[5].checked=false;
				document.ipmc.qtyF.value=0;
				document.ipmc.qtyFC1.value=0;
				document.ipmc.qtyFC2.value=0;
				document.ipmc.qtyFC3.value=0;

				document.ipmc.qtyF.disabled=true;
				document.ipmc.qtyFC1.disabled=true;
				document.ipmc.qtyFC2.disabled=true;
				document.ipmc.qtyFC3.disabled=true;
				}

//REMOVE YOUTH REGISTRATION
function removedailyY(){
				document.ipmc.dayMY.checked=false;
				document.ipmc.dayTY.checked=false;
				document.ipmc.dayWY.checked=false;
				document.ipmc.dayThY.checked=false;
				document.ipmc.dayMY.disabled=true;
				document.ipmc.dayTY.disabled=true;
				document.ipmc.dayWY.disabled=true;
				document.ipmc.dayThY.disabled=true;

    document.ipmc.priceY[0].checked=false;
				document.ipmc.qtyDY.value=0;
    document.ipmc.qtyDY.disabled=true;
//    document.ipmc.disclaimer.checked=false;
}

function removefullY(){
    document.ipmc.priceY[1].checked=false;
				document.ipmc.qtyFY.value=0;
				document.ipmc.qtyFY.disabled=true;
//    document.ipmc.disclaimer.checked=false;
				}

//CALCULATION

function calculate(){

		var mydate=new Date()
		var date_day=mydate.getDay()         //0=sun; 1=mon; 2=tue ...
		var date_dd=mydate.getDate()         //1 to 31
		var date_mm=mydate.getMonth()+1 //0=jan; 1=feb; 2=mar... to 11=dec
		var date_yyyy=mydate.getYear()

price=0, priceY=0, priceC1=0, priceC2=0, priceC3=0, youth=0, children1=0, children2=0, children3=0, qty=0, qtyY=0, qtyC1=0, qtyC2=0, qtyC3=0;

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ADULTS REGISTRATION
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//ADULT DAILY RATE ROW
if (document.ipmc.price[0].checked ||
    document.ipmc.price[1].checked ||
    document.ipmc.price[2].checked){

				removefull();
				document.ipmc.remove1.checked=false;

				document.ipmc.dayM.disabled=false;
				document.ipmc.dayT.disabled=false;
				document.ipmc.dayW.disabled=false;
				document.ipmc.dayTh.disabled=false;

    document.ipmc.qtyD.disabled=false;
				document.ipmc.qtyDY.disabled=false;
				document.ipmc.qtyDC1.disabled=false;
				document.ipmc.qtyDC2.disabled=false;
				document.ipmc.qtyDC3.disabled=false;
		}

//ADULT FULL CONFERENCE ROWS
if (document.ipmc.price[3].checked ||
    document.ipmc.price[4].checked ||
    document.ipmc.price[5].checked){

				removedaily();
				document.ipmc.remove1.checked=false;

				document.ipmc.qtyF.disabled=false;
				document.ipmc.qtyFC1.disabled=false;
				document.ipmc.qtyFC2.disabled=false;
				document.ipmc.qtyFC3.disabled=false;
}

// if Single selected 

if (document.ipmc.price[0].checked){
    qty=1; 	
			document.ipmc.qtyD.value=1; 
}
if (document.ipmc.price[3].checked){
    qty=1; 	
			document.ipmc.qtyF.value=1; 
}

// if Couple selected 

if (document.ipmc.price[1].checked){
    qty=2; 	
		document.ipmc.qtyD.value=2; 
}
if (document.ipmc.price[4].checked){
    qty=2; 	
		document.ipmc.qtyF.value=2; 
}

// if Group selected 
if (document.ipmc.price[2].checked){
		qty = document.ipmc.qtyD.value;

		if (isNaN(document.ipmc.qtyD.value) ||
			  (document.ipmc.qtyD.value > 0 &&
			  document.ipmc.qtyD.value < 6))	{
			 qty=6; 
				document.ipmc.qtyD.value=6; 
		  document.ipmc.qtyD.focus();}
}

if (document.ipmc.price[5].checked){
		qty = document.ipmc.qtyF.value;

		if (isNaN(document.ipmc.qtyF.value) ||
			  (document.ipmc.qtyF.value > 0 &&
			  document.ipmc.qtyF.value < 6)){
			   qty=6; 
		    document.ipmc.qtyF.value=6; 
		    document.ipmc.qtyF.focus();}
}


// checking Children 6-12 QTY's

if (isNaN(document.ipmc.qtyDC1.value) )		{
	  document.ipmc.qtyDC1.value=0; 
	  qtyC1 =0;
		}
if (isNaN(document.ipmc.qtyFC1.value) )		{
	  document.ipmc.qtyFC1.value=0;
	  qtyC1 =0;
		}

if (document.ipmc.qtyDC1.value > 0){ 
	  qtyC1 = document.ipmc.qtyDC1.value;
    }
if (document.ipmc.qtyFC1.value > 0){ 
	  qtyC1 = document.ipmc.qtyFC1.value;
		}

// checking Children 2-5 QTY's

if (isNaN(document.ipmc.qtyDC2.value) )	{
	  document.ipmc.qtyDC2.value=0;
	  qtyC2 =0;
		}
if (isNaN(document.ipmc.qtyFC2.value) )		{
	  document.ipmc.qtyFC2.value=0;
	  qtyC2 =0;
		}

if (document.ipmc.qtyDC2.value > 0){ 
	  qtyC2 = document.ipmc.qtyDC2.value;
    }
if (document.ipmc.qtyFC2.value > 0){ 
	  qtyC2 = document.ipmc.qtyFC2.value;
		}

// checking Children 0-24 QTY's

if (isNaN(document.ipmc.qtyDC3.value) )		{
	  document.ipmc.qtyDC3.value=0;
	  qtyC3 =0;
		}
if (isNaN(document.ipmc.qtyFC3.value) )		{
	  document.ipmc.qtyFC3.value=0;
	  qtyC3 =0;
		}

if (document.ipmc.qtyDC3.value > 0){ 
	  qtyC3 = document.ipmc.qtyDC3.value;
    }
if (document.ipmc.qtyFC3.value > 0){ 
	  qtyC3 = document.ipmc.qtyFC3.value;
		}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// YOUTH REGISTRATION
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//YOUTH DAILY RATE ROW
if (document.ipmc.priceY[0].checked) {
				document.ipmc.dayMY.disabled=false;
				document.ipmc.dayTY.disabled=false;
				document.ipmc.dayWY.disabled=false;
				document.ipmc.dayThY.disabled=false;
				document.ipmc.qtyDY.disabled=false;

				removefullY();
				document.ipmc.remove2.checked=false;
		}

//YOUTH FULL CONFERENCE ROWS
if (document.ipmc.priceY[1].checked){

				document.ipmc.qtyFY.disabled=false;

				removedailyY();
				document.ipmc.remove2.checked=false;
}

// checking YOUTH QTY's
if (isNaN(document.ipmc.qtyDY.value) )	
	{
	  document.ipmc.qtyDY.value=0;
		  qtyY =0;
		}
if (isNaN(document.ipmc.qtyFY.value) )	
	{
	  document.ipmc.qtyFY.value=0;
		  qtyY =0;
	}

if (document.ipmc.qtyDY.value > 0){ 
	  qtyY = document.ipmc.qtyDY.value;
    }
if (document.ipmc.qtyFY.value > 0){ 
	  qtyY = document.ipmc.qtyFY.value;
		}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  CALCULATING REGISTRATIONS
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// ADULTS CALCULATING DAYS ATTENDING
days=0;
if (document.ipmc.dayM.checked){days +=1;}
if (document.ipmc.dayT.checked) {days +=1;}
if (document.ipmc.dayW.checked){days +=1;}
if (document.ipmc.dayTh.checked){days +=1;}

// YOUTH CALCULATING DAYS ATTENDING
daysY=0;
if (document.ipmc.dayMY.checked){daysY +=1;}
if (document.ipmc.dayTY.checked) {daysY +=1;}
if (document.ipmc.dayWY.checked){daysY +=1;}
if (document.ipmc.dayThY.checked){daysY +=1;}

//CHECKING FFM/CMI MEMBERSHIP DISCOUNTS 
//1 per person, no group eligibility 
document.ipmc.member.disabled=false;

if (document.ipmc.price[2].checked || 
    document.ipmc.price[5].checked){ 
				document.ipmc.member.checked=false;
				document.ipmc.member.disabled=true;
}

subtotal=0; 
qty = qty *1;
qtyY = qtyY *1;
qtyC1 = qtyC1 *1;
qtyC2 = qtyC2 *1;
qtyC3 = qtyC3 *1;

// PRICES DAILY RATE
if (document.ipmc.price[0].checked){price = 55;   }
if (document.ipmc.price[1].checked){price = 90/2;}
if (document.ipmc.price[2].checked){price = 40;   }
if (document.ipmc.qtyDC1.value > 0){priceC1 = 25;   }
if (document.ipmc.qtyDC2.value > 0){priceC2 = 15;   }
if (document.ipmc.qtyDC3.value > 0){priceC3 = 0;   }

if (document.ipmc.priceY[0].checked){priceY = 17;   } //YOUTH

// PRICES FULL CONFERENCE
// DAYS=1 TO AVOID THE ZERO VALUE ASIGNED
if (document.ipmc.price[3].checked){days=1; price = 160; }
if (document.ipmc.price[4].checked){days=1; price = 270/2;}
if (document.ipmc.price[5].checked){days=1; price = 150;}
if (document.ipmc.qtyFC1.value > 0){priceC1 = 80; }
if (document.ipmc.qtyFC2.value > 0){priceC2 = 50; }
if (document.ipmc.qtyFC3.value > 0){priceC3 = 0;}

if (document.ipmc.priceY[1].checked){daysY=1; priceY = 50; } // YOUTH

//CALCULATING DISCOUNT
var discount = 0;
if (document.ipmc.member.checked){discount = 10;}

//EARLY BIRD SPECIAL - REGISTER FOR THE FULL CONFERENCE BY JUNE 15TH $15 OFF
//DISCOUNT APPLY TO TOTAL REGISTRATION PER COUPLE / GROUP
var early_bird_discount=0;
var dd=15;
var mm=06;
var yyyy=2010;
var early_bird_date=new Date(yyyy,mm-1,dd+1);  //(mm-1) because 0=jan; 1=feb; 2=mar; 3=apr; 4=may; 5=jun... to 11=dec
var today_date=new Date(); 
var early_bird_days = early_bird_date - today_date; //days remaining
//document.ipmc.early_bird_days.value= early_bird_days;

if (today_date < early_bird_date &&
   (document.ipmc.price[3].checked || 
    document.ipmc.price[4].checked || 
	  document.ipmc.price[5].checked))
	{
	  early_bird_discount = 15;
			}

//CALCULATING COUPLES DISCOUNT
var couple_discount = 0;

//if ((document.ipmc.price[1].checked || document.ipmc.price[4].checked
//	 )&&(
//	  document.ipmc.fname.value.length > 0 &&
//	  document.ipmc.lname.value.length > 0 &&
//	  document.ipmc.sfname.value.length > 0 &&
//	  document.ipmc.slname.value.length > 0
//	 )&&(
//	  (document.ipmc.gender1[0].checked && document.ipmc.gender2[1].checked) ||
//	  (document.ipmc.gender1[1].checked && document.ipmc.gender2[0].checked)
//	))
//		{couple_discount = 0.1;}


subtotal = price * qty * days;

children1 = priceC1 * qtyC1 * days;
children2 = priceC2 * qtyC2 * days;
children3 = priceC3 * qtyC3 * days;

youth = priceY * qtyY * daysY;

//CALCULATING TOTAL REGISTRATION
total = subtotal - discount - early_bird_discount + children1 + children2 + children3 + youth;

document.ipmc.subtotal.value = subtotal;
document.ipmc.discount.value = discount;
document.ipmc.early_bird_discount.value = early_bird_discount;
//document.ipmc.couple_discount.value = couple_discount;
document.ipmc.children.value = children1  + children2 + children3;
document.ipmc.youth.value = youth;
document.ipmc.total.value = total;

build_item_number();

}

function tS(){ x=new Date(); x.setTime(x.getTime()); return x; } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 

function build_item_number(){
			var mydate=new Date()
			var date_day=mydate.getDay()         //0=sun; 1=mon; 2=tue ...
			var date_dd=mydate.getDate()         //1 to 31
			var date_mm=mydate.getMonth()+1 //0=jan; 1=feb; 2=mar... to 11=dec
			var date_yyyy=mydate.getYear()

   var date_hh=lZ(mydate.getHours())
			var date_ms=lZ(mydate.getMinutes())

   var item_number="", type="FX", qtyA="0", qtyY="0", qtyC="0", qtyC1="0", qtyC2="0", qtyC3="0", days=""; 
		 var dayM="x", dayT="x", dayW="x", dayTh="x";

			if (document.ipmc.price[0].checked){type="DS";  qtyA=document.ipmc.qtyD.value;}
			if (document.ipmc.price[1].checked){type="DC";  qtyA=document.ipmc.qtyD.value;}
			if (document.ipmc.price[2].checked){type="DG";  qtyA=document.ipmc.qtyD.value;}
			if (document.ipmc.price[3].checked){type="FS";  qtyA=document.ipmc.qtyF.value;}
			if (document.ipmc.price[4].checked){type="FC";  qtyA=document.ipmc.qtyF.value;}
			if (document.ipmc.price[5].checked){type="FG";  qtyA=document.ipmc.qtyF.value;}

			if (document.ipmc.qtyDY.value > 0){qtyY=document.ipmc.qtyDY.value;}
			if (document.ipmc.qtyFY.value > 0){qtyY=document.ipmc.qtyFY.value;}

			if (document.ipmc.qtyDC1.value > 0){qtyC1=document.ipmc.qtyDC1.value;}
			if (document.ipmc.qtyDC2.value > 0){qtyC2=document.ipmc.qtyDC2.value;}
			if (document.ipmc.qtyDC3.value > 0){qtyC3=document.ipmc.qtyDC3.value;}
			if (document.ipmc.qtyFC1.value > 0){qtyC1=document.ipmc.qtyFC1.value;}
			if (document.ipmc.qtyFC2.value > 0){qtyC2=document.ipmc.qtyFC2.value;}
			if (document.ipmc.qtyFC3.value > 0){qtyC3=document.ipmc.qtyFC3.value;}
			qtyC = qtyC1*1 + qtyC2*1 + qtyC3*1;

			if (document.ipmc.dayM.checked)	{dayM="M";} 
			if (document.ipmc.dayT.checked){dayT="T";} 
			if (document.ipmc.dayW.checked){dayW="W";} 
			if (document.ipmc.dayTh.checked){dayTh="T";} 
			
			if (document.ipmc.price[0].checked ||
				  document.ipmc.price[1].checked ||
				  document.ipmc.price[2].checked ){
				  days = "-"+dayM + dayT + dayW + dayTh;
			}else{
				  days = "-MTWT";
			}
			
			fname = document.ipmc.fname.value;
			fname = fname.toUpperCase();
      if (fname.length > 1)
				{y=1;}else{y=fname.length}
			fname = fname.substring(0, y)

			lname = document.ipmc.lname.value;
			lname = lname.toUpperCase();
      if (lname.length > 3)
				{y=3;}else{y=lname.length}
			lname = lname.substring(0, y)
			
			if (date_mm < 10){date_mm = "0"+date_mm;}
			if (date_dd  < 10){date_dd   = "0"+date_dd;}

			item_number = lname + "-" + fname + date_mm + date_dd + date_hh + date_ms + type + qtyA +"-"+ "Y" + qtyY + "C" + qtyC + days;
			document.ipmc.item_number.value= item_number;

}