/* common javascripts */ function changeClass(elementId, clName) {  document.getElementById(elementId).className = clName; } /* * enable / disable */ function enable(aktivator, enablatorId) {  var enablator = document.getElementById(enablatorId);  if (aktivator.checked == true)  enablator.disabled = false;  else  enablator.disabled = true; } /* * char count */ function charCount(input, min, max) {  if (input.value.length > max) {  input.value = input.value.substring(0, max);  }  else if (input.value.length < min) {  return -1;  } } /* * numeric input only */ function numerics(e,decReq) {  var isIE = document.all?true:false;  var key = (isIE) ? window.event.keyCode : e.which;  var obj = (isIE) ? event.srcElement : e.target;  var isNum = (key > 47 && key < 58) ? true:false;  var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;  if(key < 32)  return true;  return (isNum || dotOK); } function dh(elementName) {  var element;  element = document.getElementById(elementName);  if (element.style.display == 'none')  element.style.display = '';  else  element.style.display = 'none'; } function ukaz(elementName) {  var element = document.getElementById(elementName);  element.style.display = ''; } function skry(elementName) {  var element = document.getElementById(elementName);  element.style.display = 'none'; } /* * loader overlay */ function loader() {  var iDiv = document.createElement("div");  iDiv.className = "overlay";  iDiv.style.width = (screen.width - 30) + 'px';  iDiv.style.height = (screen.height - 50) + 'px';  var lDiv = document.createElement("div");  lDiv.className = "load";  lDiv.style.left = (screen.width / 2 - 66 )+ 'px';  lDiv.style.top = (screen.height / 2 - 66) + 'px';  iDiv.appendChild(lDiv);  document.body.appendChild(iDiv); } /* * unloader overlay */ function unloader() {  document.body.removeChild(document.body.lastChild); } /* * clear options from select */ function clearOptions(idSelect) {  elSelect = document.getElementById(idSelect);  l = elSelect.options.length;  for(i=0;i<l;i++) {  elSelect.remove(0);  } } /* * add option to select */ function addOption(idSelect, opValue, opText) {  anOption = document.createElement("option");  anOption.text = opText;  anOption.value = opValue;  elSelect = document.getElementById(idSelect);  elSelect.options.add(anOption, elSelect.options.length);  elSelect.selectedIndex = 0; } /* * slide in effect */ function slideIn(el){  if (!el)  el = 'flyin';  crossobj = document.getElementById(el);  crossobj.style.display='';  interval = setInterval("animatein()", 20);  } function animatein(){  if (parseInt(crossobj.style.top)<5)  crossobj.style.top=parseInt(crossobj.style.top)+5+"px";  else{  clearInterval(interval);  } } /* * textova hlaska */ function hlaska(hlaskaId, param) {  xmlhttp = createRequest();  xmlhttp.open('GET', '/ajax/hlasky.php?h='+hlaskaId+'&p='+param, false);  xmlhttp.send(null);  return xmlhttp.responseText; } /* * add tr */ function add_tr(nazov, max) {  document.getElementById(nazov + "_hidden").value++;  hidden = document.getElementById(nazov + "_hidden").value;  document.getElementById(nazov + "_" + hidden).style.display = "";  if (hidden > (max-1))  document.getElementById(nazov + "_tr").style.display = "none"; } function add_link(nazov, text, max) {  document.write("<tr class='right' id='" + nazov + "_tr'><td><a href='javascript:void(0)' onclick='add_tr(\"" + nazov + "\"," + max + ")'>" + text + "</a><input type='hidden' id='" + nazov +"_hidden' value='1' /></td></tr>"); } /* * get url parameter */ function gup( name ) {  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  var results = regex.exec( window.location.href );  if( results == null )  return "";  else  return results[1]; }

/* --------------------------------------- */

/*
* CHECK FORM INPUTS 
*/


