function popwindow(url)
{
	var popupwindow=window.open(url,true,'height=400,width=500,scrollbars=yes,top=50,left=100,resizable=yes');
	if (window.focus) {popupwindow.focus()}
}

function displayLoadingDialog() {
	var dialog = new YAHOO.widget.SimpleDialog("loading_layer", { 
		fixedcenter:true,
		modal:true,
		close: false,
    	visible:false,
		draggable:false,
		width: "300px",
		height: "300px;"});
	dialog.setBody(Dictionary.LOADING);
	
	dialog.render(document.body);
	dialog.show();
}

function displayChangeLocationBox(visible) {
	var box = $("change-location-wrapper");
	if (visible == true && box.style.display == "none") {
		box.show();
		box.observe('click', displayChangeLocationBox, true);
	}
	else {
		box.hide();
	}
}

function displayPicEditBox(picId, visible, save) {
	var picDescrEl = $("descBox_" + picId);
	var picDescrEditEl = $("descEditBox_" + picId);

	if (save) {
		setCursor('wait');
		var desc = decodeURIComponent($F("pic_desc_" + picId));
		var postBody = 'ajax=1&update=U&pic_id=' + picId + '&description=' + desc;
		new Ajax.Request(
			'add_photos_post_data.php',
			{
				method: 'post',
				postBody: postBody,
				onSuccess: function(transport) {
					if (transport.responseText == 1) {
						$("descText_" + picId).innerHTML = $F("pic_desc_" + picId);
					}
					else {
						alert(Dictionary.UPDATE_FAILED);
					}
					setCursor();
				},
				onFailure: function() {
					setCursor();
					alert(Dictionary.SERVER_CONNECTION_ERROR);
				}
			}
		)
	}
	
	if (visible) {
		picDescrEl.hide();
		picDescrEditEl.show();
	}
	else {
		picDescrEl.show();
		picDescrEditEl.hide();
	}
}

/**
 * sets cursor's style to 'wait' if style 1, to 'auto' if 0 or null 
 * @param int style
 */
function setCursor(style) {
	document.body.style.cursor = style == null?'auto':style;
}


function contactFormSubmit() {
	var form = $("send_msg_form");
	if (form.name_field.value == '') {
		alert(Dictionary.ENTER_REQUIRED_FIELD);
		form.name_field.focus();
		return;
	}
	if (form.mail_field.value == '') {
		alert(Dictionary.ENTER_REQUIRED_FIELD);
		form.mail_field.focus();
		return;
	}
	if (form.mail_field.value.match(/^[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+\.)+?[a-zA-Z]{2,6}$/) == null) {
		alert(Dictionary.EMAIL_NOT_VALID);
		form.mail_field.focus();
		return;
	}
	if (form.content_field.value == '') {
		alert(Dictionary.ENTER_REQUIRED_FIELD);
		form.content_field.focus();
		return;
	}
	if (form.securityImageValue.value == '') {
		alert(Dictionary.ENTER_REQUIRED_FIELD);
		form.securityImageValue.focus();
		return;
	}
	form.request({
		evalJSON: true,
		onSuccess: function(o) {
			try {
				var error =o.responseJSON.error;
				if (!error) {
					throw new Error(Dictionary.SERVER_ERROR);
				}
			}
			catch(e) {
				alert(e.message);
				return;
			}
			alert(o.responseJSON.message);
			if(error == 1) {
			    form.reset();
				formClose(formHeight);
                resetSecImage();
			}
		}
	})
}

function resetSecImage() {
     $("security-image").src = "images/securityimage.php?t=" + Math.random();
}

