var ETest  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

function changeFacebookStatus(url)
{       
	//tekst = "<div style=\"clear: both; width: 220px; margin: 0px 0 0px 0px;\"><a name=\"fb_share\" type=\"button\" share_url=\"" + url + "\" href=\"http://www.facebook.com/sharer.php?t=Projekt domu\">Udost^epnij</a><div style=\"margin-top: -20px; margin-left: 120px;\"><iframe src=\"http://www.facebook.com/plugins/like.php?href=" + url + "&amp;layout=button_count&amp;show_faces=false&amp;width=250&amp;action=like&amp;colorscheme=light&amp;height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:250px; height:21px;\" allowTransparency=\"true\"></iframe></div></div>";

	tekst = "<div style=\"clear: both; width: 120px; margin: 0px 0 0px 0px;\"><a name=\"fb_share\" type=\"icon\" share_url=\"" + url + "\" href=\"http://www.facebook.com/sharer.php?t=Projekt domu\" title=\"Udost^epnij na Facebook'u\">Udost^epnij</a><div style=\"margin-top: -20px; margin-left: 20px;\"><iframe src=\"//www.facebook.com/plugins/like.php?href=" + url + "&amp;send=false&amp;layout=button_count&amp;width=250&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=tahoma&amp;height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:450px; height:21px;\" allowTransparency=\"true\"></iframe></div></div>";

        document.getElementById('fb-root').innerHTML = tekst;

}

function doPic(imgName, imgBig)
{
   imgOn = imgName;
   Widok = imgBig;
   document.getElementById('widok').src = imgOn;
}

function doWidok(imgBig, id)
{
   document.getElementById('grafika').src = ("../pliki/" + id + "/widoki/" + imgBig);
}