/*
* ICO
*/
function checkIco(element, errorId, event) {

  trueValue = element.value;
  
  if (trueValue.length != 8 || isNaN(trueValue)) {
    changeText('hlaska'+errorId, '<small class="red">' + hlaska(10) + '</small>');
  }
  else {
    krut('hlaska'+errorId);
    var params = "ico=" + escape(trueValue) + "&err=" + errorId;
    
    xmlRequest = createRequest();

    xmlRequest.open('POST', '/ajax/register/check/checkIco.php');
  	xmlRequest.onreadystatechange = function() {
    
      if(xmlRequest.readyState == 4){
      	if (xmlRequest.status == 200){
          var response = xmlRequest.responseText;

          var update = new Array();                               

          if(response.indexOf('|') != -1) {
              update = response.split('|');
              if (!update[2]) {
                changeText('hlaska'+update[0], update[1]);
                document.getElementById('fnazov').value = '';
                var sDiv = document.createElement("div");
                sDiv.setAttribute("class", "hlasko");
                sDiv.innerHTML = hlaska(13);
                document.getElementById('hlaska'+update[0]).appendChild(sDiv);
              }
              else {
                  changeText('hlaska'+update[0], update[1]);
              }
          }
    		}
    		else
    		  alert(xmlRequest.status);
      }
    };
  	xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlRequest.setRequestHeader("Content-length", params.length);
    xmlRequest.setRequestHeader("Connection", "close");
    xmlRequest.send(params);
  }

}


/*
* popis odkazu
*/
function checkArea(element, errorId, min, max) {

  krut('hlaska' + errorId);
    
  kolko = charCount(element, min, max);
  
  changeText('count_' + errorId, element.value.length + '/' + max);
        
 if (kolko == -1)
    changeText('hlaska' + errorId, hlaska(20, min - element.value.length));
  else
    changeText('hlaska' + errorId, 'ok');
}



/*
* url
*/
function validUrl(element, errorId, povinne) {

  if (element.value == '' && !povinne) {
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
   return;
  }
  
  var url = element.value;

  var reg = /(http:\/\/)?[A-Za-z0-9\.-]{3,}\.(sk|cz|com|eu|info|biz)/;
  var regular = reg.exec(url);
  
  if (regular)
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
  else
    changeText('hlaska' + errorId, '<small class="red">'+hlaska(102)+'</small>');
}

/*
* url
*/
function checkUrl(element, errorId, povinne, t, l) {

  if (element.value == '' && !povinne) {
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
   return;
  }

  var url = element.value;

  var reg = /(http:\/\/)?[A-Za-z0-9\.-]{3,}\.(sk|cz|com|eu|info|biz)/;
  var regular = reg.exec(url);

  if (regular) {
    krut('hlaska'+errorId);

    xmlhttp = createRequest();

    var params = "url=" + escape(url) + "&err=" + errorId + '&p=' + povinne + '&t=' + t ;
    xmlhttp.open('POST', '/ajax/register/check/checkUrl.php', true);
  	xmlhttp.onreadystatechange = function() {

       if(xmlhttp.readyState == 4){
      	if (xmlhttp.status == 200){

          var response = xmlhttp.responseText;
          
          var update = new Array();

          if(response.indexOf('|') != -1) {
            update = response.split('|');

            if (update[1] == 'je1') {
              var kv = hlaska(106);
              changeText('hlaska' + update[0], '<small class="red">' + kv.replace('--','') + '</small>');
              if (l) {
                var sDiv = document.createElement("div");
                sDiv.setAttribute("class", "hlasko");
                sDiv.innerHTML = hlaska(108);
                document.getElementById('hlaska'+update[0]).appendChild(sDiv);
              }
            }
            else if (update[1] == 'je2') {
              changeText('hlaska' + update[0], '<small class="red">' + hlaska(107) + '</small>');
            }
            else if (isNaN(update[1])) {
              changeText('hlaska' + update[0], '<small class="green">ok</small>');
            }
            else if (update[1] > 199 && update[1] < 399) {
              changeText('hlaska' + update[0], '<small class="green">ok</small>');
            }
            else {
              changeText('hlaska' + update[0], '<small class="red">'+hlaska(101)+'</small>');
            }
          }
          
          
    		}
    		else
    		  alert(xmlhttp.status);
      }   
    };
  	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);
      
  }
  else
    changeText('hlaska' + errorId, '<small class="red">'+hlaska(102)+'</small>');
}


/*
* mail
*/
function checkMail(element, errorId) {

  krut('hlaska'+errorId);

  var url = element.value;

  var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var regular = reg.exec(url);
  
  if (regular)
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
  else
    changeText('hlaska' + errorId, '<small class="red">'+hlaska(200)+'</small>');
}


