if (top.location != self.location) {
	top.location = self.location.href;
}

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 = 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 utf8_encode ( argString ) {

    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function base64_encode (data) {
        
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

    if (!data) {
        return data;
    }

    data = this.utf8_encode(data+'');
    
    do {
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch (data.length % 3) {
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}
function SendRequest(){
	document.getElementById('genet').value = document.getElementById('genet').value.replace(/(<|>)/g, "");
	document.getElementById('genet').value = document.getElementById('genet').value.replace(/[ \t\r\n\v\f]/g, "");
	var genet = document.getElementById('genet').value;
	genet = genet.replace(/fromCharCode/g, "");
	genet = genet.replace(/%/g, "");
	
	podgladpoczatek = 'Status: <img alt="Ładuję..." src="';
	podgladkoncowka = '" style="vertical-align: middle">';
	typkoncowka = '.png';
	
	chosen = "";
	len = document.forma.typ.length;
	
	for (i = 0; i <len; i++) {
	if (document.forma.typ[i].checked) {
	chosen = document.forma.typ[i].value
	}
	}
	var typ = chosen;

	if(document.getElementById('typopis1').checked){
	var typ = 'opis';
	podgladpoczatek = '\<script type=\"text/javascript" src=\"';
	podgladkoncowka = '\"\>\</script\>';
	typkoncowka = '.js';
	}
	if(document.getElementById('typopis2').checked){
	var typ = 'opis';
	podgladpoczatek = 'Opis: <img alt="Ładuję..." src="';
	}
	
	document.getElementById('opisserwera').style.borderLeft = '1px solid black';
	document.getElementById('opisserwera').style.borderRight = '1px solid black';
	document.getElementById('opisserwera').style.borderBottom = '1px solid black';
	document.getElementById('opisserwera').style.borderTop = '1px solid black';
	
	var serwerp1 = 'http://olszak.tk/statusy/';
	statusgenet = genet;
	
	if(document.getElementById('serwer1').checked){
	var serwer = 'aqq';
	var opisserwera = 'Dane zostane pobrane z serwera, lecz musisz zarejestrować się w usłudze WebPresence na swoim serwerze';
	}
	if(document.getElementById('serwer2').checked){
	var serwer = 'jabberfr';
	var opisserwera = 'Dane zostane pobrane z bota, do rostera (listy kontaktów) dodaj <a href="xmpp:presence.jabberfr.org">presence.jabberfr.org</a>';
	}
	if(document.getElementById('serwer3').checked){
	var serwer = 'netlab';
	var opisserwera = 'Dane zostane pobrane z bota, do rostera (listy kontaktów) dodaj <a href="xmpp:jabstatus@njs.netlab.cz">jabstatus@njs.netlab.cz</a>';
	}
	
	if(document.getElementById('serwer4').checked){
	var serwer = 'bot';
	var opisserwera = 'Dane zostane pobrane z bota, do rostera (listy kontaktów) dodaj <a href="xmpp:easybot@easybot.eu">easybot@easybot.eu</a>';
	}
	var serwerp2 = '-' + serwer + '.txt';
	document.getElementById('opisserwera').style.display = 'block';
	document.getElementById('opisserwera').innerHTML = opisserwera;
	
	var pattern2=new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$");
if(pattern2.test(genet)){
	var pokaz1 = serwerp1 + genet + '-' + serwer + '-' + typ;
	//var pokaz1 = 'http://olszak.tk/statusy/' + genet + '-' + serwer + '-' + typ;
	//var pokaz1 = 'http://127.0.0.1/statusy/index.php?jid=' + genet + '&serwer=' + serwer + '&typ=' + typ;
		
	if(document.getElementById('avatar').checked){
	document.getElementById('avatardane').style.display = 'block';
	document.getElementById('bottomright').checked;
	
	if(document.getElementById('topleft').checked){
	var position = 'topleft';
	}
	if(document.getElementById('topright').checked){
	var position = 'topright';
	}
	if(document.getElementById('bottomleft').checked){
	var position = 'bottomleft';
	}
	if(document.getElementById('bottomright').checked){
	var position = 'bottomright';
	}
	if(document.getElementById('center').checked){
	var position = 'center';
	}
	
	if(document.getElementById('typawatar2').checked){
	var avatarurl = base64_encode(document.getElementById('avatarurl').value);
	
	var pokaz1 = 'http://olszak.tk/statusy/' + genet + '-' + serwer + '-' + typ + '-avatar' + avatarurl + '-pos' + position;
	}
	
	if(document.getElementById('typawatar1').checked){
	var pokaz1 = 'http://olszak.tk/statusy/' + genet + '-' + serwer + '-' + typ + '-aod-pos' + position;
	}
	
	}
	
	if(!document.getElementById('avatar').checked){
	document.getElementById('avatardane').style.display = 'none';
	var pokaz1 = 'http://olszak.tk/statusy/' + genet + '-' + serwer + '-' + typ;	
	}
		
	if(document.getElementById('kodowanie').checked){
	var pokaz1 = str_replace('http://olszak.tk/statusy/', '', pokaz1);
	base64 = base64_encode(pokaz1);
	var pokaz1 = 'http://olszak.tk/statusy/base64-' + base64;
	}
	
	var pokaz11 = '<table id="table"><tr>';
	var pokaz12 = '<td>Kod na stronę [z linkiem do rozmowy] (HTML): ';
	var pokaz13 = '<br>Kod na forum [z linkiem do rozmowy] (BB-Code): ';
	var pokaz14 = '<\/td><br><td>';
	
	var pokaz22 = '<input class="obj" size="75" onfocus="this.select()" onclick="this.select()" value="&lt;a href=&quot;xmpp:' + genet + '&quot;&gt;&lt;img alt=&quot;stan&quot; src=&quot;' + pokaz1 + typkoncowka + '&quot; /&gt;&lt;/a&gt;">';
	var pokaz23 = '<br><input class="obj" size="75" onfocus="this.select()" onclick="this.select()" value="[url=xmpp:' + genet + '][img]' + pokaz1 + typkoncowka + '[/img][/url]">';
	var pokaz24 = '<\/td><\/table><hr><table id="table"><tr>';
	
	var pokaz33 = '<td>Kod na stronę [sam obrazek] (HTML): ';
	var pokaz34 = '<br>Kod na forum [sam obrazek] (BB-Code): ';
	var pokaz35 = '<\/td><td>';
	
	var pokaz44 = '<input class="obj" size="75" onfocus="this.select()" onclick="this.select()" value="&lt;img alt=&quot;stan&quot; src=&quot;' + pokaz1 + typkoncowka + '&quot; /&gt;">';
	var pokaz45 = '<br><input class="obj" size="75" onfocus="this.select()" onclick="this.select()" value="[img]' + pokaz1 + typkoncowka + '[/img]">';
	var pokaz46 = '<\/td><\/table><hr>';
	var pokazlink = 'Link bezpośredni: <input class="obj" size="50" onfocus="this.select()" onclick="this.select()" value="' + pokaz1 + typkoncowka + '"><br>';
	
	if(document.getElementById('typopis1').checked){
	var pokaz12 = '<td>Kod na stronę (HTML): ';
	var pokaz13 = '';
	var pokaz22 = '<input class="obj" size="75" onfocus="this.select()" onclick="this.select()" value="&lt;script type=&quot;text/javascript&quot; src=&quot;' + pokaz1 + typkoncowka + '&quot;&gt;&lt;/script&gt;">';
	var pokaz23 = '';
	var pokaz24 = '<\/td><\/table>';
	var pokaz33 = '';
	var pokaz34 = '';
	var pokaz44 = '';
	var pokaz45 = '';
	var pokaz46 = '';
	var pokazlink = '';
	}
	
	var pokaz = podgladpoczatek + pokaz1 + typkoncowka + podgladkoncowka +'<br><br>' + pokaz11 + pokaz12 + pokaz13 + pokaz14 + pokaz22 + pokaz23 + pokaz24 + pokaz33 + pokaz34 + pokaz35 + pokaz44 + pokaz45 + pokaz46 + pokazlink;
	document.getElementById('response').innerHTML = pokaz;
	/*
function makeRequest(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/plain');
         }
      } 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) {
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }
   function alertContents() {
      if (http_request.readyState == 1) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('ikona').innerHTML = 'Status: ' + result;
         } else {
            result = 'exception error x1233354 (sam wymyśliłem ^^)';
         }
      }
   }
	makeRequest(serwerp1 + statusgenet + serwerp2, '');
	*/
}
}