
   function doAjax(idnumber) { 
    	if(confirm("Are you sure to delete?")){ 
    	openMask(true);
        $.ajax({  
        url: 'deletetrip',
        data: ({id : idnumber}),
        success: function(data) {
          //$('#time').html(data);
          doRemoveTrip(idnumber);
          openMask(false);
          //alert(data);
        }
      });
        }else{
            return;
        }
      }
    
    function  addTripToMyfavorite(tripid) { 	
    	openMask(true);   
        $.ajax({  
        url: 'addtriptomyfavorite',
        data: ({tripid : tripid}),
        success: function(data) {
          alert(data);
          openMask(false);
        }
      });
      }
    function  addtriptolike(tripid) { 	
    	openMask(true);   
        $.ajax({  
        url: 'addtriptolike',
        data: ({tripid : tripid}),
        success: function(data) {
          if(data!='')	
          document.getElementById('like'+tripid).innerHTML = data;
          openMask(false);
        }
      });
      }
    function  addspottolike(spotid) { 	
    	openMask(true);   
        $.ajax({  
        url: 'addspottolike',
        data: ({spotid : spotid}),
        success: function(data) {
          if(data!='')	
          document.getElementById('like'+spotid).innerHTML = data;
          openMask(false);
        }
      });
      }
    function  addSpotToMyfavorite(spotid) { 	
    	openMask(true);   
        $.ajax({  
        url: 'addspottomyfavorite',
        data: ({spotid : spotid}),
        success: function(data) {
          alert(data);
          openMask(false);
        }
      });
      }

    function spotDelete() { 
    	var spotid=document.getElementById("opspotid").value;
    	if(confirm("Are you sure to delete?")){ 	
    	openMask(true);
    	easyDialog.close();        
        $.ajax({  
        url: 'deletespot',
        data: ({id : spotid}),
        success: function(data) {
          doRemoveSpot(spotid);
          openMask(false);
        }
      });
        }else{
            return;
        }
      }
 
    function  spotRemove() { 
    	var spotid=document.getElementById("opspotid").value;
    	var tripid=document.getElementById("optripid").value;
    	//alert(tripid);
    	if(confirm("Are you sure to remove?")){ 	
    	openMask(true);
    	easyDialog.close();        
        $.ajax({  
        url: 'removespot',
        data: ({id : spotid,tripid : tripid}),
        success: function(data) {
          doRemoveSpot(spotid);
          openMask(false);
        }
      });
        }else{
            return;
        }
      }

    
    function doAjaxRefreshSpot(idnumber){
       	var spotid=document.getElementById("opspotid").value;
    		
    	openMask(true);
    	//easyDialog.close();        
        $.ajax({ 
        type : 'GET',  
	    contentType : 'application/json',  
        url: 'geteditspotjson',
        data: ({id : spotid}),
        dataType : 'json', 
        success: function(data) { 
        	//alert(data.id);
        	if(data.id != null){
    			//alert(data);
    			doReplaceSpot(idnumber,data.id,data.simg,data.name,data.address,data.category);
    		};
          openMask(false);
        }
      });
      }
    
    function spotEdit() {        
    	easyDialog.close();  
        //window.open('/index'); 
    }
    
    function doAjaxGetLastSpot(idnumber) {
    	openMask(true);
    	$.ajax( {
        	    type : 'GET',  
    	        contentType : 'application/json',  
    	        url : 'getlastspotjson',
    	        //data: ({id : idnumber}),  
    	        dataType : 'json',  
    	        success : function(data) { 	
	            //alert(data.id);       
	    		if(data.id != null){
	    		    doAddSpotList(idnumber,data.id,data.simg,data.name,data.address,data.category);
	    		};
		        openMask(false);
            } 
        });
      }

    function doAjaxGetTrip(idnumber){
    	openMask(true);
    	$.ajax( {
        	    type : 'GET',  
    	        contentType : 'application/json',  
    	        url : 'gettripjson',
    	        data: ({id : idnumber}),  
    	        dataType : 'json',  
    	        success : function(data) { 
    		document.getElementById('tripname'+idnumber).innerHTML=data.name;
    		document.getElementById('description'+idnumber).innerHTML=data.description;
    		document.getElementById('startDate'+idnumber).innerHTML=data.startDate;
    		document.getElementById('tripCategory'+idnumber).innerHTML=data.tripCategory;
			     //  alert(data.name);
		        openMask(false);
            } 
        });       
    }
	
    function doRemoveTrip(idnumber){
    	document.getElementById('tripTable'+idnumber).style.display="none";  
    }

    function doRemoveSpot(idnumber){
    	document.getElementById('spotTable'+idnumber).style.display="none";  
    }
    
    function doReplaceSpot(idnumber,spotid,spotimg,spotname,address,category){
    	
    	document.getElementById('spotimgid'+spotid).src= spotimg;
    	document.getElementById('spogimg'+spotid).innerHTML= spotname;
    	
    	/*var html = document.getElementById('spotTable'+spotid).innerHTML;

    	var listr ='<a class="iframe1"	href="spotdisplay?id='+spotid+'" target="blank"><img onmouseout="spotMouseOut();"  src="'+spotimg+'" alt="'+spotname+'" width="120" height="80" /><br></a>';
        listr+='<span id="spogimg'+spotid+'"';
        listr+=' onmouseover="spotMouseOn(spogimg'+spotid;
        listr+=",'"+spotname+"','"+address+"','"+category+"',"+spotid+");\" >"+spotname+"</span>";
    	//listr += '</li>';
    	
    	document.getElementById('spotTable'+spotid).innerHTML = html.replace(listr);
    	*/
    }

    function doAddSpotList(idnumber,spotid,spotimg,spotname,address,category){
		document.getElementById('opspotid').value = spotid;
		document.getElementById("opspotlink").href = 'spotedit?id='+spotid;
		//var listr = '<li class="show_img_ul_div" id="spotTable'+spotid+'"><a class="iframe1"	href="spotdisplay?id='+spotid+'" target="blank"><img onmouseout="spotMouseOut();"  src="http://ec2-50-19-31-1.compute-1.amazonaws.com/images/'+spotimg+'" alt="'+spotname+'" width="120" height="80" /><br></a><span id="spogimg'+spotid+'" onmouseover=spotMouseOn(spogimg${spotitem.id},'+spotname+','${spotitem.address}','${spotitem.spotCategory}',${spotitem.id});" >${spotitem.name}</span></li>';
    	var listr ='<li class="show_img_ul_div" id="spotTable'+spotid+'"><a class="iframe1"	href="spotdisplay?id='+spotid+'" target="blank"><img id="spotimgid'+spotid+'"  onmouseout="spotMouseOut();"  src="'+spotimg+'" alt="'+spotname+'" width="120" height="80" /><br></a>';
        listr+='<span id="spogimg'+spotid+'"';
        listr+=' onmouseover="spotMouseOn(spogimg'+spotid;
        listr+=",'"+spotname+"','"+address+"','"+category+"',"+spotid+");\" >"+spotname+"</span>";
    	listr += '</li>';
    	//alert(listr);
    	$("#spotlistul"+idnumber).append(listr);  
    }


    function setOpTripValue(tripid){
    	document.getElementById('optripid').value = tripid;
    }
    
    function htmlTagOpen(tripid,isopen){
    	setOpTripValue(tripid);
    	if(isopen)
    		document.getElementById("tripButton"+tripid).style.display = 'block';
    	else
    		document.getElementById("tripButton"+tripid).style.display = 'none';
    }

