//////////////////////wspolne:
function visi_notatka(co)
	{
	document.getElementById(co).style.visibility = 'visible';
	}

function visi_pm(co)
	{
	document.getElementById(co).style.visibility = 'visible';
	}


function ClearInput(value, id)
	{ 
	var input = document.getElementById(id);

	if(value == input.value)
		{
		input.value = ''; // Empty It.
		}
	
	}

   function alertContents() {
      if (http_request.readyState == 4) {
		document.getElementById('myspan').innerHTML = '...Zapisuję wiadomość...';
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result; 
			repeatloop('funkcje/ajax_shoutbox_lista.php');
         } else {
		document.getElementById('myspan').innerHTML = '...Błąd wysyłania wiadomości?...';         }
      }
   }
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   function get(obj) {
      var poststr = "shout_tekst=" + encodeURIComponent( document.getElementById("wiadomosc").value );
      makePOSTRequest('osobne/shoutbox_post_ajax.php', poststr);
	  document.getElementById("wiadomosc").value='';
   }

function visi_post(co)
{

	document.getElementById(co).style.visibility = 'visible';
	document.getElementById('post_dodaj_top').style.visibility	= 'hidden';
	document.getElementById('post_dodaj_bottom').style.visibility = 'hidden';
}

function visi_temat(co)
{
	document.getElementById(co).style.visibility = 'visible';
	document.getElementById('temat_dodaj_top').style.visibility = 'hidden';
	document.getElementById('temat_dodaj_bottom').style.visibility = 'hidden';
}

function liczwpzn(textarea, gdzie, limit) 
	{
	gdzie.value = limit - textarea.value.length;
	}

function rozciag_menu(co)
	{
	for (i = 0;i<10; i++)
		{
		if(document.getElementById('menu'+co+i))
			{
			if(document.getElementById('menu'+co+i).style.display == 'none' )
				{
				document.getElementById('menu'+co+i).style.display = '';
				}
			  else
				{
				document.getElementById('menu'+co+i).style.display = 'none';
				} 
			}
		}
	}

function formatCurrency(num) 
	{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
	}


function czyscchecked()
	{
	//alert (document.forms['koszyk'].length);
	for (i = 0;i<document.forms['koszyk'].length; i++)
		{
		if (document.forms[0].elements[i].type=='checkbox')
			{
			document.forms[0].elements[i].defaultChecked ='';
			document.forms[0].elements[i].checked='';
			}
		}
	}
		
function skrotchange() 
	{
	document.form.submit();
	}

function visi_rss(co)
	{
	if(document.getElementById('tresc'+co))
		{
		if(document.getElementById('tresc'+co).style.display == 'none' )
			{
			document.getElementById('tresc'+co).style.display = '';
			document.getElementById('link'+co).style.display = '';
			}
		  else
			{
			document.getElementById('tresc'+co).style.display = 'none';
			document.getElementById('link'+co).style.display = 'none';
			} 
		}

	}


function bbcode_podmien(otw, zam,gdzie)
	{
	pole = document.getElementById(gdzie);
	// explorer
	if (document.selection && document.selection.createRange)
		{
		pole.focus();
		sel=document.selection.createRange();
		sel.text=otw+sel.text+zam;
		pole.focus();
		}
	// firefox
	else if (pole.selectionStart||pole.selectionStart=='0')
		{
		var poczatek=pole.selectionStart;
		var koniec=pole.selectionEnd;
		pole.value=pole.value.substring(0,poczatek)+otw+pole.value.substring(poczatek,koniec)+zam+pole.value.substring(koniec,pole.value.length);
		pole.selectionStart=pole.selectionEnd=koniec+otw.length+zam.length;
		pole.focus();
		}
	return;
	}

