var divList = new Array();
var divListX = new Array();
var divListY = new Array();
var divListW = new Array();
var divListH = new Array();
var divListS = new Array();
var divListXSM = new Array();
var divListYSM = new Array();
var divListM = new Array();
var divListMType = new Array();
var winW = 630, winH = 460;
var startY = 150;
var currentDivName = "";
var currentDivMess = "";
var currentDivId = "";
var profileDir = "";
var imagesMaxZIndex = 50;
var stdImageHeight = 432
var stdImageWidth = 576;
var maxImageWidth = 940;
var maxImageHeight = 600;
var lexLang = "pl";
var gVer="0003";
var mDom = "humoristic";
var pDom = "pict.humoristic";

var showMessTab = new Array();

var NETSC = (navigator.appName =="Netscape") ? true : false;
var IE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
var OPERA = (window.opera) ? true : false;

if ((! getCookie("isIE")) && (! IE))
	setCookie("isIE","yes",365);

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
function time() {
	return Math.floor(new Date().getTime()/1000);
}

function getPeriod(t) {
	return getPeriod(t,false);
}


function getPeriod(t ,withHour) {

	var acttime = time();
	var czas = ""; 
	if (date('Y-m-d',t) == date('Y-m-d',acttime))
		czas = "dzisiaj o "+date('H:i',t);
	
	else if (date('Y-m-d',t) == date('Y-m-d',acttime- 24*60*60))
		czas = "wczoraj "+date('H:i',t);
	
	else if (date('Y-m-d',$) == date('Y-m-d',acttime- 2*24*60*60))
		czas = "przedwczoraj "+date('H:i',$t);
	
	else	{
		czas = date('Y-m-d',t);
		if (withHour != false)
			czas = czas + " o godz: "+date('H:i',t);
		czas = czas+", "+Math.floor((acttime-t)/(24*60*60))+" dni temu";
	}
	
	//."".($withHour != false?" o godz: ".date('H:i',$t):"").", ".floor((time()-$t)/(24*60*60))." dni temu";

	return czas;

}


function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

//---------------------------------------------------------------------------------------------------------------
function replaceAll(what,to,str) {
	while (str.indexOf(what) > -1)
		str = str.replace(what,to);
	return str;
}

//----------------------------------------------------------------
function getElem(elemId) {
	var elem = null;
	
	if ( document.getElementById )	
		elem = document.getElementById(elemId);  
		
	if ((elem == null) && (document.getElementsByName))
		elem = document.getElementsByName(elemId)[0];
	
	if ((elem == null) && (document.all))
		elem = document.all[elemId];  
	
	if ((elem == null) && ( document.layers )) 	
		elem = document.layers[elemId];

	return elem;
}

//----------------------------------------------------------------
function getDivInd(name) {
	for (i=0;i<divList.length;i++)	
		if (divList[i] == name)	
			return i;
	return -1;
}

//----------------------------------------------------------------
function setWindowSize() {
	if (parseInt(navigator.appVersion)>3) {
		if (NETSC) {
			winW = window.innerWidth-16;
			if (winW<980)
				winW = 980;
			winH = window.innerHeight-16;
		}
		if (IE || OPERA) {
			winW = document.body.offsetWidth-20;
			if (winW<980)
				winW = 980;
			winH = document.body.offsetHeight-20;
		}
	}
}

//----------------------------------------------------------------
function setPictAligm() {

	if (typeof picturemess != 'undefined')
		return;
	setWindowSize();
	for (i=0;i<divList.length;i++) {
		var oneDiv = getElem(divList[i]);
		oneDiv.style.visibility = "visible";
		oneDiv.style.left = Math.floor(winW/2+divListX[i]) + "px";
		if ((divListX[i] == 0) && (divListY[i] == 0))
			oneDiv.style.top = Math.floor(startY+divListY[i]) + "px";
		else 	oneDiv.style.top = Math.floor(startY+divListY[i]) + "px";
		if (oneDiv.style.zIndex > imagesMaxZIndex)
			imagesMaxZIndex = oneDiv.style.zIndex;
	}

	var oneDiv = getElem("maintbl");
	if (oneDiv) {
		oneDiv.style.visibility = "visible";
		oneDiv.style.top = Math.floor(startY) + "px";
	}


}


//----------------------------------------------------------------
function recalcAll() {
//	if (! IE)
//	if (getElem("menuTop"))
//		alert(getElem("menuTop").src);
	setWindowSize();
	setPictAligm();
	recalcMessDives();
}

//***************************************************************************************************************
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//  COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES COOKIES

