function addCartItem(cID, pID)
{
 	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);					
	
	var maxID, maxSrc;
	maxID = "maxPurchase" + pID;
	maxSrc = document.getElementById(maxID);

	var cpID, cpSrc;
	cpID = "currPurchase" + pID;
	cpSrc = document.getElementById(cpID);
	
	if(maxSrc.value==cpSrc.value)
	{
		alert("You can not purchase more than " + maxSrc.value + " of this item.");
	}
	else
	{
		var newCP;
		newCP = eval(cpSrc.value) + 1;
		cpSrc.value = newCP;				
	
		if (window.XMLHttpRequest) { 
			xmlhttp = new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
			
		var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=" + pID + "&sizeID=0";
		
		xmlhttp.open("GET",url,false); 
		xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
		xmlhttp.send(null); 
		
		if (xmlhttp.status == 200) { 
			oSource.innerHTML = xmlhttp.responseText;
			updateTotal();
		} 
		else { 
			// handle different response status here 
			alert("There was an error adding cart item");
		} 
	}
}

function addCartItemReq(cID, pID)
{
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);					
	
	var maxID, maxSrc;
	maxID = "maxPurchase" + pID;
	maxSrc = document.getElementById(maxID);

	var cpID, cpSrc;
	cpID = "currPurchase" + pID;
	cpSrc = document.getElementById(cpID);
	
	if(maxSrc.value==cpSrc.value)
	{
		alert("You can not purchase more than " + maxSrc.value + " of this item.");
	}
	else
	{
		var newCP;
		newCP = eval(cpSrc.value) + 1;
		cpSrc.value = newCP;
		
		var reqID, reqSrc;
		//reqID = "tb_reqItem";
		reqID = "ctl00_cph1_tb_reqItem";
		reqSrc = document.getElementById(reqID);
		reqSrc.value = pID;			
	
		if (window.XMLHttpRequest) { 
			xmlhttp = new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		
		var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=" + pID + "&sizeID=0";
		xmlhttp.open("GET",url,false); 
		xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
		xmlhttp.send(null); 
		if (xmlhttp.status == 200) { 
			oSource.innerHTML = xmlhttp.responseText;
			updateTotal();
		} 
		else { 
			// handle different response status here 
			alert("There was an error adding cart item");
		} 
	}
}

function removeCartCoupon(couponID, cartID)
{
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);
	
	if (window.XMLHttpRequest) { 
		xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	
	var url = "VolunteerCurrentCartItems.aspx?cartID=" + cartID + "&delCoupon=" + couponID;
	
	xmlhttp.open("GET",url,false); 
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	xmlhttp.send(null); 
	if (xmlhttp.status == 200) { 
		oSource.innerHTML = xmlhttp.responseText;
		updateTotal();
	} 
	else { 
		// handle different response status here 
		alert("There was an error removing the selecte coupon");
	} 
}

function applyCoupon()
{
	var tbID, tbSrc;
	tbID = "textbox_coupon";
	tbSrc = document.getElementById(tbID);
	
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);	
	
	var cID, cSrc;
	//cID = "tb_cart";
	cID = "ctl00_cph1_tb_cart";
	cSrc = document.getElementById(cID);
	
	if (window.XMLHttpRequest) { 
		xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	
	var url = "VolunteerCurrentCartItems.aspx?cartID=" + cSrc.value + "&couponID=" + tbSrc.value;
	xmlhttp.open("GET",url,false); 
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	xmlhttp.send(null); 
	if (xmlhttp.status == 200) { 
		oSource.innerHTML = xmlhttp.responseText;
		updateTotal();
		tbSrc.value = "";
	} 
	else { 
		// handle different response status here 
		alert("There was an error adding coupon");
	} 				

}

