﻿var CtrlFormatError = 'format is incorrect.';
var CtrlRequiredError = 'is a required field.';
var CtrlRangeError = 'is not in a valid range.';
var CtrlDateRangeError = 'should be between 01/01/1753 and 12/31/9999.';

var CtrlErrorTitle = 'The requested action was not completed.<br>Please correct the following:';

var ResultPanelErrorCssClass = 'result_panel_error';
var ResultPanelEmbeddedErrorCssClass = 'result_panel_error1';

var ClearErrorMessageList = false;
var ResultPanelDisplayMode = 3;// 1 - Modal, 2 - Not Modal, 3 - Embedded
var PressedButtonClientID;

function UploadFile(url)
{
    var height = window.document.body.scrollHeight + window.document.body.scrollTop + 35;
    var width = window.document.body.scrollWidth + 40;
    var top = (window.screen.availHeight / 2) - (height / 2);
    var left = (window.screen.availWidth / 2) - (width / 2);
    dialogHeight = height + 'px';
    dialogWidth = width + 'px';
    dialogTop = top + 'px';
    dialogLeft = left + 'px';
    var ret = ShowModalDialog(url, '650', '340'); 
    if(ret == null || ret == 'cancel')
        return 'cancel';
    else
        return ret;
}

function DownloadFile()
{
    var url = arguments[0];
    var fileName = arguments[1];
    var attachmentFilename = arguments[2];
    var source = arguments[3];
    
    if(url == null)
        url = "GetFile.aspx";
    if(fileName == null)
        fileName = "";
    if(attachmentFilename == null)
        attachmentFilename = "";
    if(source == null)
        source = "";
    
    var height = 234;
    var width = 345;
    var top = (window.screen.availHeight / 2) - (height / 2);
    var left = (window.screen.availWidth / 2) - (width / 2);
        
    window.open(url + '?filename=' + fileName + '&afilename=' + attachmentFilename + '&src=' + source, '_blank', 'top=' + top + ',left=' + left + ',height=' + height + ',width=' + width + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no');
}
//function sets a special value for zipcontrol to make letters input available when Contry selected is differ than US
function AlphaEnable(DropCtrlID, FirstCtrlID, SecondCtrlID, isError, isRequired)
{
    var drop_ctrl = document.all[DropCtrlID];
    var first_ctrl = document.all[FirstCtrlID];
    var second_ctrl = document.all[SecondCtrlID];
    
    if(drop_ctrl != null && first_ctrl != null && second_ctrl != null)
    {
        if(drop_ctrl.value != 'US')
        {
            first_ctrl.accessKey = "0";
            second_ctrl.accessKey = "0";
        }
        else
        {
            first_ctrl.accessKey = "1";
            second_ctrl.accessKey = "1";
        }        
    }
}


//redefined onkeypress event handler for ZipControl
function OnKeyPressOwn(CtrlID)
{
    var ctrl = document.all[CtrlID];
    if(ctrl != null)
    {
        if(ctrl.accessKey == "0")
            KeyDigitAlpha();
        else
            KeyDigit();
    }   
}
//redefined ondeactivate event handler for ZipControl
function OnDeactivateOwn(CtrlID, FirstCtrlID, SecondCtrlID, isError, isRequired)
{
    var ctrl = document.all[CtrlID];
    if(ctrl != null)
    {
        if(ctrl.accessKey == "0")
            CheckZipAlpha(FirstCtrlID, SecondCtrlID, isError, isRequired);
        else
            CheckZip(FirstCtrlID, SecondCtrlID, isError, isRequired);
    }   
}

function SaveCheckBoxValue(checkID, cBoxID)
{
    var obj = document.all[checkID];
    var field = document.all[cBoxID];
    if(obj != null)
    {
        if(field != null)
            field.value = obj.checked;
    }
}    
function DropCheckBox(checkID, type)
{
    var check = document.all[checkID];
        
    if(type == 'AddressControl')
    {
        for (i = 0; i < document.all.length; i++) 
        {
            var temp_ctrl = document.all[i];
            if ((temp_ctrl.id.indexOf('IsPrimary') != -1) && (temp_ctrl.id.indexOf('AddressControl') != -1))
            {
                if(temp_ctrl.id != check.id)
                    temp_ctrl.checked = false;
                else
                {
                    if(temp_ctrl.checked)
                        temp_ctrl.checked = true;
                    else
                        temp_ctrl.checked = false;
                }
                var tempName = temp_ctrl.id.replace('IsPrimary1','CheckBoxValue');
                SaveCheckBoxValue(temp_ctrl.id,tempName);                
            }
        }
    }
    
    if(type == 'EmailControl')
    {
        for (i = 0; i < document.all.length; i++) 
        {
            var temp_ctrl = document.all[i];
            if ((temp_ctrl.id.indexOf('IsPrimary') != -1) && (temp_ctrl.id.indexOf('EmailControl') != -1))
            {
                if(temp_ctrl.id != check.id)
                    temp_ctrl.checked = false;
                else
                {
                    if(temp_ctrl.checked)
                        temp_ctrl.checked = true;
                    else
                        temp_ctrl.checked = false;
                }
                var tempName = temp_ctrl.id.replace('IsPrimary1','CheckBoxValue');
                SaveCheckBoxValue(temp_ctrl.id,tempName);
           }
        }
    }
}

function SaveFileName(ctrlID, filename)
{
    if(filename != "" && filename != null)  
    {        
        var ctrl = document.all[ctrlID];
        if(ctrl != null)
        {
            ctrl.value = filename;           
            return true;
        }
        return false
        
    }
    return false;
}

var PortalUrl = "";
function SetControlType(type)
{
    var ctrl = document.all['ControlType'];
    if(ctrl != null)
        ctrl.value = type;
}

/*Set the 'Loading...' message to ListBox while updating its content*/
function SetLoadingTextToListControl(ctrlWhereID)
        {
            var ctrl_where = document.all[ctrlWhereID];            
            if(ctrl_where!=null)
            {
                var len = ctrl_where.options.length;
			    for(var i=0; i<len; i++)
				{
					ctrl_where.options.remove(0);
				}
				var item = document.createElement("Option");
				ctrl_where.options.add(item);
			    item.innerText = "Loading...";
			    item.value = "";
            }
        }     
/*Function for Income Control. Calculate Annual Amount according specified Frequency and Amount.*/
function CalculateAmount(CAmountID, CFrequencyID, CAnnualID)
    {
        var ctrl_amount = document.all[CAmountID];
        var ctrl_freq = document.all[CFrequencyID];
        var ctrl_total = document.all[CAnnualID];
        
        var totalValue = 0;
        
        if(ctrl_amount != null && ctrl_freq != null)
        {            
            var amount = new Number(ctrl_amount.value);
            var freq = new Number(ctrl_freq.value);           
            
            totalValue = amount*freq;
            
            if(ctrl_total != null)
                ctrl_total.value = totalValue;
        }                   
        
        CalculateTotalAmount();           
    }
    
/*Function for Income Control. Clear fields if they weren't loaded from DB.*/    
function ClearIncomeLine(CSourceID, CFrequencyID, CAmountID, CAnnualID)
    {
        var ctrl_source = document.all[CSourceID];
        var ctrl_amount = document.all[CAmountID];
        var ctrl_freq = document.all[CFrequencyID];
        var ctrl_total = document.all[CAnnualID];
        
        if(ctrl_source != null)
            ctrl_source.value = "";
        if(ctrl_amount != null)
            ctrl_amount.value = "";
        if(ctrl_total != null)
            ctrl_total.value = "0";  
        if(ctrl_freq != null)
            ctrl_freq.selectedIndex = 0; 
            
        CalculateTotalAmount();  
    }
/*****************************************************************/

var CheckStateTime = 0; 
var WaitingText = "Please Wait..."
var NewWaitingText = ""
var isDisplayed = false;
var focusCtrlID = null;

var IsLoading = false;
function CheckLoadingState()
{
    if (!IsLoading)
    {
		showWaitingPage(document, 0, 0, false);
		isDisplayed = false;
        NewWaitingText = "";
		CheckStateTime = 0;		
    }
    else
    {
        if(CheckStateTime >= 5000)
        {
            showWaitingPage(document, 200, 100, true);            
        }
        else
            CheckStateTime += 100;
        window.setTimeout(CheckLoadingState, 100);
    }    
}

function CheckState()
{
    return;//logic is disabled
    if (theForm.document.readyState == "complete")
    {
		if(isDisplayed == true)
		{
			ShowComboboxes(true);
			showWaitingPage(document, 250, 70, false);
			isDisplayed = false;
			NewWaitingText = "";
			CheckStateTime = 0;
		}	
    }
    else
    {
        if(theForm.document.readyState != "interactive" && isDisplayed == false)
		{
            CheckStateTime += 100;
            if(CheckStateTime == 5000)
            {
			    isDisplayed = true;
			    ShowComboboxes(false);
                showWaitingPage(document, 250, 70, true);                 
                CheckStateTime = 0;
            }
        }
    }
    window.setTimeout(CheckState, 100);
}
/*function LockScreen(isShow)
{
        var mydiv1 = theForm.document.all["WaitingDiv1"];
        
        if(mydiv1 == null)    return;
        
        mydiv1.style.width = "100%";
        mydiv1.style.height = "100%";
        mydiv1.style.backgroundImage = "url(../Images/lock_bgr.gif)"; 
        mydiv1.style.zIndex = "10";
        mydiv1.style.top  = 0;
        mydiv1.style.left  = 0;  
        mydiv1.style.position = "absolute";
        if(isShow)
            mydiv1.style.visibility = "visible";
        else
            mydiv1.style.visibility = "hidden";
        
}*/

function LockScreen(isShow)
{
    if(isShow)
    {
        ShowBackground();
        $addHandler(window, 'resize', ShowBackground); 
    }
    else
    {
        HideBackground();
        $removeHandler(window, "resize", ShowBackground);
    }
}

/// <summary>
/// Add an empty IFRAME behind the popup (for IE6 only) so that SELECT, etc., won't show through the popup.
/// Add a div for IE 7
/// </summary>			
function ShowBackground()
{
    // Get the child frame
    var element = window.document.forms[0];
    if ((Sys.Browser.agent === Sys.Browser.InternetExplorer) && (Sys.Browser.version < 7)) 
    {
        /*var childFrame = element._hideWindowedElementsIFrame;
        
        // Create the child frame if it wasn't found
        if (!childFrame) 
        {
            childFrame = document.createElement("iframe");
            childFrame.src = "javascript:'<html></html>';";
            childFrame.style.position = "absolute";
            childFrame.style.display = "none";
            childFrame.scrolling = "no";
            childFrame.frameBorder = "0";
            childFrame.tabIndex = "-1";
            childFrame.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
            element.parentNode.insertBefore(childFrame, element);
            element._hideWindowedElementsIFrame = childFrame;
        }
        
        // Position the frame exactly behind the element
        $common.setBounds(childFrame, $common.getBounds(element));
        childFrame.style.display = element.style.display;
        if (element.currentStyle && element.currentStyle.zIndex)
        {
            childFrame.style.zIndex = element.currentStyle.zIndex;
        }
        else if (element.style.zIndex) 
        {
            childFrame.style.zIndex = element.style.zIndex;
        }*/
    }
    else
    {
        var childDiv = element._hideWindowedElementsDiv;
        
        // Create the child frame if it wasn't found
        if (!childDiv) 
        {
            childDiv = document.createElement("div");
            childDiv.style.position = "absolute";
            childDiv.style.display = "none";
            childDiv.tabIndex = "-1";
            childDiv.style.backgroundColor = '#F0EFEA';
            childDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
            element.parentNode.insertBefore(childDiv, element);
            element._hideWindowedElementsDiv = childDiv;
        }
        
        // Position the frame exactly behind the element
        $common.setBounds(childDiv, $common.getBounds(element));
        childDiv.style.display = element.style.display;
        if (element.currentStyle && element.currentStyle.zIndex)
        {
            childDiv.style.zIndex = element.currentStyle.zIndex;
        }
        else if (element.style.zIndex) 
        {
            childDiv.style.zIndex = element.style.zIndex;
        }
    }
}

function HideBackground()
{
    // Hide the child frame
    if ( (Sys.Browser.agent === Sys.Browser.InternetExplorer) && (Sys.Browser.version < 7)) 
    {
        /*var childFrame = window.document.forms[0]._hideWindowedElementsIFrame;
        if (childFrame) 
        {
            childFrame.style.display = "none";
        }*/
    }
    else
    {
        var childDiv = window.document.forms[0]._hideWindowedElementsDiv;
        if (childDiv) 
        {
            childDiv.style.display = "none";
        }
    }
}

function InitializeWaitingDiv(width, height, isShow)
{
    var mydiv1 = theForm.document.all["WaitingDiv1"];
    var mydiv2 = theForm.document.all["WaitingDiv2"];
    if(mydiv1 == null || mydiv2 == null)    return;
    
    mydiv1.style.width = "100%";
    mydiv1.style.height = "100%";
    mydiv1.style.top  = 0;
    mydiv1.style.left  = 0;  
    mydiv1.style.position = "absolute";
    
    mydiv2.style.height = height;
    mydiv2.style.width = width;
    mydiv2.style.position = "absolute";
    mydiv2.style.top  = (theForm.document.body.offsetHeight - height)/2 + theForm.document.body.scrollTop;if(mydiv2.style.top.indexOf('-') != -1) mydiv2.style.top = 0;
    mydiv2.style.left  = (theForm.document.body.offsetWidth - width)/2 + theForm.document.body.scrollLeft;if(mydiv2.style.left.indexOf('-') != -1) mydiv2.style.left = 0;
    
    if( mydiv1.style.display == "" && isShow) return;
    if(!isShow)
    {
        mydiv1.style.display = "none";
        mydiv2.style.display = "none";
        mydiv1.innerHTML = "";
        mydiv2.innerHTML = "";
        return;
    }
    
    mydiv2.className = "waitingpage";    
    mydiv1.style.display = "";
    mydiv2.style.display = "";
    
    
    var text = WaitingText
    if(NewWaitingText != '')
        text = NewWaitingText
    mydiv1.innerHTML = "<table width=100% height=100% border=0 cellpadding=0 cellspacing=0><tr><td width=100% height=100% align=center valign=middle ></td></tr></table>";    
    /*mydiv2.innerHTML =  "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' height='"+ height +"' width='"+ width +"'>"+
                        "<param name='movie' value='" + PortalUrl + "images/animated_loading.swf'>"+
                        "<param name='quality' value='best'></object>";// + text + "<br><br>";*/
    
    mydiv2.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' height='"+ height +"' width='"+ width +"' align='middle'>"+
                            //"<param name='allowScriptAccess' value='sameDomain' />"+
                            "<param name='movie' value='" + PortalUrl + "images/animated_loading.swf'>"+
                            "<param name='quality' value='best'></object>"+
                            "<param name='bgcolor' value='#0066ff' />"
                            "<embed src='" + PortalUrl + "images/animated_loading.swf' quality='high' bgcolor='#0066ff' height='"+ height +"' width='"+ width +"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' />"+
                        "</object>"

}
function showWaitingPage(document, width, height, isShow)
{
    InitializeWaitingDiv(width, height, isShow);
  /*
     if(isShow)
     {
        var mydiv = theForm.document.createElement("div");
        
        mydiv.id = "mydivWaitingPageBgr";
        mydiv.style.width = "100%";
        mydiv.style.height = "100%";
        mydiv.style.top  = 0;
        mydiv.style.left  = 0;  
        mydiv.style.position = "absolute";
        mydiv.innerHTML = "<table width=100% height=100% border=0 cellpadding=0 cellspacing=0><tr><td width=100% height=100% align=center valign=middle ></td></tr></table>";
        theForm.document.body.insertBefore(mydiv);
        
        mydiv = theForm.document.createElement("div");
        mydiv.style.height = height;
        mydiv.style.width = width;
        mydiv.style.position = "absolute";
        mydiv.style.top  = (theForm.document.body.offsetHeight - height)/2 + theForm.document.body.scrollTop;if(mydiv.style.top < 0) mydiv.style.top = 0;
        mydiv.style.left  = (theForm.document.body.offsetWidth - width)/2 + theForm.document.body.scrollLeft;if(mydiv.style.left < 0) mydiv.style.left = 0;
        mydiv.className = "waitingpage";
        mydiv.id = "mydivWaitingPage";
        var text = WaitingText
        if(NewWaitingText != '')
            text = NewWaitingText
        mydiv.innerHTML = "<table width=100% height=100% border=0 cellpadding=0 cellspacing=0><tr><td width=100% height=100% align=center valign=middle class=waitingpage>" + text + "</td></tr></table>";
        theForm.document.body.insertBefore(mydiv);
     }
     else
     {
        var mydiv = theForm.document.getElementById("mydivWaitingPage");
        if (mydiv != null)
            theForm.document.body.removeChild(mydiv);
        mydiv = theForm.document.getElementById("mydivWaitingPageBgr");
        if (mydiv != null)
            theForm.document.body.removeChild(mydiv);
     }*/
}

function ShowComboboxes(hide)
{
	var frame = window;
	if (frame == null)
		return
	var doc = frame.document.forms[0];
	if (doc == null)
		return
	var els = doc.elements;
	for(i=0; i<els.length; i++)
	{
		var elem = els[i];
		if( elem.tagName == 'SELECT') 
		{
			if( hide )
				elem!=null?elem.style.visibility = "":elem=null
			else
				elem!=null?elem.style.visibility = "hidden":elem=null
		}
	}
}
function SetFocusToActiveCtrl()
{
    try
    {
        if(focusCtrlID != null)
        {
             var ctrl = document.getElementById(focusCtrlID);
                    if(ctrl != null)
                         ctrl.focus();
        }
    }
    catch(e){}
}
/************************** FormAction Comand functions ******************************
      uses on eachload of UserPage to make some action on the server side
      virtual functions on the server side:
          protected virtual void OnFormActionViewDetails(string sender, int objectID)
          protected virtual void OnFormActionDeleteObject(string sender, int objectID)
          protected virtual void OnFormAction(string sender, string action, string actionValue)
**************************************************************************************/
var theActionSender
var theAction
var theActionValue

function AJAXFormCommand(sender, action, value)
{
    switch(action)
    {
        case "navigate":
            window.navigate(value);
            break;
        default:
            theAction = window.document.all["formAction"];
            theActionSender = window.document.all["formActionSender"];
            theActionValue = window.document.all["formActionValue"];
            theActionSender.value = sender;
            theAction.value = action;
            theActionValue.value = value;
            try
            {
                __doPostBack(sender, '');
            }
            catch(e)
            {
                theForm.submit();
            }
            pausecomp(1000);
            ResetFormAction();
            break;
            
    }
}

function FormCommand(sender, action, value)
{
    switch(action)
    {
        case "navigate":
            window.navigate(value);
            break;
        default:
            theAction = window.document.all["formAction"];
            theActionSender = window.document.all["formActionSender"];
            theActionValue = window.document.all["formActionValue"];
            theActionSender.value = sender;
            theAction.value = action;
            theActionValue.value = value;
            theForm.submit();            
            pausecomp(1000);
            ResetFormAction();
            break;
            
    }
}
function pausecomp(millis) 
		{
			date = new Date();
			var curDate = null;

			do { var curDate = new Date(); } 
			while(curDate-date < millis);
		} 
function ResetFormAction()
{
    try
    {
        theAction = window.document.all["formAction"];
        theActionSender = window.document.all["formActionSender"];
        theActionValue = window.document.all["formActionValue"];
        theActionSender.value = "";
        theAction.value = "";
        theActionValue.value = ""; 
    }
    catch(e){}    
}

function OnBeforeFormUnLoad()
{
    try
    {
        focusCtrlID = document.activeElement.id;
    }
    catch(e) {}
    OnUnload();
    CheckUnsavedData();  
}
function OnUnload()
{
    
}

//Check Unsaved Data and Save it if need.
var isHaveUnsavedData = false;
var isReadOnlyPage = false;

function SetUnsavedData()
{
    isHaveUnsavedData = true;
}
function ResetUnsavedData()
{
    isHaveUnsavedData = false;
}

function CheckUnsavedData()
{
   return;//logic is disabled
   if(isReadOnlyPage == false && isHaveUnsavedData == true)
    {
        if(XstarConfirm('Would you like to save your changes on the <br>"'+ PageTitle()+ '" ?'))  
        {   
            window.returnValue='OK';   
            ResetUnsavedData();
            FormCommand("confirmSaving", "confirmSaving", -1)
            
            pausecomp(2000);
        }
    }
}
function SkipSavingData()
{
    if(isHaveUnsavedData)
    {
        ResetUnsavedData();
        window.setTimeout(SetUnsavedData, 1000);        
    }
}

// reset action on the server side after loading of the page
function OnFormLoad()
{
    theAction = window.document.all["formAction"];
    theActionSender = window.document.all["formActionSender"];
    theActionValue = window.document.all["formActionValue"];
    theAction.value = "";
    theActionValue.value = "";          
    theActionSender.value = "";          
    SetFocusToActiveCtrl()
    OnLoad();
}
function OnLoad()
{
    return;
    //should be defined in the page if need to do some action onLoad of page
}

function OnFormResize()
{
    OnResize();
}

function OnResize()
{
    return;
    //should be defined in the page if need to do some action onResize of page
}

// For Delete object action of object List 
function DeleteListItem(sender, name, id)
{
    if(isReadOnlyPage == true)
    {
        alert('You have not access to delete information on this page.')
        return;
    }
   message = "You are about to delete the " + name + ".";
   if (confirm(message))    
        FormCommand(sender, "delete", id);
   
}

function DelObjectMessage(sender, message, id)
{
    if(isReadOnlyPage == true)
        {
            alert('You have not access to delete information on this page.')
            return;
        }
    if( confirm(message) == true)
	    FormCommand(sender, "delete", id);
}
function ConfirmAction(sender, message, action,id)
{       
    if( confirm(message) == true)
	    FormCommand(sender, action, id);
}

function QueuesConfirmAction(sender, message, action,id)
{       
    var ret;
			
	ret = window.showModalDialog('Operations.Queues.Dialog.aspx?message='+message,'','dialogWidth:600px; dialogHeight:300px; help:no;status:no;');
				
	if(ret == 'Yes')
	{
		FormCommand(sender, action, id);
	}
	else
	{
	    ResetFormAction();
	}	
   
}
/************************** End of FormAction Comand functions ************************************/

function OnLoadDialog(wnd)
{
    var height = window.document.body.scrollHeight + window.document.body.scrollTop + 35;
    var width = window.document.body.scrollWidth + 40;
    var top = (window.screen.availHeight / 2) - (height / 2);
    var left = (window.screen.availWidth / 2) - (width / 2);
    dialogHeight = height + 'px';
    dialogWidth = width + 'px';
    dialogTop = top + 'px';
    dialogLeft = left + 'px';
    window.returnValue = false;
 }
 
 
function XstarConfirm(message)
{
    return XStarFullConfirm(message, '', '', '', 'confirm');  
}

function XStarDeleteConfirm()
{
    var label_mes;
    var text_mes;
    
    label_mes = arguments[0];
    text_mes = arguments[1];
	if (label_mes != null && text_mes == null) 
	{
	    return XStarFullConfirm(label_mes, '', 'Yes, remove', 'No, cancel this change', 'confirm');
	}	
	if (label_mes != null && text_mes != null) 
	{
	    return XStarFullConfirm(label_mes, text_mes, 'Yes, remove', 'No, cancel this change', 'confirm');
	}
	return false;
}

function XStarChoiceConfirm()
{
    var label_mes;
    var text_mes;
    
    label_mes = arguments[0];
    text_mes = arguments[1];
	if (label_mes != null && text_mes == null) 
	{
	    return XStarFullConfirm(label_mes, '', 'Yes, apply', 'Cancel', 'warning');
	}	
	if (label_mes != null && text_mes != null) 
	{
	    return XStarFullConfirm(label_mes, text_mes, 'Yes, apply', 'Cancel', 'warning');
	}
	return false;
}

function XStarAlert(message)
{
    XStarFullConfirm(message, '', '', '', 'alert');
    return false;
}

function XStarDownload()
{
    var label_mes;
    var dowload_types;
    var ret = 'false';
        
    dowload_types = arguments[0];
    label_mes = arguments[1];
    
	if (dowload_types != null && label_mes == null) 
	{
	    ret = XStarFullConfirm('', dowload_types, '', '', 'download');
	}	
	if (dowload_types != null && label_mes != null) 
	{
	    ret = XStarFullConfirm(label_mes, dowload_types, '', '', 'download');
	}
	return ret;
}


function XStarFullConfirm(label_message, text_message, yes_text, no_text, type)
{
    var depth = "";
    var level;
    
    levelObj = document.all['master_page_PageContent_PageHierarchyLevel'];
    if(levelObj != null) 
        level = levelObj.value
    try
    {
        if(level == null || level == 0)
            depth = "";
        else
        {
            for(i = 0; i < level; i++)
                depth += "../";
        }
    }
    catch(e)
    {
        depth = "";
    }
    
    var ret;
    var url = "confirm.aspx?";
    if(label_message != "")
        url += "message=" + label_message + "&";
    if(text_message != "")
        url += "text=" + text_message + "&";
    if(yes_text != "")
        url += "yestext=" + yes_text + "&";
    if(no_text != "")
        url += "notext=" + no_text + "&";
    if(type != "")
        url += "type=" + type;    
    ret = window.showModalDialog(depth + url, '', 'dialogWidth:308px; dialogHeight:229px;help:no;status:no'); 
    if(ret == "Yes")
        return true;
    else if(ret == "No")
        return false;
    else 
        return ret;
}

function ProcessNetWorth(url, assetsID, liabilitiesID)
{
    var ret = "";
    
    ret = ShowModalDialog(url, '950', '750', 'no'); 
    if(ret == null) return false;
    var NameArray = new Array();
    NameArray = ret.split(';')
        
    var asset_ctrl = document.all[assetsID];
    var liab_ctrl = document.all[liabilitiesID];
    
    if(asset_ctrl != null && liab_ctrl != null)
    {
        asset_ctrl.value = NameArray[0];
        liab_ctrl.value = NameArray[1];
        CalculateNetWorth();
    }
    
    return false;        
}

function PageTitle()
{
    return window.document.title; 
}

/********************************  Controls scripts ********************************/
var	key_jump = 0

// uses for allow digit only
//0 1 2 3 4 5 6 7 8 9
function KeyDigit()
{
	var k = event.keyCode
	key_jump = 0

	if( (k>=0x30 && k<=0x39) || k==13 ) {
		event.cancelBubble=false
	}
	else if(k == 47){
		event.cancelBubble=false
		event.keyCode = 0
		key_jump = 1
	}
	else if(k == 10){
		event.cancelBubble=false
		event.keyCode = 0
		key_jump = -1
	}
	else{
		event.cancelBubble=true
		event.keyCode = 0
	}
}
// uses for allow digit and alpha only
//0 1 2 3 4 5 6 7 8 9 a-z A-Z
function KeyDigitAlpha()
{
	var k = event.keyCode
	key_jump = 0

	if( (k>=0x30 && k<=0x39) || (k>=0x41 && k<=0x5a) || (k>=0x61 && k<=0x7a) || k==13 ) {
		event.cancelBubble=false
	}
	else if(k == 47){
		event.cancelBubble=false
		event.keyCode = 0
		key_jump = 1
	}
	else if(k == 10){
		event.cancelBubble=false
		event.keyCode = 0
		key_jump = -1
	}
	else{
		event.cancelBubble=true
		event.keyCode = 0
	}
}
//0 1 2 3 4 5 6 7 8 9 , . -
function KeyNumber()
{
	var k = event.keyCode
	key_jump = 0

	if( (k>=0x30 && k<=0x39) || k==13 || k==44 || k==46 || k==45) {
		event.cancelBubble=false
	}
	else if(k == 47){
		event.cancelBubble=false
		event.keyCode = 0
		key_jump = 1
	}
	else if(k == 10){
		event.cancelBubble=false
		event.keyCode = 0
		key_jump = -1
	}
	else{
		event.cancelBubble=true
		event.keyCode = 0
	}
}

function KeyUpPhonem()
{
	var k = event.keyCode
	var jmp = key_jump
	key_jump = false
	
	if( (!( (k>=0x30 && k<=0x39) || (k>=0x60 && k<=0x69) )) && (jmp==0) ) return 
	
	var from = event.srcElement
	var cnt=from.value.length
	var maxlen = from.maxLength
	
	if( from.name.charAt(2)=="3" || from.name.substr(0,2) == "zi")
		return
		
	var nextCtl
	if( cnt >= maxlen || jmp==1 ){
		var num = from.name.substr(from.name.length-1,1)
		if( num == 1 || num ==2 ) {
			num++
			nextCtl = document.all[from.name.substr(0,from.name.length-1) + num]
		}
	}
	else if( jmp==-1 && num > 1){
		nextCtl = document.all[from.name.substr(0,from.name.length-1) + num]
	}		
	if( nextCtl != null ){
		nextCtl.focus()
		nextCtl.select()
	}
}

//// uses for set focus to the next control if number of symbols amount to maxValue
function OnKeyPressProcessing(control, maxValue)
{
    try
    {
	    if (event.keyCode==9 || event.keyCode==16)
	    {
		    event.cancelBubble=false;
		    event.keyCode = 0;
		    return;
	    }
	    if (control.value.length < maxValue) return;
	    var nextControl = control.nextSibling.nextSibling;

	    if (nextControl != null)
	    {
	        if(nextControl.tagName.toLowerCase() == 'span')
		    {
		        nextControl = nextControl.nextSibling.nextSibling;
		    }
		    if (nextControl != null)
		    {
		        nextControl.focus();
		        nextControl.select();
		    }
	    }
	}
	catch(e){}	
}

//// autocalculate the age according the date
function CalculateAge(ageId, monthId, dayId, yearId)
{
		var birthday; 
		var dob_element = event.srcElement;
		var dob_val, y
		var today = new Date();
		var	years, age
		
		if( ageId == '' )
			return
		ageId = document.all[ageId];
		dob_val = document.all[monthId].value + "/" + document.all[dayId].value + "/" + document.all[yearId].value;
							
		try
		{
			birthday = new Date(dob_val);
			if(birthday == "NaN" )
			{
				if( dob_val.match(/^\d\d\d\d(19|20|21)\d\d$/g) )
				{
					birthday = new Date(dob_val.substr(4,4), dob_val.substr(0,2), dob_val.substr(2,2))
				}
				if(birthday == "NaN" )
				{
					ageId.value = ''
					return
				}
			}
			
			y = birthday.getFullYear()
			if( y < 1900 || y > 2100  )
			{
				ageId.value = ''
				return
			}
			
			years = today.getFullYear() - birthday.getFullYear();
			birthday.setYear( today.getFullYear() );
			// If your birthday hasn't occurred yet this year, subtract 1.
			if(today < birthday)
				years--
			ageId.value = years;
		}
		catch(e)
		{
			ageId.value = ''
		}
}
// Added 20 or 19 to the year value if we entered to the year ctrl 1 or 2 digit value: 12 -> 2012; 5 -> 2005
function AutocompleteYear(yearId)
{
	var ctrl_year = document.all[yearId];
	var ctrl_year_val = ctrl_year.value
	try
	{
		var num_ctrl_year_val = new Number(ctrl_year_val);
		if (ctrl_year_val == "")
			ctrl_year.value = ""
		else
		if ((num_ctrl_year_val < 30) && (num_ctrl_year_val > 9 ))
			ctrl_year.value = "20" + num_ctrl_year_val.toString()
		else
			if ((num_ctrl_year_val <= 99) && (num_ctrl_year_val >= 30 ))
				ctrl_year.value = "19"+num_ctrl_year_val.toString()
			else
				if ((num_ctrl_year_val < 10) && (num_ctrl_year_val >= 0 ))
					ctrl_year.value = "200"+num_ctrl_year_val.toString()
	}
	catch(e)
	{
		ctrl_year.value = ""; 
	}
}                                                         
// Check is entered date is correct. Set 'true' or 'false' to hidden ctrl;
function CheckDate(monthId, dayId, yearId, errorId, isRequired, partialValidation)
{
    var ctrl_error = document.all[errorId];
    if(ctrl_error == null) return;
    try
    {
        var ctrl_year = document.all[yearId];
        var ctrl_month = document.all[monthId];        
        var ctrl_day = document.all[dayId];        

        var month1 = ctrl_month.value; if (month1.length == 1) month1 = '0' + month1;
        var day1 = ctrl_day.value; if (day1.length == 1) day1 = '0' + day1;
        var year1 = ctrl_year.value;
        
        if(isRequired == "False"  && month1 == '' && day1 == '' && year1 == '')
        {
            ctrl_error.value = "false";                   
            return;
        }

        if (partialValidation)
        {
            if (day1=='')
                day1 = '01';
            if (month1=='')
                month1 = '01';
            if (year1=='')
                year1 = '1753';
        }
        date_1 = month1 + "/" + day1 + "/" + year1;
        //date_1 = ctrl_month.value + "/" + ctrl_day.value + "/" + ctrl_year.value;
        i = Date.parse(date_1);
        
        if(i < Date.parse('01/01/1753') || i > Date.parse('12/31/9999'))
        {
            ctrl_error.value = "true";   
            ctrl_error.ErrorDescription = CtrlDateRangeError;
            return;
        }
        
        date_tmp = new Date(i);
        //date_2 = (date_tmp.getMonth() + 1) + "/" + date_tmp.getDate() + "/" + date_tmp.getFullYear();
        
        var month2 = (date_tmp.getMonth() + 1)+ ''; if(month2.length == 1) month2 = '0' + month2;
        var day2 = date_tmp.getDate() + ''; if(day2.length == 1) day2 = '0' + day2;
        var year2 = date_tmp.getFullYear() + '';
        
        if(ctrl_month.isRequired != null && !ctrl_month.isRequired)
            isRequired = 'false';  
        if (month1 == month2 && day1 == day2 && year1 == year2 || (isRequired == "False"  && month1 == '' && day1 == '' && year1 == ''))//Date Is OK
        {
            ctrl_error.value = "false";                   
        }
        else    
        {
            ctrl_error.value = "true";  
            if(isRequired == "True")
                ctrl_error.ErrorDescription = CtrlRequiredError;
            else
                ctrl_error.ErrorDescription = CtrlFormatError;    
        }        
    }
    catch(e)
    {
        ctrl_error.value = "true";
    }
    
}
function GetLocaleString(numberValue)
{
    str = numberValue.toLocaleString();
    if(str.indexOf("(") == 0) str = "-" + str.substring(1, str.length - 2);
    str1 = str.substring(0, str.indexOf("."));
    str2 = "00";
    if(numberValue.toString().indexOf(".") != -1)
        str2 = numberValue.toString().substring(numberValue.toString().indexOf(".")+1);
    return str1 + "." + str2;  	        
}   

//Formating money textbox value to money format
// Check is entered value is correct. Set 'true' or 'false' to hidden ctrl;
function OnMoneyDeactivate(controlID, errorID, isRequired, minValue, maxValue)
{
	var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
	
	while (str.indexOf("$") != -1)
			str = str.replace('$', '')
	while (str.indexOf(",") != -1)
			str = str.replace(',', '')
							
	var amountValue = new Number(str);
	
    if( !isNaN(amountValue))
    {
  	    ctrl.value = '$';
  	    if(str != '')
  	        ctrl.value = ctrl.value + GetLocaleString(amountValue)
  	    if(amountValue < minValue || amountValue > maxValue)
        {
            errorCtrl.value = 'true';
            errorCtrl.ErrorDescription = CtrlRangeError;    
  	    }
    }
    else
    {
        errorCtrl.value = 'true';        
        errorCtrl.ErrorDescription = CtrlFormatError;    
    }    
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';  
    if(str == '' && isRequired == 'true')
    {
        errorCtrl.value = 'true';        
        errorCtrl.ErrorDescription = CtrlRequiredError;    
    }    
}
//Formating percent textbox value to percent format
// Check is entered value is correct. Set 'true' or 'false' to hidden ctrl;
function OnPercentDeactivate(controlID, errorID, isRequired, minValue, maxValue)
{
	var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
	
	while (str.indexOf("%") != -1)
	    str = str.replace('%', '')
    while (str.indexOf(",") != -1)
	    str = str.replace(',', '')
							
    var amountValue = new Number(str);
    if( !isNaN(amountValue))
    {
	    ctrl.value = '%';	
	    if(str != '')
  	        ctrl.value = GetLocaleString(amountValue) + ctrl.value ;  	        
  	    if(amountValue < minValue || amountValue > maxValue)
        {
            errorCtrl.value = 'true';
            errorCtrl.ErrorDescription = CtrlRangeError; 
  	    }
    }	    
    else
    {
        errorCtrl.value = 'true';        
        errorCtrl.ErrorDescription = CtrlFormatError;  
    }
    
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';  
    if(str == '' && isRequired == 'true')
    {
        errorCtrl.value = 'true';       	    
        errorCtrl.ErrorDescription = CtrlRequiredError;  
    }   
}
//Formating number textbox value to local namber format
// Check is entered value is correct. Set 'true' or 'false' to hidden ctrl;
function OnNumberDeactivate(controlID, type, errorID, isRequired, minValue, maxValue)
{
	var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
    
	while (str.indexOf(",") != -1)
	    str = str.replace(',', '')

    var amountValue = new Number(str);
	var finalResult = GetLocaleString(amountValue);
	if(type == 'int' && finalResult.indexOf(".") != -1)
	    finalResult = finalResult.substring(0, finalResult.indexOf("."));		
    if( !isNaN(amountValue))
    {
        if(str != '')
            ctrl.value = finalResult;
        if(str != '' && (amountValue < minValue || amountValue > maxValue) )
        {
            errorCtrl.value = 'true';
            errorCtrl.ErrorDescription = CtrlRangeError; 
  	    }    
    }    
    else  
    {  
        errorCtrl.value = 'true'; 
        errorCtrl.ErrorDescription = CtrlFormatError;       
    }
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';      
    
    if(str == '' && isRequired == 'true')
    {
        errorCtrl.value = 'true';  		    		
        errorCtrl.ErrorDescription = CtrlRequiredError;
    }    
}

function CheckTextCtrl(controlID, errorID, isRequired)
{
    var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
    
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';               
    	
    if(str == '' && isRequired == 'true')
    {
        errorCtrl.value = 'true'; 
        errorCtrl.ErrorDescription = CtrlRequiredError; 		    		
    }    
}
function CheckEmailCtrl(controlID, errorID, isRequired)
{
    var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
    
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';               
    	
    if(str == '' && isRequired == 'true')
    {
        errorCtrl.value = 'true';  
        errorCtrl.ErrorDescription = CtrlRequiredError;
        return
    }
        
    if(!IsValidEmail(str))
    {
        errorCtrl.value = 'true';   
        errorCtrl.ErrorDescription = CtrlFormatError;   		    		
    }    
}
function IsValidEmail(email)
{
    if(email == "") return true;
    if(email.indexOf(" ") != -1) return false;
    index = email.indexOf("@");
    if(index <= 0) return false;
    
    str = email.substring(index)
    index = str.indexOf(".");
    if(index <= 1) return false;
    
    str = str.substring(index)
    if(str.length <=1) return false;
    
    return true;
    
}
function CheckTaxCtrl(controlID, errorID, isRequired)
{
    var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
    
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';               
    	
    if(str == '' && isRequired == 'true')
    {
        errorCtrl.value = 'true';  
        errorCtrl.ErrorDescription = CtrlRequiredError;
        return;
    }    
    
    if(!IsValidTax(str))
    {
        errorCtrl.value = 'true';    
        errorCtrl.ErrorDescription = CtrlFormatError;  		    		
    }    
}

function IsValidTax(tax)
{
    if(tax == "") return true;
    
    var value = new Number(tax);
    
    if(!isNaN(value) && tax.length == 9) 
        return true;    
    
    return false;
}

function CheckYesNoCtrl(controlID, errorID, isRequired)
{
    var ctrl = document.all[controlID];
	var errorCtrl = document.all[errorID];
	var str = ctrl.value;
	errorCtrl.value = 'false';
    
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';               
    	
    if(!ctrl.checked && isRequired == 'true')
    {
        errorCtrl.value = 'true';  		
        errorCtrl.ErrorDescription = CtrlRequiredError;    		
    }    
}

// Check is entered phone is correct. Set 'true' or 'false' to hidden ctrl;
function CheckPhone(first, second, third, errorId, isRequired)
{
    var ctrl_error = document.all[errorId];
    var ctrl_first = document.all[first];
    var ctrl_second = document.all[second];        
    var ctrl_third = document.all[third];

    var str = ctrl_first.value + ctrl_second.value + ctrl_third.value
    
    if(ctrl_second.isRequired != null && !ctrl_second.isRequired)
        isRequired = 'false';               

    if(str == '')        
    {
        if(isRequired == 'true') 
        {
           ctrl_error.value = 'true';                
           ctrl_error.ErrorDescription = CtrlRequiredError;      
        }
        return;
    }
    else
    {
        var value = new Number(str);
        if (!isNaN(value))
        {
            ctrl_error.value = "false";                   
        }
        else    
        {
            ctrl_error.value = "true";   
            ctrl_error.ErrorDescription = CtrlFormatError;         
        }  
    }    
}
// Check is entered phone is correct. Set 'true' or 'false' to hidden ctrl;
function CheckPhone5(first, second, third, forth, fifth, errorId, isRequired, isInternationalCtrl,phoneTypeCtrl)
{
    var ctrl_error = document.all[errorId];
    var ctrl_first = document.all[first];
    var ctrl_second = document.all[second];
    var ctrl_third = document.all[third];
    var ctrl_forth = document.all[forth];
    var ctrl_fifth = document.all[fifth];
    var ctrl_isInternational = document.all[isInternationalCtrl];
    var ctrl_PhoneType = document.all[phoneTypeCtrl];

    var country_code = ctrl_first.value;
    var area_code = ctrl_second.value;
    var prefix = ctrl_third.value;
    var suffix = ctrl_forth.value;
    var isInternational = ctrl_isInternational.checked;
    var str = ctrl_first.value + ctrl_second.value + ctrl_third.value + ctrl_forth.value + ctrl_fifth.value
    
    if(ctrl_second.isRequired != null && !ctrl_second.isRequired)
        isRequired = 'false';
    
    if(!isInternational)
    {
        if(area_code.length < 3 || prefix.length < 3 || suffix.length < 4 || ctrl_PhoneType.selectedIndex == 0)
        {
            if(isRequired == 'true') 
            {
                ctrl_error.value = 'true';
                ctrl_error.ErrorDescription = CtrlRequiredError;
            }
            return;
        }
        else
        {
            var value = new Number(str);
            if (!isNaN(value))
            {
                ctrl_error.value = "false";                   
            }
            else    
            {
                ctrl_error.value = "true";            
                ctrl_error.ErrorDescription = CtrlFormatError;
            }  
        }    
    }
    else
    {
        if(area_code.length < 3 || prefix.length < 3 || country_code.length < 1 || ctrl_PhoneType.selectedIndex == 0)
        {
            if(isRequired == 'true') 
            {
                ctrl_error.value = 'true';
                ctrl_error.ErrorDescription = CtrlRequiredError;
            }
            return;
        }
        else
        {
            var value = new Number(str);
            if (!isNaN(value))
            {
                ctrl_error.value = "false";                   
            }
            else    
            {
                ctrl_error.value = "true";            
                ctrl_error.ErrorDescription = CtrlFormatError;
            }  
        }
    }
}


// Check is entered phone is correct. Set 'true' or 'false' to hidden ctrl;
function CheckSsn(first, second, third, errorId, isRequired, isValidateLength)
{
    var ctrl_error = document.all[errorId];
    var ctrl_first = document.all[first];
    var ctrl_second = document.all[second];        
    var ctrl_third = document.all[third];

    var str = ctrl_first.value + ctrl_second.value + ctrl_third.value
    
    if(isValidateLength == 'True' && str.length != 0 && str.length != 9)
    {
        ctrl_error.value = 'true';        
        ctrl_error.ErrorDescription = CtrlFormatError;
        return;
    }
    else
        ctrl_error.value = 'false';
    
    if(ctrl_second.isRequired != null && !ctrl_second.isRequired)
        isRequired = 'false';               
        
   
    if(str == '')        
    {
        if(isRequired == 'true') 
        {
           ctrl_error.value = 'true';                
           ctrl_error.ErrorDescription = CtrlRequiredError;      
        }
        return;
    }
    else
    {
        var value = new Number(str);
        if (!isNaN(value))
        {
            ctrl_error.value = "false";                   
        }
        else    
        {
            ctrl_error.value = "true";
            ctrl_error.ErrorDescription = CtrlFormatError;            
        }  
    }    
}

// Check is entered TAX is correct. Set 'true' or 'false' to hidden ctrl;
function CheckTax(first, second, errorId, isRequired)
{
    var ctrl_error = document.all[errorId];
    var ctrl_first = document.all[first];
    var ctrl_second = document.all[second];        
    
    var str = ctrl_first.value + ctrl_second.value;
    
    if(ctrl_second.isRequired != null && !ctrl_second.isRequired)
        isRequired = 'false';           
            
    if(str == '')        
    {
        if(isRequired == 'true') 
        {
           ctrl_error.value = 'true';                
           ctrl_error.ErrorDescription = CtrlRequiredError;      
        }
        return;
    }
    else
    {
        var value = new Number(str);
        if (!isNaN(value))
        {
            ctrl_error.value = "false";                   
        }
        else    
        {
            ctrl_error.value = "true";   
            ctrl_error.ErrorDescription = CtrlFormatError;          
        }  
    }    
}

// Check is entered Zip is correct. Set 'true' or 'false' to hidden ctrl;
function CheckZip(first, second, errorId, isRequired)
{
    var ctrl_error = document.all[errorId];
    var ctrl_first = document.all[first];
    var ctrl_second = document.all[second];        
    
    var str = ctrl_first.value + ctrl_second.value        
    if(ctrl_second.isRequired != null && !ctrl_second.isRequired)
        isRequired = 'false';   
                    
    if(str == '')        
    {
        if(isRequired == 'true') 
        {
            ctrl_error.value = 'true';                
            ctrl_error.ErrorDescription = CtrlRequiredError; 
        }
        return;
    }
    else
    {
        var value = new Number(str);
        if (!isNaN(value))
        {
            ctrl_error.value = "false";                   
        }
        else    
        {
            ctrl_error.value = "true";  
            ctrl_error.ErrorDescription = CtrlFormatError;                    
        }  
    }    
}
function CheckZipAlpha(first, second, errorId, isRequired)
{
    var ctrl_error = document.all[errorId];
    var ctrl_first = document.all[first];
    var ctrl_second = document.all[second];        
    
    var str = ctrl_first.value + ctrl_second.value        
    if(ctrl_second.isRequired != null && !ctrl_second.isRequired)
        isRequired = 'false';               
    if(str == '')        
    {
        if(isRequired == 'true')
        {
             ctrl_error.value = 'true';  
             ctrl_error.ErrorDescription = CtrlRequiredError;               
        }
        return;
    }        
    else
    {            
        ctrl_error.value = "false";                                 
    }    
}
// Check if there was a value selected in drop down ctrl. Set 'true' or 'false' to hidden ctrl;
function CheckDropDown(ctrlID,  errorId, isRequired)
{
    var ctrl_error = document.all[errorId];
    var ctrl = document.all[ctrlID];
    if(ctrl.isRequired != null && !ctrl.isRequired)
        isRequired = 'false';               
    
    if(isRequired == 'true' && !IsDropDownSelected(ctrl, isRequired))        
    {
        ctrl_error.value = 'true'; 
        ctrl_error.ErrorDescription = CtrlRequiredError;
    }    
    else
        ctrl_error.value = 'false';                           
}
function IsDropDownSelected(ctrl, isRequired)
{
    if (ctrl.length == 0) return false;
    if (isRequired == 'false') return true;
            
    //if isRequired, selected itme value should be different with first selected value
    return ctrl.value != ctrl.children[0].value;
}
function ChangeRequired(ctrlID, isRequired)
{
    var ctrl = document.all[ctrlID];
    var AsterixTR 
    try
    {   
        AsterixTR =  ctrl.parentElement.parentElement.children[0]
    }
    catch(e)
    {
        return false;
    }
    if(ctrl == null ) return false;
    ctrl.isRequired = isRequired;
    if(isRequired)
        AsterixTR.style.visibility = "visible";
    else
        AsterixTR.style.visibility = "hidden";            
        
    return true;
}
//*********************** Validation Function ***************************************
function IsValidCtrl(ctrlID)      
        {
            var ctrl = document.all[ctrlID];
            if(ctrl == null) return false;
            ValidateCtrl(ctrl);
            return ctrl.value != "true";
        }
function ValidateCtrl(ctrl)
{
    try
    {
        var isError = ctrl.value;
	    var HiglitedCtrl = ctrl.parentElement.parentElement.parentElement.parentElement;
        var HighlitedCtrlDepth = 2;
        while(HighlitedCtrlDepth > 0 && HiglitedCtrl.parentElement != null)
        {
            HiglitedCtrl = HiglitedCtrl.parentElement;
            HighlitedCtrlDepth = HighlitedCtrlDepth - 1;
        }
        if (isError == "true")
        {
            HiglitedCtrl.style.backgroundColor = "#e7c3c3";   
        }
        else
        {
            HiglitedCtrl.style.backgroundColor = "";                        
        }
    }
    catch(e){}
}
function ValidateControl(source, arguments)
{
    try
    {
        for(i = 0; i < Page_Validators.length; i++)
        {
            if(source.validationGroup == null || Page_Validators[i].validationGroup  == source.validationGroup)
                break;
        }
        if(Page_Validators[i].id == source.id)
            ClearErrorMessageList = true;
            
        var isError = arguments.Value;
	    var HiglitedCtrl = source.parentElement.parentElement;
        var HighlitedCtrlDepth = source.title;
        while(HighlitedCtrlDepth > 0 && HiglitedCtrl.parentElement != null)
        {
            HiglitedCtrl = HiglitedCtrl.parentElement;
            HighlitedCtrlDepth = HighlitedCtrlDepth - 1;
        }
        
        if (isError == "true")
        {
            var isErrorTextBoxCtrlID = document.all[source.attributes['controltovalidate'].value];
            var controlTitle;
            var errorDescription;
            
            if(isErrorTextBoxCtrlID != null)
            {
                if(isErrorTextBoxCtrlID.ControlTitle != null)
                    controlTitle = isErrorTextBoxCtrlID.ControlTitle;
                else
                    controlTitle = "Control";
                        
                if(isErrorTextBoxCtrlID.ErrorDescription != null)
                    errorDescription = isErrorTextBoxCtrlID.ErrorDescription;
                else
                    errorDescription = CtrlRequiredError;
            }
            try
            {
                switch(ResultPanelDisplayMode)
                {
                    case 1://modal
                        ResultPanelModalAddMessage(controlTitle + " " + errorDescription, CtrlErrorTitle, ResultPanelErrorCssClass);
                        break;
                    case 2://not modal
                        ResultPanelAddMessage(controlTitle + " " + errorDescription, CtrlErrorTitle, ResultPanelErrorCssClass);
                        break;
                    case 3://embedded
                        ResultPanelEmbeddedAddMessage(controlTitle + " " + errorDescription, CtrlErrorTitle, ResultPanelEmbeddedErrorCssClass);
                        break;
                }
            }  
            catch(e) {}  
            arguments.IsValid=false;
            HiglitedCtrl.style.backgroundColor = "#e7c3c3";
        }
        else
        {
            HiglitedCtrl.style.backgroundColor = "";            
            arguments.IsValid=true;
        }
    }
    catch(e)
    {
        arguments.IsValid=true;
    }
}
function HighlightCtrl(ctrlID, depth, isHighlight)
{
    var HighlitedCtrlDepth = depth;
    var HighlitedCtrl = document.all[ctrlID];
    if(HighlitedCtrl == null) return;
    while(HighlitedCtrlDepth > 0 && HighlitedCtrl.parentElement != null)
    {
            HighlitedCtrl = HighlitedCtrl.parentElement;
            HighlitedCtrlDepth = HighlitedCtrlDepth - 1;
    }
    if (isHighlight)
    {
         HighlitedCtrl.style.backgroundColor = "#e7c3c3";                     
    }
    else
    {
        HighlitedCtrl.style.backgroundColor = "";                        
    }
}


function IsControlEmpty(control)
{
	if (control.tagName == "INPUT") 
	{
		return control.value.replace('$','').replace(' ','') == '';
	}
	if (control.tagName == "SELECT") 
	{
		return (control.selectedIndex < 1);
	}				
}

//***************** For control Frame ************************
function RefreshFrame(ctrl_id)
{
    try
    {
        var FrameID = document.all[ctrl_id]; 
        if( FrameID == null) document.all["master_page_PageContent_Frame1_IFrame1"];
        if( FrameID == null) FrameID = window.frames.parent.document.all[ctrl_id]; 
        if( FrameID == null) window.frames.parent.document.all["master_page_PageContent_Frame1_IFrame1"];
        if(FrameID != null)
            RefreshFrameHeight(FrameID, ctrl_id)
    }
    catch(e){}
}
function RefreshFrameHeight(currFrame, ctrl_id)
{
        try
        {
            if(currFrame.contentWindow.window.document.title == "Welcome to ENSInet BackOffice System")
            {
                window.top.theForm.submit();
                return;
            }
            if (currFrame.contentWindow.window.document.title != "Welcome to ENSInet BackOffice System")
            {
                var frameHeight = currFrame.contentWindow.window.document.body.scrollHeight;
                var frameWidth = currFrame.contentWindow.window.document.body.scrollWidth;
                if(frameHeight < currFrame.MinHeight) frameHeight = currFrame.MinHeight;
                if(frameWidth < currFrame.MinWidth) frameWidth = currFrame.MinWidth;
                
                currFrame.height = frameHeight;        
                currFrame.width = frameWidth;
                currFrame.style.visibility = "visible";
                    
                var ParentFrameID = currFrame.document.frames.parent.document.all[ctrl_id]; 
                if( ParentFrameID == null) ParentFrameID = currFrame.document.frames.parent.document.all['master_page_PageContent_Frame1_IFrame1'];
                if( ParentFrameID != null &&  ParentFrameID != currFrame) 
                    RefreshFrameHeight(ParentFrameID);
            }    
        }
        catch(e){}        
}

function RefreshFrameSrc(o, srcID)
{
    try
    {
       var srcObj = document.all[srcID]; 
        if(srcObj != null) 
            srcObj.value = o.contentWindow.location.href;
    }
    catch(e){}
}

function fnStartInit(currFrame)
{
   currFrame.style.visibility = "hidden"; 
}
//*********************** End of Frame's functions ***********************************

function lineOver(obj, on, pos)
	{
		if( obj != null ){
			if( on )
				obj.className = 'list-hover'
			else{
				if( (pos % 2) == 0 )
					obj.className = 'list-even'
				else
					obj.className = 'list-odd'
			}
		}
	}
	
//************************* Drop Down and Radio Button List Functions ****************************//
function GetSelectedValueFromDropDown(dropDownObject)
{
	for(i = 0; i <= dropDownObject.length; i++)
			if (dropDownObject.options[i] != null && dropDownObject.options[i].selected) 
				return dropDownObject.options[i].value;
				
	return null;
}

function GetSelectedTextFromDropDown(dropDownObject)
{
	for(i = 0; i <= dropDownObject.length; i++)
			if (dropDownObject.options[i] != null && dropDownObject.options[i].selected) 
				return dropDownObject.options[i].text;
				
	return null;
}

function SelectDropDownItemByText(dropDownObject, text)
{
	for(i = 0; i <= dropDownObject.length; i++)
	{
		if (dropDownObject.options[i] != null && dropDownObject.options[i].text == text) 
		{
			dropDownObject.options[i].selected = true;
			break;
		}	
	}
}

function SelectDropDownItemByValue(dropDownObject, value)
{
	for(i = 0; i <= dropDownObject.length; i++)
	{
		if (dropDownObject.options[i] != null && dropDownObject.options[i].value == value) 
		{
			dropDownObject.options[i].selected = true;
			break;
		}	
	}
}

function GetSelectedValueFromRadioButtonList(radioButtonListClientID, length)
{
	for(i = 0; i < length; i++)
		if(document.all[radioButtonListClientID + "_" + i].checked)
			return document.all[radioButtonListClientID + "_" + i].value;
	
	return null;
}

function GetSelectedTextFromRadioButtonList(radioButtonListClientID, length)
{
	for(i = 0; i < length; i++)
		if(document.all[radioButtonListClientID + "_" + i].checked)
		{
			if(document.all[radioButtonListClientID + "_" + i].nextSibling != null
			   && document.all[radioButtonListClientID + "_" + i].nextSibling.tagName == "LABEL")
			return document.all[radioButtonListClientID + "_" + i].nextSibling.innerText;
		}	
	
	return null;
}

function SelectRadioButtonListItemByValue(radioButtonListClientID, length, value)
{
	for(i = 0; i < length; i++)
		if(document.all[radioButtonListClientID + "_" + i].value == value)
			return document.all[radioButtonListClientID + "_" + i].checked = true;
}

//open NetXPro
function Exec()
{
	try
	{
		var WshShell = new ActiveXObject("WScript.Shell");
		//var WshShell = WScript.CreateObject("WScript.Shell");

	}
	catch(e)
	{	
		if (window.confirm("To use this feature you need to enable option\n" + 
		      "'Initialize and script ActiveX controls not marked as safe'\n" + 
		      "in the Security tab of Internet Options.\n" +
		      "By pressing 'OK' you will be redirected to the web version of NetExchange Pro."))
		{
			window.open('https://www2.netxpro.com', '_blank');	
		}
		
		return;
	}
	
	try
	{
		var oExec = WshShell.Exec("C:\\Program Files\\NetExchange Pro3.0\\netexpro3.exe");
	}
	catch(e)
	{	
		if (window.confirm("NetExchange Pro is not found in your system.\n" + 
		      "By pressing 'OK' you will be redirected to the web version of NetExchange Pro."))
		{
			window.open('https://www2.netxpro.com', '_blank');
		}
		return;
	}
}

//when modal popop is opened.
function setBodyWidthAndHeightToContentWidthAndHeight() 
{
    document.body.style.width = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth) + "px";
    document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) + "px";
}

function ClearMessage(ctrl)
{
    var message = document.all[ctrl];
    if(message != null)
        message.innerHTML = '';
}

function ShowPopupExtender(BehaviorID, TargetButtonClientID)
{
    $find(BehaviorID + 'PopupBehavior').set_parentElement($get(TargetButtonClientID));
    try { event.cancelBubble = true; } catch(e) {}
    $find(BehaviorID).showPopup();
}

function ShowModalDialog(url, width, height)
{
    ShowModalDialog(url, width, height, 'yes')
}

function ShowModalDialog(url, width, height, scroll)
{
    var ret = window.showModalDialog(
                                     url, 
                                     '',
                                     'dialogWidth:' + width + 'px;'+ 
                                     'dialogHeight:' + height + 'px;' + 
                                     'help:no;status:no;' +
                                     'scroll:' + ';');
                                     
    if(ret == 'SessionExpired') 
        theForm.submit();
        
    return ret;
}
