// JavaScript Document

function zmen_pwd()
{
	document.getElementById('pass').innerHTML = '<input id="pwd" name="login_heslo" type="password" class="txt_input" maxlength="255"/>'; 
	document.getElementById('pwd').className='txt_input';
	newO = document.getElementById('pwd');
	setTimeout("newO.focus();", 10);
}

function is_array( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   bugfixed by: Cord
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: is_array('Kevin van Zonneveld');
    // *     returns 2: false
 
    return ( mixed_var instanceof Array );
}

function zkontroluj_pred_odeslanim(formular, pole)
{
	pole_kontrolovanych_inputu = pole.split(',');
	e = 0;
	prvky = document.getElementsByTagName('input');
	
	if(is_array(pole_kontrolovanych_inputu))
	{
		for(i = 0; i < pole_kontrolovanych_inputu.length; i++)
		{

			if(pole_kontrolovanych_inputu[i].substr(0, 15) == 'vlozene_soubory')
			{
				x = pole_kontrolovanych_inputu[i].split('-');
				
				y = zjisti_soubory();
				
				if(y != 1)
				{
					if(e == 0)
					{
						upozorneni('Musíte vložit alespoň jeden soubor designu.');
					}
					document.getElementById('soubory').style.borderColor='#ff0000';
					e = 1;
				}
			}
		}
		for(i1 = 0; i1 < prvky.length; i1++)
		{
			for(i = 0; i < pole_kontrolovanych_inputu.length; i++)
			{
				if(prvky[i1].name == pole_kontrolovanych_inputu[i])
				{
					co = prvky[i1].value;
										
					if(pole_kontrolovanych_inputu[i] != 'heslo' && pole_kontrolovanych_inputu[i] != 'cena' && pole_kontrolovanych_inputu[i] != 'heslo1' && pole_kontrolovanych_inputu[i] != 'email')
					{
						if(co == '')
						{
							if(e == 0)
							{
								upozorneni('Prosím vyplňte pole "'+pole_kontrolovanych_inputu[i]+'"');
							}
							e = 1;
						} 
					} else {
						if(pole_kontrolovanych_inputu[i] == 'cena')
						{
							if(formular.cena.value == '')
							{
								if(formular.cena_pouze_uni.checked == false)
								{
									if(e == 0)
									{
										upozorneni('Prosím vyplňte pole "'+pole_kontrolovanych_inputu[i]+'"');
									}
									e = 1;
									
									prvky[i1].style.borderColor='#ff0000';
								} else {
									prvky[i1].style.borderColor='';
								}
							}
						}
					
						if(pole_kontrolovanych_inputu[i] == 'heslo' || pole_kontrolovanych_inputu[i] == 'heslo1')
						{
							if(formular.heslo.value.length < 6)
							{
								if(e==0)
								{
									upozorneni('Heslo nesmí být z bezpečnostních důvodů kratší než 6 znaků!');
								}
								e=1;
								
								formular.heslo.style.borderColor='#ff0000';
								formular.heslo1.style.borderColor='#ff0000';
							}
							
							if(formular.heslo.value != formular.heslo1.value)
							{
								if(e==0)
								{
									upozorneni('Kontrolní heslo neodpovídá!');
								}
								e=1;
								
								formular.heslo.style.borderColor='#ff0000';
								formular.heslo1.style.borderColor='#ff0000';
							} else {
								formular.heslo.style.borderColor='';
								formular.heslo1.style.borderColor='';
							}
						}
						
						if(pole_kontrolovanych_inputu[i] == 'email')
						{
							zavin = co.indexOf('@');
							tec = co.indexOf('.');
							
							if(tec == -1 || zavin == -1)
							{
								if(e == 0)
								{
									upozorneni('E-mail nemá správný formát!');
								}
								formular.email.style.borderColor='#ff0000';
							}
						}
					}
					
					if(co == '')
						if(pole_kontrolovanych_inputu[i] != 'cena')
						{
							prvky[i1].style.borderColor='#ff0000';
						}
					else {
						if(pole_kontrolovanych_inputu[i] != 'cena')
						{
						prvky[i1].style.borderColor='';
						}
					}
					
				}
			}
		}
		
		if(e == 0)
		{
			formular.submit();
		}
	} else {
		chyba('Není zadáno pole inputů ke kontrole!');
	}
}

