function openGallery(url,fullscreen)
{
    if(fullscreen == 1)
    {
        window.open(rootUrl+url,'gallery','fullscreen=yes');
    }
    else
    {
        window.open(rootUrl+url,'gallery','width=740,height=570,left=50,top=50');
    }
}

function popImg(file,width,height,title)
{
		/*
    if(!title)
        title = 'Galerii';
    var pimg = window.open('','pilt','top=50px,left=50px,width='+width+',height='+height);
    pimg.document.write('<html><head><title>'+title+'</title><body style="margin:0px;background-image:url(/gallery_photos/'+escape(file)+');cursor:hand;" onclick="self.close();">');
    pimg.document.write('</html></body>');
		*/
		pop1mg('/gallery_photos/'+file, width, height, title);
}

//erkko/20061004 - kui k�ik pildid k�ivad uploadiga artikli juurde, siis miks ma popupi jaoks PEAN uppima kuskile mujale?
function pop1mg(file, width, height, title)
{
    if(!title)
        title = 'Galerii';
    var pimg = window.open('','pilt','top=50px,left=50px,width='+width+',height='+height);
    pimg.document.write('<html><head><title>'+title+'</title><body style="margin:0px;background-image:url('+escape(file)+');cursor:hand;" onclick="self.close();">');
    pimg.document.write('</html></body>');
}

function popLegal(code)
{
    doWin('legals/'+code,600,300);
}

function showLegal(id)
{
    var obj = document.getElementById('Legal_'+id);
    if(obj)
    {
        if(obj.style.display == '')
        {
            obj.style.display = 'none';
        }
        else
        {
            obj.style.display = '';
        }
    }
}
function doWin(url,w,h,name)
{
    if(!h)
        h = screen.availHeight - 100;
    if(!w)
        w = screen.availWidth - 100;
    var popUrl = '';
    if(url.indexOf('?') == -1)
        popUrl += '?';
    else
        popUrl += '&';
    popUrl += 'popUp=1';
    if(!name)
    {
        var nd = new Date;
        name = nd.getHours()+''+nd.getMinutes()+''+nd.getSeconds();
    }

    window.open(rootUrl+url+popUrl,'winName'+name,'width='+w+',height='+h+',scrollbars=1,status=1,top=50,left=50,resizable=1');
}

function popWin(url)
{
    if(url.indexOf('?') == -1)
    {
        url += '?noborder=1';
    }
    else
    {
        url += '&noborder=1';
    }
    window.open(url,'popWin','width=600,height=430,scrollbars=0,top=50,left=50,statusbar=0,status=0');
}

function popImgWin(url,n,w,h)
{
    window.open(rootUrl+url+'?popImg='+n,'popImgWin','width='+(w+100)+',height='+(h+150)+',scrollbars=yes,fullscreen=no');
}

function popImgWin2(url,n,w,h)
{
    window.open(rootUrl+url+'?popImg='+n,'popImgWin','width='+w+',height='+h+',scrollbars=auto,fullscreen=no');
}

function toggleDiv(id)
{
    var obj = document.getElementById('obj_'+id);
    if(obj.style.display == '')
    {
        obj.style.display = 'none';
        obj.style.visibility = 'hidden';
    }
    else
    {
        obj.style.display = '';
        obj.style.visibility = 'visible';
    }
}

function submitForm(n)
{
    if(document.forms[n])
    {
        document.forms[n].submit();
    }
}

function doRedirect(url)
{
    window.location = rootUrl+url;
}

