// JavaScript Document

function getTotal()
{
	var donated = document.getElementById('donation');
	var numSubs = document.getElementById('numberSubscriptions');
	var reNumOnly = /^\d+$/;
	
	/*
	if (!reNumOnly.test(numSubs.value)||!reNumOnly.test(donated.value))
	{
		alert("Number of subscriptions or dollar amount donated must be a whole number and entered without a decimal, i.e.: 3 and not 3.65");
	}
	*/
	if (numSubs.value == 0) {
		var subscriptions_total = prompt('Enter your total number of subscriptions you wish to receive:', '');
		if (subscriptions_total != null) {				
			var subtotal = subscriptions_total*document.getElementById('subscriptionPrice').value;
			var total = subtotal+donated.value/1;
			numSubs.value = subscriptions_total;
			document.getElementById('subscriptionTotal').value = subtotal;
			document.getElementById('orderTotal').value = total;			
		}
	}
	else {
			var subtotal = numSubs.value*document.getElementById('subscriptionPrice').value;
			var total = subtotal+donated.value/1;
			document.getElementById('subscriptionTotal').value = subtotal;
			document.getElementById('orderTotal').value = total;	
	}
}

function PopulateDropDown1 (name) {
	var formObj = window.opener.document.newSubscription;
	for(i=0;i<formObj.secondChoice.length;i++)
	{
		//alert(formObj.secondChoice.options[i].value);
		if(formObj.secondChoice.options[i].value == name) {
			formObj.secondChoice.options[i].selected = true;
			window.self.close()
		}
	}
}	

function PopulateDropDown2 (name) {
	var formObj = window.opener.document.newSubscription;
	for(i=0;i<formObj.thirdChoice.length;i++)
	{
		//alert(formObj.thirdChoice.options[i].value);
		if(formObj.thirdChoice.options[i].value == name) {
			formObj.thirdChoice.options[i].selected = true;
			window.self.close()
		}
	}
}	

function fillBilling (name) {
	var formObj = document.newSubscription;
	if (formObj.billingSameAsShipping.checked) {	
		document.getElementById('ccFirstName').value = document.getElementById('firstName').value;
		document.getElementById('ccLastName').value = document.getElementById('lastName').value;
		document.getElementById('ccAddress1').value = document.getElementById('address1Pri').value;
		document.getElementById('ccAddress2').value = document.getElementById('address2Pri').value;
		document.getElementById('ccCity').value = document.getElementById('cityPri').value;
		document.getElementById('ccState').value = document.getElementById('statePri').value;
		document.getElementById('ccZipCode').value = document.getElementById('zipCodePri').value;
	}
	else {
		document.getElementById('ccFirstName').value = '';
		document.getElementById('ccLastName').value = '';
		document.getElementById('ccAddress1').value = '';
		document.getElementById('ccAddress2').value = '';
		document.getElementById('ccCity').value = '';
		document.getElementById('ccState').value = '';
		document.getElementById('ccZipCode').value = ''; 
	}
}	


