/****************************************
* Script:       JSLibrary               *
* Version:      0.2                     *
* Date:         24.05.2004              *
* License:      Freeware                *
*                                       *
* Autor:        Boris Belenski          *
* Email:        b_belenski@hotmail.com  *
****************************************/

// Object
function getImage(id) { return isBr.dom?document.getElementById(id):isBr.ns4?document.images[id]:isBr.ie4?document.all[id]:0; }
function getLink(id) { return isBr.dom?document.getElementById(id):isBr.ns4?document.links[id]:isBr.ie4?document.all[id]:0; }
function getLayer(id,doc) {
 var o = 0,i;
 doc=isEmpty(doc)?document:doc;
 if(isBr.dom) o=document.getElementById(id);
 if(isBr.ie) o=document.all[id];
 if(isBr.ns4)
 {
   for(i = 0;i < doc.layers.length;i++)
   {
     var ldoc = doc.layers[i].document;
     if(ldoc[id]) return ldoc[id];
     if(ldoc.layers.length > 0)
     {
       var o = getLayer(id,ldoc);
       if(o) return o;
     }
   }
 }
 return 0;
}
function getElement(id)
{
  for (i = 0;i<document.forms.length;i++)
  {
    tv = document.forms[i];
    if (tv.name==id) return tv;
    for (j = 0;j<document.forms[i].elements.length;j++)
    {
      tv = document.forms[i].elements[j];
      if (tv.name==id) return tv
    }
  }
return 0
}

function setStatus(t) { self.status = t; return true }
function formError (m,f,e) { alert(m); document.forms[f].elements[e].focus(); return false }
function writeToLayer(id,tx) { var obj = getLayer(id); if (isBr.dom||isBr.ie4) { obj.innerHTML = ''; obj.innerHTML = tx; } else if (isBr.ns4) { obj.document.open(); obj.document.write(tx); obj.document.close(); }}
function getObjectByName(id) { tv = getImage(id); if (tv) return tv; tv = getLayer(id); if (tv) return tv; tv = getElement(id); if (tv) return tv; tv= getLink(id); if (tv) return tv; return 0 }
function getObjectByName2(id) { return getImage(id) || getLayer(id) || getElement(id) || getLink(id) }

function getElementsArray(e) {
 if(isBr.ns4)
 {
   var doc = (this == document) ? document : this.document;
   switch(e)
   {
     case 'img' : return doc.images;
     case 'div' : return doc.layers;
     case 'form' : return doc.forms;
     case 'a' : return doc.links;
     default : return 0;
   }
 }
 if(isBr.ie4) return this.all.tags(e);
 return 0;
}

// Check
function browserCheck()
{ ual = navigator.userAgent.toLowerCase();
this.op = (window.opera)?1:0;
this.op5 = ual.indexOf('opera 5')!=-1 || ual.indexOf('opera/5')!=-1;
this.op6 = ual.indexOf('opera 6')!=-1 || ual.indexOf('opera/6')!=-1;
this.opo = this.op5 || this.op6;
this.op7 = this.op && document.readyState;
this.dom = (document.getElementById)?1:0;
this.ie = document.all && !this.op;
this.ie4 = (this.ie && !this.dom)?1:0;
this.ie5u = (this.ie && this.dom)?1:0;
this.ns4 = document.layers && !this.dom;
this.com = ( this.dom || this.ie4 ) && !this.opo;
this.dio5 = this.dom || this.ie4 || this.op5 || this.op6;
return this; }

