// JavaScript Document
//===============  COMMON ========================

function check_style(element)
{
		if(window.event.type=='mouseover')
		{
			element.oClassName=element.className;
			element.className=element.className+'_hover';
		}
		else if(window.event.type=='mouseout')
		{
					element.className=element.oClassName;
		}
}

//=========================================================
	
function submit_form(form_id)
{
		try{
			//alert('a');
			document.getElementById(form_id).submit();	
		}catch(e){}	
}


//=========================================================

function go_to_caption_editor(caption,lang)
{
	
	var w;
	var o=null;
	try{
		w=window.open('/?wp=7&lg='+lang+'#'+caption,'w_admin'); 
		w.focus();
		o=w.document.getElementById(caption);
		if(!o){
				//o=w.document.getElementById('goto_site_title');
				w.window.document.location.hash='goto_site_title';		
		}
 		else o.select();

 		
	try{
	
		window.top.show_my_tabNo('1');
	}
	catch(ex){}
 		
 		
 		
 		
	}catch(e){}
	
	
	
}


//===============  ADDITIONAL ========================

//=========================================================

function mark_main_menu_unit(e)
{
	try
	{
		e.style.backgroundColor='#2F3766';
	}
	catch(ex){}
}

//=========================================================

function unmark_main_menu_unit(e)
{
	try
	{
		e.style.backgroundColor='transparent';
	}
	catch(ex){}
}


/**** FOR INTRO PAGE *****************/
function mark_add_menu_unit(id)
{
	try{
		/*document.getElementById('smu_'+id).style.backgroundColor='#FBD6D6';*/
		
		document.getElementById('smuimg_'+id).src='/img/intro_pointerhover.gif';
	}
	catch(e){}	
	
}

//=========================================================

function unmark_add_menu_unit(id)
{
	try{
		/*document.getElementById('smu_'+id).style.backgroundColor='#FFFFFF';*/
		document.getElementById('smuimg_'+id).src='/img/intro_pointer.gif';
	}
	catch(e){}	
	
}

//=========================================================

function resizeImgWin(im)
{
	var imH=im.height;
	var imW=im.width;
	
	//var w=window.document.offsetX;
	//alert(window.document.body.offsetWidth);
	
	
	//alert(imH);
	
	if(imH>600)imH=500;
	
	window.resizeTo(window.document.body.offsetWidth,imH+100);
}



//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
function disable_w_layer(){
	
	var obj=document.getElementById('w_output');
	var lockobj=document.getElementById('lock_frm');
	lockobj.style.height=obj.offsetHeight;
	lockobj.style.display="block";
}	

function disable_w_by_popup_layer(){
	
	var obj=document.getElementById('w_output');
	var lockobj_popup=document.getElementById('lock_popup_frm');
	lockobj_popup.style.height=obj.offsetHeight;
	lockobj_popup.style.display="block";
}	

function get_edit_window(url){

	var obj=document.getElementById('editor_frm');
	if(obj==null)obj=window.parent.window.document.getElementById('editor_frm');
	obj.src=url;
	window.waitToShowFrm++;
	disable_w_layer();
	show_loading();
}	

function get_popup_window(url){

	var obj=document.getElementById('popup_frm');
	obj.src=url;
	window.waitToShowFrm++;
	disable_w_by_popup_layer();
	show_loading()
}	


//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================
//======================================================================



//=========================================================

function show_loading(){
	var o=document.getElementById('loading_frm');
	o.style.display="block";
}	

//=========================================================

function hide_loading(){
	var o=document.getElementById('loading_frm');
	o.style.display="none";
}	



var waitToShowFrm=0;

//=========================================================

function frm_ready_to_show(obj)
{
	if(waitToShowFrm>0)
	{
		//alert(0);
		hide_loading();
		obj.style.display='block';
		waitToShowFrm--;
		
	}
}


//=========================================================

function scroll_output_frm()
{
	
		
		
		window.setTimeout('moveElements()',10);
		
}	

//=========================================================

function moveElements()
{
	try{

		var obj=document.getElementById('system_menu');
		obj.style.top=document.body.scrollTop +0+"px";
	}
	catch(ex){alert(ex.toString)}
}
	


//==========================================================

function checkTabsPanel(str,i)
{
	var curCookie=null;
	for(var n=0; n<=i;n++)
	{
		curCookie=getCookie(str+n);
		if(curCookie=='1')
		{
			gotoTabPanel(document.getElementById(str+n));
			return;
		}
	}
}

//==========================================================


function gotoTabPanel(tab)
{
	var obj;
	var elName=tab.id;
	var n=elName.lastIndexOf('_');

	elName=elName.substring(0,n);
	
	n=0;
	
	try{
		while(true)
		{
			document.getElementById(elName+'_tab'+n).className='sys_tab';
			document.getElementById(elName+'_tab'+n+'_area').style.display='none';
			
			try{
				deleteCookie(elName+'_tab'+n,null,null)
				
			}catch(ex){}
			n++;
		}
	}
	catch(e)
	{
		//alert(e.toString())
	}
	
	tab.className='sys_tab_selected';
	document.getElementById(tab.id+'_area').style.display='block';
	
	
	try
	{
		setCookie(tab.id,1,"","","","" );
	}
	catch(ex){}
	
}

//============================= COOKIES ======================================
//============================= COOKIES ======================================
//============================= COOKIES ======================================
//============================= COOKIES ======================================


// name - имя cookie
// value - значение cookie
// [expires] - дата окончания действия cookie (по умолчанию - до конца сессии)
// [path] - путь, для которого cookie действительно (по умолчанию - документ, в котором значение было установлено)
// [domain] - домен, для которого cookie действительно (по умолчанию - домен, в котором значение было установлено)
// [secure] - логическое значение, показывающее требуется ли защищенная передача значения cookie

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;
}


// name - имя считываемого cookie

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));
}



// name - имя cookie
// [path] - путь, для которого cookie действительно
// [domain] - домен, для которого cookie действительно
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
    	document.cookie = name + "=" +((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
        
//=============================================================================
//=============================================================================
//=============================================================================
//=============================================================================
//=============================================================================

function dyspalyElById(id,display)
{
	try{
		document.getElementById(id).style.display=display;
	}catch(ex){}
}


function show_loading_message()
{
	var o=document.getElementById('loading_frm');
	o.style.display='block';
	o.height=document.getElementById('Table_01').offsetHeight;
	//alert(document.getElementById('Table_01').offsetHeight);
	//o.style.height=document.body.clientHeight;
	scrollLoader();
}


function hide_loading_message()
{
	document.getElementById('loading_frm').style.display='none';
}


function scrollLoader()
{
	try{
		window.frames['loading_frm'].document.getElementById('message_area').style.top=(document.body.scrollTop+(document.body.offsetHeight/2))-200+'px';
	}
	catch(ex){}
	
}

