///// common functions
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function OpenNewSized(url, width, height) {  
  // alert(url);
  NWin = open (url, 'additional'+Math.floor(Math.random()*1000), 'menubar=0,location=0,status=0,toolbar=0,scrollbars=1,resizable=1,height='+height+',width='+width);
}

function getSelectIndex(obj,value) {
  for (i=0;i<obj.options.length;i++) {
     if (obj.options[i].value==value) {
        return(i);
     }
  } 
  return(-1);
}

Array.prototype.inArray = function ( search_phrase )
{
  for( var i = 0; i < this.length; i++ )
  {
    if( search_phrase == this[i] )
    {
      return i;
    }
  }
  return false;
}

///// menu
function switchDIV(id) {
  if (document.getElementById(id)) {
    if ( (!document.getElementById(id).style.display) || (document.getElementById(id).style.display=="none") ) {
         document.getElementById(id).style.display="block";
    } else {
         document.getElementById(id).style.display="none";
    }
  } 
}

function show(ID) {
      if (document.getElementById(ID)) {
              document.getElementById(ID).style.visibility="visible";
              document.getElementById(ID).style.display="block";
      }
      // alert ('show '+ID);
}

function hide(ID) {
      if (document.getElementById(ID)) {
              document.getElementById(ID).style.visibility="hidden";
              document.getElementById(ID).style.display="none";
      }
      // alert ('hide '+ID);
}

function color(obj) {
       obj.bgColor='7EC892';
       obj.childNodes[0].childNodes[0].style.oldColor=obj.childNodes[0].childNodes[0].style.color;
       obj.childNodes[0].childNodes[0].style.color='FFFFFF';
}

function uncolor(obj) {
       obj.bgColor='FFFFFF';
       if (obj.childNodes[0].childNodes[0]) {
          obj.childNodes[0].childNodes[0].style.color=obj.childNodes[0].childNodes[0].style.oldColor;
       }
}



function switchSubmenu(id) {
        if (!document.getElementById(id))  {return;}
        var obj = document.getElementById(id);
        // alert(id+'.display='+obj.display);
        if (obj.style.display!='block') {
                document.getElementById(id).style.display='block';
        } else {
                document.getElementById(id).style.display='none';
        }
}


//// music

function getCookie (name) {
        var prefix = name + "=";
        var cookieStartIndex = document.cookie.indexOf(prefix);
        if (cookieStartIndex == -1)
                return null;
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length;
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if ((name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm("Cookie превышает 4KB и будет вырезан !"))
                        document.cookie = curCookie
}
var music_status='play';
function switchMusic() {
   // http://dotupdate.wordpress.com/2007/08/15/using-wmp-and-quicktime-with-silverlight/
   if (music_status=='play') {
        if ( (document.getElementById('WMPlayer')) && (document.getElementById('WMPlayer').controls)) {document.getElementById('WMPlayer').controls.pause();}
        document.getElementById('musPicture').src="/img/mus-off.gif";
        music_status='pause';
        setCookie('music_play',0,'','/');
   } else {
        if ((document.getElementById('WMPlayer')) && (document.getElementById('WMPlayer').controls)) {document.getElementById('WMPlayer').controls.play();}
        document.getElementById('musPicture').src="/img/mus-on.gif";
        music_status='play';
        setCookie('music_play',1,'','/');
   }
}










function viewObject(name)
{
var obj = eval(name), i;

if(!obj)
{
alert("\""+name+"\" ia not an object");
return;
}

var w_Test = open("","Test","width=600,height=500,scrollbars=1");

if(!w_Test)
{
alert("Cannot open window for "+name);
return;
}

w_Test.document.open();

for(i in obj)
w_Test.document.write(name+"."+i+"="+obj[i]+"<br>");

w_Test.document.close();
}

