// JavaScript Document

function pageLoad(objID, pageName, val)
{
	//alert(pageName);
	$jq('#'+objID).load(pageName);
}

function chkUser(val)
{

	$jq('#chkUser').load('chkUser.php?MM_insert=username&email='+val);	
}

function newCity()
{

	$jq.post('newCity.php',{MM_insert:'frm_city', newcity: $jq('#newcity').val()},function(){ pageLoad('loadCity', 'city.php'), slideShowHide('addcity'); })
	
}

function newArea()
{
	//alert($jq('#city').val());
	$jq.post('newArea.php',{MM_insert:'frm_area', newarea: $jq('#area').val(), city_id: $jq('#city').val() },function(){ pageLoad('areaLoad', 'area.php?city_id='+$jq('#city').val()), slideShowHide('addarea'); })
	
}function newAreaUser()
{
	//alert($jq('#city').val());
	$jq.post('newArea.php',{MM_insert:'frm_area', newarea: $jq('#area').val(), city_id: $jq('#city').val() },function(){ pageLoad('areaLoad_user', 'area_user.php?city_id='+$jq('#city').val()), slideShowHide('addarea'); })
	
}

function newStreet()
{
	//alert($jq('#location').val());	
	$jq.post('newStreet.php',{MM_insert:'frm_street', newstreet: $jq('#newstreet').val(), city_id: $jq('#city').val(), area_id: $jq('#aera_location').val() },function(d){pageLoad('loadStreet', 'street.php?city_id='+$jq('#city').val()+'&area_id='+$jq('#aera_location').val()); })/*, slideShowHide('addstreet')*/
	
	
}

function slideShowHide(objID)
{
	$jq('#'+objID).slideToggle('fast');
	//alert('hf');
	
	
}

function setValues()
{
	if($jq('#name').val()!='' && $jq('#name').val()!= undefined) { $jq('#restnameMap').html($jq('#name').val())}	;
	
	if($jq('#city').val()!=-1) { $jq('#cityMap').html($jq('#city option:selected').text()) };
	
	if($jq('#aera_location').val()!=-1) { $jq('#areaMap').html($jq('#aera_location option:selected').text()) };
	
	if($jq('#street').val()!=-1){ $jq('#streetMap').html($jq('#street option:selected').text()) };
	
	if($jq('#address').val()!='') { $jq('#addsMap').html($jq('#address').val()) };
}

function chngCity()
{
	$jq('#cityLayer').css('display','block');
}
function cityHide()
{
	$jq('#cityLayer').css('display','none');
	//$jq('#goCity').css('display','none');	
}
function gocity()
{
	showAddress($jq('#chCity').val());
	$jq('#goCity').slideToggle('fast');	
}

function loadDetailRsg()
{
	if($jq('#userDetail').css('display')=='none')
	{
		$jq('#userDetail').load('detailReg.php',function(){$jq('#userDetail').slideDown('fast'), $jq('#detailInfo').text('[-] Detail Info');});
	}
	else
	{
		$jq('#userDetail').slideUp('fast', function(){ $jq('#userDetail').empty(), $jq('#detailInfo').text('[+] Detail Info'); });
	}
}

/*function addfoodCategory(restId, cat)
{
	//exeLoader(1);
	$jq('addFoodCategory.php', {MM_insert: 'frm_foodcat', restaurant_id: restId, category_name: cat }, function(d) { alert(d); } )
}*/

function exeLoader(val)
{
	if(val!=0)
	{
		$jq('#mydiv').css('display','block');	
	}
	else
	{
		$jq('#mydiv').css('display','none');	
	}
	//updatebox(evt)
}
function updatebox(evt)
{
	 evt = evt || window.event ;
	//alert(evt);
	boxmove=true;
	if (boxmove) {
	   mouseX=evt.pageX?evt.pageX:evt.clientX;
	   mouseY=evt.pageY?evt.pageY:evt.clientY;
	   document.getElementById('mydiv').style.left=mouseX+'px';
	   document.getElementById('mydiv').style.top=mouseY+'px';
	   //alert(mouseX+' '+mouseY)
	}
}

function addFoodCat(restId)
{
	var catName = prompt('Enter Category Name');
	if(catName!='' && catName!=null)
	{
		$jq.post('addFoodCategory.php', { MM_insert: 'frm_foodcat', restaurant_id: restId, category_name: catName } , function(d){  
										if(d!='' && d!=null)
										{
											alert(d); 
										}
										else
										{									
											pageLoad('loadFoodCategory','loadFoodCategory.php?rest_id='+restId);	
										}
									} );
	}
}


