isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isMSIE=document.all && document.all.item //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && navigator.userAgent.indexOf("Opera 7") > 0 ||
                    navigator.userAgent.indexOf("Opera/7") >= 0 //Opera 7
isNetscape4=document.layers //Netscape 4.*
isMozilla=isNetscape6=isDOM && (navigator.appName=="Netscape") //Mozilla или Netscape 6.*

// is for test only. You can delete it

// --------- News images functions -------------

var ImagesSmall = new Array;
var ImagesBig = new Array;
var ImagesId = new Array;
var Alts = new Array;
var CurImage = new Array;
var img = new Array;
var defaultFormValues = new Object();
var autofillNames = new Array('login', 'password', 'query');

var IconOn = new Image; IconOn.src = '/img/media/icon_image_on.gif';
var IconOff = new Image; IconOff.src = '/img/media/icon_image.gif';

function Preload(){
	for(i=0;i<ImagesSmall.length;i++) {
	  if(ImagesSmall[i]){
	    document.images["icon_"+i+"_0"].src = IconOn.src;
	    img[i] = new Array;
	    for(j=0; j<ImagesSmall[i].length; j++) {
	      img[i][j] = new Image;
	      img[i][j].src = ImagesSmall[i][j];
	    }
	  }
	}
}

function ShowImage(parent, index){
  ShowImage2(parent, index, ImagesId[index][CurImage[index]]);
}

function ShowImage2(parent, id, mediaid){
  var url = '/cgi-bin/kernel.cgi?module=media&act=show&parent='+parent+'&id='+id+'&mediaid='+mediaid;
  windowOpen(url);
}

function windowOpen(url){
  var width = windowOpen.arguments[1] || 550;
  var height = windowOpen.arguments[2] || 500;
  window.open(url, '', 'resizable=yes,menubar=no,status=no,scrollbars=yes,statusbar=no,toolbar=no,width='+width+',height='+height);
}

function Splash(i,j){
 document.images["icon_"+i+"_"+CurImage[i]].src = IconOff.src;

 if(img[i]){
  document.images["item"+i].src=img[i][j].src
  document.images["item"+i].width=img[i][j].width;
  document.images["item"+i].height=img[i][j].height;
 }
 else{
  document.images["item"+i].src=ImagesSmall[i][j];
 }
 document.images["item"+i].alt = Alts[i][j];

 CurImage[i] = j;
 document.images["icon_"+i+"_"+j].src = IconOn.src
}

function flip(blockid){
        var obj = document.getElementsByTagName('UL');
        for(var i in obj){
                if(!obj[i].id || obj[i].id.indexOf('block') == -1) continue;
                obj[i].style.display = obj[i].id == blockid ? 'block':'none';
        }
}

function $(){
  var obj = document.getElementsByTagName('INPUT');
  var obj1 = document.getElementsByTagName('TEXTAREA');
  var doFill;
  for(var i in obj1){
    if(!obj1[i].tagName) continue;
    obj[obj.length] = obj1[i];
  }
  for(var i in obj){
    if(!obj[i].tagName || (obj[i].type != 'text' && obj[i].type != 'password' && obj[i].type != 'textarea')) continue;
    doFill = false;
    for(var j in autofillNames) if(obj[i].name == autofillNames[j]) doFill = true;
    if(!doFill) continue;
    defaultFormValues[obj[i].name] = obj[i].value;
    obj[i].onfocus = function(){
      this.className += this.className ? ' active' : 'active';
      this.value = (this.value == defaultFormValues[this.name]) ? '' : this.value;
    };
    obj[i].onblur = function(){
      this.value = (this.value.length == 0) ? defaultFormValues[this.name] : this.value;
      var classes = this.className.split(' ');
      var res = '';
      for(var i=0; i<classes.length; i++){
        res += ((classes[i] == 'active') || !classes[i]) ? '' : classes[i]+' ';
      }
      this.className = res;
    };
  }
}

window.onload = Preload;
