function getBrowserInfo()
{
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}

function bookmark(a)
{
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}







function showPopUp(link, width, height, resizable, scrollbars, toolbar)
{
    var centerX = (screen.width - width) / 2;
    var centerY = (screen.height - height) / 2;

    var params = 'directories=no,location=no,menubar=no,resizable=' + (resizable ? 'yes' : 'no') +
                 ',scrollbars=' + (scrollbars ? 'yes' : 'no') + ',status=no,toolbar=' + (toolbar ? 'yes' : 'no') + ',width=' + width +
                 ',height=' + height + ',left=' + centerX + ',top=' + centerY;
    window.open(link, '', params);
    return false
}

function showPopUpFullscreen(link, resizable, scrollbars, toolbar)
{
//    alert(screen.availHeight+"="+ screen.availWidth);
    var params = 'directories=yes,location=yes,menubar=yes,resizable=' + (resizable ? 'yes' : 'no') +
                 ',scrollbars=' + (scrollbars ? 'yes' : 'no') + ',status=no,toolbar=' + (toolbar ? 'yes' : 'no') + ',width=' + screen.availWidth +
                 ',height=' + screen.availHeight + ',left=0,top=0';
    window.open(link, '', params);
    return false
}

function mediaSelectHref(id)
{
    var element = document.getElementById(id);
    document.location.href = '/media/'+element.value+'.html';

    return false;
}

function rubricSelectHref(id, chId)
{
    var element = document.getElementById(id);
    document.location.href = '/channels/'+chId+'/category/'+element.value+'.html';

    return false;
}

function performerSelectHref(id)
{
    var element = document.getElementById(id);
    document.location.href = '/channels/performers/'+element.value+'.html';

    return false;
}

function realtySelectHref(id)
{
    var element = document.getElementById(id);
    document.location.href = '/realty/?countrySelect='+element.value+'';

    return false;
}

var data = '';
var hours = 0;
var mins = 0;
var secs = 0;
var timer = null;
function myclock()
{

//ndata=new Date()
    // Получение показаний часов, минут и секунд
  // hours= ndata.getHours();
//    mins= ndata.getMinutes();
  //  secs= ndata.getSeconds();
    // Дополнение показаний нулем слева
    //alert(parseInt('10'));
    //alert(parseInt('09'));
    //alert(parseInt('08'));
secs = parseInt(secs,10);
mins = parseInt(mins,10);
hours = parseInt(hours,10);

    secs = secs + 1;
  if (secs == 60) {
    secs = 0;
    mins = mins + 1;
    if (mins == 60) {
      mins = 0;
      hours = hours + 1;
    }
  }
 
    if (hours < 10) {hours = "0" + hours }
    if (mins < 10) {mins = "0" + mins }
    if (secs < 10) {secs = "0" + secs }
    // Суммирование всех данных для вывода
    datastr =hours+":" + mins+":" +secs

    // Запись данных
   	var node1 = document.createTextNode(data + " " + datastr);
    
    var elem = document.getElementById('clock-time');
	elem.removeChild(elem.firstChild);
	elem.appendChild(node1);

    // Вызов функции с интервалом 1000 ms
    timer = setTimeout("myclock()", 1000);
}

function myclockchange(data1, secs1,mins1,hours1)
{
    secs = secs1;
    data = data1;
    mins = mins1;
    hours = hours1;
    
    secs = parseInt(secs,10);
    mins = parseInt(mins,10);
    hours = parseInt(hours,10);

    if (hours < 10) {hours = "0" + hours }
    if (mins < 10) {mins = "0" + mins }
    if (secs < 10) {secs = "0" + secs }
    // Суммирование всех данных для вывода
    datastr =hours+":" + mins+":" +secs

    // Запись данных
   	var node1 = document.createTextNode(data + " " + datastr);

    var elem = document.getElementById('clock-time');
	elem.removeChild(elem.firstChild);
	elem.appendChild(node1);


}


function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

/**
 * переводит страницу на другой язык
 * @param val - язык
 */
function changeLanguage(val)
{
    if(val != '')
    {
        var name = document.location.href;
        //var nameTranslate = 'http://planeta-online.tv/translate.html';

        var k = name.indexOf('#googtrans');
        if(k > 0)
            name = name.substring(0,k);
        var k2 = name.indexOf('glang=');
        if(k2 > 0 )
        {
            var before = name.substring(0,k2); //-1 так как там либо & либо ?
            var k3 = name.indexOf('&',k2); //ищем что дальше
            var after = '';
            if(k3>0)
                after = name.substring(k3+1);

            name = before+after;
        }
        name = name.replace('?&','?');
        if(name.indexOf('?')<0)
            name = name+'?';
        //alert(name);
        document.location=name+'&glang='+val+'#googtrans/ru/'+val;
        /*if(k > 0)
        {
            var newName = name.substring(0,k);
            var nameTranslate = 'http://planeta-online.tv/translate.html';*/
            //document.location=nameTranslate+'?page='+URLEncode(newName)+'&lang='+val;
            //document.location=newName+'?&glang='+val+'#googtrans/ru/'+val;
        //}else
        //{
            //document.location=nameTranslate+'?page='+URLEncode(name)+'&lang='+val;
            //document.location=name+'?&glang='+val+'#googtrans/ru/'+val;


       // }
    }
}