
function SelectAllCheckboxes(spanChk){

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
     {
       if(elm[i].checked!=xState)
         elm[i].click();       
     }
 }
 
 //Function used for checking or unchecking checkboxes in the checkbox column of
//the GridView based on whether the header checkbox is checked or unchecked.
function select_deselectAll(chkVal, idVal, chkBaseHeaderID, chkBaseID) 
{ 
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++) 
    {
		e = frm.elements[i];
        // Look for our Header Template's Checkbox
        if (idVal.indexOf(chkBaseHeaderID) != -1) 
        {
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
            if(chkVal == true) 
            {
                e.checked = true;
            } 
            else 
            {
                e.checked = false;
            }
            // Work here with the Item Template's multiple checkboxes
        } 
        if (idVal.indexOf(chkBaseID) != -1) 
        {
			// Check if any of the checkboxes are not checked, and then uncheck header select all checkbox
            if(chkVal == false) 
            {
				//Uncheck main select all checkbox
                if(e.name.indexOf(chkBaseHeaderID) != -1 && e.type == 'checkbox')
					e.checked = false;     
            }
        }
    }
}
 
// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

//Used to check and see if any items were checked when clicking to delete items from a list.
function CheckItemsToDelete()
{
    var numberChecked = CheckChecked();
    if(numberChecked > 0)
        return confirm('Are you sure you want to delete the selected items?');
    else
        return alert('No items were selected');
}

function CheckChecked()
{
    var inputs = document.getElementsByTagName("input");
    var chbxs = new Array();  //checkbox elements
    var chbxChecked = new Array(); //checked checkbox elements
    
    for(var i=0;i < inputs.length; i++)
    {
        if(inputs[i].type == "checkbox")
        {
            chbxs.push(inputs[i]);
            if(inputs[i].checked)
            {
                chbxChecked.push(inputs[i]);
            }
        }
    }
    
    return chbxChecked.length;
}
 
// Clear the text of the success message that is in the update panel...element should be label since '.innerHtml'
function ClearText(text)
{
    var ajaxText = $get(text);
    ajaxText.innerHTML = '';
}
            
            
 function OpenWindow (page,W,H) 
 {
    var myWindow;
    
	myWindow = window.open(page ,'_blank',"\'toolbar=no,directories=no,scrollbars=yes,menubar=no,resizable=yes,width=" + W + ",height=" + H + "\,top=200'");	 
	myWindow.focus();
}

var empiWindow;

function OpenEmpiWindow(url) {
    empiWindow = window.open(url, 'empWin', 'left=20,top=5,directories=0,width=900,height=900,toolbar=0,resizable=0,scrollbars=1');
    empiWindow.focus();
}

function CloseEmpiWindow() {
    if (empiWindow) {
        if (empiWindow.open && !empiWindow.closed) {
            empiWindow.close();
        }
    }
    else {
        window.close();
    }
    
}

function EmpiOpenAcctHelp() {
        
    window.opener.location = "/app.aspx?cmd=contentview&page=acctReg&group=sprw#orderingAccount";
}
 
function closePopup()
 {
    AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup();
    return false;
}


function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    
    if (isNaN(num)) {
        num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    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 (((sign) ? '' : '-') + '$' + num + '.' + cents);
}

function positionAjaxImage(id) {
    
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    var image = document.getElementById(id);
    image.style.position = 'fixed';
    
    // subtract 1/2 image height & width
    image.style.left = ((myWidth / 2) - 24) + "px";
    image.style.top = ((myHeight / 2) - 18) + "px";
}