/*
	tbg.js - Thickbox Gallery
	Version 2006-12-30
	Licensed under the MIT:
	http://www.opensource.org/licenses/mit-license.php
*/
var Req;
if(window.XMLHttpRequest){
	Req = new XMLHttpRequest();
}else if(window.ActiveXObject){
	try{
		Req = new ActiveXObject("MXSML2.XMLHTTP");
	}catch(e){
		try{
			Req = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
		}
	}
}
var Prev = "";
var Edit = false;
var Kc = "";
document.onkeydown = getKeyCode;

function saveComment(obj, target, album, filename, noajax){
	if(Kc==13){
		if(Req!=null){
			var id = obj.id.substr(2, obj.id.length-2);
			var value = obj.value;
			var url = target + "?a=" + album
			var post_string = "fn=" + filename + "&fd=" + value;
			if(Req.readyState!=0 && Req.readyState!=4){
				Req.abort();
			}
			Req.open("POST", url, true);
			Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			Req.send(post_string);
			Req.onreadystatechange = function(){
				if(Req.readyState == 4){
					if(Req.responseText==""){;
						Prev = "";
						restoreComment(obj);
						document.getElementById("anchor" + id).setAttribute("title", value);
						document.getElementById("thumbnail" + id).setAttribute("alt", value);
						document.getElementById("thumbnail" + id).setAttribute("title", value);
					}else if(Req.responseText=="0"){
						Prev = "";
						restoreComment(obj);
					}else{
						restoreComment(obj);
						window.alert(Req.responseText);
					}
				}
			}
		}else{
			window.alert(noajax);
		}
	}else if(Kc==27){
		restoreComment(obj);
	}
}

function restoreComment(obj){
	if(Prev!=""){
		obj.value = Prev;
		Prev = "";
	}
	Edit = false;
	obj.style.border = "none";
	obj.style.color = "#FFFFFF";
	obj.style.background = "#000000";
	obj.style.cursor = "pointer";
	obj.blur();
}
function activateInput(obj){
	if(!Edit){
		Prev = obj.value;
		Edit = true;
		obj.style.border = "inset 1px";
		obj.style.color = "#000000";
		obj.style.background = "#FFFFFF";
		obj.style.cursor = "text";
		obj.select();
	}
}

function getKeyCode(e){ 
	if(document.all){
		Kc = event.keyCode;
	}else if(document.getElementById){
		Kc = (e.keyCode!=0) ? e.keyCode : e.charCode;
	}else if(document.layers){
		Kc = e.which;
	}
}

function confirming(url, message){
	var close_ok = window.confirm(message);
	if(close_ok) location.href = url;
}

// this function was obsolete 2006-11-11
function changeColors(obj, fcolor, bcolor){
	obj.style.background = bcolor;
	obj.style.color = fcolor;
	obj.select();
}

