/*
setImage - funkcja podmieniajaca obrazek na inny   np. po najechaniu na niego myszka
wywołanie: <img src="/images/menu/1_test.jpg" name="test"  onmouseover="setImage(this.name,'/images/menu/2_test.jpg')" onmouseout="setImage(this.name,'/images/menu/1_test.jpg')" />
docName - parametr 'name' elementu 'img'
filePath - ścieżka do nowego pliku  (np.: /images/menu/obrazek.jpg)
*/
function setImage(docName,filePath)
{
	eval("document."+docName+".src =\""+filePath+"\"");
}
/*********************************************************************************************/
function setImage2(docName,filePath)
{
	eval("form."+docName+".src =\""+filePath+"\"");
}
/*********************************************************************************************/
function setImage_menu(docID,filePath)
{
	eval("document.getElementById(\"+docID+\").src=\""+filePath+"\"");
}

function setPhoto(photo){
	document.images.photoView.src=photo
}
/*********************************************************************************************/
function getSelection(ta)
{

	var bits = [ta.value,'','',''];
    if(document.selection)
    {
		var vs = '#$%^%$#';
        var tr=document.selection.createRange();
        if(tr.parentElement()!=ta) return null;
        bits[2] = tr.text;
        tr.text = vs;
        fb = ta.value.split(vs);
        tr.moveStart('character',-vs.length);
        tr.text = bits[2];
        bits[1] = fb[0];
        bits[3] = fb[1];
      }
    else
      {

	  if(ta.selectionStart == ta.selectionEnd) { return null; }
		bits=(new RegExp('([^]{'+ta.selectionStart+'})([^]{'+(ta.selectionEnd - ta.selectionStart)+'})([^]*)')).exec(ta.value);
		//alert(bits[0]+"|||||"+bits[1]+"|||||"+bits[2]+"|||||"+bits[3]);
      }
     return bits;
}

function matchPTags(str)
{
	str = ' ' + str + ' ';
    ot = str.split(/\[[B|U|I].*?\]/i);
    ct = str.split(/\[\/[B|U|I].*?\]/i);
    return ot.length==ct.length;
}

function addPTag(ta,pTag)
{

	bits = getSelection(ta);
	if(bits)	// gdy zaznaczono tekst
	{
		if(!matchPTags(bits[2]))
	    {
			alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
	        return;
	    }

		if(pTag == '|' || pTag == 'Space' || pTag == 'BR')
		{
			ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '' + bits[3];
		}
		else if(pTag!='A')
		{
			ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
		}
		else   //dla linków:
		{
			var href=prompt("Podaj adres strony:","http://");
			if (href!=null && href!="" && href!="http://")
			{
				ta.value = bits[1] + '[A href="' + href + '"]' + bits[2] + '[/A]' + bits[3];
			}
		}
	}
	else	//gdy brak zaznaczenia
	{
		var bits = [ta.value,'','',''];
	    if(document.selection)
	    {
			ta.focus();
			var tr=document.selection.createRange();

		}
		else
		{
			bits=(new RegExp('([^]{'+ta.selectionStart+'})([^]{'+(ta.selectionEnd - ta.selectionStart)+'})([^]*)')).exec(ta.value);
		}

		if(pTag == '|' || pTag == 'Space' || pTag == 'BR')
		{
			if(document.selection)
			{
				tr.text =  '[' + pTag + ']';
			}
			else
			{
				ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '' + bits[3];
			}
		}
		else if(pTag!='A')
		{
			if(document.selection)
			{
				tr.text =  '[' + pTag + ']' + '[/' + pTag + ']';
			}
			else
			{
				ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
			}
		}
		else 	//dla linków:
		{
			var href=prompt("Podaj adres strony:","http://");
			if (href!=null && href!="" && href!="http://")
			{
				var anchor=prompt("Opis linku:","");
				if (anchor!=null && anchor!="")
				{
					if(document.selection)
					{
						tr.text =  '[A href="' + href + '"]' + anchor + '[/A]' ;
					}
					else
					{
						ta.value = bits[1] + '[A href="' + href + '"]' + anchor + '[/A]' + bits[3];
					}
				}
			}
		}

	}

}
/*********************************************************************************************/
function displayImage(url,title,opcje_w,opcje_h)
{
	var centerWidth = (window.screen.width - opcje_w) / 2;
    var centerHeight = (window.screen.height - opcje_h) / 2;

	noweOkno = window.open( url , title,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+ opcje_w +', height='+ opcje_h + ',left=' + centerWidth + ',top=' + centerHeight);
}
/*********************************************************************************************/
function openNewWindow(url,title,opcje_w,opcje_h)
{
	var centerWidth = (window.screen.width - opcje_w) / 2;
    var centerHeight = (window.screen.height - opcje_h) / 2;

	noweOkno = window.open(url,title,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+ opcje_w +', height='+ opcje_h + ',left=' + centerWidth + ',top=' + centerHeight);
}
/*********************************************************************************************/
// sprawdzenie wypelnienia wszystkich pol formularza
function sprawdz(formularz)
{
	   for (i = 0; i < formularz.length; i++)
       {
              var pole = formularz.elements[i];
              if ((pole.type == "text" || pole.type == "password" || pole.type == "textarea" ) && pole.value == "")
              {
					alert("Proszę wypełnić wszystkie pola formularza.");
					return false;
              }
       }
       return true;
}
/*********************************************************************************************/
/*********************************************************************************************/
function scrollTop() {
	if (window.pageYOffset != undefined) return window.pageYOffset;
	if (document.documentElement.scrollTop != undefined) return document.documentElement.scrollTop;
	if (document.body.scrollTop != undefined) return document.body.scrollTop;
	return 0;
}

function show(what) {

	//document.getElementById('big_img').src = '../img/loading.gif';
	//document.getElementById('img_desc').innerHTML = 'Wczytywanie...';
	document.getElementById('img_div').style.display='block';
	document.getElementById('img_div').style.top = scrollTop() + 100 + 'px';

	var img = new Image;
	img.onload = document.getElementById('big_img').src = what;
}

function hide() {
	document.getElementById('img_div').style.display='none';
}
/*********************************************************************************************/
/************** GOOGLE MAPS ***************************************************************/

function createMarker(point, number) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(number);});
return marker;
}

function initialize() {
	
	map = new GMap2(document.getElementById("google_map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(52.178670,21.691250), 12);
	var point = new GLatLng(52.178670,21.691250);
	map.addOverlay(createMarker(point, '<b>Specjalny Ośrodek Wychowawczy</b><br/><br/>Ignaców 10<br/>tel. (025) 759 23 82'));
	map.setMapType(G_MAP_TYPE);
}

/********************************************************************************************/
