// JavaScript Document

function createURL(field){
	var url = field.value.toLowerCase();
	url = url.replace(" ","-");
	url = url.replace(".","");
	if($("#url_var").val() == ""){
		$("#url_var").val(url);
	}
}

function updateURL(){
	var url_var = $("#subof").children(":selected").attr("class");
	if(url_var){
		$("#main_cat").html(url_var + "/");
	} else {
		$("#main_cat").html('');
	}
}

function clearTmp(modify){
	if(confirm("Are you sure you want to delete these images?")){
		$.ajax({
			type: "POST",
		//	async: false,
			url: "/js/kam_ajax.php",
			data: "action=clearTmp"
		});
		if(modify){
			$("#tmp_images").html('');
			if($("#the_photos").html() == ""){
				$("#the_photos").html("No photos uploaded yet.");
			}
			$("#up_msg").hide();
			$("#clear_images").hide();
		} else {
			$("#images").val("");
			$("#the_photos").html("No photos uploaded yet.");
			$("#up_msg").hide();
			$("#clear_images").hide();
		}
	}
	return false;
}

function deletePhoto(id,file,tmp){
	if(confirm("Are you sure you want to delete this photo?")){
		var divID = file.replace(".jpg","");
		$("#manage_image"+divID).remove();
		$.ajax({
			type: "POST",
		//	async: false,
			url: "/js/kam_ajax.php",
			data: "action=deleteImage&id="+id+"&file="+file+"&tmp="+((tmp) ? "1" : "0")
		});
		var newVal = $("#images").val();
		newVal = newVal.replace(file+";","");
		newVal = newVal.replace(";"+file,"");
		newVal = newVal.replace(file,"");
		$("#images").val(newVal);
		if(newVal == ""){
			$("#the_photos").html("No photos uploaded yet.");
		}
	}
	return false;
}

$(document).ready(function(){
	$("#upload_image").bind("submit", function(u){
			if($("#new_photo").val() == ""){
				alert("Select an Image");
				return false;
			} else {
				$("#photo_wait").show();
				$("#upload_btn").hide();
			}
			return true;
		});
	
	setupZoom();
});