/*
function $(obj)
{
  return document.getElementById(obj);
}
*/
var prevBookmark=null;
function addCookie(name,val)
{
  document.cookie = name+"="+val;
}
function readCookie(cookieName) {
  var theCookie=""+document.cookie;
  var ind=theCookie.indexOf(cookieName);
  if (ind==-1 || cookieName=="") return ""; 
  var ind1=theCookie.indexOf(';',ind);
  if (ind1==-1) ind1=theCookie.length;
  return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function openModPanel()
{
  if($('modPanelBtn').getAttribute('status')==0){
    showModPanel();
    document.cookie = "blogomaniaModPanel=on";
  }else{
    closeModPanel();
    document.cookie = "blogomaniaModPanel=off";
  }
}
function showModPanel()
{
  Element.show('modPanelContent');
  $('modPanelBtn').className='hide';
  $('modPanelBtn').setAttribute('status',1);
}
function closeModPanel()
{
  Element.hide('modPanelContent'); 
  $('modPanelBtn').className='show';
  $('modPanelBtn').setAttribute('status',0);
}
function changeTemplateColumnWidth(column,opt)
{
  colCnt=$('columnCnt').value;
  n=(column==colCnt)?(column-1):(column+1);
  
  if( !$('templateColumnWidth'+n) ) return;
  
  d=parseInt($('templateColumnWidth'+column).innerHTML);
  dn=parseInt($('templateColumnWidth'+n).innerHTML);
  
  if(opt==1){
    w=(d<100)?(d+1):d;
    wn=(dn<100)?(dn-1):dn;
  }else{
    w=(d>0)?(d-1):d;   
    wn=(dn>0)?(dn+1):dn;
  }
  
  if( w < 10 || wn < 10 ) return
  
  $('templateColumn'+column).style.width=w+'%';
  $('templateColumnWidth'+column).innerHTML=w;
  $('templateColumnsWidth'+column).value=w;
  
  $('templateColumn'+n).style.width=wn+'%';
  $('templateColumnWidth'+n).innerHTML=wn;
  $('templateColumnsWidth'+n).value=wn;
}
function initSelectAction(t,form)
{
  switch(t.value)
  {
    case 'none':
      return false;
      break;
    case 'delete':
      if( confirm('Czy usunąć?') ) $(form).submit();
      break;
    default:
      $(form).submit();
  }
  t.selectedIndex = 0;
}
function selectAll(className,v)
{
  el=document.getElementsByClassName(className);
  for(q=0,cnt=el.length;q<cnt;q++){el[q].checked=v}
}
function mcolumnOff()
{
  el=document.getElementsByClassName('mcolumn');
  for(q=0,cnt=el.length;q<cnt;q++){el[q].src=el[q].src.replace(/_on/,'_off');el[q].title='Włącz';}
}
function showBookmarkContent(el,t)
{  
  if( prevBookmark != null )
  {
    $(prevBookmark).style.display='none';
    $(prevBookmark+'Bm').style.color='';
  }
  $(el).style.display='block';
  $(el+'Bm').style.color = '#E5720D';
  prevBookmark = el;
}
function showTextI18N(t)
{
  next = 1;
  els=document.getElementsByClassName('i18n_on');
  for(i=0,cnt=els.length;i<cnt;i++){ 
    els[i].style.background='none'; els[i].style.border='0';
    els[i].className = els[i].className.replace(/_on/,'');
    next = 0;
  }
  
  if( next == 1 ){
    els=document.getElementsByClassName('i18n');
    for(i=0,cnt=els.length;i<cnt;i++){
      if(els[i] != undefined)
      {
        els[i].style.background='#E142FE'; els[i].style.border='1px solid #fff';
        els[i].className += '_on';
      }
    }
    t.innerHTML = t.innerHTML.replace(/Pokaż/,'Ukryj');
  }
  else
  {
    t.innerHTML = t.innerHTML.replace(/Ukryj/,'Pokaż');
  }
}
function selectItem(obj) 
{
  t = document.getElementById(obj);
  parent = t.parentNode;
  
  el = parent.getElementsByTagName('a');
  
  for(var i=0, cnt=el.length; i<cnt; i++ )
  {
    if( el[i].className == 'selected' )
    {
      el[i].className = 'unselected';
    }
  }
  
  t.className = 'selected';

  return true;
}
function selectInputValue(select, v)
{
  var q, s=$(select), o=s.options;
  for(q=0, cnt=o.length; q<cnt; q++) if( o[q].value.toLowerCase() == v ) o[q].selected=1;
}
function insertImageDir(s1, s2, file)
{
  $(s1 + s2.substr(0, 1).toUpperCase() + s2.substr(1)).value=file;
}
function RGB2HTML(red, green, blue)
{
    var decColor = red + 256 * green + 65536 * blue;
    return decColor.toString(16);
}

//BLOG STYLES
function checkCheckboxWithElements(t,el,s1,s2)
{
  if( t.checked==1 )
  {
    Element.hide(el);
    blogStyle.set(s1,s2,'transparent');
  }
  else
  {
    Element.show(el);
  }
}
function checkCheckboxWithColor(el, color)
{
  if( color == undefined || color == 'transparent' || color == 'none' )
  {
    $(el+'NoBackground').checked = 1;
    Element.hide(el+'SliderBox');
  }
}

function BlogStyle()
{
  this.stylesheet = null;
  this.colorR     = 0;
  this.colorG     = 0;
  this.colorB     = 0;
  this.sheetID    = 1;
  this.setStylesheet();
}
BlogStyle.prototype.setStylesheet = function(v)
{
  this.stylesheet = document.styleSheets[this.sheetID];
  return this.stylesheet;
}
BlogStyle.prototype.__rules = function()
{
  if( this.stylesheet.cssRules )
  {
    return this.setStylesheet().cssRules;
  }
  else
  {
    return this.setStylesheet().rules;
  }
}
BlogStyle.prototype.__getRule = function(selector)
{
  this.insertRule(selector);
  
  for(var q=0, cnt=this.__rules().length-1; q<cnt; q++)
  {
    if( this.__rules()[q].selectorText.toLowerCase() == selector )
    {
      return this.__rules()[q];
    }
  }
  
  return false;
}

BlogStyle.prototype.insertRule = function(selector, attribute)
{ 
  if( this.find(selector) == false )
  {  
    if( this.stylesheet.cssRules )
    {
      this.setStylesheet().insertRule(selector + " {}", this.__rules().length);
    }
    else
    {
      this.setStylesheet().addRule(selector,'counter-reset: none;', this.__rules().length);
    }
  }
}
BlogStyle.prototype.set = function(selector, attribute, v)
{
  if( !this.stylesheet ) return;
  if( this.__getRule(selector) ){
    eval("this.__getRule(selector).style."+attribute+" = '"+v+"';");
  }
}
BlogStyle.prototype.get = function(selector, attribute, v)
{
  if( !this.stylesheet ) return;
  
  if( this.__getRule(selector) ){
    rule = this.__getRule(selector);
  } else {
    rule = null;
  }
  eval("this.val = rule ? rule.style."+attribute+" : null;"); 
  return this;
}
BlogStyle.prototype.find = function(selector)
{
  for(var q=0, cnt=this.__rules().length; q<cnt; q++)
  {
    if( this.__rules()[q].selectorText.toLowerCase() == selector.toLowerCase() ) return true;
  }
  return false;
}
BlogStyle.prototype.getAllRules = function()
{
  var content = '';

  for(var q=0, cnt=this.__rules().length; q<cnt; q++)
  {
    content += this.__rules()[q].selectorText.toLowerCase() + ' {' + this.__rules()[q].style.cssText.toLowerCase() + '}\n';
  }
  return content;
}
BlogStyle.prototype._prepareColor = function(v)
{
  if( this.val == '' || this.val == null || this.val.indexOf('#') != -1 )
  {
    this.colorR = v; this.colorG = v; this.colorB = v;
  }
  else
  {
    this.val = this.val.replace('rgb(','');
    this.val = this.val.replace(')','');
    
    this.colorR = this.val.slice(0, this.val.indexOf(','));
    this.colorG = this.val.slice(this.val.indexOf(',')+1, this.val.lastIndexOf(',')).replace(' ','');
    this.colorB = this.val.slice(this.val.lastIndexOf(',')+1).replace(' ','');
  }
}
BlogStyle.prototype.getValue = function(v)
{
  if( this.val == undefined || this.val == '' ) this.val = v==undefined || v=='' ? 0 : v;
  return this.val;
}
BlogStyle.prototype.getCord = function()
{
  if(!this.val) return '';
  this.val = this.val.replace('px','');
  return this.val;
}
BlogStyle.prototype.getSrc = function()
{
  if(!this.val) return '';
  this.val = this.val.replace('url(','');
  this.val = this.val.replace(')','');
  //alert(this.val);
  return this.val;
}
BlogStyle.prototype.getRGBColor = function()
{
  return 'rgb('+this.getR()+','+this.getG()+','+this.getB()+')';
}
BlogStyle.prototype.getR = function(v)
{
  this._prepareColor(v);
  r = parseInt(this.colorR);
  return isNaN(r) ? 0 : r;
}
BlogStyle.prototype.getG = function(v)
{
  this._prepareColor(v);
  r = parseInt(this.colorG);
  return isNaN(r) ? 0 : r;
}
BlogStyle.prototype.getB = function(v)
{
  this._prepareColor(v);
  r = parseInt(this.colorB);
  return isNaN(r) ? 0 : r;
}
BlogStyle.prototype.addList = function()
{
  this.set('li','listStyle','none');
  this.set('ul','margin','0');
  this.set('li','margin','0');
  this.set('li','backgroundPosition','4px center');
  this.set('li','backgroundRepeat','no-repeat');
}


//
function MySlider()
{

}
MySlider.prototype.getColorRGB = function(el)
{
  elR = $('r'+el).value;
  elG = $('g'+el).value;
  elB = $('b'+el).value;
  
  return 'rgb('+elR+','+elG+','+elB+')';
}
MySlider.prototype.setPreviewColor = function(preview, r, g, b)
{
  elPreview = $(preview);
  elR = $(r).value;
  elG = $(g).value;
  elB = $(b).value;
  
  elPreview.style.backgroundColor = 'rgb('+elR+','+elG+','+elB+')';
}
MySlider.prototype.setPreviewColorRGB = function(preview, el)
{
  elPreview = $(preview);
  elR = $('r'+el).value;
  elG = $('g'+el).value;
  elB = $('b'+el).value;
  
  elPreview.style.backgroundColor = 'rgb('+elR+','+elG+','+elB+')';
}
MySlider.prototype.setInputColor = function(input, color, t)
{
  elInput = $(input);
  elInput.value = color;
}

// UPLOADER
var stat=0;
function initUploader()
{
  stat=1;
  Element.hide('uploadSuccess');
  Element.hide('uploadError');
  Element.show('uploadLoader');
}
function watchUploader()
{
  if(stat){
    el=$('uploadFeedback').contentWindow.document.getElementById('console').innerHTML;
    el=parseInt(el);
    Element.hide('uploadLoader');
    switch(el)
    {
      case 200:
        Element.show('uploadSuccess');
        if(typeof uploadUpdater == 'function' ) uploadUpdater();
        if(typeof uploadFormCleaner == 'function' ) uploadFormCleaner();
        break;
      case 500:
        Element.show('uploadError');
        break;     
    }
	}
}

