﻿// JavaScript Document
    function Request(id,url) {
        var http_zadost = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, Opera, Konqueror...
            http_zadost = new XMLHttpRequest();
            if (http_zadost.overrideMimeType) {
                http_zadost.overrideMimeType('text/xml');
                // Podívejte na poznámku o tomto rádku níže
            }
        } else if (window.ActiveXObject) { // Internet Explorer
            try {
                http_zadost = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_zadost = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_zadost) {
            alert('Giving up :( Nemohu vytvorit XMLHTTP instanci');
            return false;
        }
        http_zadost.onreadystatechange = function() { stavObsahu(id,http_zadost); };
        http_zadost.open('GET', url, true);
        http_zadost.send(null);
    }

    function stavObsahu(id,http_zadost) {
	var id_hand = document.getElementById(id);
        if (http_zadost.readyState == 4) {
            if (http_zadost.status == 200) {
				if(id=='all'){
					var result = http_zadost.responseText;
					var id_hand = document.getElementById('email');
					if(document.getElementById('code_1').value==document.getElementById('code_2').value){
					if(Check_email(id_hand.value)){
					if(result=='True'){
						document.getElementById("reg_submit").disabled='';
					}else{
						document.getElementById("reg_submit").disabled='disabled';
					}}else{
						document.getElementById("reg_submit").disabled='disabled';
					}}else{
						document.getElementById("reg_submit").disabled='disabled';
						}
				}else{
				var result = http_zadost.responseText;
					if(result=='True'){
						if(id=='email'){
							if(Check_email(id_hand.value)){
								document.getElementById(id+'_info').innerHTML='<span style="display:block;padding:7px;color:#72a637;">Your e-mail is good to go!</span>';
							}else{
								document.getElementById(id+'_info').innerHTML='<span style="display:block;padding:0px;color:#e63c3f;">Wrong format of the e-mail. Please re-type it again!</span>';
							}
						}if(id=='login'){
							if(id_hand.value.length>2){
								document.getElementById(id+'_info').innerHTML='<span style="display:block;padding:7px;color:#72a637;">Your username is good to go!</span>';
							}else{
								document.getElementById(id+'_info').innerHTML='<span style="display:block;padding:7px 4px;color:#e63c3f;">Login must contain 3 digits at least!</span>';
							}
						}
					}else{
							if(id=='login'){
										document.getElementById(id+'_info').innerHTML='<span style="display:block;padding:0px;color:#e63c3f;">This username is already taken by another user. Choose another one!</span>';
							}if(id=='email'){
										document.getElementById(id+'_info').innerHTML='<span style="display:block;padding:0px;color:#e63c3f;">This email adress is already taken by another user! Re-type again.</span>';
								}
					}
				}
            } else {
            //    alert('Byl problém se žádostí.');
            }
        }

    }
function Check_all(){
		Request('all','/check.php?all_l=' + document.getElementById("login").value + '&all_e=' + document.getElementById("email").value);
	}
	
function Check(id){
	var id_hand = document.getElementById(id);
		if(id_hand.value){
			if(id=='login'){
				Request(id,'/check.php?login=' + id_hand.value);
			}else if(id=='email'){
				Request(id,'/check.php?email=' + id_hand.value);
			}
		}else{
			document.getElementById(id+'_info').innerHTML=' &nbsp;';
		}
}

function Check_email(url)
{
	re = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
    return url.search(re) == 0;
}

// anketa

function Request_poll(url) {
        var http_zadost = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, Opera, Konqueror...
            http_zadost = new XMLHttpRequest();
            if (http_zadost.overrideMimeType) {
                http_zadost.overrideMimeType('text/xml');
                // Podívejte na poznámku o tomto rádku níže
            }
        } else if (window.ActiveXObject) { // Internet Explorer
            try {
                http_zadost = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_zadost = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_zadost) {
            alert('Giving up :( Nemohu vytvorit XMLHTTP instanci');
            return false;
        }
        http_zadost.onreadystatechange = function() { stavObsahu_poll(http_zadost); };
        http_zadost.open('GET', url, true);
        http_zadost.send(null);
    }

  function stavObsahu_poll(http_zadost) {

        if (http_zadost.readyState == 4) {
            if (http_zadost.status == 200) {
		
			 var mistoZobrazeni = document.getElementById("poll");
      			mistoZobrazeni.innerHTML = http_zadost.responseText;

            } else {
                //alert('Byl problém se žádostí.');
            }
        }

    }
// update poctu stazeni u souboru

function Request_file(url,cesta) {
        var http_zadost = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, Opera, Konqueror...
            http_zadost = new XMLHttpRequest();
            if (http_zadost.overrideMimeType) {
                http_zadost.overrideMimeType('text/xml');
                // Podívejte na poznámku o tomto rádku níže
            }
        } else if (window.ActiveXObject) { // Internet Explorer
            try {
                http_zadost = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_zadost = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_zadost) {
            alert('Giving up :( Nemohu vytvorit XMLHTTP instanci');
            return false;
        }
        http_zadost.onreadystatechange = function() { stavObsahu_file(http_zadost,cesta); };
        http_zadost.open('GET', url, true);
        http_zadost.send(null);
    }

  function stavObsahu_file(http_zadost,cesta) {

        if (http_zadost.readyState == 4) {
            if (http_zadost.status == 200) {
		
			 var mistoZobrazeni = document.getElementById("file-count");
      			mistoZobrazeni.innerHTML = http_zadost.responseText;
				location.href='' + cesta;
            } else {
                //alert('Byl problém se žádostí.');
            }
        }

    }
	
	function zobraz(id){
	document.getElementById(id).style.display='block';
}
function skryj(id){
	document.getElementById(id).style.display='none';
}
function AskChange(id,nick){
	document.getElementById('ask_to').value=id;
	document.getElementById('ask_text').innerHTML=nick;
	skryj('ask_menu');
}
   if (document.images)
    {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "/img/menu/about-on.jpg";
      image_url[1] = "/img/menu/awards-on.jpg";
      image_url[2] = "/img/menu/clanwars-on.jpg";
      image_url[3] = "/img/menu/ask-on.jpg";
      image_url[4] = "/img/menu/clanwars-on.jpg";
      image_url[5] = "/img/menu/galleries-on.jpg";
      image_url[6] = "/img/menu/home-on.jpg";
      image_url[7] = "/img/menu/news-articles-on.jpg";
      image_url[8] = "/img/menu/scene-galleries-on.jpg";
      image_url[9] = "/img/menu/sponsors-on.jpg";
      image_url[10] = "/img/menu/team-on.jpg";
      image_url[11] = "/img/menu/tv-on.jpg";
	  
	  image_url[12] = "/img/ico-logout-on.png";
      image_url[13] = "/img/ico-profil-on.png";
      image_url[14] = "/img/ico-settings-on.png";
      image_url[15] = "/img/ico-users-over.png";
	  
       var i = 0;
       for(i=0; i<=15; i++) 
         preload_image_object.src = image_url[i];
    }
