/**
 * wpstudio.js
 *	
 * @author		Tomasz Ryczanik rycki@wp-sa.pl, Krzysztof Dembski kdemski@wp-sa.pl
 * @version		0.2
 */

// konfiguracja popupa
var dispInfoParam = 1;

// id otwartego popupa
// jesli jest zamkniety to ustawiamy 0
var idVisibleInfo = 0;


// funkcje do ustawiania pozycji kursora
var IE = document.all?true:false

if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	document.onclick = getMouseXYClick;

var tempX = -1000;
var tempY = -1000;
var screenX;
var screenY;

// wielkosc ekranu
if (typeof(window.innerWidth) == 'number') {
	screenX = window.innerWidth;
	screenY = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	screenX = document.documentElement.clientWidth;
	screenY = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	screenX = document.body.clientWidth;
	screenY = document.body.clientHeight;
}

// ustawienie przesuniecia skrola
function getScrollXY() {

	var scrollX = 0;
	var scrollY = 0;

	if (typeof(window.pageYOffset) == 'number') {
		scrollY = window.pageYOffset;
		scrollX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		scrollY = document.body.scrollTop;
		scrollX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		scrollY = document.documentElement.scrollTop;
		scrollX = document.documentElement.scrollLeft;
	}

	return [scrollX, scrollY];
}


// parametr pozwala zmieniac polozenie diva
var getXY = true;

function getMouseXYClick(e) {
	getMouseXY(e);
	getXY = false;
}

function getMouseXY(e) {

	if (false == getXY) {
		return true;
	}

	var scroll = getScrollXY();

	if (IE) {
		if (event == null) {
			return;
		}

		tempX = event.clientX + scroll[0];
		tempY = event.clientY + scroll[1];
	} else {
		if (e == null) {
			return;
		}

		tempX = e.pageX;
		tempY = e.pageY;
	}

	if (tempX < 0) {
		tempX = 0;
	}

	if (tempY < 0) {
		tempY = 0;
	}


	if (1 == dispInfoParam) {
	} else if (2 == dispInfoParam) {
		tempX = tempX - 270;
	} else if (3 == dispInfoParam) {
		tempY = tempY - 210;
	} else if (4 == dispInfoParam) {
		tempX = tempX - 270;
		tempY = tempY - 210;
	}

	if ((tempY+270) > (screenY+scroll[1])) {
		//              tempY = screenY + scroll[1] - 270;
	}

	var obj = document.getElementById('info');
	if (obj == null) {
		return false;
	}

	obj.style.top = tempY+'px';
	obj.style.left = tempX+'px';

	return true;
}

function getInfo(infoType, id, dispParam, detType) {
	// jesli aktywny jest staly popup z infomacjami obiektu - wychodzimy z funkcji
	if (0 != idVisibleInfo) {
		return true;
	}

	getXY = true;

	// konfiguracja wyswietlania popupa
	dispInfoParam = dispParam;

	// nazwa typu obiektu
	var idName = getIdName(infoType);

	// div do ktorego wrzucimy dane
	var divInfo = document.getElementById('info');
	if (divInfo == null) {
		return;
	}

	var url = 'details.html?type='+infoType+'&'+idName+'='+id;

	if (1 == infoType || 3 == infoType) {
		if (!detType) {
			alert('Brak typu szczegolowego w wywolaniu funkcji!');
			return false;
		}
		if (1 == infoType) {
			url += '&mtype='+detType;
		}
		if (3 == infoType) {
			url += '&cType='+detType;
		}
	}

	// pobieramy dane za pomoca ajaxa i wrzucamy je do naszego diva
	ajax = new wpAjax();
	ajax.opcje({'plik': url, 'onSuccess':function(ax) { divInfo.innerHTML = ax.ajaxText; }});
	ajax.start();

	// pokazujemy diva z popupem
	divInfo.style.display = 'block';
	lightup();
}

function closeInfo() {
	// jesli aktywny jest staly popup z infomacjami obiektu
	if (0 != idVisibleInfo) {
		return true;
	}

	getXY = false;
	// ukrywamy diva
	document.getElementById('info').innerHTML = '';
	document.getElementById('info').style.display = 'none';
	brightness = 0;
}

function showMoreMaterialInfo(infoType, id, materialType, boxType, dispParam) {

	getXY = true;

	var divInfo = document.getElementById('info');
	if (divInfo == null) {
		return;
	}

	// jesli popup aktywny to ukrywamy popupa i zmieniamy ikonki
	if (0 != idVisibleInfo) {

		// ukrywamy popupa
		divInfo.style.display = 'none';

		// zmieniamy ikony
		changeIcon(idVisibleInfo, 'info', boxType);

	}

	// ustawiamy id aktywnego diva
	idVisibleInfo = id;

	// konfiguracja wyswietlania popupa
	dispInfoParam = dispParam;

	// nazwa typu obiektu
	var idName = getIdName(infoType);

	// pokazujemy diva z popupem
	divInfo.style.display = 'block';

	// pobieramy dane
	ajax = new wpAjax();
	ajax.opcje({'plik':'details.html?type='+infoType+'&'+idName+'='+id+'&mtype='+materialType+'&closeIcon=1', 'onSuccess':function(ax) { divInfo.innerHTML = ax.ajaxText; }});
	ajax.start();

	// zmieniamy ikony
	changeIcon(id, 'infoClose', boxType);

	lightup();

}

function hideMoreInfo(id) {

	// ustawiamy info o deaktywacji popupa
	idVisibleInfo = 0;

	// ukrywamy diva z popupem
	document.getElementById('info').innerHTML = '';
	document.getElementById('info').style.display = 'none';

	// zamieniamy ikony
	changeIcon(id, 'info');

	brightness = 0;

}

function changeIcon(id, showIcon, boxType) {

	// ikona zamykajaca popupa
	if ('infoClose' == showIcon) {
		if ('l' == boxType && document.getElementById('showMore_l_'+id) && document.getElementById('hideMore_l_'+id)) {
			document.getElementById('showMore_l_'+id).style.display = 'none';
			document.getElementById('hideMore_l_'+id).style.display = 'block';
		}
		if ('s' == boxType && document.getElementById('showMore_s_'+id) && document.getElementById('hideMore_s_'+id)) {
			document.getElementById('showMore_s_'+id).style.display = 'none';
			document.getElementById('hideMore_s_'+id).style.display = 'block';
		}

		// ikona otwierajaca popupa
	} else {
		if (document.getElementById('showMore_l_'+id) && document.getElementById('hideMore_l_'+id)) {
			document.getElementById('showMore_l_'+id).style.display = 'block';
			document.getElementById('hideMore_l_'+id).style.display = 'none';
		}
		if (document.getElementById('showMore_s_'+id) && document.getElementById('hideMore_s_'+id)) {
			document.getElementById('showMore_s_'+id).style.display = 'block';
			document.getElementById('hideMore_s_'+id).style.display = 'none';
		}
	}
}

/**
 * getIdName na podstawie przekazangeo typu danych
 * zwraca nazwe id obiektu przekazywanego w url
 *
 * @param infoType - typ pobieranych danych
 */
