// JavaScript Document
//var ROOT_PATH="http://localhost/homeDeliver/";




function redirect_page(page_link)
{
	
	window.location.href=page_link;
	
}
function validate_templete_form(current_combo_id)
{	
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	if(selected_value!=="")
	{
		
	templete_form.submit();
	
	}
	else
	{
		return false;	
	}
	
}

//GETTING RESTAURANT FOOD ITEM BY CATEGROY
function get_r_cat_food_item(current_combo_id,food_item_id,r_id)
{
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	get_r_food_item(selected_value,food_item_id,r_id);
	
}


//GETTING RESTAURANT FOOD ITEM BY CATEGROY
function get_r_food_item(cat_id,combox_box_id,r_id)
{
	xmlHttp=get_xmlhttp();
	
	var url=ROOT_PATH+"ext/includes/ajx_get_food_item.php?action=get_r_food_item&cat_id="+cat_id+"&r_id="+r_id+"&";
	
	
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;

			addCombo_with_value(combox_box_id,values,'^','/','','')
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
}


function get_subitem_price_table(current_combo_id,item_price_td_id,r_id)
{
	
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	
	if(selected_value!="")
	{
	xmlHttp=get_xmlhttp();
	
var url=ROOT_PATH+"ext/includes/ajx_food_item_table.php?action=get_subitem_price_table&item_id="+selected_value+"&r_id="+r_id+"&";	
	
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	    if(xmlHttp.readyState==3)
	   { 			
	   }  
		 
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
	 	  document.getElementById(item_price_td_id).innerHTML=values;	
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
		
	}
	else
	{
	//alert("plase select item ");	
	}
}





function get_category_food_item(current_combo_id,food_item_id)
{
	
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	get_food_item(selected_value,food_item_id);
	
}


function get_food_item_table(current_combo_id,food_item_table_id)
{
	
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	
	if(selected_value!="")
	{
	xmlHttp=get_xmlhttp();
	
var url=ROOT_PATH+"ext/includes/ajx_food_item_table.php?action=get_food_item&item_id="+selected_value+"&";	
	
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	    if(xmlHttp.readyState==3)
	   { 			
	   }  
		 
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
	 	  document.getElementById(food_item_table_id).innerHTML=values;	
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
		
	}
	else
	{
	alert("plase select item ");	
	}
}


function get_food_item(cat_id,combox_box_id)
{
	xmlHttp=get_xmlhttp();
	
	var url=ROOT_PATH+"ext/includes/ajx_get_food_item.php?action=get_food_item&cat_id="+cat_id+"&";
	
	
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;

			addCombo_with_value(combox_box_id,values,'^','/','','')
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
}
	
	
function get_site_state_city(current_combo_id,city_box_id)
{
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	
	
	get_site_cities(selected_value,city_box_id);
	
}
function get_site_cities(state_name,combox_box_id)
{
	xmlHttp=get_xmlhttp();
	

	var url=ROOT_PATH+"ext/includes/ajx_get_contents.php?action=get_cities&state_name="+state_name+"&";
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
			
			
			addCombo_wit_detault(combox_box_id,values,"/","Select City","");
			
			
				
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
}


function get_site_city_parts(current_combo_id,combox_box_id)
{
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	var city_name=selected_value;
	
	xmlHttp=get_xmlhttp();
	
	var url=ROOT_PATH+"ext/includes/ajx_get_contents.php?action=get_city_parts&city_name="+city_name+"&";
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
			
			
			addCombo_wit_detault(combox_box_id,values,"/","Select City Parts","");
			
			
				
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
}


function get_state_cities(current_combo_id,city_box_id,postal_code_box_id)
{
	 
	var selObj = document.getElementById(current_combo_id);
	var selIndex = selObj.selectedIndex;
	selected_value=selObj.options[selIndex].value;
	
	
	
	get_cities(selected_value,city_box_id,postal_code_box_id);
	
	
	
	
}


function get_cities(state_name,combox_box_id,postal_code_box_id)
{
	xmlHttp=get_xmlhttp();
	
	var url=ROOT_PATH+"ext/includes/ajx_get_contents.php?action=get_cities&state_name="+state_name+"&";
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
			
			
			addCombo(combox_box_id,values,"/","Select City","");
			
			get_postal_codes(state_name,postal_code_box_id);
				
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
}