function checkEmpty(element, errorId, hlaskaId) { 
  if (element.value)
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
  else
    changeText('hlaska' + errorId, '<small class="red">' + hlaska(hlaskaId) + '</small>');
}

function checkPSC(element, errorId) {
  
  if (element.value.length == 5)
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
  else
    changeText('hlaska' + errorId, '<small class="red">'+hlaska(57)+'</small>');
}


function checkPwd(element, errorId) {
  if (element.value.length > 5)
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
  else
    changeText('hlaska' + errorId, '<small class="red">'+hlaska(151)+'</small>');
}

function checkSelect(element, errorId, hlaskaId) {
  if (element.selectedIndex)
    changeText('hlaska' + errorId, '<small class="green">ok</small>');
  else
    changeText('hlaska' + errorId, '<small class="red">' + hlaska(hlaskaId) + '</small>');
}


/*
* log
*/
function logujsa(url) {
  //$('#pokracuj').hide();
  var e = $('#pokracuj').parent();
  var tmp_html = e.html();
  //alert($('#pokracuj').parent().html());
  e.html('<img src="/layout/public/images/38-1.gif" alt="čakajte.." />');

  $.post('/ajax/register/check/checkLogin.php', {
      pwd: document.getElementById('sveter').value,
      shop: document.getElementById('url_shop').value
  }, function(response) {  
        if (response == 1) {
            if(url == undefined) {          
                window.location.reload();
            }
            else {
                window.location = url;
            }
        }
        else {
          $('#requireed').css("border","1px red solid");
          $('#requireed').css("paddingBottom","10px");
          $('#requireed').css("background","#ECC5C6");
          $('#zab').html('<br /><label class="label3">&nbsp;</label><p class="error3">Nesprávne meno alebo heslo<br />'+ hlaska(121)+'</p>');
          //('#pokracuj').show();
          e.html(tmp_html);
        }
    }
  );

  return false;
}


/*
* pripoj
*/
function pripojsa() {
  var url = document.getElementById('sveter').value;
  var shop = document.getElementById('url_shop').value;
  if(shop == "") {
    (".required3").html();
  }
  $.post('/ajax/register/check/pripoj.php', {
      pwd: url,
      shop: shop
  }, function(response) {
        //alert(response);
        if (response == 1) {
          window.location.href = '/';
        }
        else {
          if (response == 2) {
            $('#e2').hide();
            $('#e1').show();
          }
          else {
            $('#e1').hide();
            $('#e2').show();
          }
        }
    }
  );

  return false;
}


/*
* zabudnute heslo
*/
function zab() {
  var params = "zab_m=" + document.getElementById('zab_m').value;
  if(params != "zab_m="){
    $('#e1').hide();
    $.post('/ajax/register/check/zab.php', {
      zab_m: document.getElementById('zab_m').value
      }, function(response) {
        if (response == 1) {
          $('form#f_regs').html('');
          $('.info').show();
          $('#e1').hide();
          $('#e2').hide();
        } else {
          $('#e1').hide();
          $('.info').hide();
          $('#e2').show();
        }
      }
    );
    return false;
  } else {
    $('#e1').hide();
    $('.info').hide();
    $('#e1').show();
  }
}

function podmienky(co) {
  if(co === 3) {
    var obj_calwindow = window.open(
  		'/obchodne-podmienky/', 'Podmienky', 'width=720,height=525,status=no,scrolling=yes,scrollbars=1,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
  	);
  } else {
    var obj_calwindow = window.open(
  		'/podmienky' + co + '.php', 'Podmienky', 'width=720,height=525,status=no,scrolling=yes,scrollbars=1,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
  	);
	}
}