//***************************************************************************************************************
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function setCookie(c_name,value,expiredays) { 
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	//alert(c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()));
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) 
				c_end=document.cookie.length;
    			return unescape(document.cookie.substring(c_start,c_end));
    		} 
  	}
	return false;
}


//***************************************************************************************************************
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//  PICTURESCALC PICTURESCALC PICTURESCALC PICTURESCALC PICTURESCALC PICTURESCALC PICTURESCALC PICTURESCALC PICTURESCALC

//***************************************************************************************************************
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function savePos() {
	var savePosElem = getElem("savePos");

	uri = "";
	for (i=0;i<divList.length;i++) 
		uri += divList[i]+",";
	uri = "&ids="+uri;

	for (i=0;i<divList.length;i++) {
		var oneDiv = getElem(divList[i]);
		var xPosStr = oneDiv.style.left+0;
		var yPosStr = oneDiv.style.top+0;
		var xPos = Math.floor(parseInt(xPosStr) - winW/2);
		var yPos = Math.floor(parseInt(yPosStr) - startY);
		if ((yPos == 300) && (xPos == 0))
			yPos = 0;
		var zPos = oneDiv.style.zIndex;
		var scale = divListS[i];

		uri += "&"+divList[i]+"x="+xPos+
                	"&"+divList[i]+"y="+yPos+
                	"&"+divList[i]+"z="+zPos+
                	"&"+divList[i]+"s="+scale;
	}
	savePosElem.disabled = true;
	savePosElem.value="... zapisywanie ...";
	location.replace("/picturescalc.html?save=true"+uri);
}


//----------------------------------------------------------------
function zoomIn() {
	var divInd = getDivInd(currentDivName);
	var newS = parseFloat(divListS[divInd]) + 0.1;

	var newW = Math.floor(newS * parseFloat(divListW[divInd]));
	var newH = Math.floor(newS * parseFloat(divListH[divInd]));

	if (newW>maxImageWidth) {
		alert("Tego obrazka nie można już bardziej powiększyć.");
		return;
	}
	if (newH>maxImageHeight) {
		alert("Tego obrazka nie można już bardziej powiększyć.");
		return;
	}

	divListS[divInd] = newS;

	var currentDiv = getElem(currentDivName);
	currentDiv.innerHTML = '<img border="1" bordercolor="#000000" src="http://'+pDom+'/profile/'+profileDir+'images/'+newW+'x'+newH+'/'+currentDivName+'.jpg">';
}


//----------------------------------------------------------------
function zoomOut() {
	var divInd = getDivInd(currentDivName);
	var newS = parseFloat(divListS[divInd]) - 0.1;
	if (newS<0.1)
		return;
	divListS[divInd] = newS;
	var newW = Math.floor(newS * parseFloat(divListW[divInd]));
	var newH = Math.floor(newS * parseFloat(divListH[divInd]));

	var currentDiv = getElem(currentDivName);
	currentDiv.innerHTML = '<img border="1" bordercolor="#000000" src="http://'+pDom+'/profile/'+profileDir+'images/'+newW+'x'+newH+'/'+currentDivName+'.jpg">';
}


//----------------------------------------------------------------
function checkFilename() {
	var addImgForm = getElem("addImgForm");
	var addImgSubmit = getElem("addImgSubmit");
	var addImgFilename = getElem("addImgFilename");

 	var imgFile = addImgFilename.value.toLowerCase();
 
	if (! ((imgFile.lastIndexOf(".") != -1) &&  (imgFile.substring(imgFile.lastIndexOf(".")+1) == "jpg" || imgFile.substring(imgFile.lastIndexOf(".")+1) == "jpeg")))
		alert("Podany plik nie jest plikiem \".jpg\"!\n\nSystem przyjmuje tylko pliki JPG.\nProsimy o podanie poprawnego pliku.");
	else { 
		alert('Po kliknięciu OK plik zostanie wysłany do serwera.\nMoże to portwać do kilkudziesięciu sekund w zależności od rozmiaru pliku ze zdjęciem.\nProsimy cierpliwie czekać na przesłanie zdjęcia.\n\nKliknij OK w celu potwierdzenia.'); 
		addImgSubmit.disabled = true;
		addImgSubmit.value="... wysyłanie ...";
		addImgForm.submit();
	}
}



//***************************************************************************************************************
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//  MMESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES MESSAGES

//***************************************************************************************************************
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


