$(function(){
	var load_in_process = false;
	//Кнопки соцсетей

	$("#soc_f").bind("mouseenter",function(){
		$(this).toggleClass("soc_f1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("soc_f1");
	});
	
	$("#soc_v").bind("mouseenter",function(){
		$(this).toggleClass("soc_v1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("soc_v1");
	});
	
	$("#soc_t").bind("mouseenter",function(){
		$(this).toggleClass("soc_t1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("soc_t1");
	});
	
	$("#soc_l").bind("mouseenter",function(){
		$(this).toggleClass("soc_l1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("soc_l1");
	});
	
	//Баннер
	
	$("#loli").bind("mouseenter",function(){
		$(this).toggleClass("loli1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("loli1");
	});
	
	$("#fantasy").bind("mouseenter",function(){
		$(this).toggleClass("fantasy1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("fantasy1");
	});
	
	$("#bdsm").bind("mouseenter",function(){
		$(this).toggleClass("bdsm1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("bdsm1");
	});
	
	$("#neko").bind("mouseenter",function(){
		$(this).toggleClass("neko1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("neko1");
	});
	
	$("#guro").bind("mouseenter",function(){
		$(this).toggleClass("guro1");
	}).bind("mouseleave",function(){
		$(this).toggleClass("guro1");
	});

	//Рейтинг
	
	$('#doc_up').click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			$.ajax({
				url: 'inc/rating.php',
				type: 'POST',
				data: 't=1&p='+p,

				success: function(result) {			
                    $("#doc_r").text(result);
				}
			});	
			load_in_process = false;
		}
	});
	
	$('#doc_down').click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			$.ajax({
				url: 'inc/rating.php',
				type: 'POST',
				data: 't=2&p='+p,

				success: function(result) {			
                    $("#doc_r").text(result);
				}
			});	
			load_in_process = false;
		}
	});
	
	$('.arrow_up').click(function(){
		var c = this.getAttribute('id');
	
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'inc/crating.php',
				type: 'POST',
				data: 't=1&c='+c,

				success: function(result) {			
                    $("#ind_"+c).text(result);
				}
			});	
			
			load_in_process = false;
		}
	});
	
	$('.arrow_down').click(function(){
		var c = this.getAttribute('id');
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'inc/crating.php',
				type: 'POST',
				data: 't=2&c='+c,

				success: function(result) {			
                    $("#ind_"+c).text(result);
				}
			});	
			
			load_in_process = false;
		}
	});
	
	//подсказки
	$("#doc_up").bind("mouseenter",function(){
		return overlib('Мне нравится (^_^)');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#doc_down").bind("mouseenter",function(){
		return overlib('Мне не нравится (>_<)');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$(".varedit").bind("mouseenter",function(){
		return overlib('Кликните для редактирования информации.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#add_opt").bind("mouseenter",function(){
		return overlib('Добавить дополнительные личные сведения.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#add_cont").bind("mouseenter",function(){
		return overlib('Добавить контактные данные.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	//Диалоги
	$("#vbibor_ava").dialog({
		autoOpen: false,
		resizable: false,
		draggable: true,
		width: 430,
		height: 255
	});
	
	$("#add_param_d").dialog({
		autoOpen: false,
		resizable: false,
		draggable: true,
		width: 430,
		height: 255
	});
	
	$("#add_cont_d").dialog({
		autoOpen: false,
		resizable: false,
		draggable: true,
		width: 430,
		height: 255
	});
	
	$('#add_cont').click(function(){
		$("#add_cont_d").dialog("open");
	});
	
	$('#add_opt').click(function(){
		$("#add_param_d").dialog("open");
	});
	
	$('#param_w_close').click(function(){
		$("#add_param_d").dialog("open");
	});
	
	$('#ch_ava').click(function(){
		$("#vbibor_ava").dialog("open");
	});
	
	$("#ava_w_close").click(function(){
		$("#vbibor_ava").dialog("close");
	});
	
	$("#ri1").click(function(){
		$("#opts").removeAttr("disabled");
		$("#opt_text").attr("disabled","disabled");
	});
	
	$("#ri2").click(function(){
		$("#opt_text").removeAttr("disabled");
		$("#opts").attr("disabled","disabled");
	});
	
	//Опции
	var send_form_ready = '';
	
	$("#editp").keypress(function (e) {
		if (e.which == 13) {
			
		}
	});
	
	$(".opt_right_3").click(function(){
		var current_f = this.getAttribute('id');
		if(send_form_ready != current_f)
		{
			var c = this;
			var dataa = $(c).prev(".opt_right_2").text();
			var dataa2 = $(c).prev(".opt_right_4").text();
			var dataa3 = $(c).prev(".opt_right_5").text();
			
			$("#editp").parent().text($("#editp").val());
			$("#senddt").parent().html('<a href="javascript:void(0);"><img src="images/edit.png" alt="edit" border="0"/></a>');
			
			getComboBox(c,current_f,dataa2); 
			$(c).prev(".opt_right_2").html('<input id="editp" type="text" value="'+dataa+'" />'); 
			$(c).prev(".opt_right_5").html('<input id="editp" class="dpicker" type="text" value="'+dataa3+'" />');
			
			$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
			$(".dpicker").datepicker($.datepicker.regional["ru"]);
			$(c).html('<a href="javascript:void(0);" id="senddt"><img src="images/ok.png" alt="OK" border="0"/></a>');
			
			send_form_ready = current_f;
		}else{
			if(!load_in_process)
			{
				load_in_process = true;
				var dta = $('#editp').val();
				
				$.ajax({
					url: 'index.php',
					type: 'POST',
					data: 'module=options&action=datasave&did='+current_f+'&data='+dta,

					success: function(result) {	
						$("#editp").parent().text(dta);
						$("#senddt").parent().html('<a href="javascript:void(0);"><img src="images/edit.png" alt="edit" border="0"/></a>');
					}
				});	
				send_form_ready = '';
				load_in_process = false;
			}
		}
	});
	
	function getComboBox(c,did,data) {
		
		if(!load_in_process)
		{
			load_in_process = true;
			$(c).prev(".opt_right_4").html('<img src="images/lapa.gif" alt="wait" border="0"/>');
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=options&action=gcombo&did='+did+'&data='+data+'&pop=1',

				success: function(result) {	
					$(c).prev(".opt_right_4").html(result);
				}
			});	
			
			load_in_process = false;
		}
	}
	
	//пост
	$("#closenphelp").click(function(){
		$("#post_neko_mess").css("display","none");
	});
	
	$("#post_h1").bind("mouseenter",function(){
		return overlib('Заголовок новости должен соответствовать содержанию поста. Заголовки ваших постов не должны повторяться.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#post_h2").bind("mouseenter",function(){
		return overlib('Краткое описание поста, одно-два предложения.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#post_h3").bind("mouseenter",function(){
		return overlib('Здесь можно добавить ссылки на файлообменники для скачивания материала поста. Просто вставьте ссылку в текстовое поле и нажмите кнопку "Добавить".');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#post_h4").bind("mouseenter",function(){
		return overlib('Рисунок который будет отображаться на главной странице. Ширина рисунка не должна превышать 500 пикселей.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#post_h5").bind("mouseenter",function(){
		return overlib('Здесь вы можете выбрать рубрику в которую вы хотите поместить пост.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#post_h6").bind("mouseenter",function(){
		return overlib('Левая колонка - выбранные ключевики, правая - возможные ключевики. ');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_ind_prov").bind("mouseenter",function(){
		return overlib('Пост был проверен модератором.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_ind_no").bind("mouseenter",function(){
		return overlib('Пост недопущен к публикации.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_ind_w").bind("mouseenter",function(){
		return overlib('Пост возвращен на доработку.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_ind_op").bind("mouseenter",function(){
		return overlib('Пост опубликован.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_but_pp").bind("mouseenter",function(){
		return overlib('Перейти к опубликованному посту.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_but_send").bind("mouseenter",function(){
		return overlib('Отправить пост на проверку.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_but_red").bind("mouseenter",function(){
		return overlib('Редактировать пост.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#p_but_del").bind("mouseenter",function(){
		return overlib('Удалить пост.');
	}).bind("mouseleave",function(){
		nd();
	});
	
	$("#post_down_link_add").click(function(){
		if((trim($("#post_ssbilka1").val()) != '')&&(check_url($("#post_ssbilka1").val()))) {
			$("#post_ssbilka").append("<span>"+$("#post_ssbilka1").val()+"</span><br />");
			$("#alldownlinks").val($("#alldownlinks").val()+$("#post_ssbilka1").val()+"||");
			$("#post_ssbilka1").val('');
		}
	});
	
	var keystr = "";
	var keyval = "";
	var keystr2 = "";
	var keyval2 = "";
	$("#keysel2").change(function () {
		$("select option:selected").each(function () {
			keystr = $(this).text();
			keyval = $(this).val();
		});
	});
	
	$("#kwleft").click(function(){
		if((keystr != "")&&(keyval != "")) {
			$("#keysel1").append('<option value="'+keyval+'">'+keystr+'</option>');
			$("#keysel2 option:selected").remove();
			keystr = "";
			keyval = "";
		}
	});
	
	$("#keysel1").change(function () {
		$("select option:selected").each(function () {
			keystr2 = $(this).text();
			keyval2 = $(this).val();
		});
	});
	
	$("#kwright").click(function(){
		if((keystr2 != "")&&(keyval2 != "")) {
			$("#keysel2").append('<option value="'+keyval2+'">'+keystr2+'</option>');
			$("#keysel1 option:selected").remove();
			keystr2 = "";
			keyval2 = "";
		}
	});
	
	$("form").submit(function() {
		$("#keysel1 option").each(function () {
			$("#keywords_st").val($("#keywords_st").val()+$(this).text()+" ");
		});
		return true;
	});
	
	
	//Страница пользователя
	$("#nk_dialog").dialog({
		autoOpen: false,
		resizable: false,
		draggable: true,
		close: function(event, ui) { 
			$('#nk_dialog').html('<div style="text-align:center;"><img src="images/wait.gif" alt="Wait" border="0"/></div>'); 
		},
		width: 430,
		height: 255
	});
	
	$(".delform").click(function(){
		$("#nk_dialog").dialog({
			title: 'Удаление сообщения',
			width: 430,
			height: 210
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=nekouser&action=delform&pop=1&cid='+$(this).data().cid+'&uid='+$(this).data().uid,

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});
	
	$(".edtform").click(function(){
		$("#nk_dialog").dialog({
			title: 'Редактирование сообщения',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'parent='+$(this).data().cid+'&uid='+$(this).data().uid1+'&module=nekouser&action=edform&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});

	$(".addform").click(function(){
		$("#nk_dialog").dialog({
			title: 'Комментирование сообщения',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'parent='+$(this).data().cid+'&uid='+$(this).data().uid+'&module=nekouser&action=form&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});	
	
	
	$('.gb_arrow_up').click(function(){
		var c = $(this).data().cid;
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'inc/gbrating.php',
				type: 'POST',
				data: 't=1&c='+c,

				success: function(result) {			
                    $("#ind_"+c).text(result);
				}
			});	
			
			load_in_process = false;
		}
	});
	
	$('.gb_arrow_down').click(function(){
		var c = $(this).data().cid;
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'inc/gbrating.php',
				type: 'POST',
				data: 't=2&c='+c,

				success: function(result) {			
                    $("#ind_"+c).text(result);
				}
			});	
			
			load_in_process = false;
		}
	});
	
	$("#bsml").click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=nekouser&action=getsmiles&ta=msgfor&pop=1',

				success: function(result) {	
					return overlib(result,FIXX,elemX(elemObj('bsml')),FIXY,elemY(elemObj('bsml'))+20,WIDTH,410,STICKY);
				}
			});	
			
			load_in_process = false;
		}
		
	}).bind("mouseleave",function(){
		nd();
	});
	
	$(".but_default").click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			$(this).html('<img src="images/lapa.gif" alt="wait" style="padding: 2px 0 2px 0;" border="0"/>');
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=nekouser&action=nextmessage&pop=1&uid='+$(this).data().uid+'&start='+($(this).data().start),

				success: function(result) {	
					$("#nextmesspane").html($("#nextmesspane").html()+result);
					$(".but_default").html('показать предыдущие записи');
					load_in_process = false;
				}
			});	
			
			var mess = $(this).data().start+15;
			if(mess < $(this).data().mcount) {
				$(this).data().start = mess;
			}else{
				$(".clear").html(" ");
			}
			
			
		}
	});	
	
	//модуль комментариев
	$("#comadd").click(function(){
		$("#nk_dialog").dialog({
			title: 'Добавление комментария',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'docid='+$(this).data().docid+'&page='+$(this).data().page+'&cp_theme='+$(this).data().cp_theme+'&module=comment&action=form&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});	
	
	$(".comadd1").click(function(){
		$("#nk_dialog").dialog({
			title: 'Добавление комментария',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'docid='+$(this).data().docid+'&page='+$(this).data().page+'&cp_theme='+$(this).data().cp_theme+'&parent='+$(this).data().parent+'&module=comment&action=form&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});	
	
	$(".comed1").click(function(){
		$("#nk_dialog").dialog({
			title: 'Редактирование комментария',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'docid='+$(this).data().docid+'&page='+$(this).data().page+'&cp_theme='+$(this).data().cp_theme+'&parent='+$(this).data().parent+'&Id='+$(this).data().parent+'&module=comment&action=edit&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});	
	
	//гостевая в кабинете пользователя
	$(".addform1").click(function(){
		$("#nk_dialog").dialog({
			title: 'Комментирование сообщения',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'parent='+$(this).data().cid+'&module=gbadmin&action=form&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});	
	
	$(".edtform1").click(function(){
		$("#nk_dialog").dialog({
			title: 'Редактирование сообщения',
			width: 500,
			height: 630
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'parent='+$(this).data().cid+'&module=gbadmin&action=edform&pop=1',

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});
	
	$(".delform1").click(function(){
		$("#nk_dialog").dialog({
			title: 'Удаление сообщения',
			width: 430,
			height: 210
		});
		
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=gbadmin&action=delform&pop=1&cid='+$(this).data().cid,

				success: function(result) {	
					$("#nk_dialog").html(result);
				}
			});	
			
			load_in_process = false;
		}
		
		$("#nk_dialog").dialog("open");
	});
	
	$(".but_default1").click(function(){
	
		if(!load_in_process)
		{
			load_in_process = true;
			$(this).html('<img src="images/lapa.gif" alt="wait" border="0"/>');
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=gbadmin&action=nextmessage&pop=1&start='+$(this).data().start,

				success: function(result) {	
					$("#nextmesspane").html($("#nextmesspane").html()+result);
					$(".but_default1").html('показать предыдущие записи');
					load_in_process = false;
				}
			});	
			
			var mess = $(this).data().start+15;
			if(mess < $(this).data().mcount) {
				$(this).data().start = mess;
			}else{
				$(".clear").html(" ");
			}
		}	

	});

	//оповещения
	$(".opovesh_group_chekbox1").click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=notifications&action=setnotif&pop=1&nid='+$(this).data().nid,

				success: function(result) {	
					
				}
			});	
			
			load_in_process = false;
		}
		
		$(this).toggleClass("opovesh_group_chekbox");
		$(this).toggleClass("opovesh_group_chekbox1");
	});
	
	$(".opovesh_group_chekbox").click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=notifications&action=setnotif&pop=1&nid='+$(this).data().nid,

				success: function(result) {	
					
				}
			});	
			
			load_in_process = false;
		}
		
		$(this).toggleClass("opovesh_group_chekbox");
		$(this).toggleClass("opovesh_group_chekbox1");
	});	
	
	$(".opovesh_group_chekbox2").click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=notifications&action=setmethod&pop=1&mid='+$(this).data().mid,

				success: function(result) {	
					
				}
			});	
			
			load_in_process = false;
		}
		
		$(this).toggleClass("opovesh_group_chekbox2");
		$(this).toggleClass("opovesh_group_chekbox3");
	});
	
	$(".opovesh_group_chekbox3").click(function(){
		if(!load_in_process)
		{
			load_in_process = true;
			
			$.ajax({
				url: 'index.php',
				type: 'POST',
				data: 'module=notifications&action=setmethod&pop=1&mid='+$(this).data().mid,

				success: function(result) {	
					
				}
			});	
			
			load_in_process = false;
		}
		
		$(this).toggleClass("opovesh_group_chekbox2");
		$(this).toggleClass("opovesh_group_chekbox3");
	});	
});



function InsertSmile(code,field_id,field_name)
{
	var field_name = 'gb_message';
	if (document.getElementById(field_id).createTextRange)
	{
		document.getElementById(field_id).focus();
		document.selection.createRange().duplicate().text = code;
	}
	else if (document.getElementById && !document.all) // Mozilla
	{
    	var tarea = document.getElementById(field_id);
    	var selEnd = tarea.selectionEnd;
    	var txtLen = tarea.value.length;
    	var txtbefore = tarea.value.substring(0,selEnd);
    	var txtafter =  tarea.value.substring(selEnd, txtLen);
    	tarea.value = txtbefore + code + txtafter;
	} else {
		document.entryform.field_name.value += code;
   }
} 



function submit_check1() {
	return window.confirm('Вы действительно хотите удалить эту опцию?')
}

function submit_check2() {
	return window.confirm('Вы действительно хотите удалить этот контакт?')
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

function check_url(url) {
	if(url=='') {
		return false;
	}
	if (/^(http\:\/\/[^\/]+)\/\S+[\w\-\/]+$/.test(url)) {
		return true;
	} 
	return false;
}


//common.js
function popup(datei,name,breite,hoehe,noresize)
{ 
	var posX=(screen.availWidth-breite)/2;
	var posY=(screen.availHeight-hoehe)/2;
	var resizable = (noresize==1) ? 0 : 1;
	window.open(datei,name,"resizable="+resizable+",scrollbars=1,width=" + breite + ",height=" + hoehe + "screenX=" + posX + ",screenY=" + posY + ",left=" + posX + ",top=" + posY + "");
}


function galpop(datei,name,breite,hoehe,noresize)
{ 
	var posX=(screen.availWidth-breite)/2;
	var posY=(screen.availHeight-hoehe)/2;
	var resizable = (noresize==1) ? 0 : 1;
	var scrollbar = (document.all) ? 0 : 1;
	window.open(datei,name,"resizable="+resizable+",scrollbars="+scrollbar+",width=" + breite + ",height=" + hoehe + "screenX=" + posX + ",screenY=" + posY + ",left=" + posX + ",top=" + posY + "");
}


function textCounter(field, countfield, maxlimit)
{ 
	if (field.value.length > maxlimit)
	{ 
		field.value = field.value.substring(0, maxlimit);
	} else { 
		countfield.value = maxlimit - field.value.length;
	}
}

function elemX (element) {
	var x = 0;
	while (element) {
		x += element.offsetLeft;
		element = element.offsetParent;
	}
	return x;
}

function elemY (element) {
	var y = 0;
	while (element) {
		y += element.offsetTop;
		element = element.offsetParent;
	}
	return y;
}

function getWidth (element) {
	return element.offsetWidth;
}

function getHeight (element) {
	return element.offsetHeight;
}

function elemObj(elementId) {
	if (document.all)
		return document.all[elementId];
	else if (document.getElementById)
		return document.getElementById(elementId);
	else
		return null;
}