function addFoodCat2(restId)
{
	alert(restId);
	var catName = prompt('Enter Category Name');
	if(catName!='' && catName!=null)
	{
		$jq.post('addFoodCategory.php', { MM_insert: 'frm_foodcat', restaurant_id: restId, category_name: catName } , function(d){  
										if(d!='' && d!=null)
										{
											alert(d); 
										}
										else
										{									
											pageLoad('loadFoodCategory2','loadFoodCategory2.php?rest_id='+restId);	
										}
									} );
	}
}

function addTag()
{
	var tagName = prompt('Enter Tag Name');
	if(tagName!='' && tagName!=null)
	{
		exeLoader(1);
		
			$jq.post('addTag.php', { MM_insert: 'frm_tag', tag_name: tagName } , function(d){ if(d!='' && d!=null){alert(d)}; pageLoad('loadTag','loadTag.php')} );

		exeLoader(0);
	}
}

function addTag2()
{
	var tagName = prompt('Enter Tag Name');
	if(tagName!='' && tagName!=null)
	{
		exeLoader(1);
		
			$jq.post('addTag.php', { MM_insert: 'frm_tag', tag_name: tagName } , function(d){ if(d!='' && d!=null){alert(d)}; pageLoad('loadTag2','loadTag.php')} );

		exeLoader(0);
	}
}
/*function addFood()
{
	
	//$jq.post('addFood.php', {MM_insert:'frm_addFood', restaurant_id:$jq('#restaurant_id').val(), food_name: $jq('#food_name').val(), food_description:$jq('#food_description').val(), prize:$jq('#prize').val(), food_type:$jq('food_type').val(), food_category:$jq("input[@name='food_category']:checked").val() } , function(){} );	
	
	//alert($jq("input[@name='tag_name[]']:checked").val());
	 //$jq('input:checkbox').each( function() { this.checked = !this.checked; });
	 var result = "";
	$jq('input:checkbox[@name="tag_name"]:checked').each( function () {
	result = result + $jq(this).val() + ",";
	});
	//
	//$jq('input:checkbox').each( function() { this.checked = ''; });
	//alert(result+'mm');
	 
}*/

function deleteFood(val,restID)
{
	exeLoader(1);
	$jq.post('deleteFood.php', {food_id:val}, function(){pageLoad('loadFoodMenu','loadFoodMenuAdmin.php?rest_id='+restID);} );	
	exeLoader(0);
}
function deletecate(catId,restID)
{
$jq.post('deleteFoodCat.php',{id:catId}, function(d){alert(d);pageLoad('loadFoodMenu','loadFoodMenuAdmin.php?rest_id='+restID);tb_remove();} );
}
function edit_foodCate()
{
$jq.post('edit_foodCate_ajx.php', {restaurant_id:$jq('#restaurant_id').val(),category_name:$jq('#category_name').val(),catid:$jq('#catid').val()},function(){$jq('#loadFoodMenu').load('loadFoodMenuAdmin.php?rest_id='+$jq('#restaurant_id').val());tb_remove();});//alert($jq('#restaurant_id').val()+","+$jq('#catid').val()+","+$jq('#category_name').val());

}

function objHideShow(obj,linkObj)
{
	$jq('#'+obj).slideToggle('fast', function()
											  { 
											  	if($jq('#'+obj).css('display')=='none')
												{
													$jq(linkObj).children().html('[+]'); 
												}
												else
												{
													$jq(linkObj).children().html('[-]');	
												}
											  });
	
}

function chkpassword()
{
	var pass=$jq('#password').val();
	var pass2=$jq('#repassword').val();	
	if(pass==pass2 && pass2!='')	
	{
		$jq('#no').css('visibility','hidden');
		$jq('#yes').css('visibility','visible');	
	}
	else
	{
		$jq('#yes').css('visibility','hidden');	
		$jq('#no').css('visibility','visible');
	}
}

////////////////////////////////Chat Window///////////////////
function startChat()
{
	window.open("http://www.google.com/talk/service/badge/Start?tk=z01q6amlqa762cfjpog66sf1bs3ihg18mgp1b1217pkj83s6t6r65dp5gide1ke0u9d98hatrsn2n5q26v564rhhgjoju9bj9fs22fo8it59ghaab6rus4jmbcvthp93m6dvc2oaaqbk5kbv0s63b53r7bsjjrll7429a5mdrl2rvnusbbmppgrcjdfb59mto8s","Live Help - Beafoodie.com","location=0,status=0,scrollbars=0,width=300,height=400"); 
}


//$jq(document.body).mouseover( function() { updatebox(event); } );

//Comments are reviewed before publishing to prevent spam.