function getIdName(infoType) {
	var idName = '';
	switch(infoType) {
		case '1':
			idName = 'mid';
			break;
		case '2':
			idName = 'uid';
			break;
		case '3':
			idName = 'cid';
			break;
		case '4':
			idName = 'aid';
			break;
	}
	return idName;
}



var brightness = 0;
function lightup() {
	if (brightness <= 95) {
		if (brightness == 100) {
			brightness = 99;
		}
		obj = document.getElementById('info');
		obj.style.opacity = '.' + brightness;
		obj.style.filter  = 'alpha(opacity=' + brightness + ')';
		brightness       += 10;
		window.setTimeout("lightup()", 30);
	}
}

function pause(millisecondi) {

	var now = new Date();
	var exitTime = now.getTime() + millisecondi;
	while(true) {
		now = new Date();
		if(now.getTime() > exitTime) return;
	}
}

function getHint(hintVal) {
	getXY = true;
	dispInfoParam = 2;
	var divInfo = document.getElementById('info');
	if (divInfo == null) {
		return;
	}

	divInfo.innerHTML = '<p class="hintText">'+hintVal+'</p>';
	divInfo.style.display = 'block';
}

function closeHint() {
	getXY = false;
	var divInfo = document.getElementById('info');
	if (divInfo == null) {
		return;
	}
	divInfo.innerHTML = '';
	divInfo.style.display = 'none';
}

function ajaxAction(opt) {
	ajx = new ajaxActionPrepare();
	ajx.opcje(opt);
	ajx.start();
}


var ajaxResponse = '';


function ajaxActionPrepare() {
	var axp        = new Object();
	axp.funcAfter  = null;
	axp.ajxDiv     = null;
	axp.action     = '';
	axp.extraparam = '';
	axp.formName   = null;
	axp.view       = '';

	axp.opcje = function(opt) { for(i in opt) if(typeof(axp[i])=='undefined') axp.param[i]=opt[i]; else axp[i]=opt[i];	}

	axp.start = function() {

		// jesli dostalismy nazwe formularza to preparujemy posta i wysylamy ajaxem
		if (axp.formName) {

			//var poststr = '';
			var f = document.forms[axp.formName];
			var params = new Array();
			
			for (i=0; i<f.length; i++) {
				params[f.elements[i].name] = f.elements[i].value;				
			}

			if (axp.funcAfter && typeof('function' == axp.funcAfter)) {
				WP.ajax.post({ url: document.URL, params: params, 'onSuccess':function(ax) { ajaxResponse = ax.text; axp.funcAfter(); }});
			} else {
				WP.ajax.post({ url: document.URL, params: params });
			}

		// w przeciwnym wypadku sprawdzamy preperujemy get i wysylamy
		} else {

			if (axp.view) {
				var url = axp.view;
			} else {
				var url = document.URL;
			}
			
			var last   = url.lastIndexOf(',');
			var prefix = '';
			
			if (last > 0) {
			    var prefix = url.substring(0, last);
			}

			if (axp.action) {
				prefix += ',_action,'+axp.action;
			}
			
			if (axp.extraparam) {
				prefix += axp.extraparam;
			}

			if (last > 0) {
			    url = prefix + url.substring(last, url.length);
			} else {
			    url = 'true,1' + prefix + ',' + url;
			}

			if (axp.funcAfter && typeof('function' == axp.funcAfter)) {
				WP.ajax.get({ url: url, 'onSuccess':function(ax) { ajaxResponse = ax.text; axp.funcAfter(); }});
			} else {
				WP.ajax.get({ url: url });
			}
		}
	}

	return axp;
}


//detekcja wersji flasha
function getFlashVersion() {
	return WP.flash.getVersion();
}


//detekcja typu przegladarki
function getBrowserType() {
	browserType = "";
	if (WP.isOpera) {
		browserType = "opera";
		return browserType;
	} else if (WP.isIE) {
		browserType = "msie";
		return browserType;
	} else if (WP.isGecko) {
		browserType = "gecko"; // poprzednio zwracalo 'mozilla'
		return browserType;
	} else {
		browserType = "other";
		return browserType;
	}
}


//sprawdzenie czy system to windows
function isWin() {
	return WP.isWin;
}


//ukrywanie select'ow
var i;
var selekty=[];
if (document.getElementsByTagName) {
	selekty=document.getElementsByTagName("SELECT");
} else if (document.all) {
	selekty=document.all.tags("SELECT");
}

function setSelects(visMode) {
	for(i=0;i<selekty.length;i++) {
		if (selekty[i].style) selekty[i].style.visibility=visMode;
	}
}


licz=0;
function otworz(nazwa,szer,wys) {
config='left=100,top=100,width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
kitekSC='okno' + licz;
stadion=window.open('',kitekSC,config)
stadion.document.write('<HTML><HEAD>');
stadion.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">');
stadion.document.write('<TITLE>Wirtualna Polska - Foto-Galeria</title>');
stadion.document.write('<script language="javascript">');
stadion.document.write('setTimeout(');
stadion.document.write('"self.close()');
stadion.document.write(';",70000)');stadion.document.write('</');
stadion.document.write('script>');
stadion.document.write('</HEAD>');
stadion.document.write('<body bgcolor=white leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>');
stadion.document.write('<DIV align=center><a href=# onclick="javascript:self.close();"><img src='+nazwa+' border=0></A></DIV>');
stadion.document.write('</body></html>');
stadion.focus();
licz+=1;
}


function show(id) {
	$(id).show();
}


function showDisp(id, howdisplay) {
    var obj = $(id);
    obj.style.display = howdisplay;
}


function hide(id) {
	$(id).hide();
}


function showInParent(div) {
	parent.$(div).show();
}


function hideInParent(div) {
	parent.$(div).hide();
}


/**
 * linkConfirm potwierdzenie przeniesienia na dana strone 
 * 
 * @param string message - komunikat
 * @param string link - url 
 */
function linkConfirm(message, link) {
	var answer = confirm(message);
	if (answer) {
		location = link;
	}
}


/**
 * removeConfirm - potwierdzenie usuniecia
 * 
 * @param string formName - nazwa formularza
 * @param string message - komunikat
 */
function removeConfirm(formName, message) {
	var answer = confirm(message);
	if (answer) {
		document.forms[formName].submit();
	}
}


/**
 * deleteItemConfirm - potwierdzenie usuniecia oraz dodanie 
 * elementu o wskazanej nazwie
 * 
 * @param string formName - nazwa formularza
 * @param string message - komunikat 
 * @param string delElementName - nazwa dla wygenerowanego inputa 
 */
function deleteItemConfirm(formName, message, delElementName) {
	var answer = confirm(message);
	if (answer) {
		var objForm = document.forms[formName];

		var hid = document.createElement('input');
		hid.setAttribute('type', 'hidden');
		hid.setAttribute('name', delElementName);
		hid.setAttribute('value', 'yes');
		objForm.appendChild(hid);

		objForm.submit();
	}
}


/**
 * downFile - uwidacznia diva z 'wesja na telefon' w prezentacji
 */
function downFile() {
	$('p3gp').innerHTML = $('downFileDiv').innerHTML;
	showElement('p3gp', 'block');
	changeVisibleDiv('disDownF', 'enDownF');
}


/**
 * closeDownFile - zamyka diva z 'wesja na telefon' w prezentacji
 */