function get_postal_codes(state_name,combox_box_id)
{
	
	xmlHttp=get_xmlhttp();
	
	var url=ROOT_PATH+"ext/includes/ajx_get_contents.php?action=get_postal_codes&state_name="+state_name+"&";
	xmlHttp.onreadystatechange=function()
	{
	  
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
			
			
			addCombo(combox_box_id,values,"/","Select postal_code","");
				
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
	
	

	
	
}


function get_xmlhttp(){

var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
        }
      catch (e)
        {
        alert('Your browser does not support AJAX!');
        return false;
        }
      }
    }
   
   return  xmlHttp;
   

}

function test()
{
	
}
function show_cities_zip_table(state_check_box,state_name)
{
	try
	{
	document.getElementById(state_name).style.display="none"; 
	document.getElementById("postal_"+state_name).style.display="none";
	
	
	if(state_check_box.checked)
	{
		document.getElementById(state_name).style.display="block";
		document.getElementById("postal_"+state_name).style.display="block";
	}
	else
	{
		deselect_city_table(state_name);
		deselect_zip_code("postal_"+state_name);

		
	}
	
	}catch(Exception)
	{
		
	}
	
}


function show_item_table(category_check_box,category_name)
{
	try
	{
	document.getElementById(category_name).style.display="none"; 
		
	if(category_check_box.checked)
	{
		document.getElementById(category_name).style.display="block";
	}
	else
	{
		deselect_item_table(category_name);
		

		
	}
	
	}catch(Exception)
	{
		
	}
	
}


function select_chkbox(chkboxs,table_name,limit){


if(document.getElementById(chkboxs).checked==true){

select_all(chkboxs,table_name,limit);
}else{

deselect_all(chkboxs,table_name,limit)

}

}
function select_all(chkboxs,table_name,limit){



var tbl=document.getElementById(table_name);

//alert(tbl.tBodies[0].rows.length);
var name="";

for(var a=0;a<=limit;a++){
name="Checkbox_"+(a+1)+"";

try
{
document.getElementById(name).checked=true;
}catch( ex)
{
	
}


}

}



function deselect_all(chkboxs,table_name,limit){



var tbl=document.getElementById(table_name);
//alert(tbl.tBodies[0].rows.length);
var name="";

for(var a=0;a<=limit;a++){

name="Checkbox_"+(a+1)+"";

try
{
document.getElementById(name).checked=false;
}catch( ex)
{
	
}
}

}




//FUNCTION WILL SHOW THE CITY PART TABLE OF PARTICULAR CITY (HTML VIEW)
function show_city_part_table(city_check_box,city_name)
{
	try
	{
	document.getElementById(city_name).style.display="none"; 
	
	if(city_check_box.checked)
	{
		document.getElementById(city_name).style.display="block";
	}
	else
	{
		 deselect_city_part(city_name);
		
	}
	
	}catch(Exception)
	{
		
	}
	
}
function addCombo_wit_detault(combobox_id,values,split_char,default_text,default_value)
{	 
		var combo = document.getElementById(combobox_id);  
		//combo.innerHTML="";
		
		var count;
		
	
		for (count = 0 ; count <= combo.options.length ; count++){
		combo.remove (0);
	
	
		}
		var option ="";
	
	

		
		var values_array=values.split(split_char);
		
		var record=0;
		
		if(values_array.length>1)
		{
				
				
			
			while (record < values_array.length-1)
			 {
				option = document.createElement("option"); 
				 text_value= values_array[record];
				option.text =text_value.replace(/^\s+|\s+$/g, '') ;
				option.value = values_array[record]; 
				
			
				try 
				{  
				combo.add(option, null); //Standard  
				}
				catch(error)
				{  
				combo.add(option); // IE only  
				} 
				
				record+=1;
		 
			 }
			 
			
			 
			 
		}
		else
		{		
		
				option = document.createElement("option");  
				if(default_text)
				{
					option.text =default_text;
				}
				else
				{
					option.text = "Select";  
				}
				if(default_value)
				{
					option.value =default_value;
				}
				else
				{
					option.value = "";
				}
				
				
				try 
				{  
				combo.add(option, null); //Standard  
				}
				catch(error)
				{  
				combo.add(option); // IE only  
				} 
				
			
			
		}
		 return true;
	

}  



