function DisableChildElements(elem) {
    if (!elem || typeof(elem) == "undefined" || typeof(elem.children) == "undefined" || !elem.children) return;
    
    if (elem.children.length > 0)
        for (var idx=0; idx < elem.children.length; idx++) {
            DisableChildElementsInObject (elem.children[idx]);
        }
}

function DisableChildElementsInObject (elem) {
    if (typeof(elem) == "undefined") return;
    
    if (typeof(elem.children) != "undefined" && elem.children.length > 0)
        for (var idx=0; idx < elem.children.length; idx++) {
            DisableChildElementsInObject (elem.children[idx]);
        }
    
    if (typeof(elem.tagName) != "undefined") {
        if (elem.tagName == "A")
            elem.disabled = true;
        if ((elem.tagName == "SPAN" || elem.tagName == "TD") && elem.children.length == 0)
            elem.disabled = true;
        if (elem.tagName == "INPUT")
            elem.readOnly = true;
    }
}

function GetElementByID(elm)  
{  
    if (document.getElementById) {  
        if (typeof elm == "string") {  
            return document.getElementById(elm);  
        }  
    }  
    else if (document.layers) {  
        if (typeof elm == "string") {  
            // just one layer deep  
            return document.layers[elm]  
        }  
    }  
    else if (document.all) {  
        if (typeof elm == "string") {  
            return document.all(elm)  
        }  
    }  
      
    return null;
} 

function SetFocus (elem_id)
{
	try
		{
			GetElementByID(elem_id).focus();
		}
	catch (e) {}
}

function HideElement (elem_id)
{
	try
		{
			GetElementByID(elem_id).style.display = "none";
		}
	catch (e) {}
}

function ShowElement (elem_id)
{
	try
		{
			GetElementByID(elem_id).style.display = "inline";
		}
	catch (e) {}
}

function SetFocus (elem_id)
{
	try
		{
			GetElementByID(elem_id).style.display = "inline";
		}
	catch (e) {}
}

function SetDialogResult (res, closeWindow)
{
	window.returnValue = res
	if (typeof(closeWindow) == "undefined" || closeWindow) window.close()
}

function RefreshPostData()
{
    __theFormPostData = ""
    WebForm_InitCallback()
}

function prepareCallBackArgument(arg)
{
    return arg + '_' + Math.random() * 100000
}

function setElementValue (elementID, value)
{
    var el = $get(elementID);
    
    if (el != null && typeof(el.value) != "undefined") {
        el.value = value;
    }
}

function registerSelfDispose (id)
{
    var tree = GetElementByID (id);
    if (tree)
    {
        tree.dispose = function() {
            if (this.childNodes && this.childNodes.length > 0) {
                for (var i = this.childNodes.length - 1; i >= 0; i--) {
                    var node = this.childNodes[i];
                    this.removeChild (node);
                }
            }
        }
    }
}

function OpenStandartDialog(dlgName, dialogWidth, dialogHeight, resInput, dialogParams, dialogParamsClientFunction, dialogParamsClientFunctionParams)
{
	if (typeof(dialogParamsClientFunction) != 'undefined')
		dialogParams = dialogParamsClientFunction(dialogParams, dialogParamsClientFunctionParams);

	var x = (screen.width - dialogWidth) / 2;
	var y = (screen.height - dialogHeight) / 2;

	var formName = dlgName.indexOf('http') == 0 ? dlgName :
	    full_web_root +'/Dialogs/' + dlgName

	var rnd = Math.random()
	formName += formName.indexOf('?') == -1 ? '?' : '&'
	formName += 'random=' + rnd;

	if (typeof(dialogParams) != "undefined") formName += '&' + dialogParams;

	//var res = window.showModalDialog(formName, '', params);
	var res;
	if (window.showModalDialog) {
        // IE Modal dialog call
	var params = 'dialogWidth=' + dialogWidth + 'px; dialogHeight=' + dialogHeight + 'px; dialogLeft=' + 
			x + 'px; dialogTop=' + y + 'px; border=thin; help=no; status=no; center=yes; resizable=yes; scroll=yes;';
        res = window.showModalDialog(formName, '', params);
	
    } 
    else 
    { 
        // Netscape Modal dialog call
       var params = 'width=' + dialogWidth + ',height=' + dialogHeight + ',screenX=' + 
			x + ',screenY=' + y + ',status=no,resizable=yes,scrollbars=yes,modal=yes'; 
       var WindowObjectReference = window.open(formName, '', params);
       WindowObjectReference.focus();
    }
	
	if (resInput != null && resInput != "undefined" && $get(resInput))
		$get(resInput).value = res

	return typeof(res) != "undefined";
}

var pbControl = null;

function AvoidDoubleCallback() {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(AvoidDoubleCallback_BeginRequestHandler);
    prm.add_endRequest(AvoidDoubleCallback_EndRequestHandler);
}
    
function AvoidDoubleCallback_BeginRequestHandler(sender, args) {
    pbControl = args.get_postBackElement();  //the control causing the postback
    if (pbControl)
        pbControl.disabled = true;
}

function AvoidDoubleCallback_EndRequestHandler(sender, args) {
    if (pbControl) {
        pbControl.disabled = false;
        pbControl = null;
    }
}

function FixCalendarDate(date,ff,calendar) {
    var c = CalendarPopup_FindCalendar(calendar); 
    var mas = new Array; 
    mas = date.split('/'); 

    if (mas.length == 3) { 
        var day = parseInt(mas[1]); 
        var month = parseInt(mas[0]); 
        var year = parseInt(mas[2]); 

        if (year > 2000) return; 

        var century = parseInt(year / 1000); 
        var yy = year % 100; 

        while (century < 2) {century ++; } 

        year = century * 1000 + yy; 
        month--; 

        c.SelectDate(new Date(year, month, day)); 
    }
}
                