// ************************************************
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (preloadFlag == true) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		ord = newImage("obchod/images/ordinaceA.png");
		o05 = newImage("obchod/images/m5a.png");
		o06 = newImage("obchod/images/m6a.png");
		o07 = newImage("obchod/images/m7a.png");
		o08 = newImage("obchod/images/m8a.png");
		preloadFlag = true;
	}
}
function posliSubmit(act)
{
	document.Form.action = act;
	document.Form.method = "post";
	document.Form.submit(); 
}
// ************************************************
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "")
};

function generuj_znaky($delka_hesla)
{
	$skupina_znaku = '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	$vystup = '';
	$pocet_znaku = strlen($skupina_znaku)-1;
	for ($i=0;$i<$delka_hesla;$i++) 
	{ 
		$vystup = $vystup + $skupina_znaku[mt_rand(0,$pocet_znaku)]; 
	}
	return $vystup;
}

// ************************************************
function ajax(stranka, kam)
{
    var httpRequest;
    
    if(typeof window.ActiveXObject != 'undefined')
    {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {  
        httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", stranka, true);
    httpRequest.onreadystatechange= function () 
    {
        processRequest(httpRequest, kam) 
    };
    httpRequest.send(null);
}


function processRequest(httpRequest, kam) 
{
    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
            if (typeof kam == 'string') 
            {
                document.getElementById(kam).innerHTML = httpRequest.responseText;
            }
            if (typeof kam == 'function') 
            {
                kam(httpRequest.responseText);
            }
        }
        else
        {
            alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
        }
    }
    else
    {
        if (typeof kam == 'string' && kam != '') 
        {
            document.getElementById(kam).innerHTML = 'Čekejte...';
        }
    }
} 

var Url = {
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}
		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
