function ChkSub(subid)
{
	if(CheckAllOK(subid) == true)
	{
		if(document.forms["OrderFrm_"+subid].m_quantity.value == 0)
		{
			alert("Please choose how many would you like.");
			return false;
		}
		else { document.forms["OrderFrm_"+subid].submit(); }
	}
}

function CheckAllOK(subid)
{
	var tmpClass = "_tmp_"+subid;
	c = document.getElementsByClassName(tmpClass);
	
	for (i=0;c[i];i++)
	{
		if(c[i].value > 0)
		{
			var temp = "mess_"+c[i].name+"_"+subid;
			
			msg = document.getElementById(temp).value;
			alert(msg);
			return false;
		}
	}
	
	return true;
}

function CheckedChoices(limit,groupname,currfield,hiddenfield,currentChoice)
{
	arrelements = hiddenfield + groupname;
	
	arr = document.getElementsByName(arrelements);
	
	cnt=0;
	
	var count = 0;
	for(i=0;i<arr.length;i++)
	{
		var temp = document.getElementById(currfield + arr[i].value)
		
		if (temp.checked == true)
		{
			count++;
			tmpel = temp;
		}
		
	}
	
	if(count > limit)
	{
		append = "";
		if(limit == 1) append = ".";
		else append = "s.";
		
		/*alert("You're limited to "+limit+" choice"+append);*/
		/*tmpel.checked = false;*/
		for(i=0;i<arr.length;i++)
		{
			var temp = document.getElementById(currfield + arr[i].value)
			
			temp.checked = false;
			
		}
		document.getElementById("chk_"+currentChoice).checked = true;
		return true;
	}
	else
	{
		return true;
	}
}


function ChkSubBox(sid,chkboxcnt)
{
	if(chkboxcnt == 0) return true;
	sboxs = document.getElementById(sid);
	isboxchecked = document.getElementById('chk_'+sid).checked;
	if((chkboxcnt != 0) && isboxchecked) sboxs.style.display = "block";
	else sboxs.style.display = "none";
}

function FillMsgAlertFields(prefix, el, minquantity, ischecked)
{
	if(minquantity)
	{
		var tmp = prefix + el;
		
		var val = ischecked == false ? 1 : 0;
		
		document.getElementById(tmp).value = val;
		
	}
}

function ChangePrices(sdid, ischecked)
{
	arr = document.getElementsByName("sep_price");
	
	for(i=0;i<arr.length;i++)
	{
		arr[i].style.display="none";
	}
	
	if(ischecked)
	{
		for(i=0;i<arr.length;i++)
		{
			if(arr[i].id=="sep_price_"+sdid)
			{
				arr[i].style.display="";
			}
		}
	}
}

function SFManualUniversal(ordertype)
{
	if(ordertype==2)
	{
		if(confirm("Pleasse confirm you will pick up your order by yourself!"))
		{
				restInstruction = document.RestInstructionFrm.restInstruction.value;
				document.forms.manualTip.restInstruction_hidden.value=restInstruction;

				choosedordertype = document.getElementById('choosedordertype');
				choosedordertype.value = ordertype;

				document.manualTip.submit();
		}
	}
	else
	{
		restInstruction = document.RestInstructionFrm.restInstruction.value;
		document.forms.manualTip.restInstruction_hidden.value=restInstruction;

		choosedordertype = document.getElementById('choosedordertype');
		choosedordertype.value = ordertype;

		document.manualTip.submit();
	}
}


function SetColor()
{
	
	document.getElementById("percentage_10").style.color="#4481DA";
	document.getElementById("percentage_15").style.color="#4481DA";
	document.getElementById("percentage_20").style.color="#4481DA";
	document.getElementById("percentage_25").style.color="#4481DA";
}

function SetTip(tip,clicked)
{
	SetColor();
	document.getElementById("gratnum").value=tip;
	document.getElementById("percentage_"+clicked).style.color="#F58220";
}

function UseDiscount(discountId, link)
{
	window.location=link+'?use='+discountId;
}