﻿// JScript File
// Get ElementByID

// Get ListBox item index by name
function getListBoxItemIndexByName(ListBox,Name) {
    var i;
    for(i=0; i<ListBox.options.length;i++)
        if(ListBox.options[i].text == Name)
            break;
    return i==ListBox.options.length?-1:i;
}

// Get ListBox item index by value
function getListBoxItemIndexByValue(ListBox,Value) {
    var i;
    for(i=0; i<ListBox.options.length;i++)
        if(ListBox.options[i].value == Value)
            break;
    return i==ListBox.options.length?-1:i;
}

// Select ListBox, DropDownList item by value
function selectListBoxItemByValue(ListBox,Value) {
    var i;
    for(i=0; i<ListBox.options.length; i++)
        if(ListBox.options[i].value == Value)
            ListBox.selectedIndex = i;
}

// Clear ListBox, DropDownList items
function clearListBox(ListBox){
  for (var i=ListBox.options.length-1; i>=0; i--){
    ListBox.options[i] = null;
  }
  ListBox.selectedIndex = -1;
}

function ref(id){
    return document.getElementById(id);
};

function _FocusNextControl(obj,e){
    if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	//alert(obj);
	if (obj) {
	    if (code == 13) { obj.focus(); return false; }
	}
};

function _CloseOnEsc(e) {
    //var code;
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (code == 27) { window.close(); return; }
};

function DisplayObj(id){
    var obj =  ref(id);
    obj.style.display = obj.style.display == 'none' ? 'block' : 'none';
};

function confirmDelDocument(docID,docTitle) {
    if(confirm('Do you realy want to delete this Document: ' + unescape(docTitle.replace(/\+/g,  ' ').replace(/'&#39;'/g,  '')) + ' ?')) {
        var responseUrl = 'http://' + window.location.host + window.location.pathname + '?documentID=' + docID + '&action=delete';
        window.location = responseUrl;
    }
    else {
        return false;
    }
};
	    