function sethome(o,siteurl,sitename) {
	var name = navigator.appName;
        var useragent = navigator.userAgent;
        var version = parseInt(navigator.appVersion);
        var needtoknow = 1;
                
        if ( useragent.indexOf("MSIE") != -1) {
		var index = navigator.userAgent.indexOf("MSIE ");
                if ( index != -1 ) {
                	version = parseInt(navigator.userAgent.substring(index+5,index+6));
                }
                if ( version > 4) {
                	o.style.behavior='url(#default#homepage)'; o.setHomePage(siteurl);
                        needtoknow = 0;
               	}
        }
        if (needtoknow != 0) {
                openBrWindow('/help/makehomepage.html','winMakeHomepage','location=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=450');
        }
}



function oc(obj) {
    obj.style.display = (obj.style.display=="none") ? "" : "none";
}

function ocid(id) {
	obj=document.getElementById(id);
	oc(obj);
}

var downloadWindow=0;
var downloadWindow1=0;
var imgWindow=0;
function openPopUp(name,id) {
   if (name=='download') {
    if (!downloadWindow || downloadWindow.closed) {
     var url='http://www.anekdot-film.ru/popup.php?g='+id;
     downloadWindow=window.open(url, 'download', 'width=425, height=400, scrollbars=0, resizable=1');
    } else {
     downloadWindow.focus();
    }
   }
   if (name=='mobile') {
    if (!downloadWindow1 || downloadWindow1.closed) {
     var url='http://melody.e-vostok.ru/info_video.php?service=1028&design=1&id='+id;
     downloadWindow1=window.open(url, 'mobile', 'width=400, height=500, scrollbars=0, resizable=1');
    } else {
     downloadWindow1.focus();
    }
   }
   if (name=='img') {
    if (!imgWindow || imgWindow.closed) {
     var url='http://anekdot-film.ru/allanek.html';
     imgWindow=window.open(url, 'mobile', 'width=155, height=205, scrollbars=0, resizable=0');
    } else {
     imgWindow.focus();
    }
   }

}

 
function mover(id) {
var obj = document.getElementById(id);
 if (!obj) return false;
 if (obj.className=='mitem') obj.className='hmitem';
}

function mout(id) {
var obj = document.getElementById(id);
 if (!obj) return false;
  if (obj.className=='hmitem') obj.className='mitem';
}


var prevLmnu = null;
var isUL = false;
var step=0;

function laover(obj, prevId) {

 if (!obj) return false;
 if (obj.className!='active') obj.className='hover';

 isUL = (prevId=='');
 if (isUL) { prevId='lmenu'; }

  prevLmnu = document.getElementById(prevId);
  if (!prevLmnu) return false;

  if (prevLmnu.className!='active') 
     if (!isUL) { prevLmnu.className='hoverPrev'; } else {
	prevLmnu.style.background='none';
     }

}

var isOut=false;

function laout(obj) {

 if (isOut ) return false;
 isOut = true;
 if (!obj) return false;
 if (obj.className!='active') obj.className='';

 strS=obj.id; strS=strS.substr(5,2); i=parseInt(strS,10)+1; 
 if (i>9) strS = 'larow'+i; else strS = 'larow0'+i; 
 objN = document.getElementById(strS);  
 if (objN) {
   if (objN.className=='active' && obj.className!='hover') { obj.className='hoverPrev'; }
 } 

 if (prevLmnu && obj.className!='active') { 
  if (isUL) { prevLmnu.style.background='url(img/li_bg.gif) repeat-x'; prevLmnu.className='leftmenu';}
  else if(prevLmnu.className!='active') prevLmnu.className='';
 }

 isOut = false;
}


