String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function checkForm(keyword_text)
{	
	if(document.getElementById(keyword_text).value.trim() == "")
	{
		alert("Please Enter Keyword");
		return false;
	}
	else
		return true;
}
function setTip(ele)
{
	if(ele.value==0)
		ele.value="";
}

function IsNumeric(sText,ele,sid)
{
	//alert("hello");
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   if(sText!="")
   {
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   if(IsNumber==false)
	   {
			alert("Enter Valid Value.");
			//ele = document.getElementById("txtTax");
			ele.value=0;
			setTimeout("ele.focus();",1);
	   }
	   else
	   {
			AddTip(sText,sid);
	   }
   }
   else
   {
			ele.value=0;
			AddTip(0,sid);
   }
}
var couponid=0;
function applyCoupon(id)
{
	ele = "divCoupon"+id;
	couponid=id;
	xmlhttp=getXmlHttp();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	document.getElementById(ele).innerHTML="<img src='images/loading1.gif'>";		
	var url="applyCoupon.php";
	url=url+"?id="+id;
	xmlhttp.onreadystatechange=changeCoupon;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
}
function changeCoupon()
{
	if (xmlhttp.readyState==4)
	{
		var data = xmlhttp.responseText;
		var z = data.split("#");
		ele = "tr"+couponid;
		document.getElementById(ele).innerHTML=z[0];
		ele = "divCoupon"+couponid;
		document.getElementById(ele).innerHTML="";
		document.getElementById("td_coupon_dis").innerHTML="$"+z[1];
	}		
}
function updateCoupon(id)
{
	xmlhttp=getXmlHttp();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="applyCoupon.php";
	url=url+"?id="+id;
	xmlhttp.onreadystatechange=changeUpdateCoupon;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
}
function changeUpdateCoupon()
{
	if (xmlhttp.readyState==4)
	{
		var data = xmlhttp.responseText;
		var z = data.split("#");
		document.getElementById("td_coupon_dis").innerHTML="$"+z[1];
	}		
}
function AddTip(tip_amount,sid)
{
	xmlhttp=getXmlHttp();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	document.getElementById("divTip").innerHTML="<img src='images/loading1.gif'>";	
	var url="js/addTip.php";
	url=url+"?q="+tip_amount+"&sid="+sid;
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
	
		
}
function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		var data = xmlhttp.responseText;
		//alert(data);
		var z = data.split("#");
		document.getElementById("divTip").innerHTML="";
		var total = parseFloat(document.getElementById("hdn_subTotal").value) + parseFloat(document.getElementById("hdn_totalTax").value) + parseFloat(document.getElementById("hdn_delFee").value) + parseFloat(z[1]);
		//alert(total);
		document.getElementById("divTotal").innerHTML= "$ "+ z[0];		
////		document.getElementById("divViewTip").innerHTML="$"+z[1];	
		if(document.getElementById("ajaxTotal")!=null)
			document.getElementById("ajaxTotal").innerHTML = "Total : $"+z[0];
		
	}
}

function popupWindow(url,width,height)
{
	window.open(url,"_blank","width="+width+"px,height="+height+"px,menubar=no,toolbar=no")
}

function popupWindowMail(type,id)
{
	window.open(HTTP+type+"/"+id+"/","_blank","width=710px,height=300px,menubar=no,toolbar=no")
}


function fbs_click(u)
{	
	t=document.title;
				window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
				return false;				
}

function checkemail(strMail){
 var str=strMail;
 var filter=/^.+@.+\..{2,3}$/

 if (filter.test(str))
    testresults=true
 else {   
    testresults=false
}
 return (testresults)
}
function changeDeliveryType(val,sid)
{
//	alert(val);
	xmlhttp=getXmlHttp();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	document.getElementById("tblRightCol").innerHTML="<img src='images/loading.gif'>";		
	document.getElementById("ajaxTotal").innerHTML="<img src='images/loading.gif'>";		
	var url="js/changeDeliveryType.php";
	url=url+"?type="+val+"&sid="+sid;
	xmlhttp.onreadystatechange=typeChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
}
function typeChanged()
{
	if (xmlhttp.readyState==4)
	{
		var data = xmlhttp.responseText;
		var z = data.split("@");
		//alert(data);
		//location.reload(true);
		document.getElementById("tblRightCol").innerHTML = z[0];
		document.getElementById("ajaxTotal").innerHTML = "Total : $"+z[1];
		//alert(z[1]);
	}
}
// Ajax
	function getXmlHttp()
	{
		var xmlHttp;
		if (window.XMLHttpRequest)
  		{
  			// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlHttp=new XMLHttpRequest();
  		}
		else if (window.ActiveXObject)
  		{
  			// code for IE6, IE5
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP!");
  		} 
  		return xmlHttp;
	}

	function ajax_final_price(prod_price)
	{
		var attributes_checkboxes = document.getElementsByName("attributes[]");
                var selected_id = "";
                for(i=0; i < attributes_checkboxes.length; i++) {
                    if(attributes_checkboxes[i].checked){
                        selected_id += attributes_checkboxes[i].value + ",";
                    }
                }

		
		
		//if(selected_id != "")
		//{
			var xmlHttp=getXmlHttp();
			var url="getfinalPrice.php?att_id=" + selected_id + '&prod_price=' + prod_price;
			//alert(url);return;
			
			xmlHttp.onreadystatechange=function (){
				if(xmlHttp.readyState == 4)
				{
					var data=xmlHttp.responseText;
					document.getElementById('final_price').innerHTML=data;
                                        document.getElementById('top_final_price').innerHTML=data;

					
					if(document.getElementById('ajax_hdn_final_price'))
					{
						document.getElementById('hdn_final_price').value = document.getElementById('ajax_hdn_final_price').value;
					}
				}
				else
				{
					document.getElementById('final_price').innerHTML="<img src='images/ajax-loader1.gif' border='0'/>";
				}
			}
			xmlHttp.open("GET",url);
			xmlHttp.send(null);
		//}
	}
	
	function remove_prod_or_att(pid,type,att_index,fileName)
	{
		var xmlHttp=getXmlHttp();	

		var url="delete_att.php?type=" + type + '&att_index=' + att_index + '&prod_id=' + pid + '&fileName=' + fileName;
		
		xmlHttp.onreadystatechange=function (){
			if(xmlHttp.readyState == 4)
			{
				var data=xmlHttp.responseText;
				var arrData=data.split("##");
				if(arrData.length == 2)
				{
					document.getElementById('btnProceed').style.display='none';
					document.getElementById('final_cart').innerHTML=arrData[0];
				}
				else
				{
					document.getElementById('final_cart').innerHTML=data;
					location.reload(true);
				}
			}
			else
			{
				document.getElementById('final_cart').innerHTML="<img src='images/ajax-loader1.gif' border='0'/>";
			}
		}
		xmlHttp.open("GET",url);
		xmlHttp.send(null);
		
	}
	
	function openMenu(path)
	{
			window.location.href=path;
	}
	
