//show OR hide funtion depends on if element is shown or hidden
function ShowHide(id) { 
	
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none")
		{
			document.getElementById(id).style.display = 'block';
		} 
		else 
		{
			document.getElementById(id).style.display = 'none';			
		}	
	} 
	else 
	{ 
		if (document.layers) 
		{	
			if (document.id.display == "none")
			{
				document.id.display = 'block';
			} 
			else 
			{
				document.id.display = 'none';
			}
		} 
		else 
		{
			if (document.all.id.style.visibility == "none")
			{
				document.all.id.style.display = 'block';
			} 
			else 
			{
				document.all.id.style.display = 'none';
			}
		}
	}
}

var p1;
var oldvalue="";

function MaskPhone(object)
{
    var p2="";
    validKey = "0123456789";
    p1=object.value;	
    keyCount = p1.length;
    keyEntered = p1.substring(keyCount -1, keyCount);
    
    if (validKey.indexOf(keyEntered) == "-1")
    {
        object.innerText = p1.substring(0, keyCount - 1);
        p2=p1.substring(0, keyCount - 1);
    }
    else
    {  
        if (p1.length > oldvalue.length)
        {
            p1=p1.replace("(","");
            p1=p1.replace(")","");
            p1=p1.replace("-","");
    		
            while (p1.search(" ") != -1)
            {
	            p1=p1.replace(" ","");
            }
            
            object.value = p1;
            
            if (p1.length < 4)
            {
	            object.innerText= "(" + p1.substring(0,3);
	            p2="(" + p1.substring(0,3);
            } 
            else if (p1.length < 7)
	            {
                 object.innerText= "(" + p1.substring(0,3) + ")" + p1.substring(3,6);
                 p2= "(" + p1.substring(0,3) + ")" + p1.substring(3,6);
	            } 
	            else 
	            {
                 object.innerText= "(" + p1.substring(0,3) + ")" + p1.substring(3,6) + "-" + p1.substring(6,10);
                 p2="(" + p1.substring(0,3) + ")" + p1.substring(3,6) + "-" + p1.substring(6,10);
	            }
            }
        else
            p2=object.value;
}

    oldvalue=p2;
    object.value=p2;
}

function MaskZip(object)
{
    var p2="";
    validKey = "0123456789";
    p1=object.value;	    
    keyCount = p1.length;
    keyEntered = p1.substring(keyCount -1, keyCount);
    
    if (validKey.indexOf(keyEntered) == "-1")
    {
        object.innerText = p1.substring(0, keyCount - 1);
        p2=p1.substring(0, keyCount - 1);
    }
    else
    {     	    
    if (p1.length > oldvalue.length)
    {
        p1=p1.replace("-","");
		
        while (p1.search(" ") != -1)
        {
	        p1=p1.replace(" ","");
        }
        
        object.value = p1;
            
        if (p1.length < 6)
        {
                object.innerText= p1.substring(0,5);
	            p2= p1.substring(0,5);
        } 
        else 
        {
                object.innerText= p1.substring(0,5) + "-" + p1.substring(5,9);
	            p2= p1.substring(0,5) + "-" + p1.substring(5,9);
        }
    }
        else
            p2=object.value;
    }
    
    oldvalue=p2;
    object.value=p2;
}

function ShowPanel(event,Id)
{
    LookupPanel.startCallback(event,"id=" + Id.toString(),null,OnError);    
}    
function HidePanel()
{
    LookupPanel.hide();
    
    // *** If you don't use shadows, you can fade out
    //LookupPanel.fadeout();
}
function OnCompletion(Result)
{
    alert('done it!\r\n' + Result);
}
function OnError(Result)
{
    alert("*** Error:\r\n\r\n" + Result.message);
}   

//
// *** Modal Dialog function ***
//

//  keeps track of the delete button for the row
//  that is going to be removed
var _source;
// keep track of the popup div
var _popup;

function showConfirm(source){
    this._source = source;
    this._popup = $find('mdlPopup');
    
    //  find the confirm ModalPopup and show it    
    this._popup.show();
}

function okClick(){
    //  find the confirm ModalPopup and hide it    
    this._popup.hide();
    //  use the cached button as the postback source
    __doPostBack(this._source.name, '');
}

function cancelClick(){
    //  find the confirm ModalPopup and hide it 
    this._popup.hide();
    //  clear the event source
    this._source = null;
    this._popup = null;
}

//
// *** Update progress function ***
//

function onUpdating(){
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv'); 
    // make it visible
    updateProgressDiv.style.display = '';

    //  get the panel element        
    //  var targetPanel = $get('ctl00_DPContentPlaceHolder1_targetPanel');    
    var targetPanel = $get('targetPanelDiv');
    
    // get the bounds of both the target panel and the progress div
    var targetPanelBounds = Sys.UI.DomElement.getBounds(targetPanel);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
    
    //    do the math to figure out where to position the element (the center of the gridview)
    var x = targetPanelBounds.x + Math.round(targetPanelBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = targetPanelBounds.y + Math.round(targetPanelBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
    
    //    set the progress element to this position
    Sys.UI.DomElement.setLocation (updateProgressDiv, x, y);        
}

function onUpdated() {
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv'); 
    // make it invisible
    updateProgressDiv.style.display = 'none';
}