var arr_select = new Array(); // массив полей SELECT
arr_select[0]="reg_gender";

//*
function $(id){
    return document.getElementById(id);
}
//*/


function show_hide_auth_block(e) {
    if(document.getElementById('auth_block').style.display == 'none') {
        document.getElementById('auth_block').style.display = 'block';
    } else {
        document.getElementById('auth_block').style.display = 'none';
    }
}

function show_hide_recover_block(e) {
    if(document.getElementById('recover_block').style.display == 'none') {
        document.getElementById('recover_block').style.display = 'block';
    } else {
        document.getElementById('recover_block').style.display = 'none';
    }
}

function addMCE(control) {
    cleanMCE();
    tinyMCE.execCommand('mceAddControl', false, control);
    tinyMCE.switchClassCache = [];
}

function cleanMCE() {
    tinyMCE.idCounter = 0;
    tinyMCE.instances = new Array();
}

JS_CONFIRM_ACTION=null;

function jsConfirm(message,onConfirm){
    if ($('js_content_disabler')){
        return;
    }
	
    JS_CONFIRM_ACTION=onConfirm;
    if (typeof onConfirm!='undefined'){
        if (typeof onConfirm=='function'){
            JS_CONFIRM_ACTION=onConfirm;
        }else{
            JS_CONFIRM_ACTION=function(){
                eval(onConfirm);
            }
        }
    }


    var nDiv=document.createElement('div');
    nDiv.id='js_content_disabler';
    nDiv.style.width='100%';
    nDiv.style.height='100%';
    nDiv.style.left='0';
    nDiv.style.zIndex=1000;
    nDiv.style.backgroundColor='black';
    if (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
        nDiv.style.position='absolute';
        nDiv.style.top=document.documentElement.scrollTop+'px';
        nDiv.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=30)";
    }else{
        nDiv.style.position='fixed';
        nDiv.style.opacity='0.3';
        nDiv.style.top='0';
    }

    var cDiv=document.createElement('div');
    cDiv.id='confirm_window';
    cDiv.className='popup';
    cDiv.style.width='400px';
    cDiv.style.height='200px';
    cDiv.style.left='50%';
    cDiv.style.marginLeft='-200px';
    cDiv.style.marginTop='-100px';
    cDiv.style.zIndex=1001;
    cDiv.style.backgroundColor='white';
    if (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
        cDiv.style.position='absolute';
        cDiv.style.top=document.documentElement.scrollTop+400+'px';

    }else{
        cDiv.style.position='fixed';
        cDiv.style.top='50%';
    }
	
    //для ие делается эмуляция позитион фиксед
    if (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
        window.onscroll=function(){
            $('js_content_disabler').style.top=document.documentElement.scrollTop+'px';
            $('confirm_window').style.top=document.documentElement.scrollTop+400+'px';
        };
    }

    cDiv.innerHTML='\
	<div class="container" style="height:200px;width:400px;//width:395px">\n\
		<p class="tl_corner"></p>\n\
		<p class="tr_corner" style="left:-10px;"></p>\n\
		<p class="bl_corner"></p>\n\
		<p class="br_corner" style="left:0px;"></p>\n\
		<p class="shadow" style="width:395px;"></p>\n\
		<p class="bottom_line" style="width:395px;"></p>\n\
		<input class="btn_close" type="button" onmouseover="this.className=\'btn_close hover\'" onmouseout="this.className=\'btn_close\'" onclick="jsConfirmNo()" />\n\
		<div align="center" style="height:70px;padding:40px 20px 0px 20px;font-size:12px;">'+message+'</div>\n\
		<div align="center" style="padding:20px 20px 0px 20px">\n\
			<a class="btn_glass" '+
    'onclick="jsConfirmYes()" '+
    'onmouseover="this.className+=\' hover\'" '+
    'onmouseout="this.className=this.className.replace(\' hover\',\'\')">'+
    '<input type="button" class="l" />'+
    '<input type="button" class="c" value="Yes" />'+
    '<input type="button" class="r" />'+
    '</a>\n\
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n\
			<a class="btn_glass" '+
    'onclick="jsConfirmNo()" '+
    'onmouseover="this.className+=\' hover\'" '+
    'onmouseout="this.className=this.className.replace(\' hover\',\'\')">'+
    '<input type="button" class="l" />'+
    '<input type="button" class="c" value="No" />'+
    '<input type="button" class="r" />'+
    '</a>\n\
		</div>\n\
	</div>';

    (document.body||document.documentElement).appendChild(nDiv);
    (document.body||document.documentElement).appendChild(cDiv);
}

function jsConfirmYes(){
    JS_CONFIRM_ACTION();
    jsConfirmNo();
}

function jsConfirmNo(){
    JS_CONFIRM_ACTION=null;
    (document.body||document.documentElement).removeChild($('js_content_disabler'));
    (document.body||document.documentElement).removeChild($('confirm_window'));
    if (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
        window.onscroll=null
    }
}