//******************************************************************** ALERT WINDOW **************************************/	
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve Chipman | http://slayeroffice.com/ */

// constants to define the title of the alert and button text.
var ALERT_TITLE = "Message From MyPizza.com!";
var ALERT_BUTTON_TEXT = "OK";
var S_ID;
var P_ID;
var T_ID;
// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
  window.alert = function(txt,sid,pid,tid) {
    createCustomAlert(txt,sid,pid,tid);
  }
}

function createCustomAlert(txt,sid,pid,tid) {
  // shortcut reference to the document object
  d = document;
	S_ID=sid;
	P_ID=pid;
	T_ID=tid;
	if(S_ID!=null)
		txt = "<br>This Restaurant is Closed.<br><br>Would you like to place a future order?<br><br>";
  // if the modalContainer object already exists in the DOM, bail out.
  if(d.getElementById("modalContainer")) return;

  // create the modalContainer div as a child of the BODY element
  mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
  mObj.id = "modalContainer";
   // make sure its as tall as it needs to be to overlay all the content on the page
  mObj.style.height = document.documentElement.scrollHeight + "px";

  // create the DIV that will be the alert 
  alertObj = mObj.appendChild(d.createElement("div"));
  alertObj.style.height = "120px";
 alertObj.id = "alertBox";
  // MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
  if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
  // center the alert box
  alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
  alertObj.style.top = (((d.documentElement.scrollHeight - document.documentElement.scrollHeight)/2)+100) + "px";

  // create an H1 element as the title bar
  h1 = alertObj.appendChild(d.createElement("h1"));
  h1.appendChild(d.createTextNode(ALERT_TITLE));

  // create a paragraph element to contain the txt argument
  msg = alertObj.appendChild(d.createElement("p"));
  msg.innerHTML = txt;


  // create an anchor element to use as the confirmation button.
  if(S_ID!=null)
  {
	  btn = alertObj.appendChild(d.createElement("a"));
	  btn.id = "yesBtn";
	  btn.style.top = "15px";
	  btn.style.left = "-55px";
	  btn.appendChild(d.createTextNode("YES"));
	  btn.href = "#";
	  // set up the onclick event to remove the alert when the anchor is clicked
	  btn.onclick = function() 
	  { 
		removeCustomAlert(); 
		window.location = "index.php?file=shopExtra&sid="+S_ID+"&pid="+P_ID+"&tid="+T_ID; return false; 
	  }
	  btn1 = alertObj.appendChild(d.createElement("a"));
	  btn1.id = "noBtn";
	  btn1.style.top = "-11px";
	  btn1.style.left = "55px";
	  btn1.appendChild(d.createTextNode("NO"));
	  btn1.href = "#";
	  // set up the onclick event to remove the alert when the anchor is clicked
	  btn1.onclick = function() 
	  { 
		removeCustomAlert(); 
		//window.location = "index.php?file=shopMenu&sid="+S_ID; 
		return false; 
	  }
  }
  else
  {
	  btn = alertObj.appendChild(d.createElement("a"));
	  btn.id = "closeBtn";
	  btn.style.top = "15px";
	  btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	  btn.href = "#";
	  // set up the onclick event to remove the alert when the anchor is clicked
	  btn.onclick = function() 
	  { 
		removeCustomAlert(); 
		if(S_ID!=null)
			window.location = "index.php?file=shopExtra&sid="+S_ID+"&pid="+P_ID+"&tid="+T_ID; return false; 
	  }
  }  
}

// removes the custom alert from the DOM
function removeCustomAlert() {
  document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}

