﻿
function hideElement(element)
{
	element.style.display = 'none';
}

function unhideElement(element)
{
	element.style.display = '';
}

function setControlValue(control, value)
{
	control.value = value;
}

function popupFullScreen(url)
{
    window.open(url, 'Memberships','fullscreen=yes,scrollbars=yes');
}

function popupFixed(url)
{
    window.open(url,'Memberships','menubar=0,resizable=1,scrollbars=1,width=700,height=600');
}

function popupHelp(url)
{
    window.open(url, 'Memberships', 'menubar=0,resizable=1,scrollbars=1,width=500,height=400');
}

function popupSubscriptionSeats(url)
{
    window.open(url, 'Memberships', 'menubar=0,resizable=1,scrollbars=1,width=700,height=300');
}

function popup(url)
{
    window.open(url);
}

function popup(url, width, height)
{
    window.open(url, 'Memberships', 'menubar=0,resizable=1,scrollbars=1,width=' + width + ',height=' + height);
}

function popupPrintConfirm(url)
{
    window.open(url,'PrintOrderConfirm','left=0, top=0, location=no, menubar=yes, resizable=yes, scrollbars=yes, titlebar=no, toolbar=no');
}

function expandContract(expand, elementID, contractLinkID, expandLinkID, inputID)
{
	var element = document.getElementById(elementID);
	var contractLink = document.getElementById(contractLinkID);
	var expandLink = document.getElementById(expandLinkID);
	var input = document.getElementById(inputID);
	input.value = expand;
	if (expand)
	{
		unhideElement(element);
		unhideElement(contractLink);
		hideElement(expandLink);
	}
	else
	{
		hideElement(element);
		hideElement(contractLink);
		unhideElement(expandLink);
	}
}

function enableDisableControlBasedOnCheckBox(checkBoxID, controlID)
{
	var cssClass = "disabledTextBox";
	var checkBox = document.getElementById(checkBoxID);
	var control = document.getElementById(controlID);
	control.disabled = !checkBox.checked;	
	if (control.disabled && control.className.indexOf(cssClass) < 0)
	{
		control.className += " " + cssClass;
		control.className = trim(control.className);
	}
	else if (!control.disabled && control.className.indexOf(cssClass) >= 0)
	{
		control.className = control.className.substring(0, control.className.indexOf(cssClass)) + 
			control.className.substring(control.className.indexOf(cssClass) + cssClass.length, 
				control.className.length - 1);
		control.className = trim(control.className);
	}	
}

function enableDisableControlListBasedOnCheckBox(checkBoxID, controlIDs)
{
    var listIDs = controlIDs.split(",");
    
    for (i = 0; i < listIDs.length; i++)
    {
        if(listIDs[i] != null && listIDs[i].length > 0)
        {
            enableDisableControlBasedOnCheckBox(checkBoxID, listIDs[i]);
        }
    }
}

function trim(s)
{
	if (s.length > 0)
	{
		if (s.substring(0, 1) == " ") return trim(s.substring(1, s.length));
		else if (s.substring(s.length - 2, s.length - 1) == " ") return trim(s.substring(0, s.length - 1));
	}
	return s;
}

function checkKey(e)
{   
	checkKeyFireButtonClick(e, gDefaultButtonID);
} 

function checkKeyFireButtonClick(e, buttonID)
{ 
	var keyCode;
	if (e.keyCode == 0) keyCode = e.which;
	else keyCode = e.keyCode;
	           
	if (keyCode == 13)
	{
		var target;
		if (e.target == null) target = e.srcElement;
		else target = e.target;
		if (target != null && target.nodeName != null && 
			(target.nodeName == 'A' || 
			target.nodeName == 'TEXTAREA' ||
			(target.nodeName == 'INPUT' && 
				(target.type == null || target.type == 'button' || target.type == 'file' || 
				target.type == 'image' || target.type == 'reset' || target.type == 'submit')) ||
			target.nodeName == 'BUTTON'))
		{
			return;
		}  
		if(e.preventDefault == null)
		{
				event.returnValue=false;
				event.cancelBubble=true;
		}
		else
		{	
			e.preventDefault();	
		}
		var defaultButton = document.getElementById(buttonID);
		if (defaultButton != null) 
		{
			defaultButton.click();
		}
	}
}

