        geolocate_v4=function(lat,lon,a){
	    if (!window.count) window.count = 0;
            var urlJSON ='';
	    var myhtml="";
            count ++;
	    if (upd !== 1) {
		$("a[name='homelink']").html('Nearby Restaurants');
	      upd=1;
	    }
            var urlJSON = 'record.php?type=JSON&latent='+lat+'&longent='+lon;
	    var geocoder = new google.maps.Geocoder();
	    var latlng=new google.maps.LatLng(lat,lon);
	    var	useragent = navigator.userAgent;
	geocoder.geocode({'latLng': latlng}, function(results, status) {
	if (status == google.maps.GeocoderStatus.OK) {
		if (results[0]) {
		  loc =results[0].formatted_address;
		  var la = loc.split(',');
		  var alen=la.length + 1;
		  if (alen > 3) {if (a < 200) myhtml = la[0]; myhtml= myhtml + ' ' + la[1];  myhtml = myhtml + ' ' + la[2];} 
		  else if (alen > 2) {myhtml = la[0] + ' ' +  la[1]} 		  
		  else if (alen > 1) {myhtml= la[0]} 		  
		}
	      }
	    });	
	var stat='';
	     $.ajax({
                                      type: "GET",
					      url: "status.php",
					      success:
	     function(data, status)
					{
			stat=data;		     
            $.get(urlJSON, function() {
		if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
			if (a < 200) var f= '<img src="good.png">'; else  var f='<img src="med.png">';
			if (a < 200) navigator.geolocation.clearWatch(wid);
				var loc=   f + '&nbsp;&nbsp;&nbsp;&nbsp;' + myhtml + stat;
				$('#topmain').html(loc);
	   	  	 	$('#toploc').html(loc);
				$('#toploch').html(loc);
			        $('#toplocf').html(loc);
				$('#toplocs').html(loc);
				mapcommonbu();
		}
		else {
			var f= '<img src="med.png">';
			var loc=   f  + '&nbsp;&nbsp;&nbsp;&nbsp;' + myhtml + stat;
	                $('#topmain').html(loc);
        	        $('#toploc').html(loc);
                	$('#toploch').html(loc);
            	 	$('#toplocf').html(loc);
                	$('#toplocs').html(loc);
			mapcommonbu();
		}
	    });
	}				   
});
	  setTimeout('$("div#box").hide()',3000);	
	};
	function addTableRow(jQtable,i,j){
		jQtable.each(function(){
		var $table = $(this);
		var r = $('tr',this).length -1;
		j = j+r;
		var tds = '<tr> <td width="18" align="CENTER" ></td><td width="190" align="left"  bgcolor="<? echo $col; ?>"><span class="edititem_name" id="' + i + 'name' + j + '"></span></td><td width="114" ><span class="edititem_price" id="' + i + 'price' + j + '"></span> </td><td width="300" bgcolor="<? echo $col; ?>"><span class="edititem_desc" id="' + i + 'desc' + j + '"></span> </td></tr>';
		if($('tbody', this).length > 0){
			$('tbody', this).append(tds);
		}else {
		$(this).append(tds);
		}
		mapcommonbu();
		});
	}	
	getmytweets= function(tn) {
		$("#mytweets").getTwitter({
					userName: tn,
					numTweets: 20,
					loaderText: "Loading tweets...",
					slideIn: true,
					slideDuration: 100,
					showHeading: false,
					headingText: "Latest Tweets",
					showProfileLink: false,
					showTimestamp: true
				});

	}
	mapme=function(lat,lon) {
	       var mapdiv=	   document.getElementById('mapi');
	       mapdiv.style.height = '300px';
	       mapdiv.style.width = '300px';
	       map_options = {
		 zoom: 16,
		 center: new google.maps.LatLng(40.7208,-73.9954), // 41 kenmare
		 mapTypeId: google.maps.MapTypeId.ROADMAP
	       };
	       	       var map = new google.maps.Map(mapdiv,map_options);
	       var m = new google.maps.LatLng(lat,lon);
//	var m = new google.maps.LatLng(40.7208,-73.9954), // 41 kenmare
	       marker = new google.maps.Marker({
						position: m,
							    map: map,
							    shadow: '',
							    title: ''
							    });
	       //map.set_center(m);

	}
	function pw(msg) {
		$.modal("<div id='osx-dialog'><br><br><h3><div id='osx-modal-data'>" + msg + "</div></h3></div>")
	}
	 mapcommonbu=function(i){
	 if (i!==1) $.ajax({
                     type: "GET",
			     url: "ajax/status.php",
			     data: "",
			     success: function(msg){
			if (msg=='nok') location.href = 'index.php';
			}
	});
	$("#tweet").charCounter(140, {
		container: "<p></p>",
		classname: "counter",
		format: "%1 characters left!",
		pulse: false,
		delay: 100
	});
	$("input[name='datepicker']").datepicker();
	$('.editmenu_name').editable('ajax/editmenu.php', {
	type: 'autogrow',
	  indicator : 'Saving...',
	    tooltip   : 'Click to edit...',
		onblur : 'submit',
		callback : function (value,settings) {$ltabs.tabs('load', 1);}
	    });
	$('.autogrow').editable('ajax/editmenu.php', { 
	  type      : 'autogrow',
	    cancel    : 'Cancel',
	    submit    : 'OK',
	    indicator : '<img src="img/indicator.gif">',
		onblur : 'submit',
	cols:20,
	autogrow : {

    	},

	    tooltip   : 'Click to edit...'
	    });
	$('.editmenu_date').editable('ajax/editmenu.php', { 
	  //type      : 'datepick',
	    event    : 'click',
	    onblur : 'submit',
	    indicator : '<img src="img/indicator.gif">',
	    tooltip   : 'Click to edit date'
	    });
	$('.edititem_name').editable('ajax/editmenuitem.php', {
	  indicator : 'Saving...',
	    tooltip   : 'Click to edit name'
	    });
	$('.edititem_price').editable('ajax/editmenuitem.php', {
	  indicator : 'Saving...',
	    tooltip   : 'Click to edit price'
	    });
	$('.edititem_desc').editable('ajax/editmenuitem.php', { 
	  type      : 'textarea',
	    cancel    : 'Cancel',
	    submit    : 'OK',
	    indicator : '<img src="/ajax/loading.gif">',
	    tooltip   : 'Click to edit description'
	    });
    $(".ajaxupload").editable("ajax/uploadpdf.php", { 
        indicator : "<img src='img/indicator.gif'>",
        type      : 'ajaxupload',
        submit    : 'Upload',
        cancel    : 'Cancel',
	mid       : 2,
        tooltip   : "Click to upload PDF"
    });
    $(".ajaxuploadn").editable("ajax/uploadpdf.php", { 
        indicator : "<img src='/ajax/loading.gif'>",
        type      : 'ajaxupload',
        submit    : 'Upload',
        cancel    : 'Cancel',
	mid       : 2,
        tooltip   : "Click to upload PDF",
	    callback : function(value, settings) {
		$('#newmenu').toggle();$('#newmenurest').html(value).toggle('slow');mapcommonbu();
     	   }
    });
       $("a[name='me']").
       unbind('click').
	 bind('click',function(e) {
	   var  $t = $(e.target);
	   $("#mename").html($t.attr('namex') );
	     $('#mecont').html('<center><br> Loading .... <br><br><img src=\'/jqtouch/themes/jqt/img/loading.gif\'></center>');	     
		$('#mecont').
		  load('me.php?youid=' + $t.attr('youid') , function(){mapcommonbu();;return true;});
	 });
       $("#addfaveb").
       unbind('click').
       bind('click', function(e){
	 var $t=$(e.target);
	 var nm= $('#name').val();
	 var ad = $('#ad').val();
	 var ct= $('#ct').val();
	 var st = $('#st').val();
	 var zp= $('#zp').val();
	 var ph = $('#ph').val();
	 var em = $('#em').val();
	 var ds= $('#ds').val();
	 var cut = $('#cut').val();
	var ws = $('#ws').val();
	var wsf=$('#wsf').val();
	var fmsg= $('#fmsg').val();
	 var t = $('#ftype').val();
	 if (nm=='' || ad=='' || ct =='') {alert ('please enter name, address and city') ; return false;}
	 $("#addfaveb").attr("disabled", "true");$('#okmsg_s').toggle();
	 $.ajax({
                     type: "GET",
			     url: "/twitxml/googlegeo.php",
			     data: "outp=1&address=" + ad + "&city=" + ct + "&state=" + st + "&zip=" + zp,
			     success: function(msg){
		       $.ajax({
                           type: "POST",
				   url: "ajax/mysettingsp.php",
				   data: "msg=" + escape(fmsg) + "&t=" + t + "&name=" + nm + "&ad=" + ad + "&ct=" + ct + "&ph=" + ph + "&st=" + st + "&zp=" + zp + "&em=" + em + "&ds=" + ds +  "&ws=" + ws + "&wsf=" + wsf + "&cut=" + cut + "&latlong=" + msg,
				   success: function(msg1){
			     if (msg1=='ok') { $('#okmsg_s').toggle();var la = msg.split(',');
			mapme(la[0],la[1]);}  else {alert (msg1);$("#addfaveb").attr("disabled", "false");}
			   }
		       })
			 
			 }}
		)});       		
       $("#addmenu").
       unbind('click').
       bind('click', function(e){
	 var $t=$(e.target);
	 var nm= $('#nmname').val();
	 var ds = $('#nmdesc').val();
	 var pr= $('#nmprice').val();
	 var dt = $('#nmdate').val();
	 if (nm=='') {alert ('please enter name') ; return false;}
	$.ajax({
                           type: "POST",
				   url: "ajax/addmenup.php",
				   data: "nmname=" + nm + "&nmdesc=" + escape(ds) + "&nmprice=" + pr + "&nmdate=" + dt ,
				   success: function(msg1){
			     if (msg1=='ok') {$ltabs.tabs('load', 1);}  else {alert (msg1);}
			   }
		       })			 
		});       		
       $("#savenewtitle").
       unbind('click').
       bind('click', function(e){
	 var title= $('#titlenew').val();
	 if (title=='') {alert ('please enter a title') ; return false;}
	$.ajax({
                           type: "POST",
				   url: "ajax/editmenu.php",
				   data: "value=" + title + "&id=name",
				   success: function(msg1){
			if (msg1.indexOf('Oops') > -1) {alert ('please enter a valid title') ; return false;}
			else {
			$('#newmenu').toggle();$('#newmenu2').toggle();mapcommonbu();
//			$('#newmenurest').html(msg1).toggle('slow');$('#x').toggle();
			}
		       }
		})			 
		});       		

       $("#savenewurl").
       unbind('click').
       bind('click', function(e){
	 var url= $('#urlnew').val();
	 if (url=='') {alert ('please enter a url') ; return false;}
	pw('Please wait while the url is verified');
	$.ajax({
                           type: "POST",
				   url: "ajax/editmenu.php",
				   data: "value=" + url + "&id=url",
				   success: function(msg1){
			if (msg1.indexOf('Oops') > -1) {$.modal.close(); alert ('please enter a valid url') ; return false;}
			else {
						$ltabs.tabs('load', 1);
//			$('#newmenu').toggle();$('#newmenurest').html(msg1).toggle('slow');$('#x').toggle();mapcommonbu();
			}
		      $.modal.close();  }
		})			 
		});       		
       $("input[name='saveurl']").
       unbind('click').
       bind('click', function(e){
	$t=$(e.target);
	$id=$t.attr('idx');
	 var url= $('#url' + $id).val();
	 if (url=='') {alert ('please enter a url') ; return false;}
	pw('Please wait while the url is verified');
	$.ajax({
                           type: "POST",
				   url: "ajax/editmenu.php",
				   data: "value=" + url + "&id=url" + $id,
				   success: function(msg1){
			if (msg1.indexOf('Oops') > -1) {$.modal.close();alert ('please enter a valid url' + $id) ; return false;}
			else {
			$ltabs.tabs('load', 1);
		//	$('#newmenurest').html(msg1).toggle('slow');$('#x').toggle();mapcommonbu();
			}

				$.modal.close();		       }
		})			 
		});       		
       $("#tweetbutton").
       unbind('click').
       bind('click', function(e){
	 var st = $('#tweet').val();
	 if (st=='') {alert ('please enter something') ; return false;}
	$.modal.close();
	pw('please wait while your tweet is posted');
	$.ajax({
                           type: "POST",
				   url: "ajax/tweet.php",
				   data: "status=" + escape(st),
				   success: function(msg1){
			     if (msg1=='ok') {	$.modal.close();}  else {alert (msg1);}
			   }
		       });

		});       		
       $("a[name='deletemenu']").
       unbind('click').
       bind('click', function(e){
	 var $t=$(e.target);
	 var id= $t.attr('mid');
	 if (!confirm ('Delete Menu?  cannot undo this')) return false;
	$.ajax({
                           type: "POST",
				   url: "ajax/delmenu.php",
				   data: "id=" + id ,
				   success: function(msg1){
			     if (msg1=='ok') {$ltabs.tabs('load', 1);}  else {alert (msg1);}
			   }
		       })			 
		});
       $("a[name='tweetthis']").unbind('click').
	bind('click',function(e) {
	  e.preventDefault();
	  var $t=$(e.target);
	  var mid=$t.attr('mid');
	  pw ('<br><br>please wait....');
		// load the contact form using ajax
		$.get("ajax/tweetpreview.php?mid=" + mid , function(data){
			// create a modal dialog with the data
			$.modal.close();
			$(data).modal({
//				closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
//				position: ["15%",],
			});
		mapcommonbu();
		});
	});	       		
       $("#regb").
       unbind('click').
       bind('click', function(e){
	 var unm= $('#username').val();
	 var em = $('#email').val();
	 var em2 = $('#cemail').val();
	 var ps= $('#ps').val();	 
	 var f = $('#fid').val();
	 if (unm=='' || em=='' || ps =='' || em !== em2) {alert ('missing info and/or mismatched email') ; return false;}
	 $("#regb").attr("disabled", "true");
	$.ajax({
                     type: "GET",
			     url: "checkuser.php",
			     data: "cun=" + unm + "&em=" + em,
			     success: function(msg){
			     if (msg=='ok') {
					$.ajax({
                    type: "POST",
			  url: "registerp.php",
			  data: "g1=" + unm + "&email=" + em + "&g2=" + ps + "&f=" + f ,
			  success: function(msg1){
		if (msg1=='ok') { location.href='index.php';}  else {alert ('Sorry there was an error');$("#regb").attr("disabled", "false");}
			   }
		       })
				 }  
			     else {if (msg !== '') alert (msg);$("#regb").attr("disabled", "false"); return false;}

			}
		});	
	});
	$('#forgotb').
	unbind('click').
	bind('click',function(e){
	 var key= $('#keyp').val();
	$.ajax({
                     type: "GET",
			     url: "pwork.php",
			     data: "key=" + key ,
			     success: function(msg){
				alert ('Password reminder was sent');
					}
	})
	});	
       $('#loginsub').
       unbind('click').
	 bind('click', function(e){
	   var user=$('#login').val();
	   var ps=$('#pass').val();
	   $.ajax({
                    type: "POST",
			    url: "ajax/loginproc.php",
			    data: "e=mr&login=" + user + "&pswd=" + ps,
			    success: function(msg){
		      if (msg=='fresh') { location.href="index.php?fresh=1";} else if (msg=='nearme') {location.href="indexsave.php?miles=9";} else alert (msg);
		    }
	   });
	   
	 });
	}
//mapcommonbu end //