function Preload() {
 var i4 = new Image();
 i4.src = 'img/mnu_lred_bg.gif';
 var i5 = new Image();
 i5.src = 'img/mnu_lred_left.gif';
 var i6 = new Image();
 i6.src = 'img/mnu_lred_right.gif';
 var i1 = new Image();
 i1.src = 'img/mnu_green_bg.gif';
 var i2 = new Image();
 i2.src = 'img/mnu_green_left.gif';
 var i3 = new Image();
 i3.src = 'img/mnu_green_right.gif';
 repairActive();
}

function repairActive(){
var objLi = null;
var oList = document.getElementById('lmenu');
 if(oList) {
  objLi = oList.firstChild; i=0; 
  while(objLi) { 
   if (objLi.className=='active') {
    if (i==0) strS=''; else { 
     strS=objLi.id;  i=parseInt(strS.substr(5,2),10)-1;
     if (i>9) strS = 'larow'+i; else strS = 'larow0'+i; 
    }
    laover(objLi, strS); 
   }
   i++;
   objLi = objLi.nextSibling;
  } /* while */
 }
}

var showed = 0;

/**
* @author Karpov S.Y.
*/
function show_group_sel() {
	
	if( showed < 10 ) {
		showed++;
		document.getElementById( "g"+showed ).disabled = false;
		obj = document.getElementById( 'hidden_group_select'+showed );
		obj.style.display = "";
	} else alert( 'десяти групп должно хватить' );
}

/**
 * @author Karpov S.Y
 * @mailto qubitinua@gmail.com
*/

function post_list( mode ) {
	if( mode == 'del' ) {
		if( confirm( 'Вы действительно хотите удалить выбранные ролики?' ) ) {
			document.getElementById( 'mode' ).value = 'del';
			document.getElementById( 'formList' ).submit();
		}
	}
	if( mode == 'show' ) {
		if( confirm( 'Вы действительно хотите опубликовать выбранные ролики?' ) ) {
			document.getElementById( 'mode' ).value = 'show';
			document.getElementById( 'formList' ).submit();
		}
	}
}

/**
 * @author Karpov S.Y
 * @mailto qubitinua@gmail.com
*/
function del_confirm( url ) {
	if( confirm('Вы действительно хотите удалить выбранный ролик?') ) {
		window.location.href=url;
	}
}
/**
 * @author Karpov S.Y
 * @mailto qubitinua@gmail.com
*/
function ajax_del_confirm( playlist_id ) {
	if( confirm('Вы действительно хотите удалить выбранный плейлист?') )  {
		
		document.getElementById( 'table_pl_' + playlist_id ).style.display='none';
		del_playlist( playlist_id );
	}
}

/**
 * @author Karpov S.Y
 * @mailto qubitinua@gmail.com
*/
function change_th() {

	if( document.getElementById( 'new_subject' ).style.display == 'none' ) {
		document.getElementById( 's' ).style.display='none';
		document.getElementById( 's' ).disabled = true;
		document.getElementById( 'new_subject' ).disabled = false;
		document.getElementById( 'g' ).disabled = true;
		document.getElementById( 'new_subject' ).style.display='';
		document.getElementById( 'new_href' ).innerHTML = 'Выбрать из списка';
	} else {
		document.getElementById( 's' ).style.display='';
		document.getElementById( 's' ).disabled = false;
		document.getElementById( 'new_subject' ).disabled = true;
		document.getElementById( 'g' ).disabled = false;
		document.getElementById( 'new_subject' ).style.display='none';
		document.getElementById( 'new_href' ).innerHTML = 'Новая тема';	
	}
}

function act_disact() {
	if( document.getElementById( 'url_banner' ).disabled ) {
		document.getElementById( 'url_banner' ).disabled = false;
		document.getElementById( 'upl_banner' ).disabled = true;
	} else {
		document.getElementById( 'url_banner' ).disabled = true;
		document.getElementById( 'upl_banner' ).disabled = false;	
	}
}

function add_button_over( obj, src ) {

	if( document.getElementById( 'is_added' + obj.id ).value  != 1 )
		obj.src=src;
}

