﻿function PopupAnketa(artID,paramname,param) {
  var width=480;
  var height=540;
  var left=screen.width/2-width/2;
  var top=screen.height/2-height/2;
  var wnd = window.open("/default.asp?artID="+artID+"&"+ paramname+"="+escape(param), "anketapopup","left="+left+",top="+top+",width="+width+",height="+height+",resizable=0,status=0,scrollbars=1");
  if(wnd)
    wnd.focus();
}

function OpSmWndw(URL,resizable,scrollbars,wHeight,wWidth)
{
var smallWindow=window.open(URL,"_blank","height="+((wHeight)?wHeight:400)+",width="+((wWidth)?wWidth:500)+",status=no,toolbar=no,menubar=no,location=no,resizable="+((resizable)?resizable:"no")+",scrollbars="+((scrollbars)?scrollbars:"yes"));
if (smallWindow != null && smallWindow.opener == null) smallWindow.opener=window;
smallWindow.focus();
//return smallWindow
}


function PopupPic(name, id, width, height){
  var left=screen.width/2-width/2;
  var top=screen.height/2-height/2;
  var wnd = window.open("/services/popuppic.asp?name="+ name+"&id="+id, "","left="+left+",top="+top+",width="+width+",height="+height+",resizable=0,status=0,scrollbars=0");
  if(wnd)
    wnd.focus();
}

function PopupPicRule(){
  var wnd = window.open("/rule/index.html","","width=900,height=300,resizable=0,status=0,scrollbars=0");
  if(wnd)
    wnd.focus();
}

function PopupURL(url, width, height){
	width = (width!=null) ? width : 400;
	height = (height!=null) ? height : 400;
  var left=screen.width/2-width/2;
  var top=screen.height/2-height/2;
  var wnd = window.open(url, "","left="+left+",top="+top+",width="+width+",height="+height+",resizable=0,status=0,scrollbars=0");
  if(wnd)
    wnd.focus();
}

function PrintPreview(){
  var url = window.location.href;
  var title = window.document.title;
  if(url.indexOf("#") != -1)
  	url = url.substring(0,url.indexOf("#"));
  if(url.indexOf("?") != -1)
    url = url + "&mode=print"
  else
    url = url + "?mode=print"
  var wnd = window.open( url , "PrintPreview","width=540,height=600,resizable=1,status=0,scrollbars=1");
  if(wnd)
    wnd.focus();
}

function MailLink(){
  var url = window.location.href;
  var title = window.document.title;
  var variable = "";
  var params = location.search.substring(1).split("&");
  for (var i = 0; i < params.length; i++){
	  if (params[i].split("=")[0] == "lang"){
	    if (params[i].split("=").length > 1) variable = params[i].split("=")[1];
	  }
  }
  if (variable == "en"){
  var wnd = window.open("/services/maillink.asp?lang=en" , "MailLink","width=472,height=501,resizable=1,status=0,scrollbars=1");
  } else {
    var wnd = window.open("/services/maillink.asp" , "MailLink","width=472,height=501,resizable=1,status=0,scrollbars=1");
  }
  if(wnd)
    wnd.focus();
}

function RemoveLinks(){
	if(window.opener)
	window.opener.name = "top"
	for(i=0; i<document.links.length; i++){
		var lnk = document.links[i].href;
		if(lnk.indexOf("javascript") == -1 && lnk.indexOf("#") == -1){
			document.links[i].target="top";
			document.links[i].onclick = new Function("opener.focus();");
		}
	}
}

var imagesHidden = false;
var images = null;

function HideImages(){
  if(images == null)
    images = new Array(document.images.length);
  var selfpath = document.location.href.split("/");
  for(i=0; i<document.images.length; i++){
    if(!imagesHidden){
      var path = document.images[i].src.split("/");
      if(path.length>5 || path.length==4 || selfpath[2] != path[2]){
        images[i] = document.images[i].src;
        document.images[i].src="/images/blank.gif";
      }  
    }
    else if(images[i] != null){
      document.images[i].src=images[i];
    }
  }
  imagesHidden = !imagesHidden;
  if(imagesHidden)
    document.getElementById("hide").innerText = "Show images"
  else
    document.getElementById("hide").innerText = "Hide images"
}

