function disableBtn(btnID, causesValidation) {

    //initialize to avoid 'Page_IsValid is undefined' JavaScript error
    Page_IsValid = null;

    //check if the page request any validation
    // if yes, check if the page was valid
    if (causesValidation == 'True' && typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate();
        //you can pass in the validation group name also
    }

    //variables
    var btn = document.getElementById(btnID);
    var isValidationOk;
    if(causesValidation == 'False')
    {
        isValidationOk = true;
    }
    else
    {
        isValidationOk = Page_IsValid;
    }

    /********NEW UPDATE************************************/
    //if not IE then enable the button on unload before redirecting/ rendering
    if (navigator.appName !== 'Microsoft Internet Explorer') {
        EnableOnUnload(btnID, btn.value);
    }
    /***********END UPDATE ****************************/

    // isValidationOk is not null
    if (isValidationOk !== null) {
        //page was valid
        if (isValidationOk) {
            btn.disabled = true;
        }
        else { //page was not valid
            btn.disabled = false;
        }
    }
    else { //the page don't have any validation request
        btn.disabled = true;
    }
}


//enable the button and restore the original text value
function EnableOnUnload(btnID, btnText) {
    window.onunload = function() {
        var btn = document.getElementById(btnID);
        btn.disabled = false;
        btn.value = btnText;
    }
}

function clearAllRadios(namePrefix, radioName) 
{
    var prefix = getNamePrefix(namePrefix); 
    var tags = document.getElementsByTagName('input');
        for(i=0;i<tags.length;i++)
        {
            name = tags[i].name;
            if(name.indexOf(prefix + radioName) > -1)
            {                   
                document.getElementById(tags[i].id).checked = false;
               
            }      
           
        }
}

function isControlChecked(controlPrefix, controlName)
{
    var prefix = getControlPrefix(controlPrefix); 
    var control = document.getElementById(prefix + controlName);
    if(control.checked)
        return true;
    else
        return false;
}

//A control to enable a checkbox when a screen is loaded and due to viewstate, the checkbox is already checked
function EnableCheckBoxIfChecked(controlPrefix, controlName)
{
    var prefix = getControlPrefix(controlPrefix);
    var control = document.getElementById(prefix + controlName);
    document.write(prefix + controlName);
    if(control.checked && control.disabled == true)
    {
        control.disabled = false;
    }
}

function ChangeControlEnabledStatus(controlPrefix, controlName, status)
{
    var prefix = getControlPrefix(controlPrefix); 
    var control = document.getElementById(prefix + controlName);
    var browserName=navigator.appName; 
    if (browserName=="Microsoft Internet Explorer" && status == false)
    {
        document.getElementById(prefix + checkboxName).parentElement.setAttribute('disabled','true');
    }  
    if (browserName=="Microsoft Internet Explorer" && status == true)
    {
        document.getElementById(prefix + checkboxName).parentElement.removeAttribute('disabled');
    }       
    control.disabled = !status;
}

function clearSingleRadio(controlPrefix, radioName) 
{
    var prefix = getControlPrefix(controlPrefix); 
    var radio = document.getElementById(prefix + radioName);
    radio.checked = false;
}

function clearSingleCheckBox(controlPrefix, checkboxName) 
{
    var prefix = getControlPrefix(controlPrefix); 
    var check = document.getElementById(prefix + checkboxName);
    check.checked = false;
}

function disableSingleCheckBox(controlPrefix, checkboxName)
{
    var prefix = getControlPrefix(controlPrefix); 
    var check = document.getElementById(prefix + checkboxName);
    var browserName=navigator.appName; 
    if (browserName=="Microsoft Internet Explorer")
    {
        document.getElementById(prefix + checkboxName).parentElement.setAttribute('disabled','true');
    }
    check.disabled = true;
}

function enableSingleCheckBox(controlPrefix, checkboxName)
{
    var prefix = getControlPrefix(controlPrefix); 
    var check = document.getElementById(prefix + checkboxName);
    var browserName=navigator.appName; 
    if (browserName=="Microsoft Internet Explorer")
    {    
        document.getElementById(prefix + checkboxName).parentElement.removeAttribute('disabled');
    }
    check.disabled = false;
}

