
function adddep(){
    var name = $("#newdep").val();

    $.post("dep.php", {newname: name}, function(data){
        self.location.reload();
    });

}

function addbrand(){
    var name = $("#newbrand").val();

    $.post("brander.php", {newname: name}, function(data){
        self.location.reload();
    });

}


function save(id){
    var name = $("#d"+id).val();
    $.post("dep.php", {name: name, id: id}, function(data){
        self.location.reload();
    });

}

function del(id){
	if (confirm('Are you sure?')){
		$.post("dep.php", { del: id}, function(data){
			self.location.reload();
		});
	}

}

function savebrand(id){
    var name = $("#s"+id).val();
    $.post("brander.php", {name: name, id: id}, function(data){
        self.location.reload();
    });

}

function delbrand(id){
	if (confirm('Are you sure?')){
		$.post("brander.php", { del: id}, function(data){
			self.location.reload();
		});
	}

}

function addsub(id){
    var name = $("#newdep").val();
    $.post("dep.php", {newname: name, did: id, sub:1}, function(data){
        self.location.reload();
    });

}

function savesub(id){
    var name = $("#s"+id).val();
    $.post("dep.php", {name: name, id: id, sub:1}, function(data){
        self.location.reload();
    });

}

function delsub(id){
	if (confirm('Are you sure?')){
		$.post("dep.php", { del: id, sub:1}, function(data){
			self.location.reload();
		});
	}

}

function loaddepts(id){
    $("#deptloadarea").load("getdeps.php?id="+id);
}

function checkbrands(id, val){
	$.post("brandpop.php", {id: id, val: val}, function(data){
		$("#popdown").html(data);											
	});
	$("#popdown").slideDown();
}

function selectbrand(id, sid){
	$.post("pbrand.php", {id: id, sid:sid}, function(data){
		$("#curbrands").html(data);
		$("#popdown").slideUp();
	});
}

function removebrand(id, sid){
	if (confirm('Are you sure?')){
		$.post("pbrand.php", {del: id, sid:sid}, function(data){
			$("#curbrands").html(data);
		});
	}
}

function checksizes(id, val){
	$.post("sizepop.php", {id: id, val: val}, function(data){
		$("#popdown").html(data);											
	});
	$("#popdown").slideDown();
}

function selectsize(id, sid){
	$.post("psize.php", {id: id, sid:sid}, function(data){
		$("#cursizes").html(data);
		$("#popdown").slideUp();
	});
}

function removesize(id, sid){
	if (confirm('Are you sure?')){
		$.post("psize.php", {del: id, sid:sid}, function(data){
			$("#cursizes").html(data);
		});
	}
}

function savesize(id){
    var name = $("#s"+id).val();
    $.post("sizer.php", {name: name, id: id}, function(data){
        self.location.reload();
    });
}

function delsize(id){
	if (confirm('Are you sure?')){
		$.post("sizer.php", { del: id}, function(data){
			self.location.reload();
		});
	}
}

function addsize(){
    var name = $("#newsize").val();

    $.post("sizer.php", {newname: name}, function(data){
        self.location.reload();
    });
}

function checkcolours(id, val){
	$.post("colourpop.php", {id: id, val: val}, function(data){
		$("#popdown").html(data);											
	});
	$("#popdown").slideDown();
}

function selectcolour(id, sid){
	$.post("pcolour.php", {id: id, sid:sid}, function(data){
		$("#curcolours").html(data);
		$("#popdown").slideUp();
	});
}

function removecolour(id, sid){
	if (confirm('Are you sure?')){
		$.post("pcolour.php", {del: id, sid:sid}, function(data){
			$("#cursizes").html(data);
		});
	}
}

function savecolour(id){
    var name = $("#s"+id).val();
    $.post("colourer.php", {name: name, id: id}, function(data){
        self.location.reload();
    });
}

function delcolour(id){
	if (confirm('Are you sure?')){
		$.post("colourer.php", { del: id}, function(data){
			self.location.reload();
		});
	}
}

