function BackgroundCache() {
    try {
      //fixes the flicker in ie6
      document.execCommand('BackgroundImageCache', false, true);
    } catch(e) {}
}
function getWindowHeight()
{
	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			return document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			return document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		return window.innerHeight;
	}

    return 1000;
}
function getWindowWidth() 
{
		//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			return document.documentElement.clientWidth;
		}
		//quirks mode
		else
		{
			return document.body.clientWidth;
		}
	}
	//w3c
	else
	{
		return window.innerWidth;
	}

    return 1000;
}
//----------------------------------
//makes the supplied object fill the screen
//----------------------------------
function SetFullScreen(o)
{
    var obj = GetObject(o);
    obj.style.height = getWindowHeight();

    Show(obj);
}
//----------------------------------
//returns an object if supplied or
//gets the object if an id is given
//----------------------------------
function GetObject(o)
{
    if (typeof(o) == 'object')
        return o;
    else
        return document.getElementById(o);
}
//----------------------------------
//formats the string/number supplied into a currency string
//----------------------------------
function FormatCurrency(num, currencySymbol) 
{
    num = num.toString().replace(/\$|\,/g,'');
    if(num=='')
        return '';
        
    if(isNaN(num))
        num = "0";
        
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
        if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+ ',' + num.substring(num.length-(4*i+3));
        
    return (currencySymbol + num); // + '.' + cents);
}
//----------------------------------
//formats input control into a currency string
//----------------------------------
function FormatCtrlCurrency(ctrl,currencySymbol)
{
    try{ctrl.value=FormatCurrency(ctrl.value,currencySymbol);}
    catch(e){}
}
//----------------------------------
//formats the number specified into a percentage number
//----------------------------------
function FormatPercentage(num) 
{
    num = num.toString().replace(/\%|\,/g,'');
    if(num=='')
        return '';
        
    if(isNaN(num))
        num = "0";
        
    if (num < 1)
        return ("0" + num + '%');
    return (num + '%');
}