function closeDownFile() {
	changeVisibleDiv('enDownF', 'disDownF');
	hideElement('p3gp');
	hideElement('wpmobi');
}


/**
 * showWPMobi - uwidacznia diva z 'wysylanie linka na WPMobi' 
 */
function showWPMobi() {
	$('wpmobi').innerHTML = $('WPMobiDiv').innerHTML;
	showElement('wpmobi', 'block');
}


/**
 * showWPMobiMessage - pokazuje komunikat po zakonczonej akcji wysylania SMSa
 */
function showWPMobiMessage() {
	$('wpmobi').innerHTML = $('WPMobiDivMessage').innerHTML;
}


/**
 * showhideWPMobi - uwidacznianie i ukrywanie diva z WPMobi
 */
function showhideWPMobi() {
	var obj = $('wpmobi');
	if (obj.style.display != 'block') {
		showWPMobi();
		changeVisibleDiv('sendSmsInput', 'sendSmsMessage');
	} else {
		closeWPMobi();		
	}
}


/**
 * closeWPMobi - ukrywa diva WPMobi 
 */
function closeWPMobi() {
	hideElement('wpmobi');
}


/**
 * addToSession dodawanie materialow do sesji w administracji
 * by pamietac zaznaczone/odznaczone materialy na kolejnych podstronach
 * 
 * @param string varName - nazwa zmiennej w sesji
 * @param int value - wartosc (id materialu)
 * @param int type - typ materialu
 * @param object obj - zaznaczony obiekt checkboxa
 */
function addToSession(varName, value, type, obj) {
	var extraparam = ',varName,'+varName+',value,'+value+',type,'+type;
	if (true == obj.checked) {
		extraparam += ',act,add';
	} else {
		extraparam += ',act,delete';
	}
	ajaxAction({'view':'addtosession.html', 'extraparam':extraparam });
}


/**
 * checkAllMatAndAdd - zaznacza wszystkie materialy i zapisuje do sesji
 * 
 * @param string formName - nazwa formularza
 */
function checkAllMatAndAdd(formName, matSes) {

	changeVisibleDiv('uncheck','check','inline');

	var extraparam = ',varName,'+matSes+',act,add';

	var form = document.forms[formName];
	var urlRawparams = '';
	for (i=0; i<form.length; i++) {
		if ('checkbox' == form[i].type) {
			form[i].checked = true;
			// extraparam += ','+form[i].name+','+form[i].value;
			if(urlRawparams.length) {
				urlRawparams += '&';
			} else {
				urlRawparams += '?';
			}
			urlRawparams += form[i].name + '=' + form[i].value;
		}
	}

	ajaxAction({'view':'addtosession.html'+urlRawparams, 'extraparam':extraparam});
}


/**
 * uncheckAllMatAndRem - odzaznacza wszystkie materialy i zapisuje do sesji
 * 
 * @param string formName - nazwa formularza 
 */
function uncheckAllMatAndRem(formName, matSes) {

	changeVisibleDiv('check','uncheck','inline');
	
	var extraparam = ',varName,'+matSes+',act,delete';

	var form = document.forms[formName];
	for (i=0; i<form.length; i++) {
		if ('checkbox' == form[i].type) {
			form[i].checked = false;
			extraparam += ','+form[i].name+','+form[i].value;
		}
	}

	ajaxAction({'view':'addtosession.html', 'extraparam':extraparam});
}


/**
 * uncheckAllMaterials - odzaznacza wszystkie materialy
 * 
 * @param string formName - nazwa formularza 
 */
function checkAllMaterials(formName) {
	changeVisibleDiv('uncheck','check','inline');
	checkAll(formName);
}


/**
 * uncheckAllMaterials - odzaznacza wszystkie materialy
 * 
 * @param string formName - nazwa formularza 
 */
function uncheckAllMaterials(formName) {
	uncheckAll(formName);
	changeVisibleDiv('check','uncheck','inline');
}


/**
 * checkAllComments zaznacza wszystkie komentarze 
 * 
 * @param formName nazwa formularza 
 */
function checkAllComments(formName) {
	changeVisibleDiv('uncheck','check','inline');
	var form = document.forms[formName];
	for (i=0; i<form.length; i++) {
		if ('checkbox' == form[i].type) {
			form[i].checked = true;
		}
	}
}


/**
 * uncheckAllComments - odzaznacza wszystkie komentarze
 * 
 * @param string formName - nazwa formularza 
 */
function uncheckAllComments(formName) {
	changeVisibleDiv('check','uncheck','inline');
	var form = document.forms[formName];
	for (i=0; i<form.length; i++) {
		if ('checkbox' == form[i].type) {
			form[i].checked = false;
		}
	}
}


/**
 * setCookie ustawia cookie
 * 
 * @param name - nazwa
 * @param value - wartosc 
 * @param nDays - ilosc dni
 * @access public
 * @return 
 */
function setCookie(name,value,days) {
	var minutes = 1440 * days; // ilosc minut w podanych dniach 
	WP.cookie.set(name, value, WP.cookie.expire(minutes));
}


/**
 * readCookie czyta zawartosc cookie 
 * 
 * @param name $name 
 * @access public
 * @return 
 */
function readCookie(name) {
	return WP.cookie.get(name);
}


/**
 * eraseCookie - czysci cookie
 * 
 * @param string name - nazw cookie
 */
function eraseCookie(name) {
	WP.cookie.erase(name);
}


/**
 * unsetCookie usuwa cookie
 * potem to zmienie na jakas lepiej napisana narazie wystarczy 
 *
 * by pamietac! wykorzystane w usuwaniu cookie podczas dowiazywanie zrodel 
 * i copyrightow w galeriach
 * 
 * @param name   - nazwa cookie
 * @param path   - sciezka
 * @param domain - domena
 */
function unsetCookie(name) {
	WP.cookie.erase(name);
}


/**
 * checkAll zaznacza wszystkie checkboxy 
 * 
 * @param string formName - nazwa formularza
 */
function checkAll(formName) {
	var form = document.forms[formName]
	for (i=0; i<form.length; i++) {
		if ('checkbox' == form[i].type) {
			form[i].checked = true;
		}
	}
}


/**
 * uncheckAll odznacza wszystkie checkboxy 
 * 
 * @param string formName - nazwa formularza
 */
function uncheckAll(formName) {
	var form = document.forms[formName];
	for (i=0; i<form.length; i++) {
		if ('checkbox' == form[i].type) {
			form[i].checked = false;
		}
	}
}


/**
 * changeVisibleDiv 	ukrywa/pokazuje podane w parametrach divy
 * 			oraz czysci pola typu input w ukrywanym divie
 * 
 * @param showDivId		- div do pokazania
 * @param hideDivId		- div do ukrycia
 * @param visibleType 	- styl jaki mamy przypisac dla odkrywanego diva 
 * 			  np.(block, inline) domyslnie block
 * @param clear 	- jesli ustawiony na true to czysci wszystkie inputy
 * 			  w ukrywanym elemencie
 */
function changeVisibleDiv(showDivId, hideDivId, visibleType, clear) {

	if (!visibleType) {
		$(showDivId).style.display = 'block';
	} else {
		$(showDivId).style.display = visibleType;
	}

	var hideDivObj = $(hideDivId);
	hideDivObj.style.display = 'none';

	if (true == clear) {
		clearInputsForm(hideDivId);
	}

	return false;
}


