
function showhide(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'none')
	e.style.display = 'block';
	else
	e.style.display = 'none';
}


 // Retrieve last key pressed.  Works in IE and Netscape.  
 // Returns the numeric key code for the key pressed.  
 function getKey(e)  
 {  
	 if (window.event)  
		return window.event.keyCode;  
	 else if (e)  
		return e.which;  
	 else  
		return null;  
 }  
 // Returns true if the last key pressed was a member of the valid character list,  
 // or a control key.  Useful to restrict input in a text box when used in conjunction  
 // with the onKeyPressed() event.  
 //  
 // <INPUT NAME=INT onKeyPress="return restrictChars(event,'0123456789')">  
 //  
 // Above will allow only numeric input into the text box. This function is   
 // case insensitive so including "A" in the list is equivalent to "a".  
 function restrictChars(e, validList)  
 {  
	 var key, keyChar;  
	 key = getKey(e);  
	 if (key == null) return true;  
	 // get character - remove toLowerCase for case sensitive checking  
	 keyChar = String.fromCharCode(key).toLowerCase();  
	 // check valid characters - remove toLowerCase for case sensitive checking  
	 if (validList.toLowerCase().indexOf(keyChar) != -1)  
	 return true;  
	 // control keys  
	 // null, backspace, tab, carriage return, escape  
	 if ( key==0 || key==8 || key==9 || key==13 || key==27 )  
		return true;  
	 // else return false  
	 return false;  
 }  
 
 function numericOnly( e)  
 {  
	return restrictChars( e, "0123456789");  
 }  
   
 function alphanumericOnly( e)  
 {  
	return restrictChars( e, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");  
 } 
function refresh () {
		  $.ajax(
		  {
			type: 'post',
			url:  'shoutbox.refresh.php',
			success: function(response) { replaceSchoutbox(response); },
			errorr: function() {}
		  });
}

function replaceSchoutbox(response) {	
	var old_content	= $('#sh_content');
		response = $(response);
		//console.log("STARE: \n" + $('#sh_content').html());
		//console.log("\nNOWE: \n"+response.html());
		if (old_content.html() != response.html())
		{
			$('#shoutbox_body').fadeOut(500, function() {
				old_content.after(response);
				old_content.remove();
				$('#shoutbox_body').fadeIn(500);
				});
		}			
}
setInterval(refresh,300000);


function load_snews (pg,user,style) {
		  $.ajax(
		  {
			type: 'post',
			url:  'get.snews.php?spg='+pg+'&user='+user+'&style='+style,
			success: function(response) { replaceSnews(response); },
			errorr: function() {}
		  });
}

function replaceSnews(response) {	
	var old_content	= $('#service_content');
		response = $(response);
		//console.log("STARE: \n" + $('#sh_content').html());
		//console.log("\nNOWE: \n"+response.html());
			$('#service').fadeOut(500, function() {
				old_content.after(response);
				old_content.remove();
				$('#service').fadeIn(500);
				});		
					$('#service').css('height','auto');
}
  
 function load_news (pg,user,style) {
		  $.ajax(
		  {
			type: 'post',
			url:  'get.news.php?pg='+pg+'&user='+user+'&style='+style,
			success: function(response) { replacenews(response); },
			errorr: function() {}
		  });
} 

function replacenews(response) {	
	var old_content	= $('#akt_content');
		response = $(response);
		//console.log("STARE: \n" + $('#sh_content').html());
		//console.log("\nNOWE: \n"+response.html());
			$('#aktualnosci').fadeOut(500, function() {
				old_content.after(response);
				old_content.remove();
				$('#aktualnosci').fadeIn(500);
				});		
					$('#aktualnosci').css('height','auto');
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

 
function resize(size) {
	if(size>0)
	{
		$('body').attr('style','font-size: '+size+'px');
	}
	createCookie('resizer',size,7);
} 