﻿// JScript File

function ShowCalendar(url) {
	popUp = window.open(url, 'popupcal', 'width=200,height=270,left=300,top=250');
}

function SetCalendar(ElementId) {
    window.opener.document.getElementById(ElementId).value = window.document.MainForm.txtSelectedDate.value;
    window.close();
}

function CloseCalendar() {
    window.close();
}

function ShowPopup(url) {
    popUp = window.open(url, 'popupcal', 'Resizable=1, width=680,left=100,top=100, menubar=0');
}

function ShowHelp(url) {
    popUp = window.open(url, 'popupcal', 'top=100, menubar=0,scrollbars=1,status=0');
}
function ClosePopup() {
    window.close();
}

function ParentReload() {
    window.opener.document.location.href = window.opener.document.location.href;
}

function PageReload() {
    window.document.location.href = window.document.location.href;
}

function ActionConfirm(message) {
    if (message == null) {
        message = "Вы уверены что хотите выполнить эту операцию?";
    }
    
    if (confirm(message)) {
        window.document.getElementById('hdnConfirm').value = "1";
    }
    else {
        window.document.location.reload();
        window.document.getElementById('hdnConfirm').value = "0";
    }
}

function DDLFilter (pElementId, pWithoutPostBack) {
    var ItemsQnt;
    var CurItemIndex;
    var CurItem;    
    var CurText;
    var CurTpl = prompt('Введите подстроку поиска', '');
    var SearchResult = 0;
    
    CurItemIndex = 0;

    while (window.document.getElementById(pElementId).length > CurItemIndex)
    {
        CurItem = window.document.getElementById(pElementId).options(CurItemIndex);
        
        CurText = CurItem.text.toLowerCase();

        if (CurText.indexOf(CurTpl.toLowerCase()) > -1)
        {
            window.document.getElementById(pElementId).options(CurItemIndex).selected = true;
            SearchResult = 1;
            break;
        }
        
        CurItemIndex = CurItemIndex + 1;
    }
    
    if (SearchResult == 0)
    {
        alert('По указаной вами подстроке ничего не найдено');
    }
    
    if (!pWithoutPostBack && SearchResult != 0)
    {
       setTimeout('__doPostBack(\'' + pElementId + '\',\'\')', 0);
    }
}

function DDLSorter (object, FindString, pPostBack) 
{
    var CurItemIndex;
    CurItemIndex = 0;
    while (object.length > CurItemIndex)
    {
        CurItem = object.options(CurItemIndex);
        CurText = CurItem.text.toLowerCase();
        if (CurText.indexOf(FindString.toLowerCase()) > -1)
            {
                object.options(CurItemIndex).selected = true;
                SearchResult = 1;
                break;
            }
            
         CurItemIndex = CurItemIndex + 1;
    }
    
    
}



var SearchString = "";

function getLeft(object) {
        result = object.offsetLeft;
        if (object.offsetParent) result += getLeft(object.offsetParent);
        return result;
}

function getTop(object) {
        result = object.offsetTop;
        if (object.offsetParent) result += getTop(object.offsetParent);
        return result;
}

function DDLFind(object, keyInd, PostBack) 
{
    var keyChar = String.fromCharCode(keyInd);
    SearchString = SearchString + keyChar;
    var FindDiv = document.getElementById("FindText");
    var FindText = document.getElementById("tbFindText").value = SearchString;
    FindDiv.style.position = "absolute";
    FindDiv.style.top = getTop(object);
    FindDiv.style.left = getLeft(object) + object.offsetWidth;
    FindDiv.style.visibility = "visible";
    DDLSorter (object, FindText, PostBack); 
}

function lefttbFindText(object, keyInd)
{
    
    if (keyInd == 8||keyInd == 13)
    {
       
        ElementBlur(object);
    }
}

function ElementBlur(object)
{
SearchString = "";
document.getElementById("tbFindText").value = "";
document.getElementById("FindText").style.visibility = "hidden";
 if (object.PostBack)
    {   
        setTimeout('__doPostBack(\'' + object.Id + '\',\'\')', 0);
    }
}

function ShowDiv(divid)
{
   document.getElementById(divid).style.visibility = "visible";
}
function ShowDivNear(divid)
{
    document.getElementById(divid).style.postion = "absolute";
    object = document.getElementById(divid);
    document.getElementById(divid).style.left = window.event.x;
    document.getElementById(divid).style.top = window.event.y;
    document.getElementById(divid).style.visibility = "visible";
}

function HideDiv(divid)
{
    document.getElementById(divid).style.visibility = "hidden";
    
}

function SetPosition(ObjX,ObjY)
{
    document.getElementById(ObjX).value = window.event.x;
    document.getElementById(ObjY).value = window.event.y + document.documentElement.scrollTop;
}
