﻿var g_xml, g_xmlroot = null;

/* -- form utils -- */

function toggleControls() {
    var ids = arguments;
    var control;
    for (var i = 0; i < ids.length; i++) {
        control = $get(ids[i]);
        if (control) {
            control.style.display = control.style.display == 'block' ? 'none' : 'block';
            control.style.visibility = control.style.display == 'visible' ? 'hidden' : 'visible';            
        }
    }
}

/*function showControls() {    
    var ids = arguments;
    var control;
    for (var i = 0; i < ids.length; i++) {
        control = $get(ids[i]);
        if (control) {
            control.style.display = 'block';
            control.style.visibility = 'visible';
        }
    }

    return false;
}

function hideControls() {    
    var ids = arguments;
    var control;
    for (var i = 0; i < ids.length; i++) {
        control = $get(ids[i]);
        if (control) {
            control.style.display = 'none';
            control.style.visibility = 'hidden';
        }
    }
    return false;
}

function disableControls() {
    var ids = arguments;
    var control;
    for (var i = 0; i < ids.length; i++) {
        control = $get(ids[i]);
        if (control) {
            control.disabled = true;
        }
    }
    return false;
}

function enableControls() {
    var ids = arguments;
    var control;
    for (var i = 0; i < ids.length; i++) {
        control = $get(ids[i]);
        if (control) {
            control.disabled = false;
        }
    }
    return false;
}

function closePopupRefreshParent() {
    var url;
    
    if (arguments.length ==0)
        url = window.opener.location.href;
    else
        url = arguments[0];
        
    window.opener.location.href = url;
    window.close();
}
/* -- -- */

/* -- validators -- */
/*function DisableValidators(userControlID)
{    
    var i;
    if ((typeof(Page_Validators) != "undefined") && (Page_Validators != null)) {
        for (i = 0; i < Page_Validators.length; i++) {
            if (typeof(userControlID) != "undefined") {
                if (Page_Validators[i].id.toString().indexOf(userControlID) > -1)
                    ValidatorEnable(Page_Validators[i], false);
            }
            else
                ValidatorEnable(Page_Validators[i], false);
        }
    }
}

function EnableValidators(userControlID)
{
   var i;
    if ((typeof(Page_Validators) != "undefined") && (Page_Validators != null)) {
        for (i = 0; i < Page_Validators.length; i++) {
            if (typeof(userControlID) != "undefined") {
                if (Page_Validators[i].id.toString().indexOf(userControlID) > -1)
                    ValidatorEnable(Page_Validators[i], true);
            }
            else
                ValidatorEnable(Page_Validators[i], true);
        }
    }
}

/* -- -- */

function _closeModalPopup(behaviorID)
{
    if ($find(behaviorID))
        $find(behaviorID).hide();
    else
        alert(behaviorID + " was not found!");        
            
    return false;
}

function _showModalPopup(behaviorID)
{
    if ($find(behaviorID))
        $find(behaviorID).show();
    else
        alert(behaviorID + " was not found!");
        
    return false;
}

//centered popup window
function popup(url, name, _width, _height) {    
    var width = screen.width/2;
    var height = screen.height;
    
    if (typeof _width != 'undefined')
        width  = _width; 
    if (typeof _height != 'undefined')
        height = _height;
            
    var left   = (screen.width  - width)/2;
    var top    = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=1';
    params += ', status=no';
    params += ', toolbar=no';
    newwin=window.open(url, name, params);
    if (window.focus) {newwin.focus()}
        return false;
}

function BuildOnKeyDownScript(event, btn) {
    var key = window.event ? event.keyCode : event.which;
    if (key == 13) {
        event.returnValue=false;
        event.cancel = true;
        btn.click();
    }
}

/*function doShowConfirm(message, evt, explicitControlID) {
    var sender;

    if (typeof explicitControlID != 'undefined')
        sender = document.getElementById(explicitControlID);
    else
        sender = Event.element(evt);    
    
    if (typeof response != "undefined" && response)    
        return response;

    if (!jConfirm(unescape(message), 
    "Confirm", 
    function(r) { 
        if (r) { 
            response = true;                 
            jQuery(sender).click();
            response = false;
        }
        else
            return false;
    })); 
    
    return false;    
}

function doShowAlert(message, title)
{
    if (typeof title == 'undefined')
        title = 'Info';
        
    jAlert(unescape(message), title);
}

/*function fixIeDropDown(select) 
{
	var select = (typeof select == "string") ? document.getElementById(select) : select;

	// THIS FUNCTION IS ONLY CONCERNED WITH INTERNET EXPLORER NON-MULTIPLE SELECT NODES THAT HAVE A SPECIFIC WIDTH DEFINED
	if(!select.attachEvent || navigator.userAgent.indexOf("Opera") > -1 || select.multiple || select.currentStyle.width == "auto") { return; }

	var body = document.getElementsByTagName("body").item(0);

	var si = select.selectedIndex;

	var clone = select.cloneNode(true);
	clone.style.position = "absolute";
	clone.style.visibility = "hidden";
	clone.style.width = "auto";
	body.appendChild(clone);

	clone._initialOffsetWidth = select.offsetWidth;
	clone._initialOffsetHeight = select.offsetHeight;
	clone._autoWidth = clone.offsetWidth;

	clone = body.removeChild(clone);
	clone.style.visibility = "visible";
	clone.style.width = clone._initialOffsetWidth + "px";

	var span = document.createElement("span");
	span._isIeDropDownContainer = true;
	span.style.position = "relative";
	span.style.width = clone._initialOffsetWidth + "px";
	span.style.height = clone._initialOffsetHeight + "px";
	span.style.marginBottom = "-4"; //hmm...quirky...
	span.appendChild(clone);

	if (select.parentNode._isIeDropDownContainer){
		select.parentNode.parentNode.replaceChild(span, select.parentNode);
	}else{
		select.parentNode.replaceChild(span, select);
	}

	if (clone._autoWidth > clone._initialOffsetWidth){
		var expand = function(){
			event.srcElement.parentNode.style.zIndex = 1;
			event.srcElement.style.width = "auto";
			if (event.srcElement.offsetWidth > event.srcElement._initialOffsetWidth){
				event.srcElement.style.width = "auto";
			}else{
				event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
			}
		};
		var contract = function(){
			event.srcElement.parentNode.style.zIndex = 0;
			event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
		};
		clone.attachEvent("onactivate", expand);
		clone.attachEvent("ondeactivate", contract);
	}
	clone.selectedIndex = si;
}*/