// JavaScript Document
//===============  COMMON ========================

var wWidth = 400;
var wHeight = 400;

function showMap (url, strTitle, x, y) {

	getWinSize();
	if (url == '')
	{
		url = 'http://www.balticmaps.eu'; // 'http://www.kartes.lv/maptv.php';
	}
	var intH = wHeight - 50;
	var intW = wWidth / wHeight * intH;

	if (intW > 1200)
	{
		intH = parseInt(intH / intW * 1200);
		intW = 1200;
	}
	if (intW < 700)
	{
		intH = parseInt(intH / intW * 700);
		intW = 700;
	}
	var intLeft = parseInt((wWidth - intW) / 2);
	var intTop = parseInt((wHeight - intH) / 2);
	if (url.indexOf('?') == -1)
	{
		url += "?forced_centering=1&centerx=" + x + "&centery=" + y + "&zoom=10&TB_iframe=true&width="+intW+"&height="+intH+""
	}
	else //
	{
		url += "&forced_centering=1&centerx=" + x + "&centery=" + y + "&zoom=10&TB_iframe=true&width="+intW+"&height="+intH+""
	}

	tb_show(strTitle, url);

}

function getMapWindow() {
	window.location = '/?wp=57&lg=2&show_tb_map=true';
}

function getWinSize(){

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		wWidth = window.innerWidth;
		wHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		wWidth = document.documentElement.clientWidth;
		wHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		wWidth = document.body.clientWidth;
		wHeight = document.body.clientHeight;
	}

	wWidth = parseInt(wWidth);
	wWidth = wWidth - 35;
	wHeight = parseInt(wHeight);
	wHeight = wHeight - 35;
}

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()
	
	var winHeight=obj.style.height.replace('px','');

	if(winHeight<400 && window.parent.document.getElementById('popup_frm')!=null)
	{
		obj.style.height=window.parent.document.getElementById('popup_frm').style.height;//400;
		obj.style.top=0;
	}
	
}	

//=========================================================

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 invertVisibility(elName){
	el = $(elName);
	if(el!=null){
		if(el.style.display != "none") el.style.display = "none";
		else el.style.display = "";
	}
}
// =================================================================================