function addCartItemWithQuant(cID, pID)
{
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);
	
	var sddID, sddSrc;
	sddID = "quant" + pID;
	sddSrc = document.getElementById(sddID);
	
	var selSizeID;
	selSizeID = sddSrc.options[sddSrc.selectedIndex].value;
	
	if(selSizeID==0)
	{
		alert("Please select a Size");
	}
	else
	{
		var maxID, maxSrc;
		maxID = "maxPurchase" + pID;
		maxSrc = document.getElementById(maxID);
	
		var cpID, cpSrc;
		cpID = "currPurchase" + pID;
		cpSrc = document.getElementById(cpID);
		
		if(maxSrc.value==cpSrc.value)
		{
			alert("You can not purchase more than " + maxSrc.value + " of this item.");
		}
		else
		{
		
			var boolAddItem;
			boolAddItem = true;
		
			//try to get array from maxPurchaseList box
			var maxPLID, maxPLSrc;
			maxPLID = "maxPurchaseList" + pID;
			maxPLSrc = document.getElementById(maxPLID);
			
			var newmaxPL;
			newmaxPL = '';
			
			if(maxPLSrc.value.length!=0)
			{
				var pList;
				pList = maxPLSrc.value
				
				var arrList;
				arrList = pList.split("|");
				
				for(loop=0; loop<arrList.length-1; loop++)
				{
					var iAndq;
					iAndq = arrList[loop].split(",");
					
					//now check the selected product
					if(iAndq[0]==selSizeID)
					{
						if(iAndq[1]==0)
						{
							newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
							boolAddItem = false;
							alert("There are no more items available in this quantity.");
						}
						else
						{
							newmaxPL = newmaxPL + iAndq[0] + "," + eval(iAndq[1]-1) + "|";
						}
					}
					else
					{
						newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
					}								
				}
				
				//populate maxPLID again with new list
				maxPLSrc.value = newmaxPL;
			}
		
		
			if(boolAddItem)
			{
				var newCP;
				newCP = eval(cpSrc.value) + 1;
				
				cpSrc.value = newCP;
			
				if (window.XMLHttpRequest) { 
					xmlhttp = new XMLHttpRequest(); 
				} else if (window.ActiveXObject) { 
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
				
				var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=" + pID + "&quant=" + selSizeID;
				xmlhttp.open("GET",url,false); 
				xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
				xmlhttp.send(null); 
				if (xmlhttp.status == 200) { 
					oSource.innerHTML = xmlhttp.responseText;
					updateTotal();
				} 
				else { 
					// handle different response status here 
					alert("There was an error adding cart item");
				} 
			}
			
		}
	}
}


function addCartItemWithSize(cID, pID)
{
    var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);
	
	var sddID, sddSrc;
	sddID = "size" + pID;
	sddSrc = document.getElementById(sddID);
	
	var selSizeID;
	selSizeID = sddSrc.options[sddSrc.selectedIndex].value;
	
	if(selSizeID==0)
	{
		alert("Please select a Size");
	}
	else
	{
		var maxID, maxSrc;
		maxID = "maxPurchase" + pID;
		maxSrc = document.getElementById(maxID);
	
		var cpID, cpSrc;
		cpID = "currPurchase" + pID;
		cpSrc = document.getElementById(cpID);
		
		if(maxSrc.value==cpSrc.value)
		{
			alert("You can not purchase more than " + maxSrc.value + " of this item.");
		}
		else
		{
		
			var boolAddItem;
			boolAddItem = true;
		
			//try to get array from maxPurchaseList box
			var maxPLID, maxPLSrc;
			maxPLID = "maxPurchaseList" + pID;
			maxPLSrc = document.getElementById(maxPLID);
			
			var newmaxPL;
			newmaxPL = '';
			
			if(maxPLSrc.value.length!=0)
			{
				var pList;
				pList = maxPLSrc.value
				
				var arrList;
				arrList = pList.split("|");
				
				for(loop=0; loop<arrList.length-1; loop++)
				{
					var iAndq;
					iAndq = arrList[loop].split(",");
					
					//now check the selected product
					if(iAndq[0]==selSizeID)
					{
						if(iAndq[1]==0)
						{
							newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
							boolAddItem = false;
							alert("There are no more items available in this size.");
						}
						else
						{
							newmaxPL = newmaxPL + iAndq[0] + "," + eval(iAndq[1]-1) + "|";
						}
					}
					else
					{
						newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
					}								
				}
				
				//populate maxPLID again with new list
				maxPLSrc.value = newmaxPL;
			}
		
		
			if(boolAddItem)
			{
				var newCP;
				newCP = eval(cpSrc.value) + 1;
				
				cpSrc.value = newCP;
			
				if (window.XMLHttpRequest) { 
					xmlhttp = new XMLHttpRequest(); 
				} else if (window.ActiveXObject) { 
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
				
				var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=" + pID + "&sizeID=" + selSizeID;
				xmlhttp.open("GET",url,false); 
				xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
				xmlhttp.send(null); 
				if (xmlhttp.status == 200) { 
					oSource.innerHTML = xmlhttp.responseText;
					updateTotal();
				} 
				else { 
					// handle different response status here 
					alert("There was an error adding cart item");
				} 
			}
			
		}
	}
}

