function viewImg(image_href){
      var xstr = 'scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,location=no,resizable=yes,width=160,height=160';
      var prodWindow = window.open(image_href, 'window'+Math.round(Math.random()*1000), xstr);
      if (prodWindow) prodWindow.focus();
}

function backToSite(){
	var prodWindow = window.opener;
	if (prodWindow){
		prodWindow.focus();
		window.close();
	}
}

function housePrew(url, dir_image, image_name){
    var house_prev = document.getElementById('house');
    house_prev.innerHTML = '<a href="/view_img.php?dir_image='+dir_image+'&amp;image_name='+image_name+'" target="_blank" onclick="viewImg(this.href); return false;"><img src="'+url+dir_image+'/medium/'+image_name+'" alt="" /></a>';
}

function checkFormRequest(form){

    if(form.name.value == ''){    
        alert('Введите ФИО!');
        return false;    
    }
    if(form.email.value == '' && form.phone.value == ''){    
        alert('Задайте Tелефон или Email!');
        return false;    
    }
    if(form.email.value != '' && !checkEmail(form.email.value)){
        alert('Неверный формат Email!');
        return false; 
    }

    return true;
}

function checkFormComment(form){

    if(form.name.value == ''){    
        alert('Введите ФИО!');
        return false;    
    }
    if(form.email.value == ''){    
        alert('Введите Email!');
        return false;    
    }
    if(!checkEmail(form.email.value)){
        alert('Неверный формат Email!');
        return false; 
    }
    if(form.comment.value == ''){    
        alert('Не задан текст вопроса!');
        return false;    
    }

    return true;
}

var timer_id = null;
var activeSubmenu = 0;
var submenuTmp = new Array;
var menuSel = 0;

function viewSubmenu(num) {
try
{
    clearTimeout(timer_id);
    timer_id = null;
    if(num != activeSubmenu || (num == 0 && activeSubmenu == 0)){
        
        viewTopMenu(num);
        if(num > 0) {
            var submenu = document.getElementById('submenu_'+num);
        } else {
            var submenu = document.getElementById('submenu_1');
        }
        var parent = submenu.parentNode;
        for (var i = 0; i < parent.childNodes.length; i++) {
            var child = parent.childNodes[i];
            if (child.nodeType == 1 && child.tagName == 'DIV' && submenu != child) {
                child.style.visibility = 'hidden';
            }
        }  
        block_bg = document.getElementById('topsubmenu_block_absolute_bg');
        if(num > 0) {
            submenu.style.visibility = 'visible';
            if(submenuTmp[num] == 1){
                block_bg.style.height = '20px';
                parent.style.height = '20px';
            } else {
                block_bg.style.height = '0px';
                parent.style.height = '0px';
            }
        } else {
            block_bg.style.height = '0px';
            parent.style.height = '0px';
        }    
       //alert(parent.style.height);
        //parent.style.background = 'none';  
        activeSubmenu = num;
    }
}catch(e){alert(e);}
}

function hideSubmenu(){
    
    if (timer_id != null) {
      return;
    }
    timer_id = setTimeout('restoreSubmenu()',1000);
}

function viewTopMenu(num) {
    for(var i = 0; i < submenuTmp.length - 1; i++){
        var menu_item = document.getElementById('topmenu_'+Number(i+1));
        menu_item.src = "../img/topmenu_"+Number(i+1)+".gif";
        var sep_left = document.getElementById('sep_'+i);
        var sep_right = document.getElementById('sep_'+Number(i+1));
        sep_left.className = 'topmenu_separator';
        sep_right.className = 'topmenu_separator';
    }
    if(num > 0) {
        var sep_left = document.getElementById('sep_'+Number(num-1));
        var sep_right = document.getElementById('sep_'+num);
        var menu_item = document.getElementById('topmenu_'+num);
        sep_left.className = 'topmenu_separator_sel';
        sep_right.className = 'topmenu_separator_sel';
        menu_item.src = "../img/topmenu_"+num+"_sel.gif";
    }
}

function restoreSubmenu() {
    viewSubmenu(menuSel);
}

function viewFormQuest(){
    
    var form_quest = document.getElementById('form_quest');
    var link_to_form_quest = document.getElementById('link_to_form_quest');
    if(form_quest.style.display == 'block') {
        form_quest.style.display = 'none';
        link_to_form_quest.innerHTML = 'Задать вопрос на семинар';
    } else {
        form_quest.style.display = 'block';
        link_to_form_quest.innerHTML = 'Скрыть форму';
    }
}