function ListHasItems(controlPrefix, listName)
{
    var prefix = getControlPrefix(controlPrefix); 
    var list = document.getElementById(prefix + listName);
    
    if(list.length == 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function getNamePrefix(namePrefix)
{
       var prefix;             
       var objCrtlPrefix = document.getElementById(namePrefix);
             

       if (objCrtlPrefix)

             prefix = objCrtlPrefix.value;                 

       return prefix;
}

function getControlPrefix(controlPrefix)
{
       var prefix;             
       var objCrtlPrefix = document.getElementById(controlPrefix);
             

       if (objCrtlPrefix)

             prefix = objCrtlPrefix.value;                 

       return prefix;
}


// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		if (!hasOptions(obj)) { return; }
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
		
// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(controlPrefix, object) {
	var prefix = getControlPrefix(controlPrefix); 
    obj = document.getElementById(prefix + object);
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
function selectAllOptionsNoPrefix(object) {
    obj = document.getElementById(object);
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}

	

		
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(controlPrefix,from,to) {
	// Unselect matching options, if required
	
	//DP 05/20/09 - Modified code to add control prefix components to allow accessing server-side
	//components at runtime
	var prefix = getControlPrefix(controlPrefix); 
    from = document.getElementById(prefix + from);
    to = document.getElementById(prefix + to);

	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
			to.options[index] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}

	sortSelect(from);
	sortSelect(to);

	from.selectedIndex = -1;
	}
	
function selectSingleOption(controlPrefix, from, toText)
{
   
	var prefix = getControlPrefix(controlPrefix); 
    from = document.getElementById(prefix + from);
    toText = document.getElementById(prefix + toText);
    
	// Move them over
	if (!hasOptions(from)) 
	{ 
	    return; 
	}
	for (var i=0; i<from.options.length; i++) 
	{
		var o = from.options[i];
		if (o.selected) 
		{
		    toText.disabled = false;
		    document.write(o.Text);
			toText.Text = o.Text;
			toText.disabled = true;
			break;
		}
    }
}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(controlPrefix,from,to) {

	selectAllOptions(controlPrefix,from);
	moveSelectedOptions(controlPrefix,from,to);
	
	if (arguments.length==2) {
		moveSelectedOptions(controlPrefix,from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(controlPrefix,from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(controlPrefix,from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
}

function addClickBehavior(menuTable) {
    var tbody = menuTable.getElementsByTagName("TBODY")[0];
    var tr = tbody.getElementsByTagName("TR")[0];

    for (var i = 0; i < tr.childNodes.length; i++) {
        var td = tr.childNodes[i];
        if (td.tagName && td.tagName.toLowerCase() == 'td') {
            var anchor = td.getElementsByTagName("A")[0];
            if (anchor) {
                var onClick = td.onmouseover;
                td.onclick =
                    (function(el, method) {
                        return function(evt) {
                            method.call(el);
                            if (window.event) {
                                evt = window.event
                            }
                            evt.cancelBubble = true;
                            RemoveRootHover(el);
                        };
                    })(td, onClick);
                td.onmouseover =
                    (function(el) {
                        return function() {
                            HoverRootMenu(el);
                        };
                    })(td);
                //add cursor style
                anchor.style.cursor = "default";
                //IN ORDER FOR THE MENU SYSTEM (ON CLICK) TO OPERATE CORRECTLY
                //ANY MENU ITEM THAT HAS NO DEFAULT ACTION AT THE ROOT LEVEL (BUT EXPANDS TO REVEAL ANOTHER MENU)
                //SHOULD BE ADDED HERE. OTHERWISE IT WILL NOT OPERATE CORRECTLY. THE NAME MUST
                //EXACTLY MATCH THE TITLE NAME IN THE SITEMAP.
                //WE NEED TO DO THIS TWICE FOR EACH MENU WITH A SPACE AS DIFFERENT BROWSERS RETURN EITHER THE CHARACTER REPRESENTATION
                //OF A SPACE OR THE LITERAL SPACE
                if (anchor.href.indexOf("Manage Submissions") != -1 ||
                    anchor.href.indexOf("Manage%20Submissions") != -1 ||
                    anchor.href.indexOf("Manage Companies") != -1 ||
                    anchor.href.indexOf("Manage%20Companies") != -1 ||
                    anchor.href.indexOf("Manage Company") != -1 ||
                    anchor.href.indexOf("Manage%20Company") != -1 ||
                    anchor.href.indexOf("News") != -1 ||
                    anchor.href.indexOf("My Account") != -1 ||
                    anchor.href.indexOf("My%20Account") != -1) 
                {
                   anchor.onclick = function() { return (false); };
                }
                td.onmouseout = (
                    function(el) {
                        return function() {
                            RemoveRootHover(el)
                        }
                    }
                    )(td);
            }
        }
    }
}


function FixMenu(menuTable) {

    if (!menuTable) { return };

    var tbody = menuTable.getElementsByTagName("TBODY")[0];

    var tr = tbody.getElementsByTagName("TR")[0];

    for (var i = 0; i < tr.childNodes.length; i++) {

        var td = tr.childNodes[i];
        
        if (td.tagName && td.tagName.toLowerCase() == 'td') {

            var anchor = td.getElementsByTagName("A")[0];

            if (anchor) {

                var onClick = td.onmouseover;

                td.onclick = (function(e, method) { return function(evt) { method.call(e); if (window.event) { evt = window.event } evt.cancelBubble = true; RemoveRootHover(e); __disappearAfter = 3000; Menu_Collapse(e) } })(td, onClick);

                td.onmouseover = (function(e) { return function() { HoverRootMenu(e) } })(td);

                anchor.style.cursor = "default";

                var submnu = WebForm_GetElementById(td.id + "Items");

                if (submnu) {anchor.onclick = function() { return false }}

                td.onmouseout = (function(e) { return function() { RemoveRootHover(e) } })(td);

            }
        }
    }

}

function HoverRootMenu(item) {

    var node = (item.tagName.toLowerCase() == "td") ? item : item.cells[0];

    var data = Menu_GetData(item);

    if (!data) { return null; }

    var nodeTable = WebForm_GetElementByTagName(node, "table");

    if (data.staticHoverClass) {

        nodeTable.hoverClass = data.staticHoverClass;

        WebForm_AppendToClassName(nodeTable, data.staticHoverClass);

    }

    node = nodeTable.rows[0].cells[0].childNodes[0];

    if (data.staticHoverHyperLinkClass) {
        node.hoverHyperLinkClass = data.staticHoverHyperLinkClass;
        WebForm_AppendToClassName(node, data.staticHoverHyperLinkClass);
    }

    return node;

}

function RemoveRootHover(item) {

    var node = (item.tagName.toLowerCase() == "td") ? item : item.cells[0];

    var data = Menu_GetData(item);

    if (!data) { return null; }

    var nodeTable = WebForm_GetElementByTagName(node, "table");

    if (nodeTable.hoverClass) { WebForm_RemoveClassName(nodeTable, nodeTable.hoverClass) }

    node = nodeTable.rows[0].cells[0].childNodes[0];

    if (node.hoverHyperLinkClass) { WebForm_RemoveClassName(node, node.hoverHyperLinkClass) }

} 