/**
 * showElement pokazuje element o podanym id
 * 
 * @param idElement  - id elementu do pokazania
 * @param type $type - okresla styl pokazywanego elementu
 */
function showElement(idElement, type) {
	$(idElement).style.display = type;
	return false;
}


/**
 * hideElement ukrywa element o podanym id
 * 
 * @param idElement id elementu do ukrycia
 */
function hideElement(idElement) {
	$(idElement).style.display = 'none';
	return false;
}


/**
 * showElementIfTrue 	pokazuje/ukrywa element jesli dwie podane wartosci 
 * 										sa takie same
 * 
 * @param value1    - pierwsza wartosc
 * @param value2    - druga wartosc
 * @param idElement - id elementu do pokazania/ukrycia
 * @param type      - sposob pokazania
 */
function showElementIfTrue(value1, value2, idElement, type) {
	if (true == checkValue(value1, value2)) {
		showElement(idElement, type);
	} else {
		hideElement(idElement);
	}
	return false;
}


/**
 * checkValue sprawdza czy podane wartosci sa takie same
 * 
 * @param value1 - pierwsza wartosc
 * @param value2 - druga wartosc
 */
function checkValue(value1, value2) {
	if (value1 == value2) {
		return true;
	} else {
		return false;
	}
}


/**
 * checkEmail funkcja sprwadza poprawnosc adresu email 
 * 
 * @param value - adres email
 * @return boolen
 */
function checkEmail(value) {
	var reg = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
	if (null == value.match(reg)) {
		return false;
	}
	return true;
}


/**
 * activeInput 	aktywuje/dezaktywuje pole typu input na podstawie 
 * 							zaznaczenia/odznaczenia checkboxa
 * 
 * @param cbxChecked 		- przyjmuje wartosc: 'this.checked'
 * @param idInput 			- id naszego inputa
 * @param activeType 		- przyjmuje dwie wartosci ('onTrue', 'onFalse')
 * 												onTrue - aktywuje po zaznaczeniu checkboxa
 * 												onFalse - aktywuje po odznaczeniu checkboxa
 * @param clear 				- przyjmuje dwie wartosci ('true', 'false')
 * 												true - czysci inputa po dezaktywacji
 * 												false - pozostawia wartosc
 */
function activeInput(cbxChecked, idInput, activeType, clear) {

	var inptObj = $(idInput);

	if ('onTrue' == activeType) {
		if (true == cbxChecked) {
			inptObj.disabled = false;
		} else {
			inptObj.disabled = true;
			if (clear && true == clear) {
				clearInput(idInput);
			}
		}

	} else if ('onFalse' == activeType) {
		if (false == cbxChecked) {
			inptObj.disabled = false;
		} else {
			inptObj.disabled = true;
			if (clear && true == clear) {
				clearInput(idInput);
			}
		}
	}
	return false;
}


/**
 * clearInputsForm 	czysci w formularzu pola typu input
 * 
 * @param parentObj jesli istnieje podany id rodzica to czysci tylko
 * 									pola input zawarte w tym obiekcie
 */
function clearInputsForm(parentId) {

	if (!parentId) {
		var inputElements = document.getElementsByTagName('input');
	} else {
		var parentObj = $(parentId);
		var inputElements = parentObj.getElementsByTagName('input');
	}

	for (i = 0; i < inputElements.length; i++) {
		inputElements[i].value = '';
	}

	return false;
}


/**
 * clearInput - funkcja czysci inputa o podanym w parametrze id
 * 
 * @param idInput - id inputa ktory ma zostac wyczyszczony 
 */
function clearInput(idInput) {
	$(idInput).value = '';
	return false;
}


/**
 * _getValue Funkcja pobiera vartosc danego elementu 
 * 
 * @param idElement - id elementu
 */
function _getValue(idElement) {
	return $(idElement).value;
}


/**
 * _getText Funkcja pobiera wartosc tekstowa wskazanego elementu
 * 
 * @param idElement   - id elementu z ktorego pobieramy opis
 * @param elementType - typ elementu
 */
function _getText(idElement, elementType) {
	var text = '';
	var elementObj = $(idElement);

	if ('select' == elementType) {
		var selInd = elementObj.selectedIndex;
		text = elementObj[selInd].text;
	} else if ('checkbox' == elementType) {
		alert(elementObj.nextSibling.nodeValue);
	} else {
		text = elementObj.value;
	}
	return text;
}


/**
 * _checkElementExist sprawdzenie czy dodawany element istnieje juz 
 * w nadrzednym elemnecie podanym jako parentDiv
 * 
 * @param parentDiv - element glowny w ktorym umieszczamy nowe elementy
 * @param cbxNam    - nazwa checkboxa
 * @param value     - wartosc
 */
function _checkElementExist(parentDiv, cbxName, value) {

	var prtObj = $(parentDiv);
	var inputsObj = prtObj.getElementsByTagName('input');

	for (i=0; i<inputsObj.length; i++) {
		if (inputsObj[i].getAttribute('type') == 'checkbox' && 
				inputsObj[i].getAttribute('name') == cbxName) {
			var testValue = inputsObj[i].nextSibling.nodeValue;
			if (testValue == value) {
				return true;
			}
		}
	}
	return false;
}


/**
 * _countAddedDiv funkcja zwraca ilosc dodanych div-ow (dzieci) do diva rodzica.
 * Podczas pierwszego dodania dziecka tworzy ukryty input o wartosci 1
 * a podczas kolejnych zwieksza jego wartosc o jeden
 *  
 * @param parentDiv - id rodzica
 * @param childDiv  - podstawa nazwy elemntow dodawanych
 */
function _countAddedDiv(parentDiv, childDiv) {

	var count = 0;
	counterId = childDiv + 'CountNewDiv';

	if (!$(counterId)) {
		var parentObj = $(parentDiv);
		var newInput = document.createElement('input');
		newInput.setAttribute('type', 'hidden');
		newInput.setAttribute('id', counterId);
		newInput.setAttribute('value', 1);
		parentObj.appendChild(newInput);
		count = 1;
	} else {
		var count = parseInt($(counterId).value) + 1;
		$(counterId).value = count;
	}

	return count;
}


/**
 * _createChildDiv tworzy w elemencie rodzica kolejny element dziecko 
 * z unikalnym id podanym jako parametr count
 * 
 * @param parentDiv - id rodzica do ktorego dodajemy element
 * @param childDiv  - nazwa dodawanego elementu
 * @param count     - identyfikator
 */
function _createChildDiv(parentDiv, childDiv, count) {

	var newDivId = childDiv + 'New' + count;

	var parentObj = $(parentDiv);

	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', newDivId);
	parentObj.appendChild(newDiv);

	return newDivId;
}


/**
 * _addHiddenValue dodaje do elementu dziecka ukryty element hidden
 * zawierajacy dane do dodanie do BD.
 * 
 * @param divId     - id elementu
 * @param inputName - nazwa ukrytego elementu zawierajacego dane do dodania
 * @param value     - wartosc do dodania
 */
