
//
//	PRZEKIEROWANIE MAILTO
//
	
mailto = function(hex_string)
{
	if(hex_string){
		var chars = new Array();
		
		for(i = 0; i < hex_string.length; i = i + 2)
		{
			chars.push(parseInt(hex_string.substr(i, 2), 16));
		}
		
		document.location = 'mailto:' + eval('String.fromCharCode(' + chars.join(',') + ');');
	} else
		alert('Autor komentarza nie podał adresu e-mail.');
}

//
//	PRZELACZANIE MENU
//

var default_menu;
var last_active_menu;
var active_timeout;

set_default_menu = function()
{		
	if(last_active_menu)
		last_active_menu.className = '';
	
	if(default_menu)
		default_menu.className = 'menu_hover';
	
	last_active_menu = default_menu;
}

menu_switch = function(menu_id)
{
	var menu = document.getElementById(menu_id).firstChild;
	var nodes = menu.childNodes;
	
	for(i = 0; i < nodes.length; i++)
	{
		if(nodes[i].tagName && nodes[i].tagName == 'LI')
		{	
			if(nodes[i].className == 'menu_active')
			{
				default_menu = nodes[i];
				last_active_menu = default_menu;
			}
			
			nodes[i].onmouseover = function()
			{	
				if(active_timeout)
					clearTimeout(active_timeout);
				
				if(last_active_menu)
					last_active_menu.className = '';
				
				last_active_menu = this;
				this.className = 'menu_hover';
			}
			
			nodes[i].onmouseout = function()
			{	
				if(last_active_menu != default_menu)
					active_timeout = setTimeout('set_default_menu()', 2500);
			}
		
		}
	}
	
}
	
//
//	PRZEKIEROWANIE
//

docLoc = function(loc, base){
	document.location.href = 'http://' + document.location.hostname + document.location.pathname.substring(0, document.location.pathname.lastIndexOf('/') + 1) + loc;
}

//
// KONTROLA DLUGOSCI WPISU
//

wordControl = function(objName, maxWordLength, maxAllLength){
	var currentWord, wordLengthTab, obj;
	
	this.currentWord = '';
	this.wordLengthTab = new Array();
	this.obj = document.getElementById(objName);
	this.maxWordLength = maxWordLength;
	this.maxAllLength = maxAllLength;
	
	this.lengthTab = function(){
		var wordTab = this.obj.value.split(' ');
		
		for(i=0; i < wordTab.length; i++){
			this.wordLengthTab[i] = wordTab[i].length;
		}
	}
	
	this.textLength = function(){
		if(this.obj.value.length > this.maxAllLength){
			this.obj.value = this.obj.value.slice(0, this.maxAllLength);
			
			return false;
		} else {
			return true;
		}
	}
	
	this.wordLength = function(){
		this.textLength();
	
		var wordTab = this.obj.value.split(' ');
		
		if(wordTab.length > this.wordLengthTab.length){
			this.currentWord = wordTab[wordTab.length - 1];
		} else {
			for(i=0; i < wordTab.length; i++){
				if(wordTab[i].length != this.wordLengthTab[i]){
					this.currentWord = wordTab[i];
				}
			}
		}
		
		if(this.currentWord.length > this.maxWordLength){			
			for(i = 0; i < wordTab.length; i++){
				if(wordTab[i].length > this.maxWordLength){
					wordTab[i] = wordTab[i].slice(0, maxWordLength)+' '+wordTab[i].slice(maxWordLength);
				}
			}
			
			this.obj.value = wordTab.join(' ');
		}
		
		for(i = 0;i < wordTab.length; i++){
			this.wordLengthTab[i] = wordTab[i].length;
		}
	}
}

//
//	OKNO
//

function okno(url, name, width, height, scrolls){
	eval(name + " = window.open(url, name, 'width='+width+',height='+height+',scrollbars='+(scrolls ? scrolls : 'yes'));");
}

//
//	WSKAŹNIK SIŁY HASŁA
//

silaHasla = function(passFieldId, indFieldId){
	var passField = document.getElementById(passFieldId).value, indField = document.getElementById(indFieldId),
	labels = new Array('<span style="color:#999999">zbyt krótkie - min 6 znaków</span>',
			'<span style="color:#FF0000">bardzo słabe</span>',
			'<span style="color:#FF9900">słabe</span>',
			'<span style="color:#009900">dobre</span>',
			'<span style="color:#0066FF">bardzo dobre</span>');
	
	//	min dlugosc 6 znakow
	if(passField.length < 6){
		indField.innerHTML = labels[0];
	} else {
		indField.innerHTML = labels[1];
		
		for(i = 0; i < passField.length - 1; i++){
			// te same znaki
			if(passField.charAt(i + 1) != passField.charAt(i)){
				indField.innerHTML = labels[2];
				
				// wyrazenie alfanumeryczne i rozne wielkosci znakow
				if((passField != passField.toLowerCase() && passField != passField.toUpperCase()) || passField.match(/\d/g).length < passField.length){
					indField.innerHTML = labels[3];
					
					// specjalne
					if(passField.match(/[^a-z0-9]+/gi)){
						indField.innerHTML = labels[4];
					}	
				}
				
				break;
			}
		}
	}
}

//
//	GENERATOR LOSOWYCH HASEL
//

genHasla = function(passFieldId) {
	var pass = '', passLength = 6, charCode;
	
	while(pass.length <= passLength){
		charCode = Math.floor(Math.random()*1000);
		
		if((charCode >= 48 && charCode <= 57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122)){
			pass += String.fromCharCode(charCode);	
		}
	}
	
	if(confirm('Twoje wygenerowane hasło to: '+pass+'\nCzy chcesz go użyć?')){
		document.getElementById(passFieldId).value = pass;
	}
}