function jsAlert(message){
    if ($('js_content_disabler')){
        return;
    }

    // Хак слой для Explorera, чтобы перекрывать поля select
    // Найти все поля SELECT и вырубить их display: none
    if (ISIE()){
        var  select_list;
        for(var i = 0; i < arr_select.length; i++) {
            select_list = document.getElementById(arr_select[i]);
            if(select_list != null) {
                document.getElementById(select_list.id).style.display = "none";
            }
        }
    }


    var nDiv=document.createElement('div');
    nDiv.id='js_content_disabler';
    nDiv.style.width='100%';
    nDiv.style.height='100%';
    nDiv.style.left='0';
    nDiv.style.zIndex=1000;
    nDiv.style.backgroundColor='#000000';
    if (ISIE()){
        nDiv.style.position='absolute';
        nDiv.style.top=document.documentElement.scrollTop+'px';
        nDiv.style.filter += "alpha(opacity=30)";
    }else{
        nDiv.style.position='fixed';
        nDiv.style.opacity='0.3';
        nDiv.style.top='0';
    }

    var aDiv=document.createElement('div');
    aDiv.id='alert_window';
    aDiv.className='popup';
    aDiv.style.width='400px';
    aDiv.style.height='100px';
    aDiv.style.left='50%';
    aDiv.style.marginLeft='-200px';
    aDiv.style.marginTop='-100px';
    aDiv.style.zIndex=1001;
    aDiv.style.backgroundColor='white';
    if (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
        aDiv.style.position='absolute';
        aDiv.style.top=document.documentElement.scrollTop+300+'px';

    }else{
        aDiv.style.position='fixed';
        aDiv.style.top='50%';
    }

    //для ие делается эмуляция позитион фиксед
    if (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1){
        window.onscroll=function(){
            $('js_content_disabler').style.top=document.documentElement.scrollTop+'px';
            $('alert_window').style.top=document.documentElement.scrollTop+300+'px';
        };
    }

    aDiv.innerHTML='\
	<div class="container" style="height:100px;width:400px;">\n\
		<p class="tl_corner"></p>\n\
		<p class="tr_corner" ></p>\n\
		<p class="bl_corner"></p>\n\
		<p class="br_corner" style="left:0px;"></p>\n\
		<p class="shadow" style="width:395px;"></p>\n\
		<p class="bottom_line" style="width:395px;"></p>\n\
		<input class="btn_close" type="button" onmouseover="this.className=\'btn_close hover\'" onmouseout="this.className=\'btn_close\'" onclick="jsAlertClose()" />\n\
		<div align="center" style="height:70px;padding:40px 20px 0px 20px;font-size:12px;">'+message+'</div>\n\
	</div>';

    (document.body||document.documentElement).appendChild(nDiv);
    (document.body||document.documentElement).appendChild(aDiv);
}

function jsAlertClose(){
    (document.body||document.documentElement).removeChild($('js_content_disabler'));
    (document.body||document.documentElement).removeChild($('alert_window'));
    if (ISIE()){
        window.onscroll=null
        // Врубить все поля SELECT
        var  select_list;
        for(var i = 0; i < arr_select.length; i++) {
            select_list = document.getElementById(arr_select[i]);
            if(select_list != null) {
                document.getElementById(select_list.id).style.display = "block";
            }
        }

    }
}


function ISIE(){
    return (window.navigator.userAgent.toLowerCase().indexOf('msie')!=-1);
}

/**
 * функция вставляет флеш с помощью js
 *
 * @param String src относительный путь к флешке
 * @param Object attrs аттрибуты элемента object
 * @param Object params параметры флешки
 */
function insertFlash(src,attrs,params){
    var flashHtml='<object  type="application/x-shockwave-flash" data="'+src+'" ';
    params.movie=src;
    var attrsHtml='';
    for (var i in attrs){
        attrsHtml+=' '+i+'="'+attrs[i]+'"';
    }
    flashHtml+=attrsHtml+'>';
    for (var i in params){
        flashHtml+='<param name="'+i+'" value="'+params[i]+'" />';
    }
    flashHtml+='</object>';
    document.write(flashHtml);
}

function $ready( f ) {
    //Если DOM загружен то выполняем функцию
    if( $ready.done ) return f();
    // Если мы дополнили функцию
    if( $ready.timer ) {
        // внести ее в список исполняемых
        $ready.ready.push( f );
    } else {
        // Подключение события завершения загрузка страницы
        // на тот случай, если загрузка завершиться первой
        window.onload=this.isReady;
        // Инициализация массива исполняемых функций
        $ready.ready = [ f ];
        //Проверка DOM на готовность как можно ыстрее
        $ready.timer = setInterval( "$ready.isReady()", 13);
    }
    return true;
}
// Проверка DOM на готовность к перемещению по ее структуре
$ready.isReady=function() {
    // Если мы определили готовность страницы -
    // проигнорировать дальнейшее выполнение
    if ( $ready.done ){
        alert('done stop');
        clearInterval( $ready.timer );
        return false;
    }
    // Проверка доступности некоторых функций и элементов
    if ( document && document.getElementsByTagName && document.getElementById
        && (document.body||document.documentElement )) {
        alert('done');
        // Если они готовы, можно прекратить проверку
        clearInterval( $ready.timer );
        $ready.timer = null;
        //Выполнение всех ожидавших функций
        for ( var i = 0; i < $ready.ready.length; i++ )
            $ready.ready[i]();
			
        // Сохранение того, что было сделано
        $ready.ready = null;
        $ready.done = true;
    }
    return true;
}

