﻿// JScript File


/*
 * Get the name prefix added by .net for form elements.
 * Assumes there is an <asp:Literal /> called ctrlPrefix on the page.
 * This is where the name prefix that .net adds is stored, e.g. "ctl00_pContent_"
 * The literal's value is set up in the Page_Init(). See also Helper.SetFormPrefixValue
*/
function getIdCtrlPrefix() {
       var prefix;             
       var    objCrtlPrefix = document.getElementById("ctrlIdPrefix");
             
       if (objCrtlPrefix)
          prefix = objCrtlPrefix.value;                 

       return prefix;
}

function getNameCtrlPrefix() {
       var prefix;             
       var    objCrtlPrefix = document.getElementById("ctrlNamePrefix");
             
       if (objCrtlPrefix)
          prefix = objCrtlPrefix.value;                 

       return prefix;
}

/*
 * Get a control on a page.
*/
function getCtrlFullId(ctrlId) {
    
    var prefix = getIdCtrlPrefix();
    //alert (prefix + ctrlId);
    return prefix + ctrlId;
}

/*
 * Get a control on a page.
*/
function getCtrl(ctrlId) {
    //alert(ctrlId);
    var objCrtl = document.getElementById(getCtrlFullId(ctrlId));
    return objCrtl;
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

/*
 * limitText
 */
function limitText(limitFieldName, limitCountName, limitNum) {
    //alert('hello');
    var limitField = getCtrl(limitFieldName);
    var limitCount = document.getElementById(limitCountName);
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

/*
 * display_div
 */
function display_div(hide,show)
{
    document.getElementById(hide).style.display = "none";
    document.getElementById(show).style.display = "";
}


        
/****************************************
 * <THICKBOX> helper functions
 ****************************************/

/*
 * tb_removeIframe
 */
function tb_removeIframe() 
{
    parent.$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
}

function tb_WindowHeight()
{
    var height= parent.document.getElementById("TB_iframeContent").contentWindow.document.body.scrollHeight;
    alert('height: ' + height);
    
    //height= height + 100;
    //parent.document.getElementById("TB_iframeContent").style.height = parseInt(height)+"px";

    
}

/*
 * tb_ResizePopup
 */
function tb_ResizePopup(a_nIframeHeight, a_sPopContainerID, a_nPopContainerHeight, a_sPopContentContainerID, a_nPopContentContainerHeight)
{
    parent.document.getElementById("TB_iframeContent").style.height = a_nIframeHeight+"px";
    document.getElementById(a_sPopContainerID).style.height = a_nPopContainerHeight+"px";
    document.getElementById(a_sPopContentContainerID).style.height = a_nPopContentContainerHeight+"px";
    
}

function setElementDisplayStyle(elId, style) 
{
    var el = document.getElementById(elId);
    if (el != null)
    {
        el.style.display = style;
    }
}

/****************************************
 * </THICKBOX> helper functions
 ****************************************/