// 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();
	}
}

// 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=no,location=no,status=no,width=100,height=100,resizable=1,screenX=150,screenY=150", false);
}

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 flush_repository() {
	ajax_call(url + "inc/ajax/arepository.php?flush=1");
	document.getElementById("repository_count").innerHTML = "0";
}

/**
* 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 id_product_forum = document.getElementById("id_product_forum").value;	
	getData(url + "inc/ajax/anewsforum.php?id_news=" + id_product + "&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);	 
	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;
        }
        x = event.x + plusX;
        y = event.y + plusY;
    } 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 openPopupWindow(theUrl, width, height)
{
    window.open(encodeURI(theUrl), "_blank", "toolbar=no,scrollbars=no,location=no,status=no,width="+width+",height="+height+",resizable=0,screenX=150,screenY=150", false);
}