function recalcMessDives(xx) {

	var i=0;
	for (i=0;i<showMessTab.length;i++) {

		//if (xx==true) {
		//	alert(showMessTab[i]["divName"]+" "+showMessTab[i]["xPosDiv"]+" "+showMessTab[i]["yPosDiv"]+" "+showMessTab[i]["messName"]+" "+showMessTab[i]["xPosMess"]+" "+showMessTab[i]["yPosMess"]);
		//}
		if ((objDiv = getElem(showMessTab[i]["divName"])) == null)
			continue;

		if ((messDiv = getElem(showMessTab[i]["messName"])) == null)
			continue;

		var pos = getPos(objDiv);

		messDiv.style.left = ((-showMessTab[i]["xPosDiv"]+pos["xPos"]) + showMessTab[i]["xPosMess"]) + "px";
		messDiv.style.top  = ((-showMessTab[i]["yPosDiv"]+pos["yPos"]) + showMessTab[i]["yPosMess"]) + "px";

	}
}

//----------------------------------------------------------------
function getPos(ofObj) {

	var xPos = 0;
	var yPos = 0;
	var lastAddedxPos=0;
	var lastAddedyPos=0;
	if (ofObj.style.position != "absolute") {
		while ((typeof ofObj != "undefined") && (ofObj.tagName != "HTML"|"BODY")) {
			//alert(ofObj.tagName+" "+ofObj.offsetTop);
			
			if (lastAddedxPos != parseInt(ofObj.offsetLeft + 0)) {
				lastAddedxPos = parseInt(ofObj.offsetLeft + 0);
				xPos += lastAddedxPos;
			}
			if (lastAddedyPos != parseInt(ofObj.offsetTop + 0)) {
				lastAddedyPos = parseInt(ofObj.offsetTop + 0);
				yPos += lastAddedyPos;
			}
			if (ofObj.tagName == "iframe") 
				break;
			ofObj = (typeof ofObj.parentNode != "undefined")?ofObj.parentNode:ofObj.parentElement;
		}
	} else {
		xPos = parseInt(ofObj.offsetLeft + 0);
		yPos = parseInt(ofObj.offsetTop + 0);

	}

	var ret = new Array();
	ret["xPos"] = xPos;
	ret["yPos"] = yPos;
	return ret;
}

//----------------------------------------------------------------
function hiddeMess() {
	var messDiv = getElem("mess");
	if (messDiv == null)
		return;
	messDiv.style.visibility = "hidden";
}

//----------------------------------------------------------------
function showMess(idElem, mess, typedymek, xsm, ysm) {
	showMess(idElem, mess, typedymek, xsm, ysm, false);
}
//----------------------------------------------------------------
function showMess(idElem, mess, typedymek, xsm, ysm, messDymekCreate) {

	var newDivMess = new Array();
	var messDivName = "mess";
	if (messDymekCreate)
		mess = decodeMess(mess,true);
	else	mess = decodeMess(mess,false);

	if (messDymekCreate) {

		messDivName = idElem+"mess";
		var newDiv = document.createElement("div");
		newDiv.setAttribute("id", messDivName);
		newDiv.setAttribute("name", messDivName);
		document.body.appendChild(newDiv);

	}

	if ((messDiv = getElem(messDivName)) == null)
		return;

	messDiv.style.visibility = "hidden";
	messDiv.style.position = "absolute";
	messDiv.style.zIndex = 99999;

	if (mess=="")	{
		messDiv.style.visibility = "hidden";
		return;
	}

	if ((objDiv = getElem(idElem)) == null)
		return;

	if ((typeof xsm == "undefined") || (typeof ysm == "undefined") || (typeof typedymek == "undefined")) {
		xsm=0;
		ysm=0;
		typedymek=0;
	}


	var width = parseInt(objDiv.offsetWidth + 0);
	var height = parseInt(objDiv.offsetHeight + 0);
	var pos = getPos(objDiv);

	if (messDymekCreate) {
		newDivMess["divName"] = idElem;
		newDivMess["xPosDiv"] = parseInt(pos["xPos"] + 0);
		newDivMess["yPosDiv"] = parseInt(pos["yPos"] + 0);
	}

	messDiv.innerHTML = getDymek(mess,typedymek);
	messDiv.style.visibility = "visible";
	switch(typedymek) {
		case 1: 
			pos["yPos"] -= parseInt(messDiv.offsetHeight + 0); 
			break;
		case 2: 
			pos["yPos"] -= parseInt(messDiv.offsetHeight + 0); 
			pos["xPos"] -= parseInt(messDiv.offsetWidth + 0);
			break;
		case 3: 
			pos["xPos"] -= parseInt(messDiv.offsetWidth + 0); 
			break;
	}
	messDiv.style.left = pos["xPos"] + xsm * width + "px";
	messDiv.style.top  = pos["yPos"] + ysm * height + "px";

	if (messDymekCreate) {
		newDivMess["messName"] = messDivName;
		newDivMess["xPosMess"] = parseInt(messDiv.style.left + 0);
		newDivMess["yPosMess"] = parseInt(messDiv.style.top + 0);
		showMessTab.push(newDivMess);
	}
	
	recalcMessDives();
}



