﻿var loaded=0;
function switchImg(obj,par){
	if(document.getElementById(obj))
		obj=document.getElementById(obj);
	imgName=obj.src;
	imgName=imgName.split("/");
	imgName=imgName[(imgName.length)-1];
	imgPath=obj.src.split(imgName);
	imgPath=imgPath[0];
	imgName=imgName.split(".");
	imgSuffix=imgName[1];
	imgName=imgName[0];
	if(par==1)
		imgName=imgName+"_over."+imgSuffix;
	else{
		imgName=imgName.split("_");
		imgName=imgName[0]+"."+imgSuffix;
	}
	obj.src=imgPath+imgName;
}

function findPosition(obj){
	x=0; y=0; w=0; h=0; var el,temp;
	if(typeof(obj)=="string")
		obj=getE(obj);
	if(obj.offsetParent){
		temp=obj;
		while(temp.offsetParent){
			temp=temp.offsetParent; 
			x+=temp.offsetLeft;
			y+=temp.offsetTop;
		}
	}
	x+=obj.offsetLeft;
	y+=obj.offsetTop;
	w=obj.offsetWidth;
	h=obj.offsetHeight;
	return [x,y,w,h];
}

function extLinks(){ 
	if(!document.getElementsByTagName)
		return; 
	var anchors=document.getElementsByTagName("a"); 
	for(var i=0;i<anchors.length;i++)				
		if(anchors[i].getAttribute("href")&&anchors[i].getAttribute("rel")) 
			anchors[i].target=anchors[i].getAttribute("rel");
}

function bookmark(title,url){
	if(url=="")
		url=location.href;
	
	if(window.sidebar)
		window.sidebar.addPanel(title,url,"");
	else if(window.opera && window.print){
		el=document.createElement('a');
		el.setAttribute('href',url);
		el.setAttribute('title',title);
		el.setAttribute('rel','sidebar');
		el.click();
	}
	else if(document.all)
		window.external.AddFavorite(url,title);
}

function getE(obj){
	return document.getElementById(obj);	
}

function getEe(e){
	return e?e.target:window.event.srcElement;
}

function showE(obj,par){
	if(typeof(obj)=="string")
		obj=getE(obj);
	if(par==1)
		obj.style.display=obj.style.display=="block"?"none":"block";
	else
		obj.style.display="block";	
}

function hideE(obj){
	if(typeof(obj)=="string")
		obj=getE(obj);
	obj.style.display="none";	
}

function isDigit(e){
	e=e||event;
	iCode=(e.keyCode||e.charCode);
	return((iCode>=48&&iCode<=57)||(iCode>=37&&iCode<=40)||iCode==8||iCode==46);
}

function sendMessage(str1,str2,str3){
	tmp="ma" +"ilto:";
	tmp+=str3+"&#";
	tmp+="64;";
	tmp+=str2;
	window.location=tmp+"."+str1;
	return false;
}

function getScrollHeight(){
	h=window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;
	return h?h:0;
}

var wm=null;

onload=function(){
	menu_onload();
	extLinks();
	if(wm)webmin_init();
	if(getE("wm_search")){
		getE("wm_search").onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		getE("wm_search").onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}
	if(getE("wm_search_home")){
		getE("wm_search_home").onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		getE("wm_search_home").onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}
	if(getE("login_login")){
		getE("login_login").onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		getE("login_login").onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
		getE("login_password").onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		getE("login_password").onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}
	if(getE("map_div"))
		preload_map();
	if(getE("banners"))
		ticker();
	if(getE("premium_box")){
		els=getE("premium_box").getElementsByTagName("a");
		for(c=0;c<els.length;c++)
			els[c].onclick=function(){
				i=this.id.substr(8);
				p_showPhoto(i);
				return false;
			};
	}
};

/*  */
function show_category(obj){
	cat_id=obj.value;
	if(cat_id!=""){
		if(cat_id=="plavby")
			location.href=absPath+"plavby/";
		else
			location.href=absPath+"katalog/?catalog_category="+cat_id+"#list";
	}
}

function show_price(obj){
	p=obj.value;
	if(p!=""){
		location.href=absPath+"katalog/?catalog_price_type="+p+"#list";
	}
}

function show_continent(obj){
	c_id=obj.value;
	if(c_id!=""){
		c=c_id.split("-");
		location.href=absPath+"katalog/?catalog_continent="+c[0]+"&catalog_country="+c[1]+"#list";
	}
}

function show_term(obj){
	term=obj.value;
	if(term!=""){
		//c=c_id.split("-");
		location.href=absPath+"katalog/?"+term+"#list";
	}
}

/* image map */
var map_i=new Array();
function preload_map(){
	for(c=0;c<7;c++){
		map_i[c]=new Image();
		map_i[c].src=absPath+"templates/gfx/map/map_"+c+"a.gif";
	}
}

var active_map=0;

function hl_map(n,sw){
	el=getE("map");
	if(sw==1){
		if(n!=active_map)		
			el.src=absPath+"templates/gfx/map/map_"+n+"a.gif";
	}
	else
		el.src=absPath+"templates/gfx/map/map_0a.gif";
}

document.onkeypress=function(e){
	e=e||event;
	iCode=(e.keyCode||e.charCode);
	if(iCode==27){
		if(getE("gallery_container"))
			closeGallery();
		if(getE("p_gallery_container"))
			p_closeGallery();
		if(getE("forum_reply"))
			closeReplyBox();
	}
}

/*  */
var speed=2;
var pause=1;
var clone=1;
var start="l";
var _w,_ww,_c_w,_cnt=0,_i;
var obj=new Array();
speed=(document.all)?speed:Math.max(1,speed-1);
var ie6_cont="";
function ticker(){
	cont=getE("banners");
	if(pause){
		cont.onmouseover=function(){clearInterval(_i);}
		cont.onmouseout=function(){_i=setInterval("scroll_ticker()",20);}
	}
	_c=ie6_cont=cont.innerHTML;
	cont.innerHTML="";
	cont.style.display="block";
	_w=cont.offsetWidth;
	
	obj[0]=cont.appendChild(document.createElement('div'));
	obj[0].style.left=start=="r"?(_w-1)+"px":"-1px";
	obj[0].innerHTML=_c;
	_c_w=_ww=obj[0].offsetWidth;
	
	if(clone){
		_cnt=Math.ceil(_w/_c_w);
		for(c=1;c<=_cnt;c++){
			obj[c]=cont.appendChild(document.createElement('div'));
			obj[c].style.left=start=="r"?_w+(c*_c_w)+"px":(c*_c_w)+"px";
			obj[c].innerHTML=_c;		
		}
	}
	else
		_ww=_w>_c_w?_w:_c_w;

	_i=setInterval("scroll_ticker()",20);
}

function scroll_ticker(){
	for(c=0;c<=_cnt;c++)
		obj[c].style.left=parseInt(obj[c].style.left)>(0-_c_w)?parseInt(obj[c].style.left)-speed+"px":(clone==1?(_cnt*_ww)+"px":_ww+"px");
}

/*  */

function openLiveHelp(){
	window.open(absPath+'livehelp/livehelp.php?department=1','bubo_livehelp','width=585,height=390,menubar=no,scrollbars=1,resizable=1');	
}