function loginFocus() {
	if( document.getElementById( 'login_name' ).value == "Логин" )
		document.getElementById( 'login_name' ).value = "";
}

function loginUnFocus() {
	if( document.getElementById( 'login_name' ).value == "" )
		document.getElementById( 'login_name' ).value = "Логин";
}

function _openClose( obj_id ) {
	
	
	if( document.getElementById( 'windowBottom' + obj_id ).style.display == 'none' ) {
		
		document.getElementById( 'elemImg' + obj_id ).src = '/img/arrow_down.gif';
		new Effect.BlindDown(document.getElementById( 'windowBottom' + obj_id ));
	}
	else {
	
		document.getElementById( 'elemImg' + obj_id ).src = '/img/arrow_left.gif';
		new Effect.BlindUp(document.getElementById( 'windowBottom' + obj_id ));
	}
}
/**
 * Burime functions
 */
function check_input() {
	
	if( parseInt(document.getElementById("str_num").value) != document.getElementById("str_num").value || parseInt(document.getElementById("str_num").value)<=1 ) {
		alert( "Введите корректное количество строк буриме!" );
	} else {
	
		if( document.getElementById( "burime_string" ).value == "" ) alert( "Вверите первую строку буриме!" );
		else document.getElementById( "new_burime_form" ).submit();
	}
}

function check_new_input() {
	if( document.getElementById( "new_burime_string" ).value == "" ) alert( "Введите следующую строку буриме!" );
	else document.getElementById( "add_string_form" ).submit();
}

function show_obj( obj ) {
	obj.style.filter="alpha(opacity=100)";
	obj.style.opacity="1";
}

function hide_obj( obj ) {
	obj.style.filter="alpha(opacity=70)";
	obj.style.opacity="0.7";
}

function f_s_pllist() {

	obj = document.getElementById( "save_pllist" );
	if( obj.value == "Сохранить как..." ) {
		obj.style.filter="alpha(opacity=100)";
		obj.style.opacity="1";
		obj.value = "";
	}
}

function u_s_pllist() {
	
	obj = document.getElementById( "save_pllist" );
	if( obj.value == "" ) {
		obj.style.filter="alpha(opacity=70)";
		obj.style.opacity="0.7";
		obj.value = "Сохранить как...";
	}
}

function save_pllist() {

	var save_type = document.getElementById( "save_type_select" ).value;
	if( save_type == 1 ) {

		pllist_name = document.getElementById( "save_pllist" ).value;
		if( pllist_name == "Сохранить как..." || pllist_name == "" )  {
		
			alert( "Задайте название плейлиста" );
		} else {
			save_pllist_ajax( pllist_name );
		}
	} else {
		playlist_id = document.getElementById( 'upllist' ).value;
		save_pllist_ajax_exist( playlist_id );
	}
}

function on_del_over( table_id ) {
	document.getElementById( 'table_pl_' + table_id ).style.backgroundColor='#FEDFBF';
}
function on_del_out( table_id ) {
	document.getElementById( 'table_pl_' + table_id ).style.backgroundColor='#FACFA7';
}

function on_over( obj ) {
	obj.style.backgroundColor='#FEDFBF';
}
function on_out( obj ) {
	obj.style.backgroundColor='#FACFA7';
}

function chSaveType( obj ) {
	if( obj.value == 1 ) {
		
		document.getElementById( "save_pllist_form" ).innerHTML = pllist_save;
	} else if( obj.value == 2 ) {
	
		document.getElementById( "save_pllist_form" ).innerHTML = upllist;
	}
}

/**
 * @author: Karpov S.Y
 * @mailto: qubitinua@gmail.com
 * get all properties of objects
 */
function getOP (object) {
	var result = '';
	for (var property in object) {
		result += property + ': ' + object[property] + '\r\n';
	}
	return result;
}

document.onload = Preload;
window.onload = Preload;