// author: Renat K. (rendrtech@gmail.com)
// July 2009

function fadeOutSoon (elem)
{
	setTimeout('fadeIdOut (\''+elem+'\')', 5000);
}

function slideOutSoon (elem)
{
	setTimeout('slideIdOut (\''+elem+'\')', 5000);
}


function fadeIdOut (id)
{
	$("#"+id).fadeOut();
}

function slideIdOut (id)
{
	$("#"+id).slideUp();
}


function setPageid(form, val)
{
	form.value = val;
}


function checkAll ()
{
	$('[type=checkbox]').each(function() {
		!$(this).attr('checked') ? $(this).attr('checked', true) : $(this).attr('checked', false);
	});
}

function showResp (divId,info)
{
	document.getElementById(divId).innerHTML = info;
}


function addFormElem (f, name, val, elemType, type)
{
	var el = document.createElement(elemType);
			el.type = type;
			el.name = name;
			el.value = val;
			f.appendChild(el);
}


function hiddenData (f, name, val)
{
	if (f.name.value == 'undefined' || !f.name.value || !f.name.value == '')
		addFormElem (f, name, val, 'input', 'hidden');
	else
		f.name.value = val;
}


function showHide (id, fadet)
{
	if (document.getElementById(id).style.display == 'none')
	{
		fadeIn(id);

		if (fadet)
			fadeTo(id, 8);
	}
	else
		fadeOut(id);
}


function fadeIn (id)
{
	$('#'+id).fadeIn();
}


function fadeTo (id, to)
{
	$('#'+id).fadeTo('fast', '.'+to);
}


function fadeOut (id)
{
	$('#'+id).fadeOut();
}


function getAllById (id)
{
	return $('[id='+id+']');
}


function delAllId (iid, oid, from)
{
	var  url = baseurl+'ajax/ajax/delItem';
	
	if (confirm(labels['confirm_del_selected']))
	{
		$('[id='+iid+']').fadeOut('normal', function(){
			$(this).empty();
			$(this).remove();
		});

		$.post(url, { id: oid, db: from }, function (data){
			//success: alert(data);
		});
	}
}


function setIdContent (id, data)
{
	$("#"+id).html(data);
}


function addIdContent (id, data)
{
	$("#"+id).append(data);
}


function url2Id (url, id, data)
{
	if (!id)
		var id = '#ajaxResp';
	if (!data)
		var data = '';

	$(id).slideUp('fast', function(){
		$(this).html('<span style="height:30px;vertical-align:bottom;"><img src="'+labels['baseurl']+'images/load.gif" border="0" hspace="3">'+labels['loading']+'</span>').slideDown('fast', function(){
			$.post(url, data, function(resp){
				$(id).html(resp);
			});
		});
	});
}


function is_numeric(value)
{
	return !isNaN(value);
}


function postData (url, buttonObj, formId, loadId, resultId, dataType, withResult)
{
	if (loadId != null)
		setIdContent (loadId, '<span class="msg">'+labels['processing']+'</span>');

	if (buttonObj)
		buttonObj.disabled = true;
	
	var str = $('#'+formId).serialize();
	$.post (labels['baseurl']+url, str, function (data) {
		
		if (buttonObj)
			buttonObj.disabled = false;

		if (resultId != null)
		{
			if (withResult != null)
				addIdContent (resultId, data);
			else
				setIdContent (resultId, data);
		}
		if (loadId != null)
			setIdContent (loadId, '');

		if (resultId == null)
			return data;

	}, dataType);
}

function toggleMe ()
{
	$('#mail_login').slideToggle('fast', function(){
		if ($('#mail_link').hasClass('mail_down'))
		{
			$('#mail_link').removeClass('mail_down');
			$('#mail_link').addClass('mail_up');
		}
		else 
		{
			$('#mail_link').addClass('mail_down');
			$('#mail_link').removeClass('mail_up');
		}
	});
}

function MsgBox (textstring) {
  document.mail.login_username.value+=textstring
}
function Reset() {
	document.mail.domain.selectedIndex=0
	document.mail.login_username.value=''
}
shown=''
function OpenFile(url) {
if( shown=='' || shown.closed) {
	shown=window.open(url,'OpenFile','scrollbars=yes,status=no, high,width=295,height=320,left=0,top=0,resizable=no');
}
else{
	shown.close();
	shown=window.open(url,'OpenFile','scrollbars=yes,status=no, high,width=295,height=320,left=0,top=0,resizable=no');
}
}