var from = new Array(' ', 'Ę', 'Ó', 'Ą', 'Ś', 'Ł', 'Ż', 'Ź', 'Ć', 'Ń', 'ę', 'ó', 'ą', 'ś', 'ł', 'ż', 'ź', 'ć', 'ń', '£', '§', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '{', '[', '}', ']', ';', ':', '\'', '"', '\\', '|', '<', ',', '>', '.', '?', '/', '~', '`');
var to = new Array('_', 'e', 'o', 'a', 's', 'l', 'z', 'z', 'c', 'n', 'e', 'o', 'a', 's', 'l', 'z', 'z', 'c', 'n', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');

function file_exists (url) {
    // Returns true if filename exists  
    // 
    // version: 1102.614
    // discuss at: http://phpjs.org/functions/file_exists
    // +   original by: Enrique Gonzalez
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // %        note 1: Synchronous so may lock up browser, mainly here for study purposes. 
    // *     example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
    var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) {
        throw new Error('XMLHttpRequest not supported');
    }
 
    // HEAD Results are usually shorter (faster) than GET
    req.open('HEAD', url, false);
    req.send(null);
    if (req.status == 200) {
        return true;
    }
 
    return false;
}

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 1102.614
    // discuss at: http://phpjs.org/functions/str_replace
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = r instanceof Array,
        sa = s instanceof 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 imgPreview(target,src,alternate)
 		{
 			//if(file_exists(src)) {
 				$('img.'+target).attr('src',src);
 			//}
 			//else {
			//$('img.'+target).src = alternate;
 			//}
 		}

	function complete(content, target, preview) {
    
        if(!preview)
        document.getElementById(target).value = content;
        else
        document.getElementById(target).innerHTML = content;

    }
    
    function addHttp(obj,content) {
    
    	var begin = content.substring(0,7);
    	if(begin!='http://')
    		obj.value = 'http://'+obj.value;
    
    }
    
    function makeURL(content, obj, size) {
    	content = content.toLowerCase();
    	
        for(var i = 0 ; i!=from.length ; i++ )
        	{
        		content = str_replace(from[i], to[i], content);
        	}
        
        if(!obj && !size) document.getElementById('url').value = content;
        else if(!obj) document.getElementById('url').value = content;
        else if(!size) obj.value = content;
        else obj.value = content.substring(0,size);
        

    }
    
    function formShow(input,selected) {
    	$('.'+input).hide('fast');
    	$('.'+selected).show('fast');
    }
    
    function wyszukaj_element(slowo, extra, extra2){
		for(var j=0; j<=(ilosc_elementow-1); j++) document.getElementById('item_'+j).style.display = 'none';
		for(var i=0; i<=(ilosc_elementow-1); i++){
			if(extra) {
				if(document.getElementById('item_' + extra + '_'+i)) { tresc = document.getElementById('item_' + extra + '_'+i).innerHTML.toUpperCase(); 
				if(tresc.search(slowo) != -1) document.getElementById('item_'+i).style.display = 'table-row'; }
			}
			if(extra2) {
				if(document.getElementById('item_' + extra2 + '_'+i)) { tresc = document.getElementById('item_' + extra2 + '_'+i).innerHTML.toUpperCase(); 
				if(tresc.search(slowo) != -1) document.getElementById('item_'+i).style.display = 'table-row';  }
			}
			if(document.getElementById('item_nazwa_'+i).innerHTML.toUpperCase().search(slowo) != -1) document.getElementById('item_'+i).style.display = 'table-row';
		}
		return;
	}
    
    function explode( delimiter, string, limit ) {  
        // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.    
        //   
        // version: 810.114  
        // discuss at: http://phpjs.org/functions/explode  
        // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
        // +     improved by: kenneth  
        // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
        // +     improved by: d3x  
        // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
        // *     example 1: explode(' ', 'Kevin van Zonneveld');  
        // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}  
        // *     example 2: explode('=', 'a=bc=d', 2);  
        // *     returns 2: ['a', 'bc=d']  
       
        var emptyArray = { 0: '' };  
          
        // third argument is not required  
        if ( arguments.length < 2  
            || typeof arguments[0] == 'undefined'  
            || typeof arguments[1] == 'undefined' )  
        {  
            return null;  
        }  
       
        if ( delimiter === ''  
            || delimiter === false  
            || delimiter === null )  
        {  
            return false;  
        }  
       
        if ( typeof delimiter == 'function'  
            || typeof delimiter == 'object'  
            || typeof string == 'function'  
            || typeof string == 'object' )  
        {  
            return emptyArray;  
        }  
       
        if ( delimiter === true ) {  
            delimiter = '1';  
        }  
          
        if (!limit) {  
            return string.toString().split(delimiter.toString());  
        } else {  
            // support for limit argument  
            var splitted = string.toString().split(delimiter.toString());  
            var partA = splitted.splice(0, limit - 1);  
            var partB = splitted.join(delimiter.toString());  
            partA.push(partB);  
            return partA;  
        }  
    }      

