
function js_checkemail( email, strict)
{
 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function js_protect()
{
   document.write("<in"+"p"+"ut typ"+"e=\"h"+"idden"+"\" n"+"ame"+"=\"pro"+"tect\" val"+"ue=\"av" + "toza" + "p\">");
}

/* Выпадающее меню http://www.linedmk.com/page22.html */
function overPunkt(obj_listPunkt)
{ 
/* делаем выпадающее меню видимым */
	obj_listPunkt.childNodes[1].style.display="block"; 
/* ставим выпадающее меню ниже пункта меню */
	obj_listPunkt.childNodes[1].style.top=obj_listPunkt.offsetHeight;
/*дальше идет оформление пункта меню */ 
// obj_listPunkt.style.background="#65402A";
//obj_listPunkt.style.padding=0;
//obj_listPunkt.childNodes[0].style.border="solid 1px #000";
//obj_listPunkt.childNodes[0].style.borderBottom="none";
/* запоминаем цвет текста пункта меню, чтоб потом его можно было восстановить */ 
//color_text=obj_listPunkt.style.color;
//obj_listPunkt.style.color="#fff";
}

function outPunkt(obj_listPunkt)
{ 
/* делаем выпадающее меню невидимым */
obj_listPunkt.childNodes[1].style.display="none";
/* дальше восстанавливаем первоначальный внешний вид пункта меню */
//obj_listPunkt.style.background="transparent";
//obj_listPunkt.style.padding=1;
//obj_listPunkt.style.paddingBottom=0;
//obj_listPunkt.childNodes[0].style.border="none";
//obj_listPunkt.style.color=color_text;
}

function hidequickmsg( id )
{
   $('#d'+id ).html('');
   return false;
}

function checkmsg()
{
	if ( document.msg.message.value=="" )
  {	window.alert("Укажите текст!"); return false; }
   return true;
}
// Убирает пробельные символы слева
function ltrim(vin) {
	var ptrn = /\s*((\S+\s*)*)/;
	return vin.replace(ptrn, "$1");
}
// Убирает пробельные символы справа
function rtrim(vin) {
	var ptrn = /((\s*\S+)*)\s*/;
	return vin.replace(ptrn, "$1");
}
// Убирает пробельные символы с обоих концов
function trim(vin) {
	return ltrim(rtrim(vin));
}
function quickmsg( id, uid )
{
	var txt;
	var foto, afoto;
	var topic = '';
	var vin = $('#d'+id ).html();
	if (  vin != '' )
		return hidequickmsg( id );

	if ( uid )
	{
		topic = "<span class='grey' style='font-weight: bold;margin-top: 10px;'>Тема&nbsp;&nbsp;</span><input style='margin-top: 10px;width: 300px;' type='text' name='title' value='' /><br />";
	   txt = 'Текст личного сообщения';
	   foto = '';
	   afoto = '';
	}
	else
	{
	   txt = 'Текст ответа';
	   foto = "<div id='f"+id+"' style='display:none;'>Фото: <input type='file' name='images[]' style='width: 350px;' ><br>Фото: <input type='file' name='images[]' style='width: 350px;'><br>Фото: <input type='file' name='images[]' style='width: 350px;'></div>";
	   afoto = "&nbsp;<a style='float:right;' href='#' onclick='return js_foto(" +id+ ");'>Добавить фото</a>";
	}
   $('#d'+id ).html("<form enctype='multipart/form-data' action='/quickpost.html' method='post' name='msg'>" + topic + "<span class='grey' style='font-weight: bold;margin-top: 10px;'>"+ txt +"</span><br /><textarea name='message' rows='3' style='width: 400px;'></textarea><br>"+
	foto+"<input type='hidden' name='idowner' value='" + id + "' /><input type='hidden' name='uid' value='" + uid + "' /><input type='submit' value='Отправить' onclick='return checkmsg();'/>&nbsp;&nbsp;" +
	"<input type='submit' value='Отменить' onclick='return hidequickmsg("+id+");' />"+ afoto + "</form>");
   return false;
}

function js_foto( id)
{
	$("#f"+id).css( 'display', 'block');
	return false;
}

function quickunregmsg( id, uid )
{
	var txt;
	var topic = '';
	if ( $('#d'+id ).html() != '' )
		return hidequickmsg( id );
	
   $('#d'+id ).html("<p class='grey'>Вы должны <a href='/register.html'>зарегистрироваться</a>, если хотите отправить личное сообщение.</p>");
   return false;
}

/*
function js_ajax( script, param )
{
   $("#data").load( '/cabinet/php/ajax_' + script + '.php?' + param );
}


function js_addfoto()
{
   $("#foto").after('<tr><td align="right">Заголовок:</td><td colspan=3>\n\
<input type="text" value="" style="width: 300px;" name="titlefoto[]" /></td></tr>\n\
<tr ><td style="border-bottom: 1px solid #999;" align="right">Фотография:</td><td style="border-bottom: 1px solid #999;" colspan=3><input name="MAX_FILE_SIZE" value="6000000" type="hidden">\n\
<input name="ifoto[]" value="0" type="hidden">\n\
<input size="40" name="foto[]" type="file"></td></tr>');
   return false;
}

function js_delfoto( id, iddb )
{
   if ( confirm( 'Хотите удалить фотографию?' ))
   {
      $.get("/cabinet/php/ajax_delfoto.php", { id: id, iddb: iddb },
         function(data){   });
      $("#f" + id ).remove();

   }
   return false;
}

function js_changefoto( id, iddb )
{
   var title;
   title = $( "#ft"+id ).html();
   $("#editinput").attr('value', title );
   $("#editid").attr('value', id );
   $("#editdb").attr('value', iddb );
   return true;
}

function js_savefoto( iddb )
{
   var id, iddb, title;

   id = $("#editid").attr('value');
   iddb = $("#editdb").attr('value');
   title = $("#editinput").attr('value' );
   $.post("/cabinet/php/ajax_changefoto.php", { id: id, iddb: iddb, title: title },
      function(data){
         $( "#ft"+id ).html( title );
      });
   $.fancybox.close();
}
*/

function order( db, ud, id )
{
	$.get("/modules/ajax_updown.php", { id: id, ud: ud, db: db },
      function(data){
         $( "#o"+id ).html( data );
      });
   return false;
}

function abuse( )
{
	var txt = $("#abusetext").val();
	var id = $("#abuseid").attr( 'value' );
	var part = $("#abusepart").attr( 'value' );
	$.post("/modules/ajax_abuse.php", {txt: txt, id:id, part:part },
		function( data ) {
			if ( data == '1' )
				alert("Сообщение успешно отправлено!");
			else
				alert("Произошла ошибка!");
		}
	);
	$.fancybox.close();
	return false;
}

function js_showhide( id )
{
	if ( $("#m"+id).css('display') == 'none' )
		$("#m"+id).css('display', 'block');
	else
		$("#m"+id).css('display', 'none');
	return false;
}

function exclaimid( id, part )
{
	$("#abusetext").val( '' );
	$("#abuseid").attr( 'value', id );
	$("#abusepart").attr( 'value', part );
	return false;
}
