// JavaScript Document

function goToOption(sel, id) {
var opt, o = 0;
while (opt = sel[o++]) if (opt.id == id) sel.selectedIndex = o - 1;

/*premium = document.PledgeForm.PREMIUM[document.PledgeForm.PREMIUM.selectedIndex].value;
	premiumPos = premium.search('/');
				tempstr = premium.substr(premiumPos + 1); // get rest of string after first '/'

premiumPos2 = tempstr.search('/');  // look for second '/'
			
		if (premiumPos2 == -1) // if second '/' not found assume the rest of the string
			{   
				premiumPos2 = tempstr.length;
			}
			
			premiumPart = tempstr.substr(0,premiumPos2); // get the amount string out of the premium code
			premiumAmount = parseFloat(premiumPart);  // convert it to a number
			
document.PledgeForm.GIFT_AMOUNT3.value = Math.round(premiumAmount * 100) / 100 + '.00';

amountchange();*/
}

function goToOptionprice(sel, id) {
var opt, o = 0;
while (opt = sel[o++]) if (opt.id == id) sel.selectedIndex = o - 1;

premium = document.PledgeForm.PREMIUM[document.PledgeForm.PREMIUM.selectedIndex].value;
	premiumPos = premium.search('/');
				tempstr = premium.substr(premiumPos + 1); // get rest of string after first '/'

premiumPos2 = tempstr.search('/');  // look for second '/'
			
		if (premiumPos2 == -1) // if second '/' not found assume the rest of the string
			{   
				premiumPos2 = tempstr.length;
			}
			
			premiumPart = tempstr.substr(0,premiumPos2); // get the amount string out of the premium code
			premiumAmount = parseFloat(premiumPart);  // convert it to a number
			
document.PledgeForm.GIFT_AMOUNT3.value = Math.round(premiumAmount * 100) / 100 + '.00';

amountchange();
}


function My_Form_Validator(form)
{
	var premiumPart;
	var tempstr;
	var premiumPos;
	var premiumPos2;
	var premiumAmount;
	var premium;
    var agree;

	
        if(document.PledgeForm.totalamount.value == 0)
		{
			alert('Pledge Amount Error - please enter a dollar amount in at least one fund before clicking the "Continue Donation" button.');
			return false;
		}
		
	// see if the premium contains a '/' character (if so, then a minimum amount is coded in)
	// premium is formatted as ACCOUNT/MINIMUM_AMOUNT/DESCRIPTION
	premium = document.PledgeForm.PREMIUM[document.PledgeForm.PREMIUM.selectedIndex].value;
	premiumPos = premium.search('/');
	
	if (premiumPos > -1) // if amount is coded in
		{  
			tempstr = premium.substr(premiumPos + 1); // get rest of string after first '/'
			premiumPos2 = tempstr.search('/');  // look for second '/'
			
		if (premiumPos2 == -1) // if second '/' not found assume the rest of the string
			{   
				premiumPos2 = tempstr.length;
			}
			
			premiumPart = tempstr.substr(0,premiumPos2); // get the amount string out of the premium code
			premiumAmount = parseInt(premiumPart);  // convert it to a number
			
			if (premiumAmount > 0 && premiumAmount > form.pledgeform.totalamount.value)  // if we haven't met the minimum ...
				{
				alert('Gift Selection Error - the selected thank you gift requires a minimum pledge of $' + premiumPart + '.  Please verify your pledge amount or choose a different gift.');
				
				
				return false;
				}
		}
		
	if(document.PledgeForm.totalamount.value < 35) // if we haven't met the minimum ...
		{ 
			alert('Reminder - A one year subscription to Previews (our TV Member Guide) is only available for a pledge of $35 or more.');
		}	
// Read on Air (check page code to verify show/hide status)	
// Begin comment here to remove "Read on Air" function
	// if (document.PledgeForm.readName.checked) 
		//{
		//	agree = 'Yes';
		//}
		//else 
		//{
			//agree = 'No';
			

		//}
	
	
	
		//rdnm = 'Read name(s) on-air: '+agree;  
	//document.PledgeForm.comments2.value=document.PledgeForm.comments2.value+'\n===========\n'+rdnm+'\n===========\n';
	//document.PledgeForm.comments.value=document.PledgeForm.comments2.value;
        // End comment here to remove "Read on Air" function
	

	
//check for membercard quantity
	
		if(document.PledgeForm.membercardqty.value == 0 && document.PledgeForm.MEMBER_CARD.value== 0) {
			
		}
		
		else {
			
			membercard = "I would like " + document.PledgeForm.membercardqty.value + " Membercard(s)";
			
			document.PledgeForm.comments2.value=document.PledgeForm.comments2.value + membercard;
			document.PledgeForm.comments.value = document.PledgeForm.comments2.value;
		}
		
// end membercard qty

		amount=parseFloat(document.PledgeForm.totalamount.value);
		
		var form_qty = document.PledgeForm.membercardqty.value;
				    	
		var needed = parseFloat(form_qty * 60.00);
		
		if(document.PledgeForm.totalamount.value < needed) {
			alert('The Total Pledge amount does not equal the necessary amount for the number of Membercards requested. Please verify the amount(s) and quantities');
			return false
		}

}// End of My_Form_Validator




