
hexa=new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f')

function hex(i){if (i<0) return "00";else if (i>255)return "ff";else return ""+hexa[Math.floor(i/16)]+hexa[i%16]}
function setbg(r,g,b){hr=hex(r);hg=hex(g);hb=hex(b);bg="#"+hr+hg+hb}
function bc(hx){
//document.bgColor=hx;
document.frm.bgcol.value=hx}


function CheckSearch()
{
        var title = document.getElementById('input-title');
        var author = document.getElementById('input-author');

        if (title.value.length>=3)
                return true;
        else 
        {
                if (author.value.length>=3)
                        return true;
                else
                {
                        alert("Название или автор содержать более трех символов");
                        return false;
                }
        }
        
}


function setCookie(name, value) {
  var expire = "0, 01-01-2050 00:00:00 GMT"
  document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expire;
}

function getCookieValue(cookieName){
  var cookieValue=document.cookie;
  var cookieStartsAt=cookieValue.indexOf(" "+cookieName+"=");
  if (cookieStartsAt==-1){
    cookieStartsAt=cookieValue.indexOf(cookieName+"=");         
  }
  if (cookieStartsAt==-1){
    cookieValue=null;
  }
  else
  {
    cookieStartsAt=cookieValue.indexOf("=",cookieStartsAt)+1;
    var cookieEndsAt=cookieValue.indexOf(";",cookieStartsAt);
    if (cookieEndsAt==-1){
      cookieEndsAt=cookieValue.length;
    }
    cookieValue=unescape(cookieValue.substring(cookieStartsAt,cookieEndsAt));
  }
  return cookieValue;
}


function delCookie(name) {
  var expire = "0, 01-01-2050 00:00:00 GMT"
  document.cookie = name  + "; path=/; expires=" + expire;
}


function updateItem(n) {
  var items = getCookieValue ("basketItems");

  if (items) {
    var narray = items.split(";");
  } else {
    var narray = new Array();
  }

  for (var i=0; i<narray.length; i++) {
    if (narray[i] == n) {
      var found = i;
      break;
    }
  }
  if (found != null) {
    narray1 = new Array();
    j = 0;
    for (i = 0; i < narray.length; i++) {
      if (i != found) {
        narray1[j] = narray[i];
        j++;
      }
    }
    narray = narray1;
    
  } else {
    narray[narray.length] = n;
  }
  
  items = narray.join(";");
  setCookie("basketItems", items);
}

function toggleItem(i) {
  updateItem(i.name);
}

function clearItems() {
  setCookie("basketItems", "");
}

function switch_img(imgName, imgURL) {
//alert(document.images[imgName].src);
  document.images[imgName].src = imgURL;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


/*

$(document).ready(function() {

  var items = getCookieValue ("basketItems");
  alert(items);

  fm = $('form[@name="szak"]');

  if (fm) { 
    var items = getCookieValue ("basketItems");

    alert(items);

    if (items) {
      var narray = items.split(";");
    } else {
      var narray = new Array();
    }

    var s = '';

    for (var i=0; i<narray.length; i++) {
      found = $('form[@name="szak"]//input[@name="'+narray[i]+'"]');
      
      if (found.size()) {
        found.each(function (i) { this.checked = true; });
      } else {
        s = s + '<' + 'input type="hidden" name="'+narray[i]+'" value="1"' + '>';
      }
    }

    if (s) fm.append(s);
  }
});
*/
