function mouseOn(row)
{
  row.style.backgroundColor = '#FBE6E6';
}

function mouseOut(row)
{
  row.style.backgroundColor = '';
}

function ref(reference)
{
  parent.location.href = reference;
}

function infoAlert(info1, info2)
{
  alert(info1+"\n"+info2);
}

function showDelete(id)
{
  var newSS = document.styleSheets[0];

  document.getElementById('delete_file'+id).value = '1';
  createRule(newSS, '#span_file'+id, 'display: inline;');
}

function dialog(what, reference) 
{
  if (confirm("Opravdu chcete "+what+"?") == true)
    window.location = reference; 
  else
    return 0;
}

function blankDialog(what, reference) 
{
  if (confirm(what) == true)
    window.location = reference; 
  else
    return 0;
}

function blinkIt()
{
 if (!document.all) return;
 else
 {
   for(i=0;i<document.all.tags('blink').length;i++)
   {
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}

function seoDescriptionHeight(id)
{
  var newSS = document.styleSheets[0];
  
  var ver = navigator.appVersion;
  if ((ver.indexOf("MSIE 6") != -1) || (ver.indexOf("MSIE 7") != -1))
    var height = description.offsetHeight;
  else
  {
    var ide = document.getElementById(id);
    if (ide)
      var height = ide.offsetHeight;
  }
  height = height + 15;
  createRule(newSS, '#indescription', 'height: '+height+'px;');
}

function linkCheck(id)
{
  var checkbox = document.getElementById('link_check_'+id);
  
  if (checkbox.checked == true)
    checkbox.checked = false;
  else
    checkbox.checked = true;
}

function uncheckAll(theElement)
{
  var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length; z++)
	{
    if(theForm[z].type == 'checkbox')
      theForm[z].checked = theElement.checked;
  }
}

function numbersOnly(myfield, e, dec)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
     return true;
  
  // decimal point jump
  else if (dec && (keychar == "."))
     {
     myfield.form.elements[dec].focus();
     return false;
     }
  else
     return false;
}