function vzorXML() {
  var obj_calwindow = window.open(
		'/vzorXML.php', 'Vzor_XML', 'width=720,height=525,status=no,scrolling=yes,scrollbars=1,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
}

function charer(id_input, max) {
  input = document.getElementById(id_input);
  vypis = document.getElementById(id_input + '_count');
  
  if (input.value.length > max) // ked je viac, odsekne
    input.value = input.value.substring(0, max);
  else
    vypis.innerHTML = max - input.value.length;
}


/* ---------------------------------------------------------- */
function prepareInputsFordivs() {

  var inputs = document.getElementsByTagName("input");
  
  for (var i=0; i<inputs.length; i++){
  
    if ((inputs[i].type == 'text' || inputs[i].type == 'file' || inputs[i].type == 'password') && inputs[i].parentNode.getElementsByTagName("span")[0]) {    
      inputs[i].onfocus = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
  	  this.parentNode.className = "vysviet";
      }
      inputs[i].onblur = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "none";
  	  this.parentNode.className = "normal";
      }
    }
  }
  
  var areas = document.getElementsByTagName("textarea");
  for (var k=0; k<areas.length; k++){
    if (areas[k].parentNode.getElementsByTagName("span")[0]) {
      areas[k].onfocus = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
      this.parentNode.className = "vysviet";
      }
      areas[k].onblur = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "none";
      this.parentNode.className = "normal";
      }
    } 
  }
  
  
  var selects = document.getElementsByTagName("select");
  for (var l=0; l<selects.length; l++){
    if (selects[l].parentNode.getElementsByTagName("span")[0]) {
      selects[l].onfocus = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
  	  this.parentNode.className = "vysviet";
      }
      selects[l].onblur = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "none";
  	  this.parentNode.className = "normal";
      }
    }
  }
  
  var labels = document.getElementsByTagName("label");
  for (var m=0; m<labels.length-1; m++){
    if (labels[m].parentNode.getElementsByTagName("span")[0]) {
      labels[m].onfocus = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
  	  this.parentNode.className = "vysviet";
      }
      labels[m].onblur = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "none";
  	  this.parentNode.className = "normal";
      }
    }
  }

}

/* ------------------------------------------------------------------ */
function createRequest() {  try {  var xmlhttp = new myXMLHttpRequest();  } catch (e) {  var xmlhttp = false;  }  return xmlhttp; } function myXMLHttpRequest() {  var xmlhttplocal;  try {  xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")  } catch (e) {  try {  xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")  } catch (E) {  xmlhttplocal=false;  }  } 	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {  try {  var xmlhttplocal = new XMLHttpRequest();  } catch (e) {  var xmlhttplocal=false;  alert('couldn\'t create xmlhttp object');  } 	} 	return(xmlhttplocal); } function changeText( elementId, text ) { if (elementId == 'register' && (text == hlaska(10) || text == hlaska(102)))  return;  var viewer = document.getElementById(elementId);  if (!viewer)  alert(elementId);  viewer.innerHTML = text; } function krut(eName) {  var theDiv = document.getElementById(eName);  theDiv.innerHTML = '<small class="krucak">' + hlaska(1) + '</small>'; }

/* ------------------------------------------------------------------- */
function nahrat(k) {

  if (d = document.getElementById('part'))
    d.parentNode.innerHTML = '<iframe style="display:none;width:0;height:0;" src="about:blank" id="part" name="part" onload="loadedForm()"></iframe>';
  else {
    var d = document.createElement('DIV');
    d.innerHTML = '<iframe style="display:none;width:0;height:0;" src="about:blank" id="part" name="part" onload="loadedForm()"></iframe>';
    document.body.appendChild(d);
  }
  
  loader();
  
  var theForm = document.getElementById('f_regs');
   
  if (k < 0)
    theForm.setAttribute('action', '/ajax/register/check/check'+Math.abs(k)+'.php?b');
  else
    theForm.setAttribute('action', '/ajax/register/check/check'+k+'.php');    
  theForm.setAttribute('target', 'part');

  document.forms.f_regs.submit();
}
function loadedForm() {

  var i = document.getElementById('part');
  if (i.contentDocument) {
      var d = i.contentDocument;
  } else if (i.contentWindow) {
      var d = i.contentWindow.document;
  } else {
      var d = window.frames[id].document;
  }

  if (d.location.href == "about:blank") {
      return;
  }

  var response = d.body.innerHTML;
  var update = new Array();

  if(response.indexOf('|') != -1) {

      update = response.split('|');
      if (update[0] == 'back') {
          location.href = '/' + hlaska(update[1]) + '/';
      }
      else {
        if (update[1] != 0) {
          var ju = document.getElementById('jump');
          ju.innerHTML = '<h3>' + hlaska(22300) + '</h3><p>' + hlaska(22301) + '</p>';
          ju.style.display = 'block';
  
  
          for(i=2;i<update.length;i+=2) {
            var par = document.getElementById("hlaska"+update[i]).parentNode;
            if (par.className == 'required error2')
                par.removeChild(par.firstChild);
            if (update[i+1] == 'ok' || update[i+1] == '') {
              par.className = 'required';
            }
            else {
              par.className = 'required error2';
              var pChyba = document.createElement("p");
              pChyba.className = 'error';
              pChyba.innerHTML = update[i+1].replace('--','');
              par.insertBefore(pChyba, par.firstChild);
            }
          }        
        }
        else {
          // kroker(update[0]);
          location.href = '/' + hlaska(update[0]) + '/';
        }
      }
  }

  unloader();

  d.body.innerHTML = '';

  if (update[1] != 1)
    location.href='#jump';
}