function zkontrolovat(co, hodnota, root)
{
	document.getElementById('kontrolor').src=root+'parts/uz_reg_zkontroluj.php?co='+co+'&hodnota='+escape(hodnota);
		
	var stat = document.getElementById('kontrolor').contentWindow.document.getElementById('status').value;
	if(stat == 'error' || stat > 0)
	{
		alert(co+' již existuje. Prosím zvlote jinou hodnotu.');
		x = document.getElementsByTagName('input');
		for(i = 0; i < x.length; i++)
		{
			if(x[i].name == co)
			{
				x[i].style.borderColor = '#ff0000';
			}
		}
	} else {
			alert('error');
	}
}

function chyba(zprava)
{
	alert(zprava);
}

function upozorneni(zprava)
{
	alert(zprava);
}

function ajax_toggle_username(userid) { 
    if (window.XMLHttpRequest) { 
        http = new XMLHttpRequest(); 
    } else if (window.ActiveXObject) { 
        http = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
	
    handle = document.getElementById(userid); 
    var url = 'parts/ajax.php?'; 
    if(handle.value.length > 0) { 
        var fullurl = url + 'do=check_'+userid+'_exists&value=' + encodeURIComponent(handle.value); 
        http.open("GET", fullurl, true); 
        http.send(null); 
        http.onreadystatechange = ajax_statechange_username; 
    }else{ 
        document.getElementById(userid+'_exists').innerHTML = ''; 
    } 
} 

function ajax_statechange_username(userid) { 
    if (http.readyState == 4) { 
        var xmlObj = http.responseXML; 
        var html = xmlObj.getElementsByTagName('value').item(0).firstChild.data; 
        var targ = xmlObj.getElementsByTagName('target').item(0).firstChild.data; 
        document.getElementById(targ+'_exists').innerHTML = html; 
    } 
}

function vypni_zapni_novinky(switcher)
{
	if(switcher === true)
	{
		document.registrace.sledovat_novinky[0].disabled = false;
		document.registrace.sledovat_novinky[1].disabled = false;
	} else {
		document.registrace.sledovat_novinky[0].disabled = true;
		document.registrace.sledovat_novinky[1].disabled = true;
	}
}

function otevri_velky(root, soubor)
{
	url = root+'nahled-'+soubor+'.htm';
	window.open(url, 'nahled', 'location=no,status=no,width=900,height=600,resizable=yes,scrollbars=yes,menubar=no,toolbar=no');
}

function udelej_odkaz(adresa)
{	
	zakazane_znaky 	= new Array('ě', 'š', 'č', 'ř', 'ž', 'ý', 'á', 'í', 'é', 'ů', 'ú', 'ď', 'ť', 'ň', 'ü', ' ', ',');
	prevest_na 		= new Array('e', 's', 'c', 'r', 'z', 'y', 'a', 'i', 'e', 'u', 'u', 'd', 't', 'n', 'u', '-', '-');
	
	for(i = 0; i<zakazane_znaky.length; i++)
	{
		prom = zakazane_znaky[i];
		adresa = adresa.replace(new RegExp( prom, "g" ), prevest_na[i]);
	}
	
	return adresa.toLowerCase();
}

function zkontroluj_obrazek(soubor, idinp)
{
	zacatek = soubor.indexOf('.');
	
	if(zacatek != -1)
	{
		pripona = soubor.substr(zacatek+1);
		pripona = pripona.toLowerCase();
		
		if(pripona != 'jpg' && pripona != 'jpeg' && pripona != 'gif' && pripona != 'png')
		{
			alert('Zadaný soubor není podporovaným typem obrázku.\n Podporovány jsou obrázky jpg, gif a png.');
			document.getElementById(idinp).style.borderColor='#ff0000';
		}
	} else {
		alert('Zadaný soubor není správný typ souboru!');
		document.getElementById(idinp).style.borderColor='#ff0000';
	}
}

function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}

function zjisti_soubory()
{ 
	p = frames['pril'].document.getElementById('sprilohy').value;
	return p;
} 





function vedelijste() {
var httpRequest;

if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	httpRequest = new XMLHttpRequest();
	if (httpRequest.overrideMimeType) {
		httpRequest.overrideMimeType('text/xml');
		// See note below about this line
	}
} 
else if (window.ActiveXObject) { // IE
	try {
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) {
		try {
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (e) {}
	}
}

if (!httpRequest) {
	alert('Giving up :( Cannot create an XMLHTTP instance');
	return false;
}

var typ = Math.round(Math.random() * 20);
var url = 'parts/vedelijste.php?typ='+typ;

httpRequest.open('GET', url, false);
httpRequest.send(null);

if(httpRequest.readyState == 4)
{
	var xmldoc = httpRequest.responseXML;
	var text = xmldoc.getElementsByTagName('text').item(0).firstChild.data;
	
	document.getElementById('vedelijste').innerHTML = text;
	xt = setTimeout('vedelijste()', 10000);
}

}