function addCombo(combobox_id,values,split_char,default_text,default_value)
{	 
		var combo = document.getElementById(combobox_id);  
		//combo.innerHTML="";
		
		var count;
		for (count = 0 ; count <= combo.options.length ; count++){
		combo.remove (0);
		
	
		}
		var option ="";
	
	

		
		var values_array=values.split(split_char);
		
		var record=0;
		
		if(values_array.length>1)
		{
			while (record < values_array.length-1)
			 {
				option = document.createElement("option"); 
				 text_value= values_array[record];
				option.text =text_value.replace(/^\s+|\s+$/g, '') ;
				option.value = values_array[record]; 
				
			
				try 
				{  
				combo.add(option, null); //Standard  
				}
				catch(error)
				{  
				combo.add(option); // IE only  
				} 
				
				record+=1;
		 
			 }
		}
		else
		{		
		
				option = document.createElement("option");  
				if(default_text)
				{
					option.text =default_text;
				}
				else
				{
					option.text = "Select";  
				}
				if(default_value)
				{
					option.value =default_value;
				}
				else
				{
					option.value = "";
				}
				
				
				try 
				{  
				combo.add(option, null); //Standard  
				}
				catch(error)
				{  
				combo.add(option); // IE only  
				} 
				
			
			
		}
		 return true;
	

}  


function addCombo_with_value(combobox_id,values,value_split_char,text_split_char,default_text,default_value)
{	 

 

		var combo = document.getElementById(combobox_id);  
		//combo.innerHTML="";
	//	alert(combo.options.length);
		var count;
		for (count = 0 ; count <= combo.options.length ; count++){
		try
		{
		combo.remove (0);
		}
		catch(Exception)
		{
		}

		}
		
		try
		{
		combo.remove (0);
		}
		catch(Exception)
		{
		}
		
		var option ="";
	
	

		
		var values_array=values.split(text_split_char);
		
		var record=0;
		
		if(values_array.length>1)
		{
			while (record < values_array.length-1)
			 {
				 
				
				 var text_array=values_array[record].split(value_split_char);
				 
				 option = document.createElement("option"); 
				 text_value= text_array[0];
				
				option.text =text_value.replace(/^\s+|\s+$/g,'') ;
				
				option.value = text_array[1]; 
						
				try 
				{  
				combo.add(option, null); //Standard  
				}
				catch(error)
				{  
				combo.add(option); // IE only  
				} 
				
				record+=1;
		 
			 }
		}
		else
		{		
		
				option = document.createElement("option");  
				if(default_text)
				{
					option.text =default_text;
				}
				else
				{
					option.text = "Select";  
				}
				if(default_value)
				{
					option.value =default_value;
				}
				else
				{
					option.value = "";
				}
				
				
				try 
				{  
				combo.add(option, null); //Standard  
				}
				catch(error)
				{  
				combo.add(option); // IE only  
				} 
				
			
			
		}
		 return true;
	

} 








function deselect_item_table(table_name)
	{ 
	
	var theTable = document.getElementById(table_name);

	for( var z = 0; z < theTable.tBodies.length; z++ ) {
  for( var x = 0; x < theTable.tBodies[z].rows.length; x++ ) {
	  
	  for( var a = 0; a < theTable.tBodies[z].rows[x].cells.length; a++ ) {
		  
		    for( var b = 0; b < theTable.tBodies[z].rows[x].cells[a].childNodes[a].length; b++ ) {
   
    	var type=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeType;
			var nod_name=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeName;
			
		
		
					if(type==1)
					{
						theTable.tBodies[z].rows[x].cells[a].childNodes[b].checked=false;
						
						var nod_value=theTable.tBodies[z].rows[x].cells[a].childNodes[b];
							// alert(type+"--"+nod_name+"--"+nod_value.value);
							 
							 table_name_2=nod_value.value;
						
						
						subitem_table_name=table_name+"_00_"+table_name_2;
					
						
					deselect_sub_item(subitem_table_name);
				
						
					}
					
					
					

							

					
		}
  }
 
  }
}


 

		  
				
	}
	