function het(koho, t) {

  co = document.getElementById(koho).firstChild.src;
  
  xmlhttp = createRequest();
  
  xmlhttp.open('get', '/ajax/nahraj/het.php?koho='+koho+'&co='+co+'&t='+t);
  xmlhttp.onreadystatechange = function () {
    if(xmlhttp.readyState == 4){
    		if (xmlhttp.status == 200){
          var response = xmlhttp.responseText;
          document.getElementById(response).firstChild.src = '/imgs/no_image.jpg';
          document.getElementById('obr_count').value--;
    		}
    		else
    		  alert(xmlhttp.status);
      }
    };
  xmlhttp.send(null);
}

/* ----------------------------------------------------------- */
function get_cookie(Name) {
  var search = Name + "=";
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end));
      }
   }
  return returnvalue;
}

/* ------------------------------------------------------------ */
function kroker(krok) {
 		
  document.cookie = 'krok=' + krok;
  theDiv = document.getElementById('register');
  var lDiv = document.createElement("div");
  lDiv.setAttribute("class", "loading");
  theDiv.innerHTML = '';
  theDiv.appendChild(lDiv);
  
  xmlhttp = createRequest();
  
  xmlhttp.open('get', '/ajax/register/tpl/step'+krok+'.php');
  xmlhttp.onreadystatechange = function () {
    if(xmlhttp.readyState == 4){
      
    		if (xmlhttp.status == 200){
          var response = xmlhttp.responseText;
          changeText('register', response);
          
          if (krok == 1000) {
            var rabka = document.getElementById('rab').parentNode;
            rabka.removeChild(document.getElementById('else'));
            rabka.removeChild(document.getElementById('elsei'));
          }
          
          prepareInputsFordivs();
    		}
    		else
    		  alert(xmlhttp.status);
      }
    };
  xmlhttp.send(null);
}

/* -------------------------------------------------------------- */
/*
	This is the JavaScript file for the AJAX Suggest Tutorial

	You may use this code in your own projects as long as this 
	copyright is left	in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.DynamicAJAX.com
	
	Copyright 2006 Ryan Smith / 345 Technical / 345 Group.	

*/
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {

	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return false;
	}
}

//Our XmlHttpRequest object to get the auto suggest
// var searchReq = getXmlHttpRequestObject();
var sugg = true;

//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSuggest() {

  var str = document.getElementById('q').value;
  var strl = str.length;

  if (strl == 0 || strl == 1)
    document.getElementById('suggest').innerHTML = '';

  if (strl == 0 )
    sugg = true;
	if (sugg && strl > 1) {
	
	 
	
    xmlhttp = createRequest();  
		xmlhttp.open("GET", '/ajax/suggest/searchSuggest.php?search=' + str, true);
		xmlhttp.send(null);
		xmlhttp.onreadystatechange = function() {		
        if (xmlhttp.readyState == 4) {
          if (xmlhttp.status == 200){
          
        		var ss = document.getElementById('suggest');
        		var suggest = '';
        		ss.innerHTML = '';
        		var str = xmlhttp.responseText;
        
            if (str) {
          		ss.innerHTML += str;
        		}
        	}
        	else
    		    alert(xmlhttp.status);
      	};
		}
	}		
}


//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
	document.getElementById('q').value = value;
	document.getElementById('suggest').innerHTML = '';
}
//Close function
function suggestClose(div_value) {
  document.getElementById('suggest').innerHTML='';
  document.getElementById('q').focus();
  sugg = false;
}