function addCartItemWithSizeReq(cID, pID)
{
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);
	
	var sddID, sddSrc;
	sddID = "size" + pID;
	sddSrc = document.getElementById(sddID);
	
	var selSizeID;
	selSizeID = sddSrc.options[sddSrc.selectedIndex].value;
	
	if(selSizeID==0)
	{
		alert("Please select a Size");
	}
	else
	{
		var maxID, maxSrc;
		maxID = "maxPurchase" + pID;
		maxSrc = document.getElementById(maxID);
	
		var cpID, cpSrc;
		cpID = "currPurchase" + pID;
		cpSrc = document.getElementById(cpID);
		
		if(maxSrc.value==cpSrc.value)
		{
			alert("You can not purchase more than " + maxSrc.value + " of this item.");
		}
		else
		{
		
			var boolAddItem;
			boolAddItem = true;
		
			//try to get array from maxPurchaseList box
			var maxPLID, maxPLSrc;
			maxPLID = "maxPurchaseList" + pID;
			maxPLSrc = document.getElementById(maxPLID);
			
			var newmaxPL;
			newmaxPL = '';
			
			if(maxPLSrc.value.length!=0)
			{
				var pList;
				pList = maxPLSrc.value
				
				var arrList;
				arrList = pList.split("|");
				
				for(loop=0; loop<arrList.length-1; loop++)
				{
					var iAndq;
					iAndq = arrList[loop].split(",");
					
					//now check the selected product
					if(iAndq[0]==selSizeID)
					{
						if(iAndq[1]==0)
						{
							newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
							boolAddItem = false;
							alert("There are no more items available in this size.");
						}
						else
						{
							newmaxPL = newmaxPL + iAndq[0] + "," + eval(iAndq[1]-1) + "|";
						}
					}
					else
					{
						newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
					}								
				}
				
				//populate maxPLID again with new list
				maxPLSrc.value = newmaxPL;
			}
		
		
			if(boolAddItem)
			{
				var reqID, reqSrc;
				//reqID = "tb_reqItem";
				reqID = "ctl00_cph1_tb_reqItem";
				reqSrc = document.getElementById(reqID);
				reqSrc.value = pID;
			
				var newCP;
				newCP = eval(cpSrc.value) + 1;
				
				cpSrc.value = newCP;
			
				if (window.XMLHttpRequest) { 
					xmlhttp = new XMLHttpRequest(); 
				} else if (window.ActiveXObject) { 
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
				
				var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=" + pID + "&sizeID=" + selSizeID;
				xmlhttp.open("GET",url,false); 
				xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
				xmlhttp.send(null); 
				if (xmlhttp.status == 200) { 
					oSource.innerHTML = xmlhttp.responseText;
					updateTotal();
				} 
				else { 
					// handle different response status here 
					alert("There was an error adding cart item");
				} 
			}
			
		}
	}
}