function _addHiddenValue(divId, inputName, value) {

	var newDivObj = $(divId);

	var newInput = document.createElement('input');
	newInput.setAttribute('type', 'hidden');
	newInput.setAttribute('name', inputName);
	newInput.setAttribute('value', value);
	newDivObj.appendChild(newInput);

	return false;
}


/**
 * _addCheckbox dodaje checkbox do elementu dziecka ktory umozliwia usuniecie
 * dodanego elementu
 * 
 * @param newDivId - id elementu dziecka
 * @param cbxName  - nazwa checkboxa
 * @param count    - identyfiaktor
 */
function _addCheckbox(newDivId, cbxName, count) {

	var newDivObj = $(newDivId);

	var val = 'New' + count;

	var newInput = document.createElement('input');
	newInput.setAttribute('type', 'checkbox');
	newInput.setAttribute('name', cbxName);
	newInput.setAttribute('value', val);
	newDivObj.appendChild(newInput);

	return false;
}


/**
 * _addLabel funkcja dodaje label do checkboxa 
 * 
 * @param newDivObj 
 * @param idName 
 * @param text 
 */
function _addLabel(newDivObj, idName, text) {

	var newLabel = document.createElement('label');
	newLabel.setAttribute('for', idName);
	newLabel.innerHTML = text;
	newDivObj.appendChild(newLabel);

	return false;
}


/**
 * _addDescription dodaje opis do dodanego wczesniej checkboxa 
 * 
 * @param newDivId - id elementu dziecka 
 * @param text     - tekst do dodania
 */
function _addDescription(newDivId, text) {

	var newDivObj = $(newDivId);

	var textNode = document.createTextNode(text);
	newDivObj.appendChild(textNode);

	return false;
}


/**
 * addSimpleItem Funkcja dodaje nowy element do elementu rodzica.
 * Umozliwia odczytanie i zapis tylko jednego pola (input lub select)
 * Nowy element zawiera uryte pole z danymi potrzebnymi do zapisu do BD,
 * checkbox wraz z wygenerowanym opisem umozliwiajacy usuniecie elementu
 * 
 * @param parentDiv    - element do ktorego dodajemy nowe elementy
 * @param childDiv     - nazwa elementu dodawanego (podstawa nazwy do ktorego 
 *                       zostanie doklejony identyfikator)
 * @param hidName      - nazwa elementu ukrytego (zawiera dane potrzebne do
 *                       zapisu do BD)
 * @param cbxName      - nazwa checkboxa ktory ma zostac dodany do nowego elementu
 *                       by umozliwic usuniecie dodanego elementu
 * @param newElementId - id elementu z ktorego pobierana zostaje wartosc do dodania
 * @param typeElement  - typ elementu z ktorego odczytamy wartosc (input, select)
 * @param typeCheck    - typ sprawdzania
 * @param divDeleteButton - id buttonu do usuwania elementow
 */
function addSimpleItem(parentDiv, childDiv, hidName, cbxName, newElementId, typeElement, typeCheck, divDeleteButton) {

	var inputName = hidName + '[New][]';

	var value = _getValue(newElementId);
	var text = ' ' + _getText(newElementId, typeElement);

	if (!value) {
		alert('Nie mozna dodać nowego elementu.');
		return false;
	}

	if (typeCheck) {
		switch (typeCheck) {
			case 'email':
			if (false == checkEmail(value)) {
				alert('Adres email ma nieprawidlowy format.');
				return false;
			}
			break;
		}
	}

	if (true == _checkElementExist(parentDiv, cbxName, text)) {
		alert('Podany element juz istnieje');
		return false;
	}

	var count = _countAddedDiv(parentDiv, childDiv);

	var newDivId = _createChildDiv(parentDiv, childDiv, count);

	_addHiddenValue(newDivId, inputName, value);

	_addCheckbox(newDivId, cbxName, count);

	_addDescription(newDivId, text);

	checkButtonVisible(divDeleteButton, parentDiv, 'block');

	return true;
}


/**
 * removeSimpleItem usuwa element wskazany za pomoca parametru childDiv
 * z nadrzednego elementu rodzica podanego w parametrze parentDiv. 
 * Usuwa te elementy, ktorych checkboxy o nazwie przekazanej w parametrze 
 * cbxName sa zaznaczone. Pobiera z nich wartosc i dopisuje do ukrytej tablicy 
 * elementy do usuniecia z BD.
 * 
 * @param parentDiv       - element glowny z ktorego usuwamy elementy
 * @param childDiv        - podstawa nazwy elemntu do usniecia (do niej zostanie 
 *                          doklejony, pobrany identyfikator z zaznaczonych checkboxow
 *                          i na tej podstawie zostana usuniete elementy)
 * @param cbxName         - nazwa checkboxow do sprawdzenia
 * @param deleteArrayName - nazwa tablicy do ktorej dopisujemy usuniete elementy
 */
function removeSimpleItem(parentDiv, childDiv, cbxName, deleteArrayName, divDeleteButton) {

	var removeArray = new Array();
	var j = 0;

	var parentObj = $(parentDiv);

	var inputsObj = parentObj.getElementsByTagName('input');

	for (i=0; i<inputsObj.length; i++) {
		if (inputsObj[i].getAttribute('type') == 'checkbox' && 
				inputsObj[i].getAttribute('name') == cbxName && 
				inputsObj[i].checked == true) {

			var value = inputsObj[i].getAttribute('value');

			if (!isNaN(value)) {
				_addHiddenValue(parentDiv, deleteArrayName, value);
			}

			var divId = childDiv + value;

			var removeDiv = $(divId);
			removeArray[j] = removeDiv;
			j += 1;

		}
	}

	for (k=0; k<removeArray.length; k++) {
		rem = parentObj.removeChild(removeArray[k]);
	}

	checkButtonVisible(divDeleteButton, parentDiv, 'block');

	return false;
}


/**
 * checkButtonVisible funkcja na podstawie zadanych parametrow
 * ukrywa lub pokazuje przycisk do usuwania div
 * jesli w nadrzednym div-ie (parentDiv) nie ma elementow podrzednych 
 * to ukrywa div-a (divDeleteButton) w kturym znajduje sie button, 
 * a jesli sa jakies inne div-y to pokazuje div-a z przyciskiem
 * 
 * @param divDeleteButton - div w ktorym znajduje sie przycisk do usuwania
 * @param parentDiv       - nadrzedny div w ktorym znajduja sie div-y elementy
 */
function checkButtonVisible(divDeleteButton, parentDiv, visibleType) {

	parentObj = $(parentDiv);
	var countDiv = parentObj.getElementsByTagName('div').length;

	if (0 != countDiv) {
		if (!visibleType) {
			$(divDeleteButton).style.display = 'block';
		} else {
			$(divDeleteButton).style.display = visibleType;
		}
	} else {
		$(divDeleteButton).style.display = 'none';
	}

}


/**
 * sendSms generuje zapytanie ajaxowe wysylajace sms 
 */
function sendSms(number, f) {
	var extraparam = ',number,'+number+',f,'+f;
	
	showWPMobiMessage();
	ajaxAction({'action':'sendSms', 'extraparam':extraparam, 'funcAfter': function() {}});
}


function setPhoneNumber() {
//	alert('numer');
	//$('phoneNumber').innerHTML = document.getElemnetById('number').value;
}