//----------------------------------------------------------------
function getDymek(mess,type) {
	mess = '<h3>'+mess+'</h3>';

	switch(type) {
		case 0:
		return '<table border="0" cellpadding="0" cellspacing="0"><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek1.gif" width="19" height="23" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek2.gif" height="23"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek3.gif" width="11" height="23" border="0" ></td></tr><tr><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek4.gif"></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek5.gif">'+mess+'</td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek6.gif"></td></tr><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek7.gif" width="19" height="6" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek8.gif" height="6"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/0/dymek9.gif" width="11" height="6" border="0" ></td></tr></table>';
		break;

		case 1:
		return '<table border="0" cellpadding="0" cellspacing="0"><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek1.gif" width="19" height="6" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek2.gif" height="6"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek3.gif" width="11" height="6" border="0" ></td></tr><tr><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek4.gif"></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek5.gif">'+mess+'</td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek6.gif"></td></tr><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek7.gif" width="19" height="23" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek8.gif" height="23"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/1/dymek9.gif" width="11" height="23" border="0" ></td></tr></table>';
		break;

		case 2:
		return '<table border="0" cellpadding="0" cellspacing="0"><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek1.gif" width="11" height="6" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek2.gif" height="6"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek3.gif" width="19" height="6" border="0" ></td></tr><tr><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek4.gif"></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek5.gif">'+mess+'</td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek6.gif"></td></tr><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek7.gif" width="11" height="23" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek8.gif" height="23"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/2/dymek9.gif" width="19" height="23" border="0" ></td></tr></table>';
		break;

		case 3:
		return '<table border="0" cellpadding="0" cellspacing="0"><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek1.gif" width="11" height="23" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek2.gif" height="23"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek3.gif" width="19" height="23" border="0" ></td></tr><tr><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek4.gif"></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek5.gif">'+mess+'</td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek6.gif"></td></tr><tr><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek7.gif" width="11" height="6" border="0" ></td><td background="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek8.gif" height="6"></td><td><img src="http://'+mDom+'/files/'+lexLang+'/'+gVer+'/dymek/3/dymek9.gif" width="19" height="6" border="0" ></td></tr></table>';
		break;
	}

}

//----------------------------------------------------------------
function encodeMess(mess) {
	return replaceAll("'","--apos1--",replaceAll("\"","--apos--",replaceAll("\r","--r--",replaceAll("\n","--n--",replaceAll(";","--sred--",mess)))));
}


//----------------------------------------------------------------
function decodeMess(mess,isHTML) {
	var dividder = "-mEsS-";
	mess = replaceAll("--apos1--","'",replaceAll("--apos--","\"",replaceAll("--r--","\r",replaceAll("--n--","\n",replaceAll("--sred--",";",mess)))))
	if (mess.indexOf(dividder) === -1) {
		if (! isHTML)
			return mess;
		else return replaceAll("\n","<br>",replaceAll("\r","<br>",replaceAll("\r\n","<br>",replaceAll("\r\n","<br>",mess))));
	} else {
		var ddiv = mess.indexOf(dividder);
		var m1 = mess.substr(0,ddiv);
		var m2 = mess.substr(ddiv+dividder.length);
		if (! isHTML)
			return m1+wordwrap(m2,50,"\n");
		else return m1+wordwrap(replaceAll("\n","<br>",replaceAll("\r","<br>",replaceAll("\r\n","<br>",replaceAll("\r\n","<br>",m2)))),50,"<br>");
	}
}

