function DoAction(form, action, paramsString) {
    if (action) {
        var oper = null;
        for (var i = 0; i < document.forms[form].elements.length; i++)
            if (document.forms[form].elements[i].name == "action") {
                oper = document.forms[form].elements[i];
                break;
        }
            if (!oper) {
            oper = document.createElement("INPUT");
            oper.type = "hidden";
            oper.name = "action";
            document.forms[form].appendChild(oper);
        }
        oper.value = action;
    }
    if (paramsString != null && paramsString != "") {
        var params = new Array();
        var pairs = paramsString.split('&');
        for (var i = 0; i < pairs.length; i++) {
            nameVal = pairs[i].split('=');
            params[nameVal[0]] = nameVal[1];
        }
        for (p in params) {
            var param = null;
			for (var i = 0; i < document.forms[form].elements.length; i++)
				if (document.forms[form].elements[i].name == p) {
					param = document.forms[form].elements[i];
					break;
				}
				if (!param) {
					param = document.createElement("INPUT");
					param.type = "hidden";
					param.name = p;
					document.forms[form].appendChild(param);
			}
			param.value = params[p];
        }
    }
    document.forms[form].submit();
}

function ShowElement(id) {
    if (document.getElementById(id).style.display != 'none')
        document.getElementById(id).style.display = 'none';
    else document.getElementById(id).style.display = 'block';
}

function SelectImage(id, i) {
	var obj = document.getElementById(id);
	obj.src = "/images/loader.gif";
	var img = new Image();
	img.onload = function() {
		obj.style.display = "none";
		obj.src = img.src;
		$("#" + id).fadeIn(1000);
		
		if (curphoto > 0) document.getElementById("prev").style.visibility = "visible";
		else document.getElementById("prev").style.visibility = "hidden";
		if (curphoto < photos.length - 1) document.getElementById("next").style.visibility = "visible";
		else document.getElementById("next").style.visibility = "hidden";
	}
	img.src = photos[i];
	document.getElementById("pic_" + curphoto).style.opacity = "";
	curphoto = i;
	document.getElementById("pic_" + curphoto).style.opacity = 1;
	//setInterval(doScrollLeft, 6);
	//$(".scrollableArea").scrollLeft($("#pic_" + curphoto).offset().left);
}

function ValidateMessage() {
	var result = true;
	$("#mname,#memail,#mtext").each(function() {
		var obj = $(this);
		if (obj.val().replace(/(^\s+)|(\s+$)/g, "") == "" || (obj.attr("defaultText") && obj.val() == obj.attr("defaultText"))) result = false;
	});
	if (!result) document.getElementById("err_cont").style.visibility = "visible";
	return result;
}

var photos = null;
var photonotes = null;
var curphoto = 0;
function ShowPhoto(i) {
	var photo = $("#curphoto");
	//document.getElementById("curphoto").src = "/images/loader.gif";
	var img = new Image();
	img.onload = function() {
		photo.attr("src", img.src);
		if (document.getElementById("photonote")) $("#photonote").text(photonotes[curphoto]);
		var arrayPageSize = getPageSize();
		if (img.width > arrayPageSize[2] - 170) photo.width(arrayPageSize[2] - 170);
		else photo.width(img.width);
		if (img.height > arrayPageSize[3] - 90) photo.height(arrayPageSize[3] - 90);
		else photo.height(img.height);
		showMyLightbox("photogallery");
	}
	img.src = photos[i];
	showMyLightbox("photogallery");
	curphoto = i;
	if (curphoto == 0) document.getElementById("prevphoto").style.visibility = "hidden";
	else document.getElementById("prevphoto").style.visibility = "visible";
	if (curphoto == photos.length - 1) document.getElementById("nextphoto").style.visibility = "hidden";
	else document.getElementById("nextphoto").style.visibility = "visible";
}
function NextPhoto() {
	if (curphoto < photos.length - 1) ShowPhoto(curphoto+1);
}
function PrevPhoto() {
	if (curphoto > 0) ShowPhoto(curphoto - 1);
}
function ClosePhoto() {
	//$("#curphoto").attr("src", "/images/loader.gif");
	hideMyLightbox('photogallery');
}
function prev() {
	if (curphoto > 0) SelectImage('image', curphoto-1);
}
function next() {
	if (curphoto < photos.length - 1) SelectImage('image', curphoto+1);
}