/* ************ dreamweaver functions ********** */
function MM_swapImgRestore()
{ //v3.0
    var i,x,a=document.MM_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
    {
        x.src=x.oSrc;
    }
}

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function pImg(file,w,h,title)
{
    var ww = window.open('','pimg','width='+w+',height='+h);
    ww.document.write('<html><head><title>'+unescape(title)+'</title></head><body style="margin:0px;background-image:url('+rootUrl+'img/'+file+');">');
    ww.document.write('<a href="javascript:self.close();"><img src="/gfx/s.gif" border="0" width="98%" height="98%" alt="'+unescape(title)+'" border="0"></a>');
    ww.document.write('</body></html>');
    ww.focus();
}
function resizeWin(w,h)
{
    self.resizeTo(w,h);
}
function calcImgSize(NewWidth,NewHeight,minusWidth,minusHeight)
{
    var MaxWidth = (window.innerWidth ? window.innerWidth : document.body.offsetWidth) - (minusWidth ? 100 : 0);
    var MaxHeight = (window.innerHeight ? window.innerHeight : document.body.offsetHeight) - (minusHeight ? 150 : 0);

    if(NewWidth > MaxWidth && MaxWidth > 0)
    {
        NewHeight = Math.round((MaxWidth / NewWidth) * NewHeight);
        NewWidth = MaxWidth;
    }
    if(NewHeight > MaxHeight && MaxHeight > 0)
    {
        NewWidth = Math.round((MaxHeight / NewHeight) * NewWidth);
        NewHeight = MaxHeight;
    }

    return 'width="'+NewWidth+'" height="'+NewHeight+'"';

}

function calcImgSizeNew(NewWidth,NewHeight)
{
    var MaxWidth = 480;
    var MaxHeight = 480;

    if(NewWidth > MaxWidth && MaxWidth > 0)
    {
        NewHeight = Math.round((MaxWidth / NewWidth) * NewHeight);
        NewWidth = MaxWidth;
    }
    if(NewHeight > MaxHeight && MaxHeight > 0)
    {
        NewWidth = Math.round((MaxHeight / NewHeight) * NewWidth);
        NewHeight = MaxHeight;
    }

    return 'width="'+NewWidth+'" height="'+NewHeight+'"';

}

function calcImgSize2(NewWidth,NewHeight)
{
    var MaxWidth = 480;
    var MaxHeight = 480;
		var Sizes = new Array(2);

    if(NewWidth > MaxWidth && MaxWidth > 0)
    {
        NewHeight = Math.round((MaxWidth / NewWidth) * NewHeight);
        NewWidth = MaxWidth;
    }
    if(NewHeight > MaxHeight && MaxHeight > 0)
    {
        NewWidth = Math.round((MaxHeight / NewHeight) * NewWidth);
        NewHeight = MaxHeight;
    }

		Sizes[0] = NewWidth;
		Sizes[1] = NewHeight;

    return Sizes;

}

function planetsoul()
{
    window.open(rootUrl+'data/mp3player.html','mp3radio','width=200,height=200');
}

function printWindow() {
	browserVersion = parseInt(navigator.appVersion)
	if (browserVersion >= 4) window.print()
}

function prevImage() {
  prevImg = currentImage - 1;
  if (prevImg > 0 && document.forms['0'].elements['link_' + prevImg]){
    imageLink = document.forms['0'].elements['link_' + prevImg].value;
    if (imageLink.length > 0){
      width = imageLink.substring(imageLink.indexOf('W=') + 2, imageLink.indexOf('&H='));
      height = imageLink.substring(imageLink.indexOf('H=') + 2, imageLink.indexOf('&Gallery'));
      enlargeimage(imageLink, width, height, prevImg);
      currentImage = prevImg;
    }
  }
}

function nextImage() {
  nextImg = currentImage + 1;
  if (document.forms['0'].elements['link_' + nextImg]){
    imageLink = document.forms['0'].elements['link_' + nextImg].value;
    if (imageLink.length > 0){
      width = imageLink.substring(imageLink.indexOf('W=') + 2, imageLink.indexOf('&H='));
      height = imageLink.substring(imageLink.indexOf('H=') + 2, imageLink.indexOf('&Gallery'));
      enlargeimage(imageLink, width, height, nextImg);
      currentImage = nextImg;
    }
  }
}

function toggleDivVisibility(id){
  var obj = document.getElementById(id);
  if (obj.style.display == ''){
    obj.style.display = 'none';
    obj.style.visibility = 'hidden';
  }
  else{
    obj.style.display = '';
    obj.style.visibility = 'visible';
  }
}

function setCKey(f, ckeystr)
{
	f.ckey.value = ckeystr;
}