﻿// JScript File

function expcl(obj_st ,def_cont)
{
  var par_n = document.getElementById(obj_st);
  var par_c = document.getElementById(obj_st+"c");
  var par_img = document.getElementById(obj_st+"im");
  if ((par_n)&&(par_img)&&(par_c))
  { 
       
      if (par_c.isexp)
      {
        par_c.isexp = false;
        par_c.style.display = "none";
        par_img.src = "/DESIGN/PIC4TREE/gcl1.gif";
      } 
      else
      {
        par_c.isexp = true;
        par_c.style.display = "block";
        par_img.src ="/DESIGN/PIC4TREE/gop1.gif";
        
        if (!((par_n.isfill)||(def_cont)))
        {
          par_c.innerHTML = "Загружается..."; 
          GalleryService.GetChNode4Gallery(obj_st,OnSucceededExpcl,OnFailedExpcl);
          par_n.isfill = true;
        }
      }
 
  } 
}

function OnSucceededExpcl(result, userContext, methodName)
{
  var par_n = document.getElementById(result.id4par);
  var par_c = document.getElementById(result.id4par+"c");
  var par_img = document.getElementById(result.id4par+"im");
  
  if ((par_n)&&(par_c)&&(par_img))
  {
    par_c.isexp = true;
    par_c.style.display = "block";
    par_img.src ="/DESIGN/PIC4TREE/gop1.gif";
    par_c.innerHTML = result.chnodes;
  }
}

function OnFailedExpcl(error,userContext, methodName )
{
  alert("Ошибка загрузки сервера");
}
 
var submtimer = 0;
var cursm = null;
function showmenu(sender_obj,p_sm)
{
  hidemenu(cursm);
  cursm = null;
  if (sender_obj)
  {
    var b = Sys.UI.DomElement.getBounds(sender_obj);
    var subm = $get(p_sm);
    Sys.UI.DomElement.setLocation(subm,b.x,(b.y+b.height));
    subm.style.display = "block";
    cursm = subm;
  }
}

function hidemenu(p_sm)
{
  if (cursm != null)
  {
    cursm.style.display = "none";
  }
}

function beginhide()
{
   timer1 = setTimeout("showmenu(null,null)",500);
   submtimer = 1;
}

function cancelhide()
{
  if (submtimer)
  {           
    clearTimeout(timer1);
    submtimer = 0;
  }
}

function f2(x){ x.focus(); x.select(); }
function ResetParams()
{
  var v_mode = document.getElementById("hmode4params");
  if (v_mode)
  {
    MainParamsService.GetMainParams(v_mode.value,true,true,"",null,OnSucceededGetMainParams,OnFailedGetMainParams);
  }
}

function CheckEmptyText(cbName, tbObject)
{
    if (tbObject.tagName == "SELECT")
        document.getElementById(cbName).checked = (tbObject.value != '0');
    else
        document.getElementById(cbName).checked = (tbObject.value != '');
}

function GetElementValueById(pElementName)
{
    var tmpElement = document.getElementById(pElementName);
    if ((tmpElement) && (tmpElement.type))
    {
        if (tmpElement.type == "checkbox")
        {
            if (tmpElement.checked)
                return tmpElement.value;
            else
                return "";
        }
        else
            return tmpElement.value;
    }
    return "";
}

function ChangModeParams(p_mode)
{
    var p_img_id = "";
    var himg = document.getElementById("id4modify");
    if (himg)
        p_img_id = himg.value;
    var tmpParams = new Object;
    tmpParams.O = GetElementValueById("O");
    tmpParams.M = GetElementValueById("M");
    tmpParams.R = GetElementValueById("R");
    tmpParams.X = GetElementValueById("X");
    tmpParams.J = GetElementValueById("J");
    tmpParams.N = GetElementValueById("N");
    tmpParams.JQ = GetElementValueById("JQ");
    tmpParams.IM = GetElementValueById("IM");
    tmpParams.VM = GetElementValueById("VM");
    tmpParams.V = GetElementValueById("V");
    tmpParams.FS = GetElementValueById("FS");
    tmpParams.RE = GetElementValueById("RE");
    tmpParams.XE = GetElementValueById("XE");
    tmpParams.VE = GetElementValueById("VE");
    tmpParams.alb_id = GetElementValueById("alb_id");
    tmpParams.select_thema = GetElementValueById("select_thema");
    tmpParams.input_comment = GetElementValueById("input_comment");
    tmpParams.user_url = GetElementValueById("user_url");
    tmpParams.GEO_LINK = GetElementValueById("GEO_LINK");
    tmpParams.GEO_NOT_PRIVATE = GetElementValueById("GEO_NOT_PRIVATE");
    tmpParams.GEO_POINT_ID = GetElementValueById("GEO_POINT_ID");
    MainParamsService.GetMainParams(p_mode,false,true,p_img_id,tmpParams,OnSucceededGetMainParams,OnFailedGetMainParams);
}

function OnSucceededGetMainParams(result, userContext, methodName)
{
    var par_d = document.getElementById("div4mainpar");
    var tmpTabModeComp = document.getElementById("TabModeComp");
    
    if ((par_d) && (tmpTabModeComp))
    {
        par_d.innerHTML = result.parbody;
        SetUploadMode(tmpTabModeComp.className == "tabs_current_a");
    }
}

function OnFailedGetMainParams(error,userContext, methodName )
{
    alert("Ошибка загрузки параметров с сервера");
}

function DelSinglImg(p_loc)
{
    if (confirm('Вы действительно хотите удалить это изображение?'))
    {
        location.href = p_loc;
    } 
}

