/* (c) 2008 doPodnájmu.cz, <info@dopodnajmu.cz> */

function resp() {

	dojo.toggleClass(dojo.byId('resp'),'hide');
	dojo.byId('respText').focus();
}

function sendReply(id)
{
	// id
	rId = id;

	// text
	rText = $('textarea[name=replyText]').val();
	if (rText.length == 0) {
		$('textarea[name=replyText]').focus();
		return false;
	}
	
	// email
	emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	rEmail = $('input[name=replyEmail]').val().toLowerCase();
	if (!emailRegExp.test(rEmail)) {
		$('input[name=replyEmail]').select();
		return false;
	}
	
	$.post(
		'/misc/processx.php',
		{reply: true, replyId: rId, replyText: rText, replyEmail: rEmail},
		function(data){
			if (data.val) {
				$('textarea[name=replyText]').val('');
				$('input[name=replyEmail]').attr('value','');
			}
			alert(data.msg);
		},
		'json'
	);
}

function sendRec(id)
{
	// id
	rId = id;

	// email
	emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	rEmail = $('input[name=recEmail]').val().toLowerCase();
	if (!emailRegExp.test(rEmail)) {
		$('input[name=recEmail]').select();
		return false;
	}
	
	$.post(
		'/misc/processx.php',
		{rec: true, recId: rId, recEmail: rEmail},
		function(data){
			if (data.val) {
				$('input[name=recEmail]').attr('value','');
			}
			alert(data.msg);
		},
		'json'
	);
}

function sendReport(id)
{
	// id
	rId = id;

	// text
	rText = $('textarea[name=reportText]').val();
	if (rText.length == 0) {
		$('textarea[name=reportText]').focus();
		return false;
	}
	
	$.post(
		'/misc/processx.php',
		{report: true, reportId: rId, reportText: rText},
		function(data){
			if (data.val) {
				$('textarea[name=reportText]').val('');
			}
			alert(data.msg);
		},
		'json'
	);
}

function sendEdit(id)
{
	// id
	eId = id;

	// heslo
	eHeslo = $('input[name=editHeslo]').val();
	if (eHeslo.length == 0) {
		$('input[name=editHeslo]').focus();
		return false;
	}

	$.post(
		'/misc/processx.php',
		{edit: true, editId: eId, editHeslo: eHeslo},
		function(data){
			if (data.val) {
				window.location.href = data.url;
			} else {
				alert(data.msg);			
				$('input[name=editHeslo]').select();
			}
		},
		'json'
	);
}

