
function SelectAll(id)
{
	var col = document.getElementById(id);
	for (var i=0;i<col.length;i++)
	col[i].selected= true;
	return true;
}
function UnSelectAll(id)
{
	var col = document.getElementById(id);
	for (var i=0;i<col.length;i++)
	col[i].selected= false;
	return true;
}
 

function switchTab(id,number,firstAlwaysOnTop)
{
	for(var i=0 ; i < number; i++)
	{
		if (firstAlwaysOnTop == 1 && i>0)
			$('tab_'+i).hide();
		else if (firstAlwaysOnTop == 0)
			$('tab_'+i).hide();
		
		$('button_tab_'+i).className = 'tab_inactive';	
	}
	
	$(id.id).className = 'tab_active';
	if (firstAlwaysOnTop == 1 && id.id.substr(7,5) != 'tab_0')
		$(id.id.substr(7,5)).show();
	else if (firstAlwaysOnTop == 0)
		$(id.id.substr(7,5)).show();
	
} 
function CreateSortable(action,contain,statusID)
{ 
 Sortable.create(contain,
     {dropOnEmpty:true,tag:'div',containment:[contain],constraint:'vertical', ghosting: false,
	 onUpdate:function()
	 {
		
		 new Ajax.Request(action,
		 {
			method:'post',
			parameters: Sortable.serialize(contain,{tag:"div"}),
			onComplete: function(transport)
			{
				var response = transport.responseText || "no response text";
				var status = $(statusID);
				//status.update(response);
				//status.show();
				status.hide();
			},
			onLoading: function()
			{
				var status = $(statusID);
				status.show();
				
			} ,
		    onFailure: function()
			{
				alert('...') 
			}
		}); 
  }
	});
}

function HandleRequestPost(action,inputId,outPutDiv,statusID,extraParam)
{
	new Ajax.Request(action , {
	method: 'post',
	parameters: 'parameter=' + $(inputId).value + '&extraParam=' + extraParam,
	onComplete: function(transport)
	{
		var response = transport.responseText
		var notice = $(outPutDiv);
		if ($(statusID))
		{
			var status = $(statusID);
			status.hide();
		}
		notice.update(response);
		notice.show();
		
	} ,
	onLoading: function()
	{
		if ($(statusID))
		{
			var status = $(statusID);
			status.show();
		}
	} ,
	onFailure: function()
	{
		alert('...');
	}
});
}

function HandleRequestGet(action,outPutDiv,statusID,append)
{
	append = typeof(append) != 'undefined' ? append : FALSE;
	new Ajax.Request(action , {
	method: 'get',
	onComplete: function(transport)
	{
		var response = transport.responseText
		var notice = $(outPutDiv);
		var status = $(statusID);
		status.hide();
		if (append === true)
			notice.innerHTML += response;
		else
			notice.update(response);
		notice.show();
		
	} ,
	onLoading: function()
	{
		var status = $(statusID);
		$(outPutDiv).hide();
		status.show();
		
	} ,
	onFailure: function()
	{
		alert('...');
	}
});
}

function showOrHideElement(id)
{
	
	var element;
	element = $(id);
	
	if (!element)
		return false;
	
	if (element.style.display == 'none')
		Effect.BlindDown(id,{duration : 0.3});
	else
		Effect.BlindUp(id,{duration : 0.3});
	
}
//Nowa strona do TinyMCE
function addPageBreak(id)
{ 
	var newData = '{e4PageBreak}'; 
	tinyMCE.execInstanceCommand(id,'mceInsertContent', false, newData); 
}

//email do TinyMCE
function mcePutEmail(id)
{ 
	var mail1 = window.prompt("Podaj pierwszy czlon adresu:");
	if (mail1!=null && mail1!="")
	{
		var mail2 = window.prompt("Podaj drugi czlon adresu:");
		if (mail2!=null && mail2!="")
		{
			var mail3 = window.prompt("Podaj nazwe linku:","e-mail");
			if (mail3==null || mail3=="")
				mail3 = "e-mail"
			var data = '<script type="text/javascript">';
			data += 'var text = \'<a href="\' + \'mail\' + \'to:\' + mail1 + \'@\' + mail2">\'+ mail3+\'</a>;';
			data += 'document.write(text);';
			data += '</script>';	
			tinyMCE.execInstanceCommand(id,'mceInsertContent', false, data); 	
			return;
		}
	}

	return false;
	
}

function HandleRequestForm(action,formId,outPutDiv,statusID)
{
	new Ajax.Request(action , {
	method: 'post',
	parameters: $(formId).serialize(true),
	onComplete: function(transport)
	{
		var response = transport.responseText
		var notice = $(outPutDiv);
		var status = $(statusID);
		status.hide();
		notice.update(response);
		notice.show();
		
	} ,
	onLoading: function()
	{
		var status = $(statusID);
		status.show();
		
	} ,
	onFailure: function()
	{
		alert('');
	}
});
}

function exceptionWindow(msg, divId, divClass)
{
	$(divId).show();
	$(divId).innerHTML += msg;
	
}


function textCounter(fieldId,cntfieldId,maxlimit)
{
	var field = $(fieldId);
	if (field.value.length > maxlimit)
	{ 
		field.value = field.value.substring(0, maxlimit);
		return false;
	}
	else
	{
		$(cntfieldId).innerHTML = maxlimit - field.value.length;
		return true;
	}
	return false;
}