function shBlock(id)
{
var item;

item = document.getElementById(id);

if( item.style.display == 'none' || item.style.display == '')
{
item.style.display = 'block';
}
else
{
item.style.display = 'none';
}
}
 function parseRecordsZlecVirt(xml) {
        record = xml.getElementsByTagName("record");
			if (record.length==0) 
			{
			return;
			}
			
		result = "";
        d = document.getElementById("dataTable");
		for (i = d.rows.length-1; i >= 0; i--)	{d.deleteRow(i);}

		for (i = 0; i < record.length; i++) {
			tr = document.createElement("tr");
				for (j = 0; j < 8 ;j++) 
					{
					td = document.createElement("td");
					td.innerHTML =record[i].childNodes[j].childNodes[0].nodeValue;			
					tr.appendChild(td);
					}
		
		    d.appendChild(tr);
		}
        info = xml.getElementsByTagName("info");
			if (info.length==0) 
			{
			return;
			}
			

		tr = document.createElement("tr");
		td = document.createElement("td");
		td.setAttribute("colspan","6");
		td.innerHTML ="Min: "+info[0].childNodes[0].childNodes[0].nodeValue+" Max: "+info[0].childNodes[1].childNodes[0].nodeValue+ " Wol: " +info[0].childNodes[2].childNodes[0].nodeValue+" Obr: "+info[0].childNodes[3].childNodes[0].nodeValue;

		tr.appendChild(td);
		d.appendChild(tr);
		return result;
    }


    function parseRecordsShout(xml) {
        record = xml.getElementsByTagName("record");
			if (record.length==0) 
			{
			document.title = 'GraGiełdowa.pl - Wirtualna Gra Giełdowa';
			return;
			}
			
		result = "";
        d = document.getElementById("dataTable");
		for (i = d.rows.length-1; i >= 0; i--)	{d.deleteRow(i);}
		document.title = 'Shoutbox - Nowa wiadomość';

		for (i = 0; i < record.length; i++) {
			if (i%2==0)
				{
				tr = document.createElement('tr');
				tr.setAttribute('class','shout_odd');
				}
			if (i%2!=0)
				{
				tr = document.createElement('tr');
				}
			
				td = document.createElement("td");
				td.innerHTML =record[i].childNodes[0].childNodes[0].nodeValue;			
				td.setAttribute('class','shout_time');
				tr.appendChild(td);

				td = document.createElement("td");

				login=record[i].childNodes[1].childNodes[0].nodeValue;
				login="<nobr>"+login+"</nobr>";
td.innerHTML = "<a class='forum_profil_link' href='?go=p_profil&login="+record[i].childNodes[1].childNodes[0].nodeValue+"'>"+login+"</a>";	
				td.setAttribute('class','shout_login');
				tr.appendChild(td);
				
				td = document.createElement("td");
				td.innerHTML = record[i].childNodes[3].childNodes[0].nodeValue;		
				td.setAttribute('class','shout_message');
				tr.appendChild(td);
			    d.appendChild(tr);
		}
        return result;
    }
function parseRecordsShoutTest(xml) 
	{
    record = xml.getElementsByTagName("record");
	if (record.length==0) 
		{
		document.title = 'GraGiełdowa.pl - Wirtualna Gra Giełdowa';
		return;
		}
	lista	=document.getElementById("shoutbox_wiadomosci").innerHTML;
	document.title = 'Shoutbox - Nowa wiadomość';
	for (i = 0; i < record.length; i++) 
		{
		login=record[i].childNodes[1].childNodes[0].nodeValue;
		lista = lista+'<span class="shout_time">'+record[i].childNodes[0].childNodes[0].nodeValue+'</span>';
		lista = lista+'<a class="forum_profil_link" href="?go=p_profil&login='+record[i].childNodes[1].childNodes[0].nodeValue+'">'+login+'</a>';	
		lista = lista+'<span class="shout_message">'+record[i].childNodes[3].childNodes[0].nodeValue+'</span><br/>';
		}
	document.getElementById("shoutbox_wiadomosci").innerHTML =lista;
	setScrollBottom();
	return 1;
    }
    function getRecords(parametr) 
		{
    
        advAJAX.get(
			{
            url : parametr,
            onInitialization : function() 
				{
	            },

			onSuccess : function(obj) 
				{
				if (parametr=='funkcje/ajax_shoutbox_lista.php')
					{
					parseRecordsShout(obj.responseXML);
					}
				if (parametr=='osobne/not_virtual.php')
					{
					parseRecordsZlecVirt(obj.responseXML);
					}
		       }
			});
		}

   function getRecords_test(parametr) 
		{
    
        advAJAX.get(
			{
            url : parametr,
            onInitialization : function() 
				{
	            },

			onSuccess : function(obj) 
				{
				if (parametr=='osobne/shoutbox_lista_ajax.php')
					{
					parseRecordsShoutTest(obj.responseXML);
					}
				if (parametr=='osobne/not_virtual.php')
					{
					parseRecordsZlecVirt(obj.responseXML);
					}
		       }
			});
		}


function repeatloop(parametr)
{
getRecords(parametr); 
}


function repeatloop2(parametr)
{
getRecords_test(parametr); 
}

function setScrollBottom()
{
var scrolledDiv = document.getElementById('shoutbox_wiadomosci');
scrolledDiv.scrollTop = scrolledDiv.scrollHeight;
}