// pri registraci aby bralo Enter
function Check_Key_Login(e) {
   var $key = 0;

   if (document.all) {
      $key = window.event.keyCode;
   } else {
      $key = e.which;
   }

   if ($key == 13) {
      document.getElementById("logs").submit();
	}
}

function validateEmail(elementValue){  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
   return emailPattern.test(elementValue);  
} 
 
// auto refresh na zmenu jazyka v poste
function Change_Lang() {
	selected_lang = document.getElementById("langs");
	selected_lang = selected_lang.options[selected_lang.selectedIndex];
	selected_lang = selected_lang.value;
	
	document.getElementById("lang").value = selected_lang;
	document.getElementById("language").submit();
}

//ShowImage
// zobrazi obrazek...
function ShowImage(filename) {
  window.open(encodeURI(url + "foto.php?img=" + filename), "_blank", "toolbar=no,scrollbars=yes,location=no,status=no,width=100,height=100,resizable=1,screenX=150,screenY=150", false);
}

function checkEnter(e){
 //e is event object passed from function invocation
  var characterCode //literal character code will be stored in this variable
  
  if(e && e.which){ //if which property of event object is supported (NN4)
    e = e
    characterCode = e.which //character code is contained in NN4's which property
  }
  else {
    e = event
    characterCode = e.keyCode //character code is contained in IE's keyCode property
  }
  
  if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
    pager(document.getElementById('to_page').value)
    return false
  }
  else {
    return true
  }  
}

