/* JQuery */

$(function() {
    $("select#cat1").change(function(){
		if ($(this).val()!=0) {					
			$.getJSON("index.php",{catid: $(this).val(), pg: 'category-json'}, function(j){
																					
			  //var options = '<option value="0">Select All</option>';
			  var options = '';
			  
			  for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].value + '">' + j[i].title + '</option>';
			  }
			  $("select#cat2").html(options);
			})
		} else {
			$("select#cat2").html("");
		}
	})
	
});


/* End Jquery */

function get_price() {
	
	val=$("#code").val(); 
	
	$.getJSON("index.php",{code: val, pg: 'price-json'}, function(j) {
		
		if(j != '-1') {
			if (j != '0') { 
				$("#price").html("$" + j);  $("#stock").html("<span style=\"color: #ffffff;\">prices excl. gst</span>"); $("#add").val(val);
			} else { 
			  ("#price").html("$ 0.00");  $("#stock").html("Out of stock"); $("#add").val("0");
			}
		} else {
			$("#price").html("$ 0.00");  $("#stock").html("Invalid part number"); $("#add").val("0");
		}
				  
			
			  
			})				  
					  
}



function show_bar_window(sid,h,w)
{
  var popup = window.open(sid, "News",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=' + h + ',height=' + w);
}



function DoDel(iserial)
{
	if (confirm("Are you sure?"))
	{
		window.location.href=iserial;
	}
}


function show(menu,btn) {
	div=document.getElementById(menu);
	a=document.getElementById(btn);
	
	tmp=getObUpperLeft(a);
	
	if (menu=="menu1") { xtop=25; xleft=170; }
	if (menu=="menu2") { xtop=25; xleft=0; }
	div.style.top=(parseInt(tmp[1]) + xtop) + 'px';
	div.style.left=(parseInt(tmp[0]) - xleft) + 'px';
	
	div.style.display='';

}

function hide(menu) {
	div=document.getElementById(menu).style.display='none';
}

function getObUpperLeft(obj) {
    var curLeft = curTop = 0;
    if (obj.offsetParent) {
        curLeft = obj.offsetLeft
        curTop = obj.offsetTop
        //alert("objName= "+obj.id+"  offsetLeft= "+obj.offsetLeft+"  offsetTop= "+obj.offsetTop+"  hasLayout= "+obj.currentStyle.hasLayout);
        while (obj = obj.offsetParent) {
            //alert("objName= "+obj.id+"  offsetLeft= "+obj.offsetLeft+"  offsetTop= "+obj.offsetTop+"  hasLayout= "+obj.currentStyle.hasLayout);
            curLeft += obj.offsetLeft
            curTop += obj.offsetTop
        }
    }
    return [curLeft,curTop];
}
