/* 
** Funkcje obsługi biblioteki advAjax 
*/

/* Pobranie wartości z adresu url i zapisanie jej w polu o id id */
function getResult(url, id)
{
	advAJAX.get({
		url: url,
		onLoad : function(obj)
		{
			document.getElementById(id).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			document.getElementById(id).innerHTML = obj.responseText;
      }
	});
}

/* Pobranie danych przesłanych przez formularz o id formId i zapisanie jej w polu o id id */
function getForm(formId, id)
{
	advAJAX.assign(document.getElementById(formId), 
	{
		onLoad : function(obj)
		{
			document.getElementById(id).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			document.getElementById(id).innerHTML = obj.responseText;
      }   
   });
}
/* Pobranie i wykonanie akcji */
function getFormAndAction(formId, id, action)
{
	advAJAX.assign(document.getElementById(formId), 
	{
		onLoad : function(obj)
		{
			document.getElementById(id).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			eval(action);		
			document.getElementById(id).innerHTML = obj.responseText;
      }   
   });
}
/* Pobierz po potwierdzeniu */
function confirmGetResult(q, url, id)
{
	if(confirm(q))
	{
		getResult(url, id);
		return true;
	}
	else
	{
		return false;
	}
}
/* Wysyła informacje */
function sendInfo(id, info)
{
	document.getElementById(id).innerHTML = info;
}
/* Wykonaj i odśwież widok */
function updateAndRefresh(url, id, url2, id2)
{
	advAJAX.get({
		url: url,
		onLoad : function(obj)
		{
			document.getElementById(id).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			getResult(url2, id2);			
			document.getElementById(id).innerHTML = obj.responseText;
      }
	});}
/* Wykonaj i odśwież widok */
function confirmUpdateAndRefresh(q, url, id, url2, id2)
{
	if(confirm(q))
	{	
		advAJAX.get({
			url: url,
			onLoad : function(obj)
			{
				document.getElementById(id).innerHTML = 'Pobieranie danych...';
			},    	
   		onSuccess : function(obj) 
   		{
				getResult(url2, id2);			
				document.getElementById(id).innerHTML = obj.responseText;
      	}
		});
	}
}
/* Pobranie danych przesłanych przez formularz o id formId i zapisanie jej w polu o id id */
function getFormAndGo(formId, id, url, id2)
{
	advAJAX.assign(document.getElementById(formId), 
	{
		onLoad : function(obj)
		{
			document.getElementById(id).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			document.getElementById(id).innerHTML = obj.responseText;
			setTimeout("getResult('" + url + "','" + id2 + "');", 3000);
      }   
   });
}
/* Pobranie danych przesłanych przez formularz o id formId i zapisanie jej w polu o id id */
function getResultAndGo(url, id, url2, id2)
{
	advAJAX.get({
		url: url,
		onLoad : function(obj)
		{
			document.getElementById(id).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			document.getElementById(id).innerHTML = obj.responseText;
			setTimeout("getResult('" + url2 + "','" + id2 + "');", 3000);
      }
	});
}
/*
** Inne funkcje
*/
/* Pokazanie / ukrycie elementu o id */
function showHide(id)
{
	obj = document.getElementById(id);
	obj.style.display = (obj.style.display == "block" ? "none" : "block");
}
function hide(id)
{
	obj = document.getElementById(id);
	obj.style.display = "none";
}
function show(id)
{
	obj = document.getElementById(id);
	obj.style.display = "block";
}
/* DEV */
function isTrue(Result)
{
	if(Result)
	{
		alert('ok');	
	}
	else
	{
		alert('error');	
	}
}
/* Ponowne wczytanie iFrame */
function reloadIframe (id) 
{
	var f = document.getElementById(id);
	f.src = f.src;
}

/* FCKEditor functions */
/* Wyczyszczenie danych */
function clearHtmlEditor(id)
{
	var oEditor = FCKeditorAPI.GetInstance(id);
	oEditor.SetHTML('');
}
/* Zapisanie danych */
function saveHtmlEditor(id)
{
	var oEditor = FCKeditorAPI.GetInstance(id);
	oEditor.UpdateLinkedField();
}
/* Wysyła informacje */
function sendInfo(id, info)
{
	document.getElementById(id).innerHTML = info;
}
/* Funkcja specyficzna dla NEW FORM - sprawdzenie wypełnienia pola i wyświetlenie info w nazwaPola__Info */
function checkField(val, id)
{
	if(val)
	{
		sendInfo(id, 'Ok');	
	}
	else
	{
		sendInfo(id, 'Error');	
	}
}
/* Alert This */
function alertThis(id)
{
	obj = document.getElementById(id);
	alert(obj.value);
}

/* MegaKombos */
function getResultGetFormAndGo(formUrl, formFrameId, formId, formCommentFrameId, redirectUrl, redirectFrameId)
{
	advAJAX.get({
		url: formUrl,
		onLoad : function(obj)
		{
			document.getElementById(formFrameId).innerHTML = 'Pobieranie danych...';
		},    	
   	onSuccess : function(obj) 
   	{
			document.getElementById(formFrameId).innerHTML = obj.responseText;
			advAJAX.assign(document.getElementById(formId), 
			{
				onLoad : function(obj)
				{
					document.getElementById(formCommentFrameId).innerHTML = 'Pobieranie danych...';
				},    	
   			onSuccess : function(obj) 
   			{
					document.getElementById(formCommentFrameId).innerHTML = obj.responseText;
					setTimeout("getResult('" + redirectUrl + "','" + redirectFrameId + "');", 3000);
      		}   
   		});
      }
	});
}



/* Kolorki Menu,manager */
function mmActive(id)
{
	if(activeElement)
	{
		if(activeElement != id)
		{		
			document.getElementById(activeElement).style.background='#fff';
		}
	}	
	activeElement = id;
}
/* Reset Active */
function mmReset()
{
	activeElement = '';
}

activeElement = '';
/* Zmiana po najechaniu */
function mmOn(id)
{
	document.getElementById(id).style.background='#F0F8FF';
}
/* Zmiana po odjechaniu */
function mmOff(id)
{
	if(id == activeElement)
	{
		document.getElementById(id).style.background='#FFF380';
	}
	else
	{
		document.getElementById(id).style.background='#fff';			
	}
}

/* Otwarcie powiększenia zdjęcia */
function popImage(photo)
{
	window.open ("popup.php?photo=" + photo,
"mywindow","menubar=0,resizable=0,width=200,height=200"); 
}