function addcolour(){
    var name = $("#newcolour").val();
	var hex = $("#newhex").val();

    $.post("colourer.php", {newname: name, hex: hex}, function(data){
        self.location.reload();
    });
}

function checkdeps(val){
	$.post("fronter.php", {val: val}, function(data){
		$("#popdown").html(data);											
	});
	$("#popdown").slideDown();
}

function addtofront(id){
	self.location = 'fpage.php?a='+id;	
}

function specialme(id){
	var flag = $("#special"+id).val();
	$.post("special.php", {id: id, flag: flag}, function(data){
		if (flag == 0){
			$("#special"+id).val("1");
			$("#special"+id).attr("checked", true);
					
		}
		else {
			$("#special"+id).val("0");
			$("#special"+id).attr("checked", false);	
		}
	});
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width=500px,height=600px,left = 100,top = 100');");
}
function getprods(val, type, num, wotm, func){
	$("#resultbox").load("smlsrch.php?val="+val+"&type="+type+"&num="+num + "&wotm="+wotm+"&func="+func);
}


function changestat(id, stat){
	$.post("changestat.php", {id: id, stat: stat}, function(){
		self.location.reload();															
	});
	
}

function removeimage(id, i){
	if (confirm('Are you sure?')){
		$.post("removeimage.php", {id: id, i: i}, function(){
			self.location = "changeimage.php?id="+id;														
		});
	}
}	

function loadplantbox(spec){
	$("#addbox").html("");
	$("#addbox").hide();
	$.get("linkdb.php?type=plant&spec="+spec, function(data){	
		$("#addbox").html(data);
		$("#addbox").slideDown();							  
	});	
}
function loadrecipebox(){
	$("#addbox").html("");
	$("#addbox").hide();
	$.get("linkdb.php?type=recipe", function(data){	
		$("#addbox").html(data);
		$("#addbox").slideDown();							  
	});	
}

function updateimages(id, type){
	$("#images").load("images.php?id="+id+"&type="+type);
}

function removeplantimage(id, num){
	$.post("removeplantimage.php", {id: id, num:num}, function(data){
		updateimages(id, 'plantdb');														  
	});
}

function removeproductimage(id, num){
	$.post("removeproductimage.php", {id: id, num:num}, function(data){
		updateimages(id, 'products');														  
	});
}

function adddblink(type, id, spec){
	if (spec == ""){
		$("#"+type+"db").load("linker.php?type="+type+"&id="+id+"&spec="+spec);	
	}
	else {
		q = $("#q"+id).val();
		$("#"+type+"db").load("linker.php?type="+type+"&id="+id+"&spec="+spec+"&q="+q);		
	}
	$("#addbox").hide();
}

function removeme(type, num, spec){
	$("#"+type+"db").load("linker.php?type="+type+"&num="+num+"&spec="+spec);		
}	

function addpack(id, num, month){
	$("#prodlist").html("<center><img src='../images/ajax-loader.gif' /></center>");
	
	$.post("addprodtopack.php", {id: id}, function(data){
		$("#prodlist").load("curpacks.php");										 
	});
	tb_remove();
}

function removepack(id){
	$("#prodlist").html("<center><img src='../images/ajax-loader.gif' /></center>");
	$.post("removepack.php", {id: id}, function(data){
		$("#prodlist").load("curpacks.php");										 
	});
}

function pickaccessories(id){
	$.fn.colorbox({href: '#accessbox', inline:true, opacity: .4});	
}

function checkacc(id, val){
	$.post("accpop.php", {id: id, val: val}, function(data){
		$("#popdown").html(data);											
	});
	$("#popdown").slideDown();
}

function selectacc(id, sid){
	$.post("pacc.php", {id: id, sid:sid}, function(data){
		$("#curacc").html(data);
		$("#popdown").slideUp();
	});
}
function removeacc(id, sid){
	if (confirm('Are you sure you want to remove?')){
		$.post("pacc.php", {del: id, sid:sid}, function(data){
			$("#curacc").html(data);
		});
	}
}