function show_sub_item(item_check_box,table_name)
{
	
	
	try
	{
	document.getElementById(table_name).style.display="none"; 
	
	if(item_check_box.checked)
	{
		document.getElementById(table_name).style.display="block";
	}
	else
	{
		 deselect_sub_item(table_name);
		
	}
	
	}catch(Exception)
	{
		
	}
	

}
function deselect_sub_item(table_name)
	{ 
	
	
		
		var theTable = document.getElementById(table_name);

	for( var z = 0; z < theTable.tBodies.length; z++ ) {
  for( var x = 0; x < theTable.tBodies[z].rows.length; x++ ) {
	  
	  for( var a = 0; a < theTable.tBodies[z].rows[x].cells.length; a++ ) {
		  
		    for( var b = 0; b < theTable.tBodies[z].rows[x].cells[a].childNodes[a].length; b++ ) {
   
    	var type=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeType;
			var nod_name=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeName;
			
		
		
					if(type==1)
					{
						theTable.tBodies[z].rows[x].cells[a].childNodes[b].checked=false;
						
						var nod_value=theTable.tBodies[z].rows[x].cells[a].childNodes[b];
							// alert(type+"--"+nod_name+"--"+nod_value.value);
							 
						
						
					}
					
					
					

							

					
		}
  }
 
  }
}


 


		
	


 

		  
				
	}


function deselect_city_table(table_name)
	{ 
	
	var theTable = document.getElementById(table_name);

	for( var z = 0; z < theTable.tBodies.length; z++ ) {
  for( var x = 0; x < theTable.tBodies[z].rows.length; x++ ) {
	  
	  for( var a = 0; a < theTable.tBodies[z].rows[x].cells.length; a++ ) {
		  
		    for( var b = 0; b < theTable.tBodies[z].rows[x].cells[a].childNodes[a].length; b++ ) {
   
    	var type=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeType;
			var nod_name=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeName;
			
		
		
					if(type==1)
					{
						theTable.tBodies[z].rows[x].cells[a].childNodes[b].checked=false;
						
						var nod_value=theTable.tBodies[z].rows[x].cells[a].childNodes[b];
							// alert(type+"--"+nod_name+"--"+nod_value.value);
							 
							 table_name=nod_value.value;
							 
						deselect_city_part(table_name);
				
						
					}
					
					
					

							

					
		}
  }
 
  }
}


 

		  
				
	}


function deselect_item_subitem(table_name)
	{
		
		var theTable = document.getElementById(table_name);

	for( var z = 0; z < theTable.tBodies.length; z++ ) {
  for( var x = 0; x < theTable.tBodies[z].rows.length; x++ ) {
	  
	  for( var a = 0; a < theTable.tBodies[z].rows[x].cells.length; a++ ) {
		  
		    for( var b = 0; b < theTable.tBodies[z].rows[x].cells[a].childNodes[a].length; b++ ) {
   
    	var type=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeType;
			var nod_name=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeName;
			
		
		
					if(type==1)
					{
						theTable.tBodies[z].rows[x].cells[a].childNodes[b].checked=false;
						
						var nod_value=theTable.tBodies[z].rows[x].cells[a].childNodes[b];
							// alert(type+"--"+nod_name+"--"+nod_value.value);
							 
						
						
					}
					
					
					

							

					
		}
  }
 
  }
}


 


		
	}
	