function CalcDisplayAmount(amt)
{
	var displayAmt;
	var amtValue;
	
	number = amt;
	
	if (isNaN(amt)==true) //not a valid number
		{ 
			displayAmt = '0.00';
			displayAmt = number.replace(",","");
			return displayAmt;		
		}

	if (amt.length==0) // no value at all
    	{
			displayAmt = '0.00';
			
			return displayAmt;	
		}

	// round to 2 places after the decimal point
	
	
	
	amtValue = parseFloat(amt);
	amtValue = Math.round(amtValue * 100) / 100;
	
	
	//	if user enters in value less than 0, make it 0
	if (amtValue < 0) 
			amtValue = 0;
	
	//	if it doesn't contain decimal point, add it 
	if (amtValue == Math.round(amtValue))
		{
			displayAmt = amtValue + '.00';
		}
		
	// else if it only contains one place after the decimal, add one more
	else if (amtValue * 10 == Math.round(amtValue * 10)) 
		{
			displayAmt = amtValue + '0';
		}

	// else it contains 2 places after the decimal, just return it
	else 
		{
			displayAmt = amtValue;
		}
		
	return displayAmt;
}


function checktot()
{
	
    amount=parseFloat(document.PledgeForm.totalamount.value);
		
	var form_qty = document.PledgeForm.membercardqty.value;
				    	
	var needed = parseFloat(form_qty * 60.00);
	
	for (var i=0; i < document.PledgeForm.chkmmbcard.length; i++)
   		{
   			if (document.PledgeForm.chkmmbcard[i].checked)
      			{
      				var rad_val = document.PledgeForm.chkmmbcard[i].value;
      
					if (rad_val == 1) 
						{ 
							if (amount < 60.00)
								{
									alert('The WSIU Membercard is only available for a pledge of $60 or more.  Please verify the dollar amount(s) entered.');
	    							return false;
								}
							else
								if (form_qty == 0)
									{
									document.PledgeForm.MEMBER_CARD.value='Yes';
									document.PledgeForm.membercardqty.value='1';
									}
								else
									
									if (amount < needed)
										{
										alert('The Total Pledge amount does not equal the necessary amount for the number of Membercards requested. Please verify the amount(s) and quantities');
										return false;
										}
								
						}
						
					
				}
				
				else { //its unchecked
					if(document.PledgeForm.membercardqty.value !=0) {
						document.PledgeForm.chkmmbcard[0].checked=true;
						document.PledgeForm.MEMBER_CARD.value='Yes';
					}
				}
   		}
}


function amountchange()
{
	var total;

	//change display format
	
	
	document.PledgeForm.GIFT_AMOUNT1.value=CalcDisplayAmount(document.PledgeForm.GIFT_AMOUNT1.value);
	document.PledgeForm.GIFT_AMOUNT2.value=CalcDisplayAmount(document.PledgeForm.GIFT_AMOUNT2.value);
	document.PledgeForm.GIFT_AMOUNT3.value=CalcDisplayAmount(document.PledgeForm.GIFT_AMOUNT3.value);	
    document.PledgeForm.GIFT_AMOUNT5.value=CalcDisplayAmount(document.PledgeForm.GIFT_AMOUNT5.value);
	
	//Calc total 
	total=parseFloat(document.PledgeForm.GIFT_AMOUNT1.value)+ 
	parseFloat(document.PledgeForm.GIFT_AMOUNT2.value)+
	parseFloat(document.PledgeForm.GIFT_AMOUNT3.value)+
	parseFloat(document.PledgeForm.GIFT_AMOUNT5.value);
	
	total = Math.round(total * 100) / 100;
	
	document.PledgeForm.totalamount.value=CalcDisplayAmount(total);	
	
	checktot();
}
// End CalcDisplayAmount


function get_radio_value()
{
	for (var i=0; i < document.PledgeForm.chkmmbcard.length; i++)
   		{
   			if (document.PledgeForm.chkmmbcard[i].checked)
      			{
     			 	var rad_val = document.PledgeForm.chkmmbcard[i].value;
     			}
   		}
}
// End get_radio_value
//

function copycomments () {
document.PledgeForm.comments.value = document.PledgeForm.comments2.value;	
}