function GetTitle(){
  if(opener)
    if(opener.document.title)
      this.document.title = opener.document.title;
}


function ToggleBranch(element){
  if(element.tagName == "IMG"){
    var div = element.parentNode.parentNode.parentNode.parentNode.parentNode; //TD->TR->TBODY->TABLE->DIV
    var folder = element.parentNode.nextSibling;
    if(element.src.indexOf("_minus.gif")!=-1){
      element.src = element.src.substring(0, element.src.indexOf("_minus.gif")) + "_plus.gif";
      folder.childNodes.item(0).src = "/images/tree/folder_closed.gif";
      var childs = div.childNodes;
      for(var i=1; i< childs.length; i++){
        if(childs[i].tagName == "DIV"){
          childs[i].style.display = "none";
          childs[i].style.visibility = "hidden";
        }
      }
      div.setAttribute("expanded", "false");
    }
    else{
      element.src = element.src.substring(0, element.src.indexOf("_plus.gif")) + "_minus.gif";
      folder.childNodes.item(0).src = "/images/tree/folder_open.gif";
      var childs = div.childNodes;
      for(var i=1; i< childs.length; i++){
        if(childs[i].tagName == "DIV"){
          childs[i].style.display = "block";
          childs[i].style.visibility = "visible";
        }
      }
      div.setAttribute("expanded", "true");
    }
  }
}

function ExpandVisual(table){
  var img = table.getElementsByTagName("IMG");
  if(img.length >= 2){
    var x = img[img.length-1].src.indexOf("_closed.gif");
    if(x != -1)
      img[img.length-1].src = "/images/tree/folder_open.gif";
    x = img[img.length-2].src.indexOf("_plus.gif");
    if(x != -1)
      img[img.length-2].src = img[img.length-2].src.substring(0, x) + "_minus.gif";
  }
}

function ExpandAll(){
  var rootDiv = document.getElementById("SiteMap");
  if(rootDiv){
    var childs = rootDiv.getElementsByTagName("DIV");
    for(var i=0; i<childs.length; i++){
        if(childs[i].getAttribute("expanded") != "true"){
          ExpandVisual(childs[i].childNodes.item(0));
          childs[i].setAttribute("expanded", "true")
        }
        if(childs[i].parentNode != rootDiv){
          childs[i].style.display="block";
          childs[i].style.visibility = "visible";
        }
    }
  }
}

function CollapseVisual(table){
  var img = table.getElementsByTagName("IMG");
  if(img.length >= 2){
    var x = img[img.length-1].src.indexOf("_open.gif");
    if(x != -1)
      img[img.length-1].src = "/images/tree/folder_closed.gif";
    x = img[img.length-2].src.indexOf("_minus.gif");
    if(x != -1)
      img[img.length-2].src = img[img.length-2].src.substring(0, x) + "_plus.gif";
  }
}

function CollapseAll(){
  var rootDiv = document.getElementById("SiteMap");
  if(rootDiv){
    var childs = rootDiv.getElementsByTagName("DIV");
    for(var i=0; i<childs.length; i++){
        if(childs[i].getAttribute("expanded") == "true"){
          CollapseVisual(childs[i].childNodes.item(0));
          childs[i].setAttribute("expanded", "false")
        }
        if(childs[i].parentNode != rootDiv){
          childs[i].style.display="none";
          childs[i].style.visibility = "hidden";
        }
    }
  }
}

function switchTab(id){
	var tab_table = document.getElementById(id).parentNode;
	var tabs = tab_table.childNodes;
	for(i=0; i<tabs.length; i++)
		if(tabs[i].className=="selected"){
			tabs[i].className="";
			document.getElementById(tabs[i].id+"_div").style.display="none";
			break;
		}
	document.getElementById(id).className="selected";
	document.getElementById(id+"_div").style.display="block";
}

function checkClear(obj, mask) {

	if (obj.value=mask) {
		obj.value = '';
	}
}

function opros_comment(id) {
	if (document.getElementById(id).style.display=='none') {
		document.getElementById(id).style.display='';
	} else {
		document.getElementById(id).style.display='none';
	} 
}

function shareLink(){
		document.getElementById("tools-layer-share").style.display="block";
}