function editProfile(form) {

	$('formAction').value = 'userEdit';
	form.submit();

}


function addPhoneNumber(nr1, nr2, nr3) {

	var newNumber = nr1 + nr2 + nr3;

	// sprawdzamy poprawnosc nr telefonu
	if (false == checkPhoneNumber(newNumber)) {
		return;
	}

	if (true == checkNumberExist(newNumber)) {
		alert('Podany numer juz istnieje.');
		return;
	}

	$('actPhoneNumber').value = 'add';

	$('formAction').value = 'phoneNumber';

	ajaxAction({'formName':'userProfileForm', 'funcAfter': function() { setNewNumber(newNumber);}});

}


function setNewNumber(nr) {

	clearInput('inpPhone1');
	clearInput('inpPhone2');
	clearInput('inpPhone3');

	var parentDiv = $('phonesNumber');
	var numbers = parentDiv.getElementsByTagName('div');
	if (0 == numbers.length) {
		$('mmsDesc').style.display = 'none';
		parentDiv.style.display = 'block';
	}

	parentDiv.innerHTML += ajaxResponse;
}


function removePhoneNumber(nr, code) {

	ajaxAction({'action':'phoneNumber', 'extraparam':',phone,'+nr+',code,'+code+',act,delete', 'funcAfter': function() { removeNumber(nr);}});
}


function removeNumber(nr) {

	if ('1' == ajaxResponse) {

		var parentDiv = $('phonesNumber');
		var numbers = parentDiv.getElementsByTagName('div');
		if (1 == numbers.length) {
			showElement('mmsDesc', 'block');
			parentDiv.style.display = 'none';
		}

		var remElement = $('phone_'+nr);

		parentDiv.removeChild(remElement);

	}
}


function checkPhoneNumber(nr) {
	var re = new RegExp("^[0-9]{9}$");
	if (null == nr.match(re)) {
		alert('Nieprawidlowy numer telefonu.');
		return false;
	}
	return true;
}


function checkNumberExist(nr) {
	if ($('phone_'+nr)) {
		return true;
	} else {
		return false;
	}
}


function scrollingList(divParent, actElement) {

	if (null == actElement) {
		return;
	}

	var element = $(actElement);

	var div = $(divParent);

	var parentElement = element.offsetParent;

	var elementY = 0;
	while (element != null) {
		elementY += element.offsetTop;
		element = element.offsetParent;
	}
	element = div;
	while (element != null) {
		elementY -= element.offsetTop;
		element = element.offsetParent;
	}

	elementY -= 85;

	div.scrollTop = Math.max(0, elementY);
}


/**
 *  lista materialow w playliscie 
 */
var playListMaterials = Array();


/**
 * addToList 
 * 
 * @param mid $mid 
 * @param mtype $mtype 
 */
function addToList(mid, mtype, title, urlThumb, uid, ownerName, url) {

	var cookieIsset = false;

	var	cookie = readCookie('playList');
	var parentDiv = $('userPlayList');


	if (!cookie) {
		var boxParent = $('boxUserPlayList');
		if (boxParent) {
			boxParent.style.display = 'block';
		}
		var optDiv = $('playListOpt');
		if (optDiv) {
			optDiv.style.display = 'block';
		}

		cookie = mid;

	} else {

		var materials   = cookie.split(',');


		for (var i=0; i<materials.length; i++) {
			if (materials[i] == mid) {
				cookieIsset = true;
			}
		}

		if (false === cookieIsset) {
			cookie += ','+mid;
		}
	}

	setCookie('playList', cookie, 30);

	if (false === cookieIsset && parentDiv) {

		var typeName = getTypeName(mtype);

		// staly kod z urlem
		var html = '<div class=\"cont\" id=\"matUserList_'+mid+'\"><div class=\"mat\"><a href=\"'+url+'\"><img src=\"'+urlThumb+'\" alt=\" \" class=\"fotSmall\" /></a><div class=\"div_left\"><h4><a href=\"'+url+'\" >'+title+'</a></h4><p><br /><span class="author">Dodal: <a href=\"uid,'+uid+',profil.html\" class=\"author\">'+ownerName+'</a></span><span>Typ materialu: '+typeName+'</span></p></div><div class=\"div_right\"><a href=\"javascript:void(0);\" onclick=\"javascript:removeFromList('+mid+', '+mtype+');\"><img src=\"http://i.wp.pl/a/i/wideohosting/ico_minus.gif\" title=\"usun material z listy\" /></a></div><br clear=\"all\" /></div></div>';

		parentDiv.innerHTML += html;

	}
	// staly kod z urlem
	$('addToList_'+mid).style.background = 'url(http://i.wp.pl/a/i/wideohosting/ico_plus_g.gif) 10% 10% no-repeat';

	showPlayList();
}


/**
 * removeFromList 
 * 
 * @param mid $mid 
 * @param mtype $mtype 
 */
function removeFromList(mid, mtype) {

	var	cookie = readCookie('playList');
	var newCookie = '';

	if (cookie) {

		var materials = cookie.split(',');

		if (1 == materials.length) {
			var boxParent = $('boxUserPlayList');
			if (boxParent) {
				boxParent.style.display = 'none';
			}
			var optDiv = $('playListOpt');
			if (optDiv) {
				optDiv.style.display = 'none';
			}
		}

		for (var i=0; i<materials.length; i++) {
			if (materials[i] != mid) {
				if (newCookie) {
					newCookie += ','+materials[i];
				} else {
					newCookie = materials[i];
				}

			} else {
				var playListElement = $('userPlayList');
				var delElement = $('matUserList_'+mid);
				playListElement.removeChild(delElement);
			}
		}
	}

	setCookie('playList', newCookie, 30);
	// staly kod z urlem
	$('addToList_'+mid).style.background = 'url(http://i.wp.pl/a/i/wideohosting/ico_plus.gif) 10% 10% no-repeat';
}


function checkMaterialsInPlayList() {

	var	cookie = readCookie('playList');

	if (cookie) {
		var materials = cookie.split(',');

		for (var i=0; i<materials.length; i++) {

			var mid = materials[i];

			if ($('addToList_'+mid)) {
				// staly kod z urlem
				$('addToList_'+mid).style.background = 'url(http://i.wp.pl/a/i/wideohosting/ico_plus_g.gif) 10% 10% no-repeat';
			}
		}
	}
}


function getTypeName(mtype) {

	var typeName = '';

	switch(mtype) {
		case 1:
			typeName = 'wideo';
			break;
		case 2:
			typeName = 'foto';
			break;
		case 3:
			typeName = 'audio';
			break;
	}

	return typeName;
}


function showPlayList() {
	showElement('userPlayList', 'block');
	var cookie = readCookie('playList');
	if (cookie) {
		showElement('playListOpt', 'block');
	}
	showElement('hideListLink', 'block');
	hideElement('showListLink');
	setCookie('playListVisible', 'true', 30);
}


function hidePlayList() {
	hideElement('userPlayList');
	hideElement('playListOpt');
	hideElement('hideListLink');
	showElement('showListLink', 'block');
	setCookie('playListVisible', 'false', 30);
}