//----------------------------------------------------------------
function saveMess() {

	var imgDiv = getElem("mainpict");
	if (imgDiv == null)
		return;
	var messDiv = getElem("mess");
	if (messDiv == null)
		return;
	var messText = getElem("messarea");
	var saveMessElem = getElem("saveMess");

	if (messText.value.length > 200) {
		alert("Tekst opisu nie może przekraczać 200 znaków.\nAktualnie wprowadzony opis zawiera "+messText.value.length+" znaków.\n\nProszę poprawić opis przed zapisaniem");
		return;
	}

	var uri = "&pictId="+pictId;
	uri += "&mType="+mType;

	var xcrd=0;
	var ycrd=0;

	switch(mType) {
		case 1: 
			ycrd = parseInt(messDiv.offsetHeight + 0); 
			break;
		case 2: 
			ycrd = parseInt(messDiv.offsetHeight + 0); 
			xcrd = parseInt(messDiv.offsetWidth + 0);
			break;
		case 3: 
			xcrd = parseInt(messDiv.offsetWidth + 0); 
			break;
	}



	var xsm = (parseInt(messDiv.style.left+0) - parseInt(imgDiv.offsetLeft+0) + xcrd)/parseInt(imgDiv.offsetWidth + 0);
	uri += "&xsm="+Math.min(Math.max(0,xsm),1);


	var ysm = (parseInt(messDiv.style.top+0) - parseInt(imgDiv.offsetTop+0) + ycrd)/parseInt(imgDiv.offsetHeight + 0);
	uri += "&ysm="+Math.min(Math.max(0,ysm),1);

	uri += "&mess=" + encodeMess(messText.value);
	saveMessElem.disabled = true;
	saveMessElem.value="... zapisywanie ...";
	location.replace("/index.html?show=picturesmess&save=true"+uri);
}


//----------------------------------------------------------------
function deleMess() {
	var imgDiv = getElem("mainpict");
	if (imgDiv == null)
		return;
	var messDiv = getElem("mess");
	if (messDiv == null)
		return;
	var messText = getElem("messarea");
	var deleMessElem = getElem("deleMess");
	messText.value="";

	var uri = "&pictId="+pictId;
	uri += "&mType="+mType;

	var xcrd=0;
	var ycrd=0;

	switch(mType) {
		case 1: 
			ycrd = parseInt(messDiv.offsetHeight + 0); 
			break;
		case 2: 
			ycrd = parseInt(messDiv.offsetHeight + 0); 
			xcrd = parseInt(messDiv.offsetWidth + 0);
			break;
		case 3: 
			xcrd = parseInt(messDiv.offsetWidth + 0); 
			break;
	}



	var xsm = (parseInt(messDiv.style.left+0) - parseInt(imgDiv.offsetLeft+0) + xcrd)/parseInt(imgDiv.offsetWidth + 0);
	uri += "&xsm="+Math.min(Math.max(0,xsm),1);


	var ysm = (parseInt(messDiv.style.top+0) - parseInt(imgDiv.offsetTop+0) + ycrd)/parseInt(imgDiv.offsetHeight + 0);
	uri += "&ysm="+Math.min(Math.max(0,ysm),1);

	uri += "&mess=" + encodeMess(messText.value);
	deleMessElem.disabled = true;
	deleMessElem.value="... zapisywanie ...";
	location.replace("/index.html?show=picturesmess&save=true"+uri);
}

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
	if  (document.getElementById) {
		(function() {

			if (window.opera) 
				document.write("<input type='hidden' id='Q' value=' '>");

			var dragok = false;
			var y,x,d,dy,dx;

			function move(e){
				if (!e) e = window.event;
				if (dragok) {
					d.style.left = dx + e.clientX - x + "px";
					d.style.top  = dy + e.clientY - y + "px";
					var navi = getElem("navi");
					if (navi) {
						currentDivName = d.id;
						navi.style.visibility = "visible";
						navi.style.left = dx + e.clientX - x + "px";
						navi.style.top  = dy + e.clientY - y + "px";
					}
					return false;
				}
			}

			function down(e) {
				if (!e) e = window.event;
				var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
				while ((typeof temp != "undefined") && (temp.tagName != "HTML"|"BODY") && (temp.className != "dragclass")) 
					temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;


				if (temp.className == "dragclass") {
					if (window.opera) 
						document.getElementById("Q").focus();
					dragok = true;
					imagesMaxZIndex++;
					temp.style.zIndex = imagesMaxZIndex;
					d = temp;
					dx = parseInt(temp.style.left+0);
					dy = parseInt(temp.style.top+0);
					x = e.clientX;
					y = e.clientY;
					var navi = getElem("navi");
					if (navi) {
						currentDivName = d.id;
						navi.style.visibility = "visible";
						navi.style.left = dx + "px";
						navi.style.top  = dy + "px";
					}
					document.onmousemove = move;
					return false;
				}
			}

			function up() {
				dragok = false;
				document.onmousemove = null;
			}


			document.onmousedown = down;
			document.onmouseup = up;

		})();
	}