function removeCartItem(cID, pID, delID, qID, sID)
{
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);	
	
	var cpID, cpSrc;
	cpID = "currPurchase" + pID;
	cpSrc = document.getElementById(cpID);
	
	var reqID, reqSrc;
	//reqID = "tb_reqItem";
	reqID = "ctl00_cph1_tb_reqItem";
	reqSrc = document.getElementById(reqID);
	
	if(pID==reqSrc.value)
	{
		reqSrc.value = "0";
	}
	
	var newCP;
	newCP = eval(cpSrc.value) - qID;
	
	cpSrc.value = newCP;
	
	if(sID!=0)
	{
		//reset quantity purchased via size
		//try to get array from maxPurchaseList box
		var maxPLID, maxPLSrc;
		maxPLID = "maxPurchaseList" + pID;
		maxPLSrc = document.getElementById(maxPLID);
		
		var newmaxPL;
		newmaxPL = '';
		
		var tempNum;
		if(maxPLSrc.value.length!=0)
		{
			var pList;
			pList = maxPLSrc.value
			
			var arrList;
			arrList = pList.split("|");
			
			for(loop=0; loop<arrList.length-1; loop++)
			{
				var iAndq;
				iAndq = arrList[loop].split(",");
				//now check the selected product
				if(iAndq[0]==sID)
				{
					tempNum = eval(iAndq[1]) + eval(qID);
					newmaxPL = newmaxPL + iAndq[0] + "," + tempNum + "|";
				}
				else
				{
					newmaxPL = newmaxPL + iAndq[0] + "," + iAndq[1] + "|";
				}								
			}
			
			//populate maxPLID again with new list
			maxPLSrc.value = newmaxPL;
		}					
	}
	
	if (window.XMLHttpRequest) { 
		xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	
	var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=" + pID + "&delCart=" + delID;
	
	xmlhttp.open("GET",url,false); 
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	xmlhttp.send(null); 
	if (xmlhttp.status == 200) { 
		oSource.innerHTML = xmlhttp.responseText;
		updateTotal();
	} 
	else { 
		// handle different response status here 
		alert("There was an error removing cart item");
	} 
}

function updateTotal()
{
	var tID, tSrc;
	tID = "hiddenTotal";
	tSrc = document.getElementById(tID);
	
	var thisO, oSource;	
	thisO = "totalcart";
	oSource = document.getElementById(thisO);	
	oSource.innerHTML = tSrc.value;
}

function catchKey()
{
	if (event.keyCode == 13)
		{
			alert(" Looks like you pressed the Enter key.  \n\ \n\ Please be sure to use the buttons provided \n\ to submit any data or navigate the site.");
			event.returnValue = false;
		}
}

function confirmCartItems(vid)
{
	if(checkRequiredItem() == true)
		{
			//parent.changeNextPage('selectproducts', vid);
			document.location.href = "VolunteerMakePaymentInformation.aspx";
		}
}

function confirmCartItemsTickets(vid)
{
	if(confirm2() == true)
		{
			//parent.changeNextPage('selectproducts', vid);
			document.location.href = "TicketSalesMakePaymentInformation.aspx";
		}
}

function confirmExistingCartItems(vid)
{
	if(checkRequiredItem() == true)
		{
			//parent.changeNextPage('selectproducts', vid);
			//parent.loadVolunteerPay('Payment Information','VolunteerMakePaymentInformation');
			document.location.href = "VolunteerMakePaymentInformation.aspx";
		}
}

function confirm2()
{
	return confirm('Please verify the item(s) in your cart. \n\ \n\ Press CANCEL if you would like to change the item(s) \n\ currently in your cart. \n\ \n\ Press OK if you do not want to change anything \n\ and continue to the payment page.');
}

function checkRequiredItem()
{
	var reqID, reqSrc;
	//reqID = "tb_reqItem";
	reqID = "ctl00_cph1_tb_reqItem";
	reqSrc = document.getElementById(reqID);
	
	if(reqSrc.value=="0")
	{
		alert("You need to add the Volunteer Package to your cart in order to continue.");
		return false;
	}
	else
	{
		return confirm2();
	}
}