function scrollListing(el) {

	if (null == el) {
		return;
	}

	var element = $(el);

	var div = $('userPlayList');

	var parentElement = element.offsetParent;

	var elementY = 0;
	while (element != null) {
		elementY += element.offsetTop;
		element = element.offsetParent;
	}
	element = div;
	while (element != null) {
		elementY -= element.offsetTop;
		element = element.offsetParent;
	}

	elementY -= 50;

	div.scrollTop = Math.max(0, elementY);
}


function removePlayList() {

	var	cookie = readCookie('playList');

	if (cookie) {

		var removeArray = Array();
		var j = 0;

		var materials = cookie.split(',');

		for (var i=0; i<materials.length; i++) {
			var mid = materials[i];
			var delElement = $('matUserList_'+mid);
			removeArray[j] = delElement;

			if ($('addToList_'+mid)) {
				// staly kod z urlem
				$('addToList_'+mid).style.background = 'url(http://i.wp.pl/a/i/wideohosting/ico_plus.gif) 10% 10% no-repeat';
			}

			j += 1;

		}

		var parentObj = $('userPlayList');

		for (k=0; k<removeArray.length; k++) {
			rem = parentObj.removeChild(removeArray[k]);
		}

	}

	eraseCookie('playList');

	hideElement('playListOpt');
	hideElement('boxUserPlayList');
}


// ustawiamy id albumu jesli jest by nie przekazywac za kazdym razem
// podczas zmiany materialu w albumie
var albumId = 0;


/**
 * getComments zwraca za pomoca funkcji ajaxowej liste komentarzy danego typu
 * 
 * @param int type    - typ komentarza:
 *                      1 - komentarze do materialu
 *                      3 - komentarze do profilu
 * @param int id      - id materialu lub uzytkownika
 * @param string view - widok z ktorego weszlismy
 * @param int mType   - type materialu lub 0 jesli komentarze dotyczza profilu
 * @param int aid     - id albumu lub 0 jesli ogladamy material nie w albumie
 * @param int page    - strona wynikow w liscie komentarzy domyslnie 1
 */
function getComments(type, id, view, mType, aid, page) {

	if (aid) {
		albumId = aid;
	}
	var idName = getCommentName(type);
	var divInfo = $('comments');
	
	if (divInfo == null) {
		return;
	}
	
	var str = optViewComments+'?'+idName+'='+id+'&page='+page+'&view='+view+'&mtype='+mType+'&aid='+albumId;

	WP.ajax.get({ url: str, 'onSuccess':function(ax) { divInfo.innerHTML = ax.text; }});
}

/**
 * addCommentForm wyswietla za pomoca funkcji ajaxowej formularz
 * umozliwiajacy komentowanie uzytkownika i materialu
 * 
 * @param int type    - typ komentarzy
 *                      1 - materialow
 *                      3 - usera
 * @param int id      - id materialu lub uzytkownika
 * @param string view - widok z ktorego weszlismy
 * @param int mType   - typ materialu lub 0 jesli komentujemy uzytkownika
 */
function addCommentForm(type, id, view, mType) {
	var idName = getCommentName(type);
	var divInfo = $('comments');
	
	if (divInfo == null) {
		return;
	}
	
	WP.ajax.get({ url: optViewAddComment + '?'+idName+'='+id+'&view='+view+'&mtype='+mType+'&aid='+albumId, 'onSuccess':function(ax) { divInfo.innerHTML = ax.text; }});
}

/**
 * addComment za pomoca funkcji ajaxowej wysyla postem formularz do dodawania opini
 * 
 * @param int type    - typ komentarza
 *                      1 - materialu
 *                      3 - uzytkownika
 * @param int id      - id materialu lub uzytwkonika
 * @param int ownerId - jesli komentujemy uzytkownika to jest to jego id,
 *                      jesli komentujemy material to jest to id wlasciciela materialu
 */
function addComment(type, id, ownerId) {

	var idName  = getCommentName(type);
	var url     = optViewAddComment+'?'+idName+'='+id;
	var divInfo = $('comments');

	if (divInfo == null) {
		return;
	}

	var params = new Array();
	params['_action']	= 'addComment';
	params['ownerId']	= ownerId;
	params['title']		= $('inptTitle').value.replace(/&/g, "%26");
	params['comment']	= $('txtComment').value.replace(/&/g, "%26");
	params['view']		= $('inptView').value;
	
	if ($('inptName') && $('inptName').value) { params['name'] = $('inptName').value.replace(/&/g, "%26"); }
	if ($('inptEmail') && $('inptEmail').value) { params['email'] = $('inptEmail').value; }
	if ($('inptMType') && $('inptMType').value) { params['mtype'] = $('inptMType').value; }
	if (albumId) { params['aid'] = albumId; }

	WP.ajax.post({ url: url, params: params, 'onSuccess':function(ax) { divInfo.innerHTML = ax.text; }});
}

/**
 * getCommentName na podstawie typu komentarza pobiera nazwe dla id
 * 
 * @param int infoType - typ kometarzy
 */
function getCommentName(infoType) {
	var idName = '';
	switch(infoType) {
		case '1':
			idName = 'mid';
			break;
		case '2':
			idName = 'aid';
			break;
		case '3':
			idName = 'uid';
			break;
	}
	return idName;
}


function addCommentToModerate(id, type) {
	var answer = confirm('Czy na pewno chcesz zglosic komentarz do moderacji?');
	if (answer) {
		ajaxAction({'action':'addCommentToModerate', 'extraparam':',id,'+id+',type,'+type, 'funcAfter': function() { commentInfo(id);}});
	}
}


function commentInfo(id) {
	$('addCommToMod_'+id).style.display = 'none';
	$('addedCommToMod_'+id).style.display = 'block';
	$('commentsComm').innerHTML = ajaxResponse;
	showElement('commentsComm', 'block');
}


function commentIsModerated() {
	$('commentsComm').innerHTML = '<p>Komentarz zostal juz zgloszony do moderacji.</p>';
	showElement('commentsComm', 'block');
}


function blockLink(showLink, hideLink) {
	$('actionComm').innerHTML = ajaxResponse;
	showElement('actionComm', 'block');
	hideElement('notifyFriend');
	//hideElement('addToAlbum');
	hideElement('toModerate');
	changeVisibleDiv(showLink, hideLink, 'inline');
}


function addToFavourite(id) {
	ajaxAction({'action':'addToFavourite', 'extraparam':',actType,ajax', 'funcAfter': function() { blockLink('addToFavNoAct', 'addToFavAct');}});

	var cookie = readCookie('favMaterials');
	if (cookie) {
		cookie += ':' + id;
	} else {
		cookie = id;
	}
	setCookie('favMaterials', cookie, 7);
}


function addToModerate(id) {
	ajaxAction({'action':'addToModerate', 'extraparam':',actType,ajax', 'funcAfter': function() { blockLink('addToModNoAct', 'addToModAct');}});
	var cookie = readCookie('modMaterials');
	if (cookie) {
		cookie += ':' + id;
	} else {
		cookie = id;
	}
	setCookie('modMaterials', cookie, 7);
}