//----------------------------------
//formats input control percentage
//----------------------------------
function FormatCtrlPercentage(ctrl)
{
    try{ctrl.value=FormatPercentage(ctrl.value);}
    catch(e){}
}      
//----------------------------
//removes control border upon control becomes in focus
//----------------------------
function RmvBrd(obj)
{
    try
    {
        if(obj.blur)obj.blur();
    }
    catch(e){}
}
//----------------------------
//checks if the event supplied was generated from user pressing enter - usually used during keydown
//THIS FUNCTION REPLACES IsEvent AND SUPPORTS IE AND FIREFOX
// e is the event generated 
//if enter was pressed we cancel the event
//----------------------------
function IsEnterKey(e)
{
    var keycode = e.keyCode ? e.keyCode : e.which;
    if (keycode != 13)
        return false;
      
    //now cancel the event on enter - ie supports window.event
    if (window.event)
        e.returnValue=false;
    else      
        e.preventDefault();    
    
    return true;
}
//replaces html text with the equivalent text
function HTMLToText(htmlText)
{
    while(htmlText.search('<BR/>') > -1)
        htmlText=htmlText.replace('<BR/>','\r\n');
      
    while(htmlText.search('<BR>') > -1)
        htmlText=htmlText.replace('<BR>','\r\n');
    
    return htmlText;
}
//----------------------------
//clears all checkboxes under the supplied div
//----------------------------
function ClearListCheckBoxes(list)
{
    var divList = GetObject(list);
    
    var checkboxNodes = divList.getElementsByTagName('input');
    for (var j=0; j < checkboxNodes.length;j++)
    {
        var childNode = checkboxNodes[j];
        try{childNode.checked = false;}
        catch(e){}
    }
}
//----------------------------
//generates a delimited string with all selected ids under the div specified
//----------------------------
function GetSelectedCheckboxesIds(list, delimiter)
{
    var divList = GetObject(list);
    
    var checkboxNodes = divList.getElementsByTagName('input');
    
    var selectedIds='';
    for (var j=0; j < checkboxNodes.length;j++)
    {
        var childNode = checkboxNodes[j];
        try
        {   
            if(childNode.checked == true)
            {
                if(selectedIds!='')
                    selectedIds+=delimiter;
                    
                selectedIds+=childNode.id;
            }
        }
        catch(e){}
    }
    
    return selectedIds;
}
//----------------------------
//generates a delimited string with all selected values under the div specified
//----------------------------
function GetSelectedCheckboxesValues(list, delimiter)
{
    var divList = GetObject(list);
    
    var checkboxNodes = divList.getElementsByTagName('input');
    
    var selectedIds='';
    for (var j=0; j < checkboxNodes.length;j++)
    {
        var childNode = checkboxNodes[j];
        try
        {   
            if(childNode.checked == true)
            {
                if(selectedIds!='')
                    selectedIds+=delimiter;
                    
                selectedIds+=childNode.value;
            }
        }
        catch(e){}
    }
    
    return selectedIds;
}
//----------------------------
//----------------------------
//checks if any checkbox is selected under the specified list
//----------------------------
function IsAnyCheckboxSelected(list)
{
    var divList = GetObject(list);
    
    var checkboxNodes = divList.getElementsByTagName('input');
    
    for (var j=0; j < checkboxNodes.length;j++)
    {
        var childNode = checkboxNodes[j];
        try
        {   
            if(childNode.checked == true)
                return true;
        }
        catch(e){}
    }
    
    return false;
}
//----------------------------
//enables/disables all input controls under the specified div
//----------------------------
function EnableDivInputControls(div, isEnable)
{
    var divNode = GetObject(div);
    
    var ctrlNodes = divNode.getElementsByTagName('input');
    for (var j=0; j < ctrlNodes.length;j++)
    {
        var childNode = ctrlNodes[j];
        EnableControl(childNode,isEnable);
    }
}
//----------------------------
//enables/disables the specified control object/id
//----------------------------
function EnableControl(o, isEnable)
{
    var ctrl=GetObject(o);
    if (isEnable)
        ctrl.removeAttribute('disabled');
    else
        ctrl.setAttribute('disabled','disabled');
}
function GetDivInnerText(divId)
{
    var text='';
    var div = document.getElementById(divId);
    if (div!=null)
        text=div.innerHTML;

    return text;
}
//----------------------------
//refreshes the specified div html
//----------------------------
function RefreshDivHTML(divId, html)
{
    var div = document.getElementById(divId);
    if (div!=null)
        div.innerHTML = html;
}
//----------------------------
//creates a new div, append it to specified parent, and returns it
//----------------------------
function CreateDiv(parent, divId)
{
    var parentCtrl = GetObject(parent);

    var div = document.createElement('div');
    div.id = divId;
    parentCtrl.appendChild(div);
    
    return div;   
}
//----------------------------
//removes all node from child node up to parent
//----------------------------
function RemoveNodeBranch(topParent, childNode)
{
    var parent = GetObject(topParent);
    var child = GetObject(childNode);
    
    if(parent==null || child==null)
        return;
     
    //finds the top child on the specified parent
    var childParent = child.parentNode;
    while(childParent!=null && childParent!=parent)
    {
        child = childParent;
        var childParent = child.parentNode;
    }
    
    if(childParent!=null)
        childParent.removeChild(child);
}
//----------------------------
//removes all object child nodes
//----------------------------
function RemoveAllChildren(o)
{
    var parent = GetObject(0);
    if(parent==null)
        return;
        
    while ( parent.childNodes.length > 0 )
    {
        parent.removeChild(parent.firstChild);       
    } 
}
//----------------------------
//enforces a textbox max length, based on max length provided
//----------------------------
function TextBoxMultilineMaxLength(txt,maxLength)
{
   try
   {
    return (txt.value.length <= (maxLength-1));
   }   
   catch(e){return true;}
}
//----------------------------
//switches checkbox to opposite value - might be used with Settimeout when we need to return false
//on onclick event, but still want to switch the value
//----------------------------
function ToggleCheckbox(o)
{
    var obj = GetObject(o);
    if(obj!=null)
    {
        obj.checked=!obj.checked;
        RmvBrd(obj);
    }
}
//--------------------------------
//clears value of text xontrol
//--------------------------------
function ClearTextControlValue(id)
{
    var text = document.getElementById(id);
    if (text != null)
        text.value = '';
}
//----------------------------
//utility function to refresh the viewstate - can be used just before callback
//to refresh the view state, so server code gets the most current user values
//----------------------------
function RefreshViewState()
{
    __theFormPostData = ''; 
    WebForm_InitCallback();
}
//----------------------------------------------
//used for ajax operation, to evaluate the javascript returned from the server
//----------------------------------------------
function Return(arg, cxt)
{
    eval(arg);
}
//----------------------------------------------
//shows a centered modal dialog and hooks up the hide button
//----------------------------------------------
var dialogManager;
function ShowDialog(id)
{
    if (!dialogManager)
        dialogManager = new YAHOO.widget.OverlayManager();
    
    var existingDialog = dialogManager.find(id);
    if (existingDialog) {
        existingDialog.show();
    }
    else {
        var dialog = new YAHOO.widget.Panel(id, {
            fixedcenter: true, 
            modal: true,
            close: false,
            underlay: 'shadow', 
            iframe: true,
            visible: false} );

        YAHOO.util.Event.addListener(id + 'Hide', 'click', function(e) {this.hide();if (e && e.preventDefault) e.preventDefault(); return false;}, dialog, true);
        dialog.render(document.forms[0]);
        dialog.show();   
        dialogManager.register(dialog);
    }
}
//----------------------------------------------
//hides a dialog based on the id
//----------------------------------------------
function HideDialog(id)
{
    var dialog = dialogManager.find(id);
    if(dialog)
        dialog.hide();
}
//----------------------------------------------
//hides all dialogs created with ShowDialog
//----------------------------------------------
function HideAllDialogs()
{
    if (dialogManager)
        dialogManager.hideAll();
}
function ShowAllDialogs()
{
    if (dialogManager)
        dialogManager.showAll();
}
//----------------------------------
//starts the spelling process on the calling document
//----------------------------------   
function SpellerStart(spellId)
{
    var spell = GetRadSpell(spellId);
        
    var arrSources = SpellerGetValidSourceControls(null);
    var textSource = new SpellerGetControlsTextSource(arrSources);
    
    spell.SetTextSource(textSource); 
    spell.StartSpellCheck();
}
//----------------------------------
//starts the spelling process on the calling document but only for controls under the parent
//----------------------------------   
function SpellerStartByParent(spellId, parentId)
{
    var spell = GetRadSpell(spellId);
    
    var arrSources = SpellerGetValidSourceControls(parentId);
    var textSource = new SpellerGetControlsTextSource(arrSources);

    spell.SetTextSource(textSource);
    spell.StartSpellCheck();
}
//----------------------------------
//gets all controls on page that should be spelled checked - returns an array
//if parent specified, only add controls under that parent
//----------------------------------   
function SpellerGetValidSourceControls(parent)
{
    var arrSources = new Array();
    var childControls = document.getElementsByTagName("body")[0].getElementsByTagName("*");
    for (var j=0; j < childControls.length;j++)
    {
        var item = childControls[j];
        var isValidSource = false;
        switch(item.tagName.toUpperCase())
        {
            case 'INPUT':
                isValidSource = (item.type.toUpperCase()=='TEXT');
                break;
                
            case 'TEXTAREA':
                isValidSource = true;
                break;
        }
        
        if(isValidSource)
        {
            //only add if parent not specified, or item related to parent
            if(parent==null || IsRelatedNodes(parent, item))
            {
                arrSources.push(new HtmlElementTextSource(item));
            }
        }
    }
    
    return arrSources;
}
//----------------------------------
//checks if the child object exists under the parent object, and returns true if it does
//----------------------------------   
function IsRelatedNodes(parent, potentialChild)
{    
    var parentToTest = GetObject(parent);
    var childNode = GetObject(potentialChild);
    if(parentToTest==null || childNode==null)
        return false;
        
    var nextParent = childNode.parentNode;
    while(nextParent!=null)
    {
        if(nextParent==parentToTest)
            return true;
            
        nextParent = nextParent.parentNode;
    }
    
    return false;
}
//----------------------------------
//converts the controls to the structure required by the speller
//----------------------------------   
function SpellerGetControlsTextSource(sources)
{
	this.sources = sources;
	
	this.GetText = function()
	{
		var texts = [];
		for (var j = 0; j < this.sources.length; j++)
		{
			texts[texts.length] = this.sources[j].getText();
		}
		return texts.join("<controlSeparator><br/></controlSeparator>");
	}
	
	this.SetText = function(text)
	{
		var texts = text.split("<controlSeparator><br/></controlSeparator>");
		for (var j = 0; j < this.sources.length; j++)
		{
			this.sources[j].setText(texts[j]);
		}
	}
}
//----------------------------------
//opens a window limited in size for basic info such as policy, terms etc
//----------------------------------   
function ShowNotice(url)
{
    window.open(url,'Scopings',config='height=550, width=500, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
} 
//----------------------------------
//opens a window limited in size for feedback
//----------------------------------   
function ShowFeedback(url)
{
    window.open(url,'Scopings',config='height=400, width=500, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
} 