function ChangeColor(id, ischecked)
{
	if(ischecked)
	{
		if(document.getElementById(id))
		{
			document.getElementById(id).className = 'optionDiv';
		}
	}
	else
	{
		if(document.getElementById(id))
		{
			document.getElementById(id).className = '';
		}
	}
}

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)
			var temp2 = document.getElementById("div_" + arr[i].value)
			
			temp.checked = false;
			if(temp2)
			{
				temp2.className = "";
			}
			
		}
		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");
  var arr = getElementsByName_iefix("span", "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("Please confirm you will pick up your order by yourself!\n\n Cannot order from Drinks category for takeout"))
		{
				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)
{
	var gratuity;
	gratuity = 0;
	if(document.getElementById("gratnum"))
	{
		gratuity = document.getElementById("gratnum").value;
	}
	
	if(gratuity>0)
	{
		window.location=link+'?use='+discountId+'&grat='+gratuity;
	}
	else
	{
		window.location=link+'?use='+discountId;
	}
}

function ShowQualifiedDiscounts(id, cancelId, orderType)
{
	document.getElementById(id).style.display='';
	document.getElementById(cancelId).setAttribute('onclick', 'this.disabled=true;SFManualUniversal('+orderType+')');
}

function ShowHideDiscountAvailability(discountId, sufix)
{
	discounts = getElementsByName_iefix("div", "discountAvailabilityBlocks"+sufix);
	for (var i = 0; i < discounts.length; i++)
	{
		discounts[i].style.display="none";
	}
	
	document.getElementById("discountAvailability_"+discountId+sufix).style.display="";
}

function HideDiscountAvailability(discountId, sufix)
{
	document.getElementById("discountAvailability_"+discountId+sufix).style.display="none";
}

function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