function firstChoicePrice(name) {	
	var breakLoop = 0;
	var obj = new Array();
		obj[0] = new Array();
		obj[0][0] = 'P1';
		obj[0][1] = 185;
		obj[0][2] = 148;
		obj[0][3] = 148;	
	
		obj[1] = new Array();
		obj[1][0] = 'P2';
		obj[1][1] = 185;
		obj[1][2] = 148;
		obj[1][3] = 148;	

		obj[2] = new Array();
		obj[2][0] = 'P3';
		obj[2][1] = 185;
		obj[2][2] = 148;
		obj[2][3] = 148;	
		
		obj[3] = new Array();
		obj[3][0] = 'O1';
		obj[3][1] = 360;
		obj[3][2] = 288;
		obj[3][3] = 288;
		
		obj[4] = new Array();
		obj[4][0] = 'F2';
		obj[4][1] = 200;
		obj[4][2] = 164;
		obj[4][3] = 164;
		
		obj[5] = new Array();
		obj[5][0] = 'F3';
		obj[5][1] = 200;
		obj[5][2] = 164;
		obj[5][3] = 164;
		
		obj[6] = new Array();
		obj[6][0] = 'F4';
		obj[6][1] = 200;
		obj[6][2] = 164;
		obj[6][3] = 164;
		
		obj[7] = new Array();
		obj[7][0] = 'F5';
		obj[7][1] = 200;
		obj[7][2] = 164;
		obj[7][3] = 164;
		
		obj[8] = new Array();
		obj[8][0] = 'F6';
		obj[8][1] = 200;
		obj[8][2] = 164;
		obj[8][3] = 164;
		
//
		obj[9] = new Array();
		obj[9][0] = 'H2';
		obj[9][1] = 200;
		obj[9][2] = 164;
		obj[9][3] = 164;
		
		obj[10] = new Array();
		obj[10][0] = 'H3';
		obj[10][1] = 200;
		obj[10][2] = 164;
		obj[10][3] = 164;
		
		obj[11] = new Array();
		obj[11][0] = 'H4';
		obj[11][1] = 200;
		obj[11][2] = 164;
		obj[11][3] = 164;
		
		obj[12] = new Array();
		obj[12][0] = 'H5';
		obj[12][1] = 200;
		obj[12][2] = 164;
		obj[12][3] = 164;
		
		obj[13] = new Array();
		obj[13][0] = 'H6';
		obj[13][1] = 200;
		obj[13][2] = 164;
		obj[13][3] = 164;	

//		
		obj[14] = new Array();
		obj[14][0] = 'C2';
		obj[14][1] = 200;
		obj[14][2] = 164;
		obj[14][3] = 164;
		
		obj[15] = new Array();
		obj[15][0] = 'C3';
		obj[15][1] = 200;
		obj[15][2] = 164;
		obj[15][3] = 164;
		
		obj[16] = new Array();
		obj[16][0] = 'C4';
		obj[16][1] = 200;
		obj[16][2] = 164;
		obj[16][3] = 164;
		
		obj[17] = new Array();
		obj[17][0] = 'C5';
		obj[17][1] = 200;
		obj[17][2] = 164;
		obj[17][3] = 164;
		
		obj[18] = new Array();
		obj[18][0] = 'C6';
		obj[18][1] = 200;
		obj[18][2] = 164;
		obj[18][3] = 164;
//
		obj[19] = new Array();
		obj[19][0] = 'D2';
		obj[19][1] = 200;
		obj[19][2] = 164;
		obj[19][3] = 164;
		
		obj[20] = new Array();
		obj[20][0] = 'D3';
		obj[20][1] = 200;
		obj[20][2] = 164;
		obj[20][3] = 164;
		
		obj[21] = new Array();
		obj[21][0] = 'D4';
		obj[21][1] = 200;
		obj[21][2] = 164;
		obj[21][3] = 164;
		
		obj[22] = new Array();
		obj[22][0] = 'D5';
		obj[22][1] = 200;
		obj[22][2] = 164;
		obj[22][3] = 164;
		
		obj[22] = new Array();
		obj[22][0] = 'D6';
		obj[22][1] = 200;
		obj[22][2] = 164;
		obj[22][3] = 164;
//
		obj[23] = new Array();
		obj[23][0] = 'A2';
		obj[23][1] = 215;
		obj[23][2] = 176;
		obj[23][3] = 176;
		
		obj[24] = new Array();
		obj[24][0] = 'A3';
		obj[24][1] = 215;
		obj[24][2] = 176;
		obj[24][3] = 176;
		
		obj[25] = new Array();
		obj[25][0] = 'A4';
		obj[25][1] = 215;
		obj[25][2] = 176;
		obj[25][3] = 176;
		
		obj[26] = new Array();
		obj[26][0] = 'A5';
		obj[26][1] = 215;
		obj[26][2] = 176;
		obj[26][3] = 176;
		
		obj[27] = new Array();
		obj[27][0] = 'A6';
		obj[27][1] = 215;
		obj[27][2] = 176;
		obj[27][3] = 176;
//
		obj[28] = new Array();
		obj[28][0] = 'A2';
		obj[28][1] = 215;
		obj[28][2] = 176;
		obj[28][3] = 176;
		
		obj[29] = new Array();
		obj[29][0] = 'A3';
		obj[29][1] = 215;
		obj[29][2] = 176;
		obj[29][3] = 176;
		
		obj[30] = new Array();
		obj[30][0] = 'A4';
		obj[30][1] = 215;
		obj[30][2] = 176;
		obj[30][3] = 176;
		
		obj[31] = new Array();
		obj[31][0] = 'A5';
		obj[31][1] = 215;
		obj[31][2] = 176;
		obj[31][3] = 176;
		
		obj[32] = new Array();
		obj[32][0] = 'A6';
		obj[32][1] = 215;
		obj[32][2] = 176;
		obj[32][3] = 176;
//		
		obj[33] = new Array();
		obj[33][0] = 'B1';
		obj[33][1] = 215;
		obj[33][2] = 176;
		obj[33][3] = 176;
		
		obj[34] = new Array();
		obj[34][0] = 'B2';
		obj[34][1] = 215;
		obj[34][2] = 176;
		obj[34][3] = 176;
		
		obj[35] = new Array();
		obj[35][0] = 'B3';
		obj[35][1] = 215;
		obj[35][2] = 176;
		obj[35][3] = 176;
		
		obj[36] = new Array();
		obj[36][0] = 'B4';
		obj[36][1] = 215;
		obj[36][2] = 176;
		obj[36][3] = 176;
		
		obj[37] = new Array();
		obj[37][0] = 'B5';
		obj[37][1] = 215;
		obj[37][2] = 176;
		obj[37][3] = 176;

		obj[38] = new Array();
		obj[38][0] = 'B6';
		obj[38][1] = 215;
		obj[38][2] = 176;
		obj[38][3] = 176;		
//
		obj[38] = new Array();
		obj[38][0] = 'E1';
		obj[38][1] = 215;
		obj[38][2] = 176;
		obj[38][3] = 176;
		
		obj[39] = new Array();
		obj[39][0] = 'E2';
		obj[39][1] = 215;
		obj[39][2] = 176;
		obj[39][3] = 176;
		
		obj[40] = new Array();
		obj[40][0] = 'E3';
		obj[40][1] = 215;
		obj[40][2] = 176;
		obj[40][3] = 176;
		
		obj[41] = new Array();
		obj[41][0] = 'E4';
		obj[41][1] = 215;
		obj[41][2] = 176;
		obj[41][3] = 176;
		
		obj[42] = new Array();
		obj[42][0] = 'E5';
		obj[42][1] = 215;
		obj[42][2] = 176;
		obj[42][3] = 176;

		obj[43] = new Array();
		obj[43][0] = 'E6';
		obj[43][1] = 215;
		obj[43][2] = 176;
		obj[43][3] = 176;	
		
		for(a=0;a<obj.length;a++)
		{
			if (obj[a][0] == name) {
				document.getElementById('playCodeHidden').value = obj[a][1];
				document.getElementById('playCodeAHidden').value = obj[a][2];
				document.getElementById('playCodeBHidden').value = obj[a][3];
					var formObj = document.newSubscription;
					var numOfPlays;
							//alert('Value1=' + document.getElementById('playCodeHidden').value);
							//alert('Value2=' + document.getElementById('playCodeAHidden').value);
							//alert('Value3=' + document.getElementById('playCodeBHidden').value);					
					for(i=0;i<formObj.playCode.length;i++)
					{
						if(formObj.playCode[i].checked) {
							counter = i + 1
							numOfPlays = 1;
								//alert(document.newSubscription.donation.value);
								document.getElementById('subscriptionPrice').value = obj[a][counter];
								document.getElementById('subscriptionTotal').value = (document.getElementById('numberSubscriptions').value * obj[a][counter]);
								var total = document.getElementById('subscriptionTotal').value;
								var donation = document.getElementById('donation').value;
								total = parseInt(total) + parseInt(donation);
								//alert('Total =' + total);
								document.getElementById('orderTotal').value = total;
						}
					}
					if (numOfPlays!=1)
					{
						//document.getElementById('playCodeChoice').style.className = 'errorRedTextBold';
						//alert("You have not specified play code. Please select a play code and submit again.");
						//return false;
					}				
				break;
			}		
		}		
}