function changeBookmark(id)
{
  var newSS = document.styleSheets[0];

  if (id==1)
  {
    createRule(newSS, '#bookmark_on1', 'display: block;');
    createRule(newSS, '#bookmark_off1', 'display: none;');
    createRule(newSS, '#bookmark_text1', 'display: block;');

    createRule(newSS, '#bookmark_on2', 'display: none;');
    createRule(newSS, '#bookmark_off2', 'display: block;');
    createRule(newSS, '#bookmark_text2', 'display: none;');
    createRule(newSS, '#bookmark_on3', 'display: none;');
    createRule(newSS, '#bookmark_off3', 'display: block;');
    createRule(newSS, '#bookmark_text3', 'display: none;');
    createRule(newSS, '#bookmark_on4', 'display: none;');
    createRule(newSS, '#bookmark_off4', 'display: block;');
    createRule(newSS, '#bookmark_text4', 'display: none;');
    createRule(newSS, '#bookmark_on5', 'display: none;');
    createRule(newSS, '#bookmark_off5', 'display: block;');
    createRule(newSS, '#bookmark_text5', 'display: none;');
  }
  else if (id==2)
  {
    createRule(newSS, '#bookmark_on2', 'display: block;');
    createRule(newSS, '#bookmark_off2', 'display: none;');
    createRule(newSS, '#bookmark_text2', 'display: block;');

    createRule(newSS, '#bookmark_on1', 'display: none;');
    createRule(newSS, '#bookmark_off1', 'display: block;');
    createRule(newSS, '#bookmark_text1', 'display: none;');
    createRule(newSS, '#bookmark_on3', 'display: none;');
    createRule(newSS, '#bookmark_off3', 'display: block;');
    createRule(newSS, '#bookmark_text3', 'display: none;');
    createRule(newSS, '#bookmark_on4', 'display: none;');
    createRule(newSS, '#bookmark_off4', 'display: block;');
    createRule(newSS, '#bookmark_text4', 'display: none;');
    createRule(newSS, '#bookmark_on5', 'display: none;');
    createRule(newSS, '#bookmark_off5', 'display: block;');
    createRule(newSS, '#bookmark_text5', 'display: none;');
  }  
  else if (id==3)
  {
    createRule(newSS, '#bookmark_on3', 'display: block;');
    createRule(newSS, '#bookmark_off3', 'display: none;');
    createRule(newSS, '#bookmark_text3', 'display: block;');

    createRule(newSS, '#bookmark_on1', 'display: none;');
    createRule(newSS, '#bookmark_off1', 'display: block;');
    createRule(newSS, '#bookmark_text1', 'display: none;');
    createRule(newSS, '#bookmark_on2', 'display: none;');
    createRule(newSS, '#bookmark_off2', 'display: block;');
    createRule(newSS, '#bookmark_text2', 'display: none;');
    createRule(newSS, '#bookmark_on4', 'display: none;');
    createRule(newSS, '#bookmark_off4', 'display: block;');
    createRule(newSS, '#bookmark_text4', 'display: none;');
    createRule(newSS, '#bookmark_on5', 'display: none;');
    createRule(newSS, '#bookmark_off5', 'display: block;');
    createRule(newSS, '#bookmark_text5', 'display: none;');
  }  
  else if (id==4)
  {
    createRule(newSS, '#bookmark_on4', 'display: block;');
    createRule(newSS, '#bookmark_off4', 'display: none;');
    createRule(newSS, '#bookmark_text4', 'display: block;');

    createRule(newSS, '#bookmark_on1', 'display: none;');
    createRule(newSS, '#bookmark_off1', 'display: block;');
    createRule(newSS, '#bookmark_text1', 'display: none;');
    createRule(newSS, '#bookmark_on2', 'display: none;');
    createRule(newSS, '#bookmark_off2', 'display: block;');
    createRule(newSS, '#bookmark_text2', 'display: none;');
    createRule(newSS, '#bookmark_on3', 'display: none;');
    createRule(newSS, '#bookmark_off3', 'display: block;');
    createRule(newSS, '#bookmark_text3', 'display: none;');
    createRule(newSS, '#bookmark_on5', 'display: none;');
    createRule(newSS, '#bookmark_off5', 'display: block;');
    createRule(newSS, '#bookmark_text5', 'display: none;');
  }  
  else if (id==5)
  {
    createRule(newSS, '#bookmark_on5', 'display: block;');
    createRule(newSS, '#bookmark_off5', 'display: none;');
    createRule(newSS, '#bookmark_text5', 'display: block;');

    createRule(newSS, '#bookmark_on1', 'display: none;');
    createRule(newSS, '#bookmark_off1', 'display: block;');
    createRule(newSS, '#bookmark_text1', 'display: none;');
    createRule(newSS, '#bookmark_on2', 'display: none;');
    createRule(newSS, '#bookmark_off2', 'display: block;');
    createRule(newSS, '#bookmark_text2', 'display: none;');
    createRule(newSS, '#bookmark_on3', 'display: none;');
    createRule(newSS, '#bookmark_off3', 'display: block;');
    createRule(newSS, '#bookmark_text3', 'display: none;');
    createRule(newSS, '#bookmark_on4', 'display: none;');
    createRule(newSS, '#bookmark_off4', 'display: block;');
    createRule(newSS, '#bookmark_text4', 'display: none;');
  }  
}