function displayWindowWR(url, width, height, nazwa, id, rzut)
{
   window.open(url + '&nazwap=' + nazwa + '&idp=' + id + '&rzut=' + rzut ,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayPromesa(url, width, height, nazwa)
{
   window.open(url + '?nazwa=' + nazwa ,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=yes,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayCharakterystyka(url, width, height, nazwa)
{
   window.open(url + '?nazwa=' + nazwa ,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=yes,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayWindow(url, width, height)
{
   window.open(url,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayLustro(url, width, height)
{
   window.open(url,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayTablica(nazwa, width, height)
{
   window.open(strona + "/popUp/tablica.php?nazwa=" + nazwa,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function displayArchPakiet(nazwa, width, height)
{
   window.open(strona + "/popUp/archpakiet.php?nazwa=" + nazwa,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=no,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function display(url)
{
   window.open(url,'','');
   return false;
}

function promocja_func(co,gdzie) {
var pokaz = 'pokaż';
var ukryj = 'ukryj';
	if(document.getElementById(gdzie).innerHTML == pokaz) {
		document.getElementById(co).style.display = "block";
		document.getElementById(gdzie).innerHTML = ukryj;
	} else {
		if(document.getElementById(gdzie).innerHTML == ukryj) {
			document.getElementById(co).style.display = "none";
			document.getElementById(gdzie).innerHTML = pokaz;
		}
	}
}

function setCheckboxes(the_form, do_check)
{
    var elts      = document.forms[the_form].elements['notes[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        }
    } else {
        elts.checked        = do_check;
    }

    return true;
}


function notes_submit(val)
{
   document.getElementById('sub').value = val;
   
   if (val == 2)
      document.forms['notesik'].target='_blank';
   else
      document.forms['notesik'].target='_self';
      
   document.forms['notesik'].submit();
}

function pokaz_regulamin(url, width, height)
{
   window.open(url,"displayWindow",'width=' + width + ',height=' + height +
      ',resizable=no,scrollbars=yes,menubar=no,personalbar=no,toolbar=no,' +
      'status=no' );
}

function zglosreklamacje()
{
   error = '';
   if (document.getElementById('imie').value == '') error += "Podaj imie i nazwisko\n";
   if (document.getElementById('tresc').value == '') error += "Podaj czego dotyczy reklamacja\n";
   if (!ETest.test(document.getElementById('mejl').value)) error += "Podaj poprawny adres e-mail.\n";
   if (document.getElementById('zgoda').checked != 1) error += "Aby wys^3aae zg^3oszenie musisz zgodziae\n si^e na wykorzystanie twoich danych.\n";

   if (error != '')
   {
      alert (error);
      return false;
   }
   else
      return true;
}

function zglosblad()
{
   error = '';
   if (document.getElementById('tresc').value == '') error += "Podaj opis bledu\n";
   if (document.getElementById('lnk').value == '') error += "Podaj link do bledu\n";
   if (!ETest.test(document.getElementById('mejl').value)) error += "Podaj poprawny adres e-mail.\n";
   
   if (error != '')
   {
      alert (error);
      return false;
   }
   else
      return true;
}

function polaczenie_szyfrowane()
{
	if (location.protocol=="http:") {
  		location.href = location.href.replace(/^http:/, "https:")
	}
}

function polaczenie_nieszyfrowane()
{
	if (location.protocol=="https:") {
  		location.href = location.href.replace(/^https:/, "http:")
	}
}

function zgoda_func(co,gdzie) {
var pokaz = 'pokaż';
var ukryj = 'ukryj';
	if(document.getElementById(gdzie).innerHTML == pokaz) { 
		document.getElementById(co).style.display = "block";
		document.getElementById(gdzie).innerHTML = ukryj;
	} else {
		if(document.getElementById(gdzie).innerHTML == ukryj) { 
			document.getElementById(co).style.display = "none";
			document.getElementById(gdzie).innerHTML = pokaz;
		}
	}
}

function promocja_mtm_func(co,gdzie) {
var pokaz = 'pokaż';
var ukryj = 'ukryj';
	if(document.getElementById(gdzie).innerHTML == pokaz) { 
		document.getElementById(co).style.display = "block";
		document.getElementById(gdzie).innerHTML = ukryj;
	} else {
		if(document.getElementById(gdzie).innerHTML == ukryj) { 
			document.getElementById(co).style.display = "none";
			document.getElementById(gdzie).innerHTML = pokaz;
		}
	}
}

function main_zakladki(co) {
	document.getElementById('main_zakladki_1').style.display = "none";
	document.getElementById('main_linki_1').style.fontWeight = "normal";
	document.getElementById('main_linki_1').style.color = "black";
	document.getElementById('main_zakladki_2').style.display = "none";
	document.getElementById('main_linki_2').style.fontWeight = "normal";
	document.getElementById('main_linki_2').style.color = "black";
	document.getElementById('main_zakladki_3').style.display = "none";
	document.getElementById('main_linki_3').style.fontWeight = "normal";
	document.getElementById('main_linki_3').style.color = "black";
	
	document.getElementById('main_zakladki_' + co).style.display = "block";
	document.getElementById('main_linki_' + co).style.fontWeight = "bold";
	document.getElementById('main_linki_' + co).style.color = "red";
}

function fj_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=fj_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function fj_showHideLayers() {
  var i,p,v,obj,args=fj_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=fj_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function checkAll(name, name_form) {

	var checked = true;
		  
	if(document.getElementById(name).checked == false) checked = false;
		
		  
		 field = document.getElementById(name_form);
		  
		 for (i = 0; i < field.length; i++)
		 field.elements[i].checked = checked ;
}

var bluractive = false;

function str_replace (search, replace, subject, count) {
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = Object.prototype.toString.call(r) === '[object Array]',
        sa = Object.prototype.toString.call(s) === '[object Array]';
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i = 0, sl = s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j = 0, fl = f.length; j < fl; j++) {
            temp = s[i] + '';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length - s[i].length) / f[j].length;
            }
        }
    }
    return sa ? s : s[0];
}

function OnBlur () {
	if(bluractive) document.getElementById('sug_div').style.display='none';
}

function ajaxFunction(){
	var szukajnazwa = document.getElementById('nzw').value;
if(szukajnazwa.length > 0) {
	var sug_div = document.getElementById('sug_div');
	sug_div.innerHTML += '<p><img src="../gfx/ajax-loader.gif" width="50" height="50" /></p>';
	sug_div.style.display = "block";
	var ajaxRequest;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	//receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
 			if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		   		var sug_div = document.getElementById('sug_div');
 			  	var pl_z = new Array ('±','ę','ó','ł','Ľ','ż','¶','ć','ń',' ','(',')','"');
				var pl_na = new Array('a','e','o','l','z','z','s','c','n','_','','','');
				//clear document
				sug_div.innerHTML = '';
				var xmldoc = ajaxRequest.responseXML;
				var projekt_nodes = xmldoc.getElementsByTagName("projekt"); 
				var n_projekt = projekt_nodes.length;
				for (i = 0; i < n_projekt; i++) {
				  	var id = projekt_nodes[i].getAttribute('id');
					var nazwa_node = projekt_nodes[i].getElementsByTagName("nazwa");
					var nazwaurl = str_replace (pl_z, pl_na, nazwa_node[0].firstChild.nodeValue.toLowerCase());
					var thumb_node = projekt_nodes[i].getElementsByTagName("thumb");
					var pow_uz_node = projekt_nodes[i].getElementsByTagName("pow_uz");
					sug_div.innerHTML += '<table class="projekt" onclick="location.href=\''+strona+'/projekt_domu/'+nazwaurl+'/'+id+'\'"><tr onmouseover="this.className=\'over\'; bluractive=false;" onmouseout="this.className=\'out\'; bluractive=true;"><td><img class="miniatura" src="'+strona+'/pliki/'+ id +'/'+ thumb_node[0].firstChild.nodeValue + '" alt="Projekt domu '+thumb_node[0].firstChild.nodeValue+'" /></td><td><table><tr><td><strong>'+nazwa_node[0].firstChild.nodeValue+'</strong><span class="projektid"> - '+id+'</span></td></tr><tr><td class="dane">pow. użytkowa: <span>'+pow_uz_node[0].firstChild.nodeValue+'</span></td></tr></table></td></tr></table>';
				}
				if(n_projekt > 0) sug_div.style.display = "block";
			}
	}
	var param = 'nazwa=' + szukajnazwa;
	ajaxRequest.open("POST", strona+"/sugestions/getSugestions.php", true);
	ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-2');
	ajaxRequest.send(param);
} else {
	var sug_div = document.getElementById('sug_div');
	sug_div.style.display = "none";
}
}