function addUserToModerate() {
	if ('' == document.sendToModerate.description.value) {
		alert('Okresl powód zgloszenia tego uzytkownika do moderacji.');
	} else if (10 > document.sendToModerate.description.value.length) {
		alert('Podany powód zgloszenia jest zbyt krótki.');
	} else {
		ajaxAction({'formName':'sendToModerate', 'funcAfter': function() { hideForm('userToModerate') }});
		$('actionComm').innerHTML = ajaxResponse;
		showElement('actionComm', 'block');
		changeVisibleDiv('addToModNoAct', 'addToModAct', 'inline');
	}
}

function addToModerateForm() {
	hideElement('actionComm');
	hideElement('notifyFriend');
	//hideElement('addToAlbum');
	showElement('toModerate', 'block');
}


function addToModerate() {
	if ('' == document.sendToModerate.description.value) {
		alert('Okresl powód zgloszenia tego materialu do moderacji.');
	} else if (10 > document.sendToModerate.description.value.length) {
		alert('Podany powód zgloszenia jest zbyt krótki.');
	} else {
		ajaxAction({'formName':'sendToModerate', 'funcAfter': function() { hideForm('toModerate') }});
		$('actionComm').innerHTML = ajaxResponse;
		showElement('actionComm', 'block');
		changeVisibleDiv('addToModNoAct', 'addToModAct', 'inline');
	}
}


function addToAlbumForm() {
	hideElement('actionComm');
	hideElement('notifyFriend');
	hideElement('toModerate');
	//showElement('addToAlbum', 'block');
}


function addToAlbum() {
	//ajaxAction({'formName':'materialToAlbums', 'funcAfter': function() { hideForm('addToAlbum') }});
}


function sendToFriendForm() {
	hideElement('actionComm');
	//hideElement('addToAlbum');
	hideElement('toModerate');
	showElement('notifyFriend', 'block');
}


function sendToFriend() {
	ajaxAction({'formName':'sendEmailToFriend', 'funcAfter': function() { hideForm('notifyFriend') }});
	$('emailsParent').innerHTML = '';
	hideElement('delEm');
}


function hideForm(formName) {
	hideElement(formName);
	if('addToAlbum'!=formName)
		$('actionComm').innerHTML = ajaxResponse;
	showElement('actionComm', 'block');
}


function getComm(idCom, loginUrl) {
	hideElement('notifyFriend'); 
	//hideElement('addToAlbum');
	hideElement('toModerate');
	var com = '';
	switch(idCom) {
		case 1:
			com = 'Opcja dostępna po zalogowaniu. <a href="' + loginUrl + '">Zaloguj się</a>';
			break;
		case 2:
			com = 'Nie posiadasz albumów, do których móglbyś dodać materiał.';
			break;
		case 3:
			com = 'Materiał został już zgłoszony do moderacji.';
			break;
		case 4:
			com = 'Ten materiał już znajduje się w Twoich ulubionych.';
			break;
	}

	$('actionComm').innerHTML = com;
	showElement('actionComm', 'block');
}


/**
 * setLogo ustawia id materialu i typ oraz submituje formularz
 * 
 * @param idMaterial - id materialu
 * @param type       - typ materialu 
 */
function setLogo(idMaterial, type) {

	var matInpt = $('idMatThumb');
	matInpt.setAttribute('name', 'matThumb['+idMaterial+']');
	matInpt.setAttribute('value', type);

	document.albumMaterialsForm.submit();

}


function getAlbumContent(aid, mid, mtype, seq) {
	if (seq <= 0) {
	    seq = 0;
	}
	
	var extraparam = ',aid,'+aid+',mid,'+mid+',mtype,'+mtype+',seq,'+seq;
	ajaxAction({'view':'album_prezentacja.html', 'extraparam':extraparam, 'funcAfter': function() { setAlbumContent(mid, mtype); }});
}


function setAlbumContent(id, type) {
	mid = id;
	mtype = type;
	$('albumPresentation').innerHTML = ajaxResponse;
}


function acceptContent(backUrl, mid) {
	if (true == $('remember').checked) {
		setCookie('eroticContent', 'accept', '100');
	} else {
		var cookie = readCookie('matAccepted');
		if (cookie) {
			cookie += ':' + mid;
		} else {
			cookie = mid;
		}
		setCookie('matAccepted', cookie, 100);
	}
	location = backUrl;
}


function resign(backUrl, mid) {
	if (true == $('remember').checked) {
		setCookie('eroticContent', 'block', '100');
	} else {
		var cookie = readCookie('matBlocked');
		if (cookie) {
			cookie += ':' + mid;
		} else {
			cookie = mid;
		}
		setCookie('matBlocked', cookie, 100);
	}
	if(-1 != backUrl.indexOf('?')) {
		location=backUrl+'&accept=0';
	} else {
		location=backUrl+'?accept=0';
	}
}


var ic = new Array();

for(var i=0;i<=5;i++) {
	ic[i]=new Image();
	// staly kod z urlem
	ic[i].src = optImagesLocation + '/g2_'+i+'.gif';
};

var cOb=new Array();
var timer;


function rOv(obj, evt) {
	if(!cOb[obj.name])
		cOb[obj.name]=obj.src;

	if(document.all && !window.opera)
		evt=event;

	on=getM(getCCWT(evt).x);
	obj.style.cursor="pointer";
	
	if (document[obj.name].src != ic[on].src) {
		document[obj.name].src = ic[on].src;
	}
}


function rOf(obj) {
	if(cOb[obj.name]) {
		obj.src=cOb[obj.name];
	}
}


var markCount = 0;
var actMark = 0;

function rOc(obj,evt, id, mcCount, markFloat) {
	if (document.all && !window.opera) {
		evt=event;
	}

	markCount    = mcCount + 1;
	on   = getM(getCCWT(evt).x);
	form = $('votingForm');

	var cookie = readCookie('voting');
	if (cookie) {
		cookie += ':' + id + '=' + on;
	} else {
		cookie = id + '=' + on;
	}
	setCookie('voting', cookie, 7);
	form.mark.value = on;

	actMark = Math.ceil((markFloat * (markCount-1) + on) / markCount);
	$('actVote').src = ic[actMark].src
	$('imgVoteBlock').src = ic[on].src;
	$('imgVoteBlock').show();
	$('imgVote').hide();
	
	//changeVisibleDiv('imgVoteBlock', 'imgVote', 'inline');
	$('actMarcCount').innerHTML = '[ ' + markCount + ' glosów ]';
	ajaxAction({'formName':'votingForm'});
}


function getM(objMX) {
	on=0;
	if(objMX>=0 && objMX<=13) on=1;
	if(objMX>=14 && objMX<=25) on=2;
	if(objMX>=26 && objMX<=39) on=3;
	if(objMX>=40 && objMX<=52) on=4;
	if(objMX>=53 && objMX<=67) on=5;
	return on;
}


function getCCWT(evt) {
	var coords = { x: 0, y: 0};
	if(document.all && !window.opera) {
		evt = window.event;
		coords.x=evt.offsetX;
		coords.y=evt.offsetY;
	} else {
		var Element=evt.target;
		var cTLeft=0;
		var cTTop=0;
		while (Element.offsetParent) {
			cTLeft+=Element.offsetLeft; 
			cTTop+=Element.offsetTop;
			Element = Element.offsetParent ;
		}
		coords.x=evt.pageX-cTLeft;
		coords.y=evt.pageY-cTTop;
	}
	return coords;
}



