var root = "/";
//var root = "/12go/";
var win = "win/";
var xmlHttp;
var xmlHttp2;
var xmlHttp3;

function mouseOnTD(obj)
{
	obj.style.cursor = "hand";
}
function defaultTD(obj)
{
	//obj.style.backgroundColor = "#ffffff";
	obj.style.cursor = "default";
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
	// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function GetXmlHttpObject2()
{
	var xmlHttp2=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp2=new XMLHttpRequest();
	} catch (e) {
	// Internet Explorer
		try {
			xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp2;
}

function ajax_getCustomer(str, path, o_no)
{
	//alert(str);
	//document.getElementById("dest").style.display = "inline";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url=path+"/ajax/get_customer.php";
	url=url+"?phone="+str+"&path="+path+"&o_no="+o_no;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4) { 
		document.getElementById("customer").innerHTML=xmlHttp.responseText;
		var phone = document.getElementById("phone").value.length;
		var street = document.getElementById("street_name").value;
		var p = document.getElementById("phone").value.substring(0,1);
				
		if((p != '0' && phone == 8) || phone == 10) {
			if(street.length > 0) document.getElementById("price").focus();
		}
	}
}

function ajax_getMSG()
{
	//alert(str);
	//document.getElementById("dest").style.display = "inline";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="./ajax/get_msg.php";
	//url=url+"?phone="+str;
	xmlHttp.onreadystatechange=get_msg;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function get_msg() 
{ 
	if (xmlHttp.readyState==4) { 
		var response = xmlHttp.responseText;
		if(response) {
			document.getElementById("msg").innerHTML=response;
		}
	}
}

function ajax_sendRequest()
{
	//alert(str);
	//document.getElementById("dest").style.display = "inline";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="../ajax/get_new.php";
	//url=url+"?phone="+str;
	xmlHttp.onreadystatechange=handleResponse;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function handleResponse() 
{ 
	if (xmlHttp.readyState==4) { 
		var response = xmlHttp.responseText;
		if(response) {
			document.getElementById("d_status").innerHTML=response;
			
			var sound = document.getElementById("sound").value;
			var times = document.getElementById("sound_times").value;
			//alert(sound+times);
			
			if(sound == 'on') {
				if(times == 1) Sound.play('ringin.mp3');
				if(times == 2) {
					Sound.play('ringin.mp3');
				}
			}
			
			//if(sound == 'on') document.getElementById("soundeffect").src = "ringin.mp3";
			
		}
	}
}

function ajax_getStreet(str, path)
{
	//alert(str);
	var s_no = document.getElementById("street_no").value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url=path+"/ajax/get_street.php";
	url=url+"?street="+str+"&street_no="+s_no;
	xmlHttp.onreadystatechange=stateStreet;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateStreet() 
{ 
	if (xmlHttp.readyState==4) { 
		document.getElementById("find_street").innerHTML=xmlHttp.responseText;
	}
}

function ajax_getStreetwS(str, path)
{
	//alert(str);
	var s_no = document.getElementById("suburb").value;
	var ss_no = document.getElementById("street_no").value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url=path+"/ajax/get_streetws.php";
	url=url+"?street="+str+"&suburb="+s_no+"&street_no="+ss_no;
	xmlHttp.onreadystatechange=stateStreetwS;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateStreetwS() 
{ 
	if (xmlHttp.readyState==4) { 
		document.getElementById("find_street").innerHTML=xmlHttp.responseText;
	}
}

function ValidFood(e) {	
	//219 ~ 221
	if(e.keyCode == 219) ajax_getFood();

}

function ajax_getFood()
{
	//alert(str);
	//var s_no = document.getElementById("street_no").value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url=path+"/ajax/get_food.php";
	url=url+"?shop_no="+shop;
	xmlHttp.onreadystatechange=stateFood;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateFood() 
{ 
	if (xmlHttp.readyState==4) { 
		document.getElementById("find_food").innerHTML=xmlHttp.responseText;
	}
}

function MenuOption() {
	
	var option = document.getElementById("menu_option").value;
	if(option == 1) {
		document.getElementById("option_1").style.display = "inline";
		document.getElementById("option_2").style.display = "none";
	} else if(option == 2) {
		document.getElementById("option_1").style.display = "none";
		document.getElementById("option_2").style.display = "inline";
	} else {
		document.getElementById("option_1").style.display = "none";
		document.getElementById("option_2").style.display = "none";
	}
}


function MiniCalendar(field)
{
    w_name = "calendar"
    url = "../ajax/mini_cal.php?field=" + field;
    Width = 240;
    Height = 150;
    Top = 170;
    Left = 380;
    window_string = "toolbar=no,menubar=no,resizable=no,scrollbarow=no, width=" + Width + ",height=" + Height + ",top=" + Top + ",left=" + Left;
    window.open(url,w_name,window_string);
}

function Put_Address(street, suburb, dguide) {
	
	document.getElementById('street_name').value = street;
	document.getElementById('suburb').value = suburb;
	document.getElementById('find_street').style.display = 'none';
	
	document.getElementById('dguide').value = dguide;
	document.getElementById('dguide_div').innerHTML = dguide;
	
	document.getElementById('price').focus();
}


function Put_Addressws(street, dguide) {
	
	document.getElementById('street_name_0').value = street;
	document.getElementById('find_street').style.display = 'none';
	document.getElementById('dguide').value = dguide;
	document.getElementById('dguide').focus();
}

function Delete(no, c_name) {
	
	result = confirm("Are you sure to delete it?");
	if(result) {
		location.href="../inc/delete.php?no="+no+"&c_name="+c_name;
	}
}

function DeleteCustomer(no, c_name, links) {
	
	result = confirm("Are you sure to delete it?");
	//result = confirm(links);
	if(result) {
		location.href="../inc/delete.php?no="+no+"&c_name="+c_name+"&"+links;
	}
}

function Logout() {
	location.href = root+"inc/logout.php";
}

////////////////////////////////////////////////////////////////////////////////////////////////////windows function//////////////////////
function openWindow(w_name,u_address)
{
   // w_name = "login_window"
    target = document.location.href;
    url = "login_window.php?target_url=" + document.location.href;
    Width = 500;
		Height = 200;
    window_string = "toolbar=no,menubar=no,resizable=no,scrollbars=no, width=" + Width + ",height=" + Height;
	window.open(url,w_name,window_string);
}


function newWindow(w_name,edit_no, wid, het)
{
   // w_name = "login_window"
    target = document.location.href;
    url = root+win+w_name+".php?target_url="+target+"&edit_no="+edit_no;
    Width = wid;
		Height = het;
    window_string = "toolbar=no,menubar=no,resizable=no,scrollbars=yes, width=" + Width + ",height=" + Height;
		window.open(url,w_name,window_string);
}

function editWindow(w_name,edit_no)
{
   // w_name = "login_window"
    target = document.location.href;
    url = w_name+".php?target_url="+target+"&edit_no="+edit_no;
    Width = 600;
	  Height = 200;
    window_string = "toolbar=no,menubar=no,resizable=no,scrollbars=no, width=" + Width + ",height=" + Height;
	window.open(url,w_name,window_string);
}


//MESSAGE SCRIPT________________________________________________________________________________________----
function InputMessage(no) {
	str = prompt("Please Enter short message:","");
	target = document.location.href;
	location.href=root+"inc/input_msg.php?target_url="+target+"&o_no="+no+"&msg="+str;
}

//validation script

function ValidatePhone(e) {
	
	if(e.keyCode == 9 || e.keyCode == 13) {
		var phone = document.getElementById('phone').value.length;
		if(!(phone == 0 || phone == 8 || phone == 10)) {
			alert("Phone number must be 8 digit or 10 digit");
			document.getElementById('phone').focus();
			return e.returnValue=false;
		}		
	}	else if(e.keyCode == 8) e.returnValue = true;
	else if(!(e.keyCode > 47 && e.keyCode < 58) && !(e.keyCode > 95 && e.keyCode < 106)) e.returnValue=false;
}

//menu ajax

function ajax_getOption(category,menu)
{
	//alert(str);
	srt = document.getElementById("sort").value;
	
	t_number = document.getElementById("t_number").value;
	t_size_limit = document.getElementById("t_size_limit").value;
	
	t_size = null;
	for(i=1;i<t_size_limit;i++) {
		if(document.getElementById("t_size_"+i).checked) 
			t_size = document.getElementById("t_size_"+i).value;
	}	
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="../ajax/get_option.php";
	url=url+"?category="+category+"&menu="+menu+"&srt="+srt+"&t_size="+t_size+"&t_number="+t_number;
	xmlHttp.onreadystatechange=getOption;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function getOption() 
{ 
	if (xmlHttp.readyState==4) { 
		document.getElementById("option").innerHTML=xmlHttp.responseText;
	}
}

function ajax_showOption(menu, show_div)
{
	//alert(show_div);
	//document.getElementById("dest").style.display = "inline";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="../ajax/get_option2.php";
	url=url+"?menu="+menu;
	xmlHttp.onreadystatechange=function()
	{
	if(xmlHttp.readyState==4)
	  {document.getElementById(show_div).innerHTML=xmlHttp.responseText}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajax_getTakeAway(str, o_no)
{
	//alert(str);
	//document.getElementById("dest").style.display = "inline";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="../ajax/get_takeaway.php";
	url=url+"?phone="+str+"&o_no="+o_no;
	xmlHttp.onreadystatechange=stateTakeaway;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateTakeaway() 
{ 
	if (xmlHttp.readyState==4) { 
		document.getElementById("customer").innerHTML=xmlHttp.responseText;
		var phone = document.getElementById("phone").value.length;
		/*var street = document.getElementById("street_name").value;
		var p = document.getElementById("phone").value.substring(0,1);
				
		if((p != '0' && phone == 8) || phone == 10) {
			//if(street.length > 0) document.getElementById("price").focus();
		}
		*/
	}
}

function Payprocedure(no) {
		
	location.href=root+"order/paid.php?order_no="+no;	
	
}

function Print_Invoice(no) {		
			
	location.href=root+"win/invoice_s.php?order_no="+no+"&ask=1&path=pickup";
		
}