function stockChange(id, radio)
{
  var newSS = document.styleSheets[0];
  var stock_actual_1  = readCookie("stock_actual_1");
  var stock_actual_2  = readCookie("stock_actual_2");
  var stock_actual_3  = readCookie("stock_actual_3");
  var stock_actual_4  = readCookie("stock_actual_4");
  var stock_actual_5  = readCookie("stock_actual_5");
  
  if (!stock_actual_1) stock_actual_1 = '';
  if (!stock_actual_2) stock_actual_2 = '';
  if (!stock_actual_3) stock_actual_3 = '';
  if (!stock_actual_4) stock_actual_4 = '';
  if (!stock_actual_5) stock_actual_5 = '';

  if (id)
  {
    if (radio)
    {
      var stock_actual = stock_actual_1;
      createRule(newSS, '.connect_'+stock_actual, 'display: none;');
      var connect = '-'+id;

      createRule(newSS, '.connect_'+connect, 'display: block;');
      
      createCookie('stock_actual_1', connect, 365);
    }
    else
    {
      if (stock_actual_5)
        var stock_actual = stock_actual_1+stock_actual_2+stock_actual_3+stock_actual_4+stock_actual_5;
      else if (stock_actual_4)
        var stock_actual = stock_actual_1+stock_actual_2+stock_actual_3+stock_actual_4;
      else if (stock_actual_3)
        var stock_actual = stock_actual_1+stock_actual_2+stock_actual_3;
      else if (stock_actual_2)
        var stock_actual = stock_actual_1+stock_actual_2;    
      else if (stock_actual_1)
        var stock_actual = stock_actual_1;
      
      createRule(newSS, '.connect_'+stock_actual, 'display: none;');

      var connect_this = document.getElementById('select_'+id).value;
      connect_this = '-'+connect_this;
      
      if (id==1)
        var connect = connect_this+stock_actual_2+stock_actual_3+stock_actual_4+stock_actual_5;
      if (id==2)
        var connect = stock_actual_1+connect_this+stock_actual_3+stock_actual_4+stock_actual_5;
      if (id==3)
        var connect = stock_actual_1+stock_actual_2+connect_this+stock_actual_4+stock_actual_5;
      if (id==4)
        var connect = stock_actual_1+stock_actual_2+stock_actual_3+connect_this+stock_actual_5;
      if (id==5)
        var connect = stock_actual_1+stock_actual_2+stock_actual_3+stock_actual_4+connect_this;

      createRule(newSS, '.connect_'+connect, 'display: block;');
      
      createCookie('stock_actual_'+id, connect_this, 365);
    }
  }
  else
  {
    if (stock_actual_5)
      createRule(newSS, '.connect_'+stock_actual_1+stock_actual_2+stock_actual_3+stock_actual_4+stock_actual_5, 'display: block;');
    else if (stock_actual_4)
      createRule(newSS, '.connect_'+stock_actual_1+stock_actual_2+stock_actual_3+stock_actual_4, 'display: block;');
    else if (stock_actual_3)
      createRule(newSS, '.connect_'+stock_actual_1+stock_actual_2+stock_actual_3, 'display: block;');
    else if (stock_actual_2)
      createRule(newSS, '.connect_'+stock_actual_1+stock_actual_2, 'display: block;');    
    else if (stock_actual_1)
      createRule(newSS, '.connect_'+stock_actual_1, 'display: block;');
  }
}

function stockHide(connect)
{
  var newSS = document.styleSheets[0];  
  createRule(newSS, '.connect_'+connect, 'display: none;');
}

function stockInit(id, connect)
{
  createCookie('stock_actual_'+id, connect, 365);
}

function stockReset()
{
  createCookie('stock_actual_1', '', 365);
  createCookie('stock_actual_2', '', 365);
  createCookie('stock_actual_3', '', 365);
  createCookie('stock_actual_4', '', 365);
  createCookie('stock_actual_5', '', 365);
}

function show_variant(id)
{
  var newSS = document.styleSheets[0];
  var check = document.getElementById('check_'+id).checked;

  if (check == true)
    createRule(newSS, '.var_'+id, 'display: inline;');
  else
    createRule(newSS, '.var_'+id, 'display: none;');
}

function hide_variant(id)
{
  var newSS = document.styleSheets[0];
  
  createRule(newSS, '.var_'+id, 'display: none;');
}

function createRule(stylesheet, selektor, deklarace)
{
  if (stylesheet.cssRules)
  {
    var rules = stylesheet.cssRules;
  } else if (stylesheet.rules)
  {
    var rules = stylesheet.rules;
  }
  
  var index = rules.length;
  
  if (stylesheet.insertRule)
  {
    var ruleText = selektor+'{'+deklarace+'}';
    stylesheet.insertRule(ruleText, index);
  } else if (stylesheet.addRule)
  {
    stylesheet.addRule(selektor, deklarace, index);
  }
}
	