function checkEmail(e) { var reg = /[_a-z0-9\-]+(\.[_a-z0-9\-]+)*@[a-z0-9\-]+(\.[a-z0-9\-]+)*(\.[a-z]{2,4})/ig; return reg.test(e) }
function isEmpty (_v,_r) { var _tv=( _v==null || _v=="undefined" || _v.length<1 ); return ( _r==null || _r=="undefined" )?_tv:(_tv?_r:_v) } // Проверка за празна _v. Ако е празна връща _r
function isNaNP (v) { return ( v==null || v=="undefined" || isNaN(val) ) }
function isLow (v,c) { c = (isNaNP(c)?0:c); return ( isNaNP(val) && v<c ) }
function isHigh (v,c) { c = (isNaNP(c)?0:c); return ( isNaNP(val) && v>c ) }
function isInRange (v,c1,c2) { c1=(isNaNP(c1)?0:c1); c2=(isNaNP(c2)?1:c2); if (c1>c2) return ( !isNaNP(v) && v >= c2 && val <= c1 ); return ( !isNaNP(val) && val >= c1 && val <= c2 ) }
function isDefined (vn) { return !eval( 'typeof( '+cvar+' ) == "undefined"' ); }
function isDefined2 (vn) // Experimental
{
  function handleError() { isDefinedFlag=false; return true; }
  var isDefinedFlag=true, oldOnError=window.onerror;
  window.onerror=handleError;
//  try { eval(vn); } catch (e) { isDefinedFlag=false; } window.onerror=oldOnError; return isDefinedFlag;
  eval('try { '+cvar+'; } catch (e) { isDefinedFlag=false; }'); window.onerror=oldOnError; return isDefinedFlag;
//  try { eval(vn+'='+vn); } catch (e) { isDefinedFlag=false; } window.onerror=oldOnError; return isDefinedFlag;
}
function  isDateErr(v) {
  var tv=new Date();
  if (!e_date.exec(v)) return 4;
  if (RegExp.$1<1 || RegExp.$1>31) return 1;
  if (RegExp.$2-1<1 || RegExp.$2-1>12) return 2;
  if (RegExp.$3<tv.getFullYear()) return 3;
  return 0;
}

// Values
function selectValue(f,e) { f = isEmpty(f,0); e = isEmpty(e,0); return document.forms[f].elements[e].options[document.forms[f].elements[e].selectedIndex].text;}

// Other
function str2date (v) {
  var tv,tv2;
  if (!e_date.exec(v)) return false;
  tv2="0"+(RegExp.$2-1); tv="0"+RegExp.$1;
  return (new String (RegExp.$3+(tv2.substr(tv2.length-2,2))+(tv.substr(tv.length-2,2))));
}
function antiSpam(_d,_e,_u1,_t,_ex,_u2) { _tv=_u1+(isEmpty(_u2)?'':_u2)+'@'+_d+'.'+_e; _t=isEmpty(_t)?_tv:_t; document.write('<a href="mai'+'lto:'+_tv+(isEmpty(_ex)?'':('?'+_ex))+'">'+_t+'</a>'); }
function conVis2Dis(v) { return isBr.com?v=="visible"?"block":v=="hidden"?"none":v:v; }
function corVis(v) { return isBr.com?v:isBr.ns4?v=="visible"?"show":v=="hidden"?"hide":v:v; }
function objDisp(o,v) { if (isBr.com) o.style.display = v; }
function objVis(o,v) { v = corVis(v); if (isBr.com) o.style.visibility = v; else if (isBr.ns4) o.visibility = v; }
function objVisAll(o,v) { objVis(o,v); v = Vis2Dis(v); objDisp(o,v); }

function shw(tit,cnt,w,h) { if(pwin) if(!pwin.closed) pwin.close(); pwin = window.open('',"pwin", 'width = '+w+', height = '+h+', menubar = no, personalbar = no, resizable = no, scrollbars = no, status = no, toolbar = no, top = 15, left = 15'); pwin.document.write('<html><head><title>'+tit+'</title><meta http-equiv = "Content-Type" content = "text/html; charset = windows-1251"><meta HTTP-EQUIV = "Content-Language" CONTENT = "bg"><link href = "gen.css" rel = "stylesheet" type = "text/css"></head><body leftmargin = "0" topmargin = "0" marginwidth = "0" marginheight = "0">'+cnt+'</body></html>'); }
function switchLang(l) { var regtol = new RegExp("^(.+)"+(l=="_e"?"":"_e")+"\.(htm|php|html)(.*)","i"); if(wLoc.substring(wLoc.length-1)=='/') window.location.href = wLoc.replace(regtol,"$1")+"index"+l+".htm"; else window.location.href = wLoc.replace(regtol,"$1"+l+".$2$3"); }

// initialization
if (top!=self) top.location.href = self.location.href; // Disable InFrame View
var isBr = new browserCheck(), e_date = /^(\d{1,2})[-\.\/\b](\d{1,2})[-\.\/\b](\d{2,4})$/, pwin = 0, wLoc = new String(window.location), dw = document.write, dwl = document.writeln;
if(!document.getElementById) document.getElementById = getObjectByName;
if(!document.getElementsByTagName) document.getElementsByTagName = getElementsArray;

