window.onload = function() {
    // do this stuff when the page is done loading
$('#editInPlace').load('listchipsets.php');
};

$(document).ready(function(){
				setClickable();
			  });

function setClickable() {
	$('#editInPlace').click(function() {
//		$('#editInPlace').load('listchipsets.php?edit=1');
//		var mydata = ('addnew_chipset.php?edit=1');
		var textarea = '<div><div id="editlist">'+$(this).html()+'</div><div id="addeditlist"></div>';
		var button	 = '<div id="editarea"><input type="button" value="SAVE" class="saveButton" /> OR <input type="button" value="CANCEL" class="cancelButton" /></div></div>';
		var revert = $(this).html();
        	$(this).after(textarea+button).remove();
		$('.saveButton').click(function(){saveChanges(this, false);});
		$('.cancelButton').click(function(){saveChanges(this, revert);});
		$('#editlist').load('listchipsets.php?edit=1');
	        $('#addeditlist').load('addnew_chipset.php?edit=1');
                $('.adamsaveButton').click(function(){adamsaveChanges();});
 
	})

.mouseover(function() {
	$(this).addClass("editable");
//	$('#editInPlace').load('listchipsets.php?edit=1');
})

.mouseout(function() {
	$(this).removeClass("editable");
	});
};

function removechipset(myid){
// alert(myid)
$.post('listchipsets.php?delete=' + myid + '&yes=yes');
 $('#editlist').load('listchipsets.php?edit=1');
 $('#addeditlist').load('addnew_chipset.php?edit=1');

}

function adamsaveChanges(){
var myTest  = selectchipset.chipsetid.options[selectchipset.chipsetid.selectedIndex].value;
alert("test");
//$.post('listchipsets.php',
//		{ Addnew2: 'Add',
//		  chipsetid: myTest,
//		  driverlist_id: '1'
//		},
//		function(txt){
 //                       alert( txt);
  //                      });
var site ='listchipsets.php?edit=1&Addnew=Add&chipsetid='+ myTest + '&driverlist_id=1';
$('#editlist').load(site,function(txt){ alert( txt);});

return false;  
}
function saveChanges(obj, cancel) {
	if(!cancel) {
	var myTest  = selectchipset.chipsetid.options[selectchipset.chipsetid.selectedIndex].value;
	var site ='listchipsets.php?edit=1&Addnew=Add&chipsetid='+ myTest + '&driverlist_id=1&edit=1';

		var t = $(obj).parent().siblings(0).val();

		$.post("test2.php",{
		 	 content: t
			},function(txt){
			alert( txt);
  			});
	        var myTest  = selectchipset.chipsetid.options[selectchipset.chipsetid.selectedIndex].value;

	 $('#editInPlace').load(site);
 	$('#addeditlist').load('addnew_chipset.php?edit=1');

	}else {
		var t = cancel;
	}
	if(t=='') t='(click to add text)';
//	$('#editarea;).remove();
//	$('#editInPlace').load('listchipsets.php');
//	 $(this).after.
	$(obj).parent().parent().after('<div id="editInPlace">'+t+'</div>').remove();
	 $('#editInPlace').load('listchipsets.php');

	setClickable();
}	