function deselect_city_part(table_name)
	{
		
		var theTable = document.getElementById(table_name);

	for( var z = 0; z < theTable.tBodies.length; z++ ) {
  for( var x = 0; x < theTable.tBodies[z].rows.length; x++ ) {
	  
	  for( var a = 0; a < theTable.tBodies[z].rows[x].cells.length; a++ ) {
		  
		    for( var b = 0; b < theTable.tBodies[z].rows[x].cells[a].childNodes[a].length; b++ ) {
   
    	var type=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeType;
			var nod_name=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeName;
			
		
		
					if(type==1)
					{
						theTable.tBodies[z].rows[x].cells[a].childNodes[b].checked=false;
						
						var nod_value=theTable.tBodies[z].rows[x].cells[a].childNodes[b];
							// alert(type+"--"+nod_name+"--"+nod_value.value);
							 
						
						
					}
					
					
					

							

					
		}
  }
 
  }
}


 


		
	}
	
	
	
	
	
	function deselect_zip_code(table_name)
	{
		
		var theTable = document.getElementById(table_name);

	for( var z = 0; z < theTable.tBodies.length; z++ ) {
  for( var x = 0; x < theTable.tBodies[z].rows.length; x++ ) {
	  
	  for( var a = 0; a < theTable.tBodies[z].rows[x].cells.length; a++ ) {
		  
		    for( var b = 0; b < theTable.tBodies[z].rows[x].cells[a].childNodes[a].length; b++ ) {
   
    	var type=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeType;
			var nod_name=theTable.tBodies[z].rows[x].cells[a].childNodes[b].nodeName;
			
		
		
					if(type==1)
					{
						theTable.tBodies[z].rows[x].cells[a].childNodes[b].checked=false;
						
						var nod_value=theTable.tBodies[z].rows[x].cells[a].childNodes[b];
							// alert(type+"--"+nod_name+"--"+nod_value.value);
							 
						
						
					}
					
					
					

							

					
		}
  }
 
  }
}


		
	}



function show_templete_row(curent_checkbox_id,row_id)
{
	chkbox=document.getElementById(curent_checkbox_id);
	
	
	if(chkbox.checked==true)
	{
		document.getElementById(row_id).style.display="";
		
	}
	else
	{
			document.getElementById(row_id).style.display="none";
	}
	
	
}


function doAlert(parent,title,text,height,page_link)
{
	var msg = new DOMAlert(
	{
		title: '<b>'+title+'</b>',
		text: ''+text+'',
		skin: 'default',
		width: 300,
		height: height,
		ok: {value: true, text: 'Yes',confirm_link :page_link, onclick: showValue},
		cancel: {value: false, text: 'No', onclick: showValue }
	});
	msg.show();
};
		
function showValue(sender, value,confirm_link)

{
	if(value==true)
	{
		window.location.href=confirm_link;
	}
	
	sender.close();
}






function select_chkbox(chkboxs,table_name,limit){


if(document.getElementById(chkboxs).checked==true){

select_all(chkboxs,table_name,limit);
}else{

deselect_all(chkboxs,table_name,limit)

}

}
function select_all(chkboxs,table_name,limit){



var tbl=document.getElementById(table_name);

//alert(tbl.tBodies[0].rows.length);
var name="";

for(var a=0;a<=limit;a++){
name="item_id_"+(a+1)+"";

try
{
document.getElementById(name).checked=true;
}catch( ex)
{
	
}


}

}



function deselect_all(chkboxs,table_name,limit){



var tbl=document.getElementById(table_name);
//alert(tbl.tBodies[0].rows.length);
var name="";

for(var a=0;a<=limit;a++){

name="item_id_"+(a+1)+"";

try
{
document.getElementById(name).checked=false;
}catch( ex)
{
	
}
}

}








//GETTING RESTAURANT FOOD ITEM BY CATEGROY
function show_rest_off_days(r_id)
{
	xmlHttp=get_xmlhttp();
	
	var url="../ext/includes/ajx_get_off_days.php?action=get_off_days&r_id="+r_id+"&";
	
	
	xmlHttp.onreadystatechange=function()
	{
	  document.getElementById("off_days_loading_div").style.display="block";
	  document.getElementById("off_days_form_div").style.display="none";
	   
	  if(xmlHttp.readyState==4)
	   { 
			values=xmlHttp.responseText;
			
		
			document.getElementById("off_days_loading_div").style.display="none";
			document.getElementById("off_days_form_td").innerHTML=values;
			
			
	   }  
		 
	}
	
	 var str=url;
	 xmlHttp.open('GET',str,true);
	 xmlHttp.send(null);
	
	
}