function unCheckRelatedControls(relatedControlIDList)
{
    var controlIDs = relatedControlIDList.split(",");
    
    for (i=0; i<controlIDs.length; i++)
    {
        if(controlIDs[i] != null && controlIDs[i].length > 0)
        {
            var control = document.getElementById(controlIDs[i]);
            control.checked = false;
        }
    }
}

function checkRelatedControls(setChecked, relatedControlIDList)
{
    var controlIDs = relatedControlIDList.split(",");
    
    for (i=0; i<controlIDs.length; i++)
    {
        if(controlIDs[i] != null && controlIDs[i].length > 0)
        {
            var control = document.getElementById(controlIDs[i]);
            
//            if(setChecked == "true")
//                control.checked = true;
//            else
//                control.checked = false;
            control.checked = (setChecked == "true") ? true : false;
        }
    }
}




//
// TELERIK CONTROL FUNCTIONS
//

//
// Get the associated RadWindow object
//
function GetRadWindow()
{
    //This code is used to provide a reference to the radwindow "wrapper"
	var oWindow = null;
	if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
	else if (window.frameElement && window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
	return oWindow;
}
//
// Close the RadWindow
//
function CloseRadWindow()
{
	GetRadWindow().Close();
}
//
// Close the RadWindow and reload the current page
//
function CloseReloadCurrent()
{
    GetRadWindow().BrowserWindow.document.location.reload();
    CloseRadWindow();
}
//
// Close the RadWindow and redirect page to url
//
function CloseOnReload(url)
{
	GetRadWindow().BrowserWindow.document.location.href = url;
	CloseRadWindow();
}
//
// Automatically adjust window size of Telerik RadWindow popup.
//
function SizeToFit()
{
    window.setTimeout(
        function()
        {
            var oWnd = GetRadWindow();
            if(oWnd)
            {
                var oHeight = document.body.scrollHeight + 72;
                oWnd.SetWidth(document.body.scrollWidth + 4);
                oWnd.SetHeight(oHeight > 500 ? 500 : oHeight);
            }
        }, 400);
}
//
// Override radconfirm function to enable postback support on OK button.
//
function enableRadConfirmPostback()
{
    //Replace old radconfirm with a changed version.
    var oldConfirm = radconfirm;
     //window.radconfirm = function(text, mozEvent)
     //We will change the radconfirm function so it takes all the original radconfirm attributes
    window.radconfirm = function(text, mozEvent, oWidth, oHeight, callerObj, oTitle)   
    {   
        var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually   
        //Cancel the event   
        ev.cancelBubble = true;   
        ev.returnValue = false;   
        if (ev.stopPropagation) ev.stopPropagation();   
        if (ev.preventDefault) ev.preventDefault();   
           
        //Determine who is the caller   
        var callerObj = ev.srcElement ? ev.srcElement : ev.target;   
        //Call the original radconfirm and pass it all necessary parameters   
        if (callerObj)    
        {   
            //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.   
            var callBackFn = function (arg)   
            {              
                if (arg)   
                {              
                    callerObj["onclick"] = "";             
                    if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz   
                    else if (callerObj.tagName == "A") //We assume it is a link button!   
                    {                                                          
                        try  
                        {   
                            eval(callerObj.href)   
                        }   
                        catch(e){}   
                    }   
                }   
            }   
            //We will need to modify the oldconfirm as well                
            oldConfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle); 
        }   
        return false;   
    }  
}  



//
// AJAX Control Toolkit Functions
// ------------------------------
//
// show the modal popup extender control
function showModalPopupExt()
{
    document.body.style.overflow = "hidden";
    $find("ModalBehaviour").show();
    return false;
}
function showModalPopupExtByName(popupName) {
    document.body.style.overflow = "hidden";
    $find(popupName).show();
    return false;
}
//
// hide the modal popup extender control
function hideModalPopupExt()
{
    document.body.style.overflow = "auto";
    $find("ModalBehaviour").hide();
    return false;
}
function hideModalPopupExtByName(popupName) {
    document.body.style.overflow = "auto";
    $find(popupName).hide();
    return false;
}
