//cms.js

var cms_shared_path = '';

/*
*/
cms_shared_path='/videomania';
/*
*/

function popup_page(id, w, h, s, r, prms) { //{{{
   //prms: menubar, location, status, secure, center, http_host, https_host

   if (!prms) prms = {};
   prms.caller_prm_name = 'caller_url_' + id;
   popup_page_ex(cms_shared_path+'/popup/?i=' + id, 'popup_page_' + id, w, h, s, r, prms);
} //}}}

function popup_page_ex(url, name, w, h, s, r, prms) { //{{{
   //prms: menubar, location, status, secure, center, http_host, https_host, caller_prm_name

   if (!prms) prms = {};
   var wnd_prms = '';
   var pref = '';

   if (w) wnd_prms += ',width=' + w;
   if (h) wnd_prms += ',height=' + h;
   if (s) wnd_prms += ',scrollbars=' + s;
   if (r) wnd_prms += ',resizable=' + r;
   if (prms.menubar) wnd_prms += ',menubar=1';
   if (prms.location) wnd_prms += ',location=1';
   if (prms.status) wnd_prms += ',status=1';

   var location = window.top.location;
   var proto_ch = false;
   if (prms.secure && location.protocol == 'http:') {
      pref = 'https://' + (prms.https_host || location.host);
      proto_ch = true;
   }
   else if (! prms.secure && location.protocol == 'https:') {
      pref = 'http://' + (prms.http_host || location.host);
      proto_ch = true;
   }

   if (prms.center && w && h) {
      var l, t;
      var wx, wy, ww, wh;
      if (window.screenX) {
         wx = window.screenX; wy = window.screenY;
      }
      else if (window.screenLeft) {
         wx = window.screenLeft; wy = window.screenTop;
      }
      if (window.outerWidth) {
         ww = window.outerWidth; wh = window.outerHeight;
      }
      else if (window.document && window.document.body) {
         ww = window.document.body.clientWidth;
         wh = window.document.body.clientHeight - 100;
      }
      if (wx && wy && ww && wh) {
         l = parseInt((ww - w)/2, 10) + wx;
         t = parseInt((wh - h)/2, 10) + wy;
      }
      else {
         var sw = screen.availWidth || screen.width;
         var sh = screen.availHeight || screen.height;
         l = parseInt((sw - w)/2, 10);
         t = parseInt((sh - h)/2, 10);
      }
      wnd_prms += ',left=' + l;
      wnd_prms += ',top=' + t;
   }

   if (proto_ch && prms.caller_prm_name) {
      var url_prms = {};
      url_prms[prms.caller_prm_name] = location.href;
      url = jslModifyUrl(url, url_prms);
   }

   var wnd = window.open( pref + url, name, wnd_prms.substr(1));
   
   wnd.focus();
} //}}}

function cmsjslBnrGetNode(obj, objs, sizes, invalids, invalid, level ) { //{{{ 
   for (var i = 0; i < obj.childNodes.length; i++) {
      var isinvalid = 1;
      if (obj.childNodes[i].nodeName == 'P') isinvalid = 0;
      if (i>0) {
        if (obj.childNodes[i].nodeName == 'BR' && 
            obj.childNodes[i-1].nodeName == 'BR') 
        {
          if (obj.childNodes[i].childNodes.length ==0) isinvalid = 0;
          else if (obj.childNodes[i].childNodes.length == 1) {
            if (obj.childNodes[i].childNodes[0].nodeType== 3) {
              if (obj.childNodes[i].childNodes[0].nodeValue == null) isinvalid = 0;
              var reg = /^\s*$/i;
              if (reg.test(obj.childNodes[i].childNodes[0].nodeValue)) isinvalid = 0;
            }
          }
        }
      }
      isinvalid = (invalid > 0) ? invalid : isinvalid;

      var node = obj.childNodes[i].nodeName;
      objs.push(obj.childNodes[i]);
      invalids.push(isinvalid);
      if (obj.childNodes[i].nodeType == 3) 
        sizes.push(obj.childNodes[i].nodeValue.length);
      else 
        sizes.push(0);

      cmsjslBnrGetNode(obj.childNodes[i], objs, sizes, invalids, isinvalid, level+1);
   }
} //}}}

function cmsjslBnrHTMLPlacement(id_bnr, id_html) { //{{{
   jslPostRun(function(){
	   var bnr_o  = jslObject(id_bnr);
	   var html_o = jslObject(id_html);
      try {
         var objs = new Array();
         var sizes = new Array();
         var invalids = new Array();
         var obj;
         if (bnr_o && html_o && bnr_o.parentNode) {
            cmsjslBnrGetNode( html_o, objs, sizes, invalids, 0, 0);
         }
         if (bnr_o) {
            var len = 0; var ind = 0;
            for (var i = 0; i < sizes.length; i++) { len+= sizes[i] };
            var l = len / 2;
            for (var i = 0; i < sizes.length; i++) { 
               if ((ind > l) && (i > 0)) {
                 if (invalids[i-1] == 0)
                   { obj = objs[i]; break; }; 
               }
               ind+= sizes[i];
            }
            if (obj) { 
              obj.parentNode.insertBefore( bnr_o, obj ); 
            }
            else if (html_o) {
              html_o.appendChild( bnr_o, obj ); 
            }
         }
      }
      catch (e) {};
      if (bnr_o) jslSetAttribute(bnr_o, 'display', 'block');
   });
} //}}}

function cmsjslBnrAutoMargins() { //{{{
   jslOnLoad(function(){
      var divs = document.getElementsByTagName('DIV');
      for (var i = 0; i < divs.length; i++) {
         if (/(^| )bnr_am_(([btlr]\d+)+)( |$)/.test(divs[i].className)) {
            var d=RegExp.$2;
            var empty = true;
            for (var ci=0; ci<divs[i].childNodes.length && empty; ci++) {
               if (!/^(NO)?SCRIPT$/i.test(divs[i].childNodes[ci].tagName))
                  empty = false;
            }
            if (! empty) {
               var max = 4;
               var margins = {b:'Bottom',t:'Top',l:'Left',r:'Right'};
               while(/^([btlr])(\d+)/.test(d) && max--) {
                  var t = RegExp.$1, v = RegExp.$2;
                  d=RegExp.rightContext;
                  eval('divs[i].style.margin' + margins[t] + '="' + v + 'px"');
               }
            }
         }
      }
   });
} //}}}