function new_window(url1) {
  window.open(encodeURI(url1), "_blank", "toolbar=no,scrollbars=yes,location=no,status=no,width=800,height=550,resizable=1,screenX=100,screenY=150", false);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function verify_length(id, length, text) {
	var obj = document.getElementById(id);
	if (obj.value.length < length) { 
		alert(text);
		obj.focus();
		return false;
	}
	return true;
}
		
function valid_email (email) {
	var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (email.search(validRegExp) == -1) {
		return false;
	} else {
		return true;
	} 
}

/**
* COMPARE
*/
function add_compare(id) {
	ajax_call(url + "inc/ajax/acompare.php?id=" + id);
}

function show_compare() {
	new_window(url + "compare.php");
}

function send_to_friend(id) {
	window.open(encodeURI(url + "send_to_friend.php?id=" + id), "_blank", "toolbar=no,scrollbars=yes,location=no,status=no,width=480,height=440,resizable=1,screenX=100,screenY=150", false);
}

/**
* SCHRANKA
*/
function add_to_repository (id) {
	getData(url + "inc/ajax/arepository.php?id=" + id, "repository_count");
}

function sel_to_repository() {
	getData(url + "inc/ajax/arepository.php?sel=true", "repository_count");
}

function flush_repository() {
	ajax_call(url + "inc/ajax/arepository.php?flush=1");
	document.getElementById("repository_count").innerHTML = "0";
}

/**
 ** HLIDACI PES
 */

function add_one_to_watchdog (id)
{
  getData(url + "inc/ajax/awatch_dog.php?id=" + id+"&action=add","watch_dog_count") ;
}  

function sel_to_watchdog()
{
  getData(url + "inc/ajax/awatch_dog.php?sel=true","watch_dog_count") ;
}  

function remove_from_watchdog (id)
{
  getData(url + "inc/ajax/awatch_dog.php?id=" + id+"&action=remove","watch_dog_count") ;
  setTimeout("window.location.href=window.location.href", 1000);
}  

function flush_watchdog() {
	ajax_call(url + "inc/ajax/awatch_dog.php?flush=1");
	document.getElementById("watch_dog_count").innerHTML = "0";
	window.location.href=window.location.href;
}

/**
 * zjisteni hodnoty poukazky
 */  
function GetVoucherValue(use_voucher,uniq_id)
{
  getData(url + "inc/ajax/avoucher.php?use_voucher=" + use_voucher + "&uniq_id=" + uniq_id,"voucher_value_block") ;
  //window.location.href=window.location.href;
}  

/**
 * menova kalkulacka
 */
function Calculate_Currency(code)
{
  var price=document.curr_calc.in_price.value;
  var index=document.curr_calc.currency.selectedIndex;
  var code=document.curr_calc.currency.options[index].value;
	getData(url + "inc/ajax/acurrencies.php?price=" + price + "&code=" + code,"out_price") ;
  //window.location.href=window.location.href;
}
/**
* zalozky
*/
function zal_menu_select(id) {
  var obal = document.getElementById("zalozkMenu");
  var zalozky = obal.getElementsByTagName("A");
  var i = 0;
  for (i = 0; i < zalozky.length; i++) {
    if ("zal" + id == zalozky[i].id) {
    	zalozky[i].className = "act";
    } else {
    	zalozky[i].className = "";    
    } 
  }
}


/**
* RATING
*/
function get_sel_rating() {
	var butts = document.getElementsByName("ratingbutton");
	var i = 0;
	for (i = 0; i < butts.length; i++) {
		if (butts[i].checked == true) return butts[i].value;
	}
	return null;
}

function rate(id, extend, note) {
	var mark = get_sel_rating();
	if (mark == null) return;
	var dest = "";
	if (extend == 0) dest = "rating_form"; else dest = "product_content";
	getData(url + "inc/ajax/arating.php?id_product=" + id + "&mark=" + mark + "&extend=" + extend + "&note=" + encodeURI(note) + "&preurl=" + url, dest);	
	var note_rated_span = document.getElementById("note_rated");
	if (note != "" && note != document.getElementById("def_rating_text").value) note_rated_span.innerHTML = parseInt(note_rated_span.innerHTML) + 1;
}

function show_rating(id) {
	zal_menu_select(3);
	getData(url + "inc/ajax/arating.php?id_product=" + id + "&extend=1" + "&preurl=" + url, "product_content");	
}

function show_product_info(id) {
	zal_menu_select(1);
	getData(url + "inc/ajax/aproduct.php?id=" + id + "&extend=1" + "&preurl=" + url, "product_content");	
}

/**
* FORUM
*/

function show_forum(id) {
	zal_menu_select(2);
	getData(url + "inc/ajax/aforum.php?id_product=" + id + "&preurl=" + url, "product_content");	
}

function show_forum_news(id) {
	getData(url + "inc/ajax/anewsforum.php?id_news=" + id + "&preurl=" + url, "news_forum");
}

function forum_add(id_product) {
	if (verify_forum() == false) return false;
	var subject = encodeURI(document.getElementById("subject").value);
	var name = encodeURI(document.getElementById("name").value);
	var email = encodeURI(document.getElementById("email").value);
	var text = encodeURI(document.getElementById("text").value);
	var id_product_forum = document.getElementById("id_product_forum").value;	
	var require_admin = 0;
	if (document.getElementById("require_admin").checked == true) require_admin = 1;
	getData(url + "inc/ajax/aforum.php?id_product=" + id_product + "&title=" + subject + "&email=" + email + "&name=" + name + "&content=" + text + "&require_admin=" + require_admin + "&id_product_forum=" + id_product_forum, "product_content");
	var forum_count = document.getElementById("forum_count");	
	forum_count.innerHTML = parseInt(forum_count.innerHTML) + 1;	
}

function forum_news_add(id_product) {
	if (verify_forum() == false) return false;
	var subject = encodeURI(document.getElementById("subject").value);
	var name = encodeURI(document.getElementById("name").value);
	var email = encodeURI(document.getElementById("email").value);
	var text = encodeURI(document.getElementById("text").value);
	var public_key = encodeURI(document.getElementById("captcha_public_key").value);
	var private_key = encodeURI(document.getElementById("private_key").value);
	var id_product_forum = document.getElementById("id_product_forum").value;	
	getData(url + "inc/ajax/anewsforum.php?id_news=" + id_product + "&public_key=" + public_key + "&private_key=" + private_key + "&title=" + subject + "&email=" + email + "&name=" + name + "&content=" + text + "&id_product_forum=" + id_product_forum, "news_forum");
}

function forum_reply(id_product_forum) {
	document.getElementById("id_product_forum").value = id_product_forum;
	var subj_text = document.getElementById("forum" + id_product_forum + "subject").innerHTML;
	document.getElementById("subject").value = "Re: " +  subj_text;
}

/**
* DOWNLOAD
*/
function show_download(id) {
	zal_menu_select(4);
	getData(url + "inc/ajax/adownload.php?id=" + id + "&preurl=" + url, "product_content");
}

/**
*  PRODUCT VISIT
*/
var call_product_visits = false;

/**
* ON MOUSE OVER IMAGE 
**/
var timerT = false;

function show_small(filename, title, url) {
	if (show_small_image == false) return;
	if (timerT) clearTimeout(timerT); 
	

	var posl_lomitko = filename.lastIndexOf("/") + 1;
	
	if (!filename || filename.substring(posl_lomitko) == "none.gif") return;
	
	
	var old_filename = filename.substring(posl_lomitko + 3);
	var small_div = document.getElementById("smallDiv");
	var path = filename.substring(0, posl_lomitko);
	
	
	var new_filename = "sm_" + old_filename;
	small_div.innerHTML = "<a href='" + url + "'><strong>" + title + "</strong><br /><img src='" + path + new_filename + "' alt='" + title + "' title='" + title + "' /></a>";
	var cmd = "del_show();";
	timerT = setTimeout(cmd, 600); 
}

function del_show() {
	clearTimeout(timerT);
   //alert('ttYpos '+ttYpos+', ttXpos '+ttXpos);	 
	var small_div = document.getElementById("smallDiv");	
	small_div.style.top = eval(ttYpos - 86) + "px";
	small_div.style.left = eval(ttXpos - 90) + "px";
	small_div.style.visibility = "visible";
}

function image_hide() {
	var small_div = document.getElementById("smallDiv");
	small_div.style.visibility = "hidden";
}



var ttXpos = 0, ttYpos = 0;
var ttXadd = 10, ttYadd = -10;
var ttDisplay = 0, ttHoldIt = 0;
// Check if browser does support dynamic content and dhtml
var ttNS4 = (document.layers) ? 1 : 0;           // the old Netscape 4
var ttIE4 = (document.all) ? 1 : 0;              // browser wich uses document.all
var ttDOM = (document.getElementById) ? 1 : 0;   // DOM-compatible browsers
if (ttDOM) { // if DOM-compatible, set the others to false
    ttNS4 = 0;
    ttIE4 = 0;
}

if ( (ttDOM) || (ttIE4) || (ttNS4) ) {
    // reference to TooltipContainer
    if (ttNS4) var myTooltipContainer = document.TooltipContainer;
	else if (ttIE4) var myTooltipContainer = document.all('TooltipContainer');
	else if (ttDOM) var myTooltipContainer = document.getElementById('TooltipContainer');
    // mouse-event
    
    document.onmousemove = mouseMove;
    if (ttNS4) document.captureEvents(Event.MOUSEMOVE);
} 

function mouseMove(e) {
    var x=0, y=0, plusX=0, plusY=0, docX=0; docY=0;
    if (navigator.appName.indexOf("Explorer")!=-1) {
        if (document.documentElement && document.documentElement.scrollTop) {
            plusX = document.documentElement.scrollLeft;
            plusY = document.documentElement.scrollTop;
            docX = document.documentElement.offsetWidth + plusX;
            docY = document.documentElement.offsetHeight + plusY;
        } else {
//            plusX = document.body.scrollLeft;
//            plusY = document.body.scrollTop;
//            docX = document.body.offsetWidth;// + plusX;
//            docY = document.body.offsetHeight;// + plusY;
        }
        if (navigator.appVersion.search('MSIE 8.0') == -1)
        {
          x = event.x + plusX;
          y = event.y + plusY;//alert('test');
        }
        else
        {
          x = event.x;
          y = event.y;
        }
        //alert('t');
    } else {
        x = e.pageX;
        y = e.pageY;
        docX = document.body.clientWidth;
        docY = document.body.clientHeight;
    }
    ttXpos = x;
    ttYpos = y;
    if ((ttXpos ) > docX)
        ttXpos = ttXpos - ((ttXadd * 2));
    if ((ttYpos) > docY)
        ttYpos = ttYpos - ((ttYadd * 2));
}

function intrigue(text)
{    
   	getData(url + "inc/ajax/aintriguer.php?inp=" + text,"intriguer") ;
}

function MouseEvent(e)
{
  if(e) {
    this.e = e;
  } else {
    this.e = window.event;
  }
  
  if(e.pageX) {
    this.x = e.pageX;
  } else {
    this.x = e.clientX;
  }

  if(e.pageY) {
    this.y = e.pageY;
  } else {
    this.y = e.clientY;
  }
  
  if(e.target) {
    this.target = e.target;
  } else {
    this.target = e.srcElement;
  }
}