function newRule(id)
{
  var newSS = document.styleSheets[0];
  
  if (id == "10")
  {
    createRule(newSS, '.deliver', 'display: none;');
    createCookie("deliver_cookie", id, 365);
  }
  if (id == "11")
  {
    createRule(newSS, '.deliver', 'display: block;');
    createCookie("deliver_cookie", id, 365);
  }    
  if (id == "20")
  {
    createRule(newSS, '.invoice', 'display: none;');  
    createCookie("invoice_cookie", id, 365);
  } 
  if (id == "21")
  {
    createRule(newSS, '.invoice', 'display: block;');  
    createCookie("invoice_cookie", id, 365);
  } 
}

function navigator_order()
{
  var aaa = document.getElementById('order').value;
  location.href=(aaa);
}

function navigator_products()
{
  var aaa = document.getElementById('products').value;
  location.href=(aaa);
}

function navigator_glproducer()
{
  var aaa = document.getElementById('glproducer').value;
  location.href=(aaa);
}

function navigator_serie()
{
  var aaa = document.getElementById('serie').value;
  location.href=(aaa);
}

function navigator_dir()
{
  var aaa = document.getElementById('dir').value;
  location.href=(aaa);
}

function navigator_price()
{
  var aaa = document.getElementById('price').value;
  location.href=(aaa);
}

function navigator_medium()
{
  var aaa = document.getElementById('medium').value;
  location.href=(aaa);
}

function navigator_duration()
{
  var aaa = document.getElementById('duration').value;
  location.href=(aaa);
}

function navigatorToID(id)
{
  var aaa = document.getElementById(id).value;
  location.href=(aaa);
}

function locationToID(where, direct)
{
  if (direct)
    location.href=(where);
  else
  {
    var aaa = document.getElementById(where).value;
    location.href=(aaa);
  }
}

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 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 openNewWindow(reference)
{
  window.open(reference, '');
}

function NetShops()
{
  url = 'http://www.netshops.cz/';
  window.open(url, '');
}

function openPhoto(server, id)
{
  iMyWidth = (window.screen.width/2) - (400 + 10)
  iMyHeight = (window.screen.height/2) - (300 + 25)
  Fokus = window.open(server+"/photo.php?id="+id, "","height=600,width=800,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=yes");
  Fokus.focus()
}

function eraseText(what)
{
  string = document.getElementById(what).value;
  first = string.substr(0,1);
  sixth = string.substr(5,1);
  if ((first==' ') || (first=='U') || (sixth=='X'))
    document.getElementById(what).value = '';
}

function hideCetelemButton()
{
  var newSS = document.styleSheets[0];
  createRule(newSS, '#send_request', 'display: none;');
}

function checkBox(id, what)
{
  var checkbox = document.getElementById(what+id);
  
  if (checkbox.checked == true)
    checkbox.checked = false;
  else
    checkbox.checked = true;
}

rating = {
	
	imgOff : "/_img/star_off.gif",
	imgOn : "/_img/star_on.gif",
	
	highlight : function (n) {
		n = ((n >= 0) && (n <= 5)) ? n : 0;
		for (var i = 1; i <= 5; i++) {
			var elm = document.getElementById("rating" + i);
			if (elm) {
				elm.src = (n <= i-1) ? rating.imgOff : rating.imgOn;
			}
		}
	}
}

function numberFormat_1(text) {
	//Reverse string
	//Loop through adding every character
	//If index = 3, add a comma
	//Reverse string
	text = text.split("").reverse().join("");
	var output = "";
	var j=0;
	for(var i = 0;i<text.length;i++) {
		output += text.charAt(i);
		j++;
		if(j==3 && i != text.length-1) {
			output += " ";
			j=0;
		}
	}
	output = output.split("").reverse().join("");
	return output;
}

var deliver_cookie = readCookie("deliver_cookie");
newRule(deliver_cookie);

var invoice_cookie = readCookie("invoice_cookie");
newRule(invoice_cookie);