function updateReqItem(thisID)
{
	alert("update item..." + thisID);
}

function loadCurrItems(cID)
{
	var thisO, oSource;	
	thisO = "cartitems";
	oSource = document.getElementById(thisO);	
	
	if (window.XMLHttpRequest) { 
		xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	
	var url = "VolunteerCurrentCartItems.aspx?cartID=" + cID + "&productID=0&sizeID=0";
	xmlhttp.open("GET",url,false); 
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult') 
	xmlhttp.send(null); 
	if (xmlhttp.status == 200) { 
		oSource.innerHTML = xmlhttp.responseText;
		updateTotal();
	} 
	else { 
		// handle different response status here 
		alert("There was an error loading cart data...");
	} 
}




function showHideCvv2()
{
	var thisdiv, divsrc;
	thisdiv = "cvv2info";
	divsrc = document.getElementById(thisdiv);
	
	if(divsrc.style.display=="block")
		{
			divsrc.style.display = "none";
		}
	else
		{
			divsrc.style.display = "block";
		}
}

function changePayType(thisType)
{
	var ccID, ccSrc;
	//ccID = "rbCC";
	ccID = "ctl00_cph1_rbCC";
	ccSrc = document.getElementById(ccID)
	
	var ckID, ckSrc;
	ckID = "ctl00_cph1_rbCK";
	ckSrc = document.getElementById(ckID);
	
	var introID, introSrc;
	introID = "payIntro";
	introSrc = document.getElementById(introID);
	
	if(introSrc.style.display=="block")
	{
		introSrc.style.display = "none";
	}
	
	var payCCID, payCCSrc;
	payCCID = "payCC";
	payCCSrc = document.getElementById(payCCID);
	
	var payCCListID, payCCListSrc;
	payCCListID = "payCCList";
	payCCListSrc = document.getElementById(payCCListID);
	
	var payCKID, payCKSrc;
	payCKID = "payCK";
	payCKSrc = document.getElementById(payCKID);
	
	//User Selected Credit Cart
	if(thisType==0)
	{
		ckSrc.checked = false;
		payCCSrc.style.display = "block";
		payCCListSrc.style.display = "block";
		payCKSrc.style.display = "none";
	}
	
	if(thisType==1)
	{
		ccSrc.checked = false;
		payCCSrc.style.display = "none";
		payCCListSrc.style.display = "none";
		payCKSrc.style.display = "block";
		
	}		
}

function changePayTypeCCOnly(thisType)
{
	var ccID, ccSrc;
	ccID = "ctl00_cph1_rbCC";
	ccSrc = document.getElementById(ccID)
	
	var introID, introSrc;
	introID = "payIntro";
	introSrc = document.getElementById(introID);
	
	if(introSrc.style.display=="block")
	{
		introSrc.style.display = "none";
	}
	
	var payCCID, payCCSrc;
	payCCID = "payCC";
	payCCSrc = document.getElementById(payCCID);
	
	var payCCListID, payCCListSrc;
	payCCListID = "payCCList";
	payCCListSrc = document.getElementById(payCCListID);
	
	//User Selected Credit Cart
	if(thisType==0)
	{
		payCCSrc.style.display = "block";
		payCCListSrc.style.display = "block";
	}
		
}

function verifyShiftSel()
{
    var boolChecked;
    boolChecked = "0";
    for (var i = 0; i < document.aspnetForm.length; i++){
		if (document.aspnetForm.elements[i].type=="checkbox"){
		        if(document.aspnetForm.elements[i].checked==true)
		        {
		            boolChecked = "1";
		        }
		}
	}
	
	if(boolChecked!="0")
	{
	    var btnID, btnSrc;
	    btnID = "ctl00_cph1_btnSave";
	    btnSrc = document.getElementById(btnID);
	    btnSrc.click();
	}
	else
	{
	    alert("Please select at least one shift and a location preference to continue.");
	    return false;
	}
}
