﻿/*----------Paging--------------*/
var RelatedPaging = function(args)
{
	for (var i in args)
		this[i] = args[i];
};

RelatedPaging.prototype = 
{
	Viewing		: null,
	TotalItem	: null,
	ItemPerPage	: null,
	CurPage		: null,
	TotalPage	: null,
	Sort		: null,
	Asc			: null,
	
	btn_First	: null,
	btn_Back	: null,
	btn_Next	: null,
	btn_Last	: null,
	btn_Go1		: null,
	btn_Go2		: null,
	
	onchange	: null,
	
	InitPaging : function()
	{	
		$get(this.btn_First).onclick	= this.PagingChange.bindAsEventListener(this, -2);		
		$get(this.btn_Back).onclick		= this.PagingChange.bindAsEventListener(this, -1);
		$get(this.btn_Next).onclick		= this.PagingChange.bindAsEventListener(this, 1);
		$get(this.btn_Last).onclick		= this.PagingChange.bindAsEventListener(this, 2);
		$get(this.btn_Go1).onclick		= this.PagingChange.bindAsEventListener(this, 0);
		if($get(this.btn_Go2)!=null)
		    $get(this.btn_Go2).onclick		= this.PagingChange.bindAsEventListener(this, 0);
		$get(this.ItemPerPage).onchange	= this.PagingChange.bindAsEventListener(this, -2);
	},
	
	PagingChange : function(event,cmd)
	{
		var curPage		= parseInt($get(this.CurPage).value);
		var totalPage	= parseInt($get(this.TotalPage).innerHTML);
		
		switch (cmd)
		{
			case -1	:
			case 1	:
				curPage += cmd;
				break;
			case -2 :
				curPage = 1;
				break;
			case 2 :
				curPage = totalPage;
				break;
		}
		if (curPage > 0 && curPage <= totalPage && this.onchange)
		{
			var pSize	= $get(this.ItemPerPage).value;
			if($(this.Sort)!= null) sort = $get(this.Sort).value; else sort = "";
			if($(this.Asc)!= null)  asc  = $get(this.Asc).value;  else asc = "";
			this.onchange(event,curPage, pSize, sort, asc);
		}
		return false;
	},
	
	SetPaging : function(curPage, pSize, sort, asc, totalItem, totalPage)
	{
		var startItem	= pSize * (curPage - 1) + 1;
		var endItem		= 0;
		if (curPage == totalPage)
			endItem	= totalItem;
		else
			endItem = startItem - 1 + pSize * 1;
			
		$get(this.Viewing).innerHTML	= startItem + " - " + endItem;
		$get(this.TotalItem).innerHTML	= totalItem;
		$get(this.ItemPerPage).value	= pSize;
		$get(this.CurPage).value		= curPage;
		$get(this.TotalPage).innerHTML	= totalPage;
		if($(this.Sort)!=null) $(this.Sort).value			= sort;
		if($(this.Asc) !=null)  $(this.Asc).value			= asc;
	}
}
var pagingOptionsBottom1 = new RelatedPaging(
{
	Viewing		: 'lbl_ShowingNumber_A5_009',
	TotalItem	: 'lbl_ItemTotal_A5_009',
	ItemPerPage	: 'gBItem_ddl_ItemPerPage_A5_009',
	CurPage		: 'gbtngo1_tbx_Page_A5_009',
	TotalPage	: 'gnext_glast_gpagebtngo_gbtngo1_lbl_PageTotal_A5_009',
	Sort		: 'gUnderSort_ddl_SortBy_A5_005',
	Asc			: 'gUnderSort_ddl_SortBy2_A5_005',
	
	btn_First	: 'gfirst_ibt_First_A5_009',
	btn_Back	: 'gback_ibt_Back_A5_017',
	btn_Next	: 'gnext_ibt_Next_A5_017',
	btn_Last	: 'glast_ibt_Last_A5_009',
	btn_Go1		: 'gbtngo1_ibt_Go_A5_009',
	btn_Go2		: 'gUnderSort_ibt_Go_A5_010',
	onchange	: GetProduct
});
/*----------End Paging--------------*/

function GenSelectState(ControlNameDDL,ControlNameTBX)
{
    var state=$(ControlNameDDL);
    if(state!=null)
    {
        if(ControlNameDDL=='ddl_Fname_A5_005' )
            if( state.selectedIndex==0)
                $(ControlNameTBX).value='';
            else
                $(ControlNameTBX).value =state.options[state.selectedIndex].value;
        else
            $(ControlNameTBX).value =state.options[state.selectedIndex].text;
        if(ControlNameDDL=='grpBilling_grpRegistration_ddl_State_A5_105' && $("hdf_BillState_005")!=null)
            $("hdf_BillState_005").value=state.options[state.selectedIndex].value;            
        else
            if($("hdf_ShippState_005")!=null)
                $("hdf_ShippState_005").value=state.options[state.selectedIndex].value;
    }        
    else
    {
        state=$(ControlNameDDL);
        if(state!=null)
        {
            
                $(ControlNameTBX).value =state.options[state.selectedIndex].text;
        }   
    }
       
}
var flag = false;
function assamechange(ParentControl,ParentControl2,GroupName,GroupName2,ControlID)
{
    if($(ControlID))
    {
        flag = ($(ControlID).checked == true) ? true : false;
        
        var elem=document.getElementById(ParentControl);
        var elem2=document.getElementById(ParentControl2);
        var  childs=elem.getElementsByTagName("select");   
        var  childs2=elem2.getElementsByTagName("select");
        for(i=0;i<childs.length;i++)
        {            
            if(childs[i].id.indexOf(GroupName)>=0)
            {
               childs[i].disabled = flag;
               childs[i].options[childs[i].selectedIndex].text = childs2[i].options[childs2[i].selectedIndex].text;
               childs[i].options[childs[i].selectedIndex].value = childs2[i].options[childs2[i].selectedIndex].value;
            } 
        }
        childs=elem.getElementsByTagName("input");   
        childs2=elem2.getElementsByTagName("input");  
        for(i=1;i<childs.length;i++)
        {            
            if(childs[i].id.indexOf(GroupName)>=0)
            {
               childs[i].disabled = flag;
               var index = i;
               childs[i].value = (flag==true) ? childs2[index-1].value : "";
            } 
        }
        childs=elem.getElementsByTagName("span");   
        for(i=0;i<childs.length;i++)
        {        
                
            if((childs[i].controltovalidate) && childs[i].controltovalidate.indexOf(GroupName)>=0)
            {
                if(flag==true)
                    childs[i].style.display = 'none';
                
                childs[i].validationGroup =(flag==true)?"GrpTemp" : "GroupRegis";
            } 
        }     
        SelectCountry('grpShipping_grpRegistration_ddl_Country_A5_305','grpShipping_grpRegistration_ddl_State_A5_305','grpShipping_grpRegistration_tbx_State_A5_305',null);
        return false;
    }
}
var flagASAE = false;
function assameasEmail(arrParentControl,ControlFormID,ControlID)
{
    if($(ControlID))
    {
        flagASAE = ($(ControlID).checked == true) ? true : false;
        
        for(var i=0;i<arrParentControl.split(',').length;i++)
        {
            var ParentControl = $(arrParentControl.split(',')[i]);
            var  childs=ParentControl.getElementsByTagName("input");
             for(var j=1;j<childs.length;j++)
                {            
                    if(childs[j].id.indexOf('Email')>=0)
                    {
                        childs[j].value =(flagASAE==true)? $(ControlFormID).value : '';
                    } 
                }
        }
    }
}
/*------------ Patient Process---------------*/

function GetDataFormPatient(ParentControl,GroupName,GroupValidate,IsGet)
{
    var arr = new Array();
    var elem=document.getElementById(ParentControl);
    if(elem!=null)
    {
             
        var s_arrayvalue="",s_arraystyle="",s_name="",s_pass="",s_flag="", s_Country,s_State,s_email="",s_code="";                     
        var  childs=elem.getElementsByTagName("select");  
        for(i=0;i<childs.length;i++)
        {            
            if(childs[i].id.indexOf(GroupName)>=0)
            {
                value =childs[i].getAttribute("att_DefineControl");
                switch (value)
                {
                    case "102016"://address1                                    
                        s_arrayvalue += childs[i].options[childs[i].selectedIndex].value+',';
                        s_arraystyle += value+',';
                        s_Country = childs[i].options[childs[i].selectedIndex].text;
                        break;
                    case "102017"://address1        
                        s_State = childs[i].options[childs[i].selectedIndex].text;
                        break;
                    case "103728"://Gender        
                        s_arrayvalue += childs[i].options[childs[i].selectedIndex].value + ',';
                        s_arraystyle += value + ',';
                        break;
                    
                }
            } 
        }

        childs=elem.getElementsByTagName("input");
        for(i=0;i<childs.length;i++)
        {            
            if(childs[i].id.indexOf(GroupName)>=0)
            {
                value =childs[i].getAttribute("att_DefineControl");
                valueinput=childs[i].value.replace(',','');
                    if(value!=null)   
                    {                 
                        switch (value)
                        {
                         
                            case "103799":
                                break;
                            case "102011": // FN
                            case "102817": // MN
                            case "102012": // LN
                                s_name += valueinput.replace(' ','');
                                s_arrayvalue += valueinput + ',';
                                s_arraystyle += value + ',';                          
                                break;
                            case "103730":
                                var a = childs[i].value;    
                                break;  
                            default:
                                s_arrayvalue += valueinput + ',';
                                s_arraystyle += value + ',';
                                break;
                        }
                    }
                    else
                    {
                        if(childs[i].checked && IsGet == 1)
                        {
                            s_arrayvalue += valueinput + 'PrP,';
                            s_arraystyle += childs[i].parentNode.getAttribute('att_DefineControl') + ',';
                            
                        }
                    }
            } 
        }
        
        arr[0] = s_name;
        arr[1] = s_arrayvalue;
        arr[2] = s_arraystyle;
    }
   return arr;
}
function AddNewPatient(ParentControl,GroupName,GroupValidate,event)
{
    OnPleaseWait("AdminDvWait",event);
    var validationResult=false;    
    validationResult = Page_ClientValidate(GroupValidate);
    $('grpPatient_tbx_ID_A5_005').value = "";
    if(validationResult==true)
    {
       var s_arrayvalue="",s_arraystyle="",s_name="",s_pass="",s_code="";              
       var arr = GetDataFormPatient(ParentControl,GroupName,GroupValidate,0);
       if(arr && arr.length >0)
       {
           new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
            {
	            method			: "post", // Setup Method            
	            parameters		: 
	            {
		            cmd			    : 2016,
		            name            : arr[0], //s_name
		            sData           : arr[1],//s_arrayvalue
		            arraystyle      : arr[2],//s_arraystyle
		            code            : s_code
	            },
	            onSuccess		: function(transport)
	            { // Event Success --> do...		  
                    switch(transport.responseText)      
                    {
                        case "-1":       
                            alert('Can not insert this customer,please check your information again');                 
                            break;
                        case "1":        
                            break;
                        default:
                            alert('Make Patient information successfully.');   
                            var obj = transport.responseText;
                            GetPatientInformation(obj,ParentControl,GroupName,event);
                            $('grpPatient_tbx_ID_A5_005').value = obj;
                            GetPatientList(event,'pnl_A5_L4_X2_Y3_007');
                            break;
                    		               
                   }
	            },   
                onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
            });
        }     	
	  OffPleaseWait("AdminDvWait");   	
    }
    else
        OffPleaseWait("AdminDvWait");   	
    
}
function ResetPatientClick(ParentControl,GroupName,GroupValidate,event)
{
    $('form1').reset();
    Enable_Disable(ParentControl,GroupName,GroupValidate,event);
    
}
function Enable_Disable(ParentControl,GroupName,GroupValidate,event)
{
    var flaged = false;
    flaged = ($('grpPatient_rbl_ShipTo_A5_005_0').checked == true)? true : false;
    var arrOO = $(ParentControl).getElementsByTagName('input');
    for(var i = 0;i<arrOO.length;i++)
    {
        arrOO[i].disabled = flaged;
    }
    arrOO = $(ParentControl).getElementsByTagName('select');
    for(i = 0;i<arrOO.length;i++)
    {
        arrOO[i].disabled = flaged;
    }
    $('grpPatient_tbx_ID_A5_005').disabled = true;
}
function NextPatientClick(ParentControl,GroupName,GroupValidate,event)
{
    OnPleaseWait("AdminDvWait",event);
    var validationResult=false;   
    var ooo = $('grpPatient_rbl_ShipTo_A5_005_0'); 
    if(ooo.checked==true)
    {
        new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
             {
	                method			: "post", // Setup Method            
	                parameters		: 
	                {
		                cmd			    : 2016,
		                name            : '', //s_name
		                sData           : '',//s_arrayvalue
		                arraystyle      : '',//s_arraystyle
		                id              : '000000',              
		                code            : ''
	                },
	                onSuccess		: function(transport)
	                { // Event Success --> do...		  
                        switch(transport.responseText)      
                        {
                           case "1":                                   
                                window.open(Path100 + '51678/Product.aspx','_parent');
                                break;
                           default:
                                if(transport.responseText != "" && transport.responseText != "0")
                                {
                                    window.open(Path100 + '51678/Product.aspx','_parent');
                                }
                                break;
                        }
	                },   
                    onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
                });
              	
	      OffPleaseWait("AdminDvWait");   	
    }
    else
    {
        validationResult = Page_ClientValidate(GroupValidate);
        if(validationResult==true)
        {
           var s_arrayvalue="",s_arraystyle="",s_name="",s_pass="",s_code="";              
           var ID = $('grpPatient_tbx_ID_A5_005').value;
           var arr = GetDataFormPatient(ParentControl,GroupName,GroupValidate,1);
           if(arr && arr.length >0)
           {
               new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
                {
	                method			: "post", // Setup Method            
	                parameters		: 
	                {
		                cmd			    : 2016,
		                name            : arr[0], //s_name
		                sData           : arr[1],//s_arrayvalue
		                arraystyle      : arr[2],//s_arraystyle
		                id              : ID,              
		                code            : s_code
	                },
	                onSuccess		: function(transport)
	                { // Event Success --> do...		  
                        switch(transport.responseText)      
                        {
                            case "-1":
                                alert('Please,choose exactly item to next shopping');                        
                                break;
                            case "1":                                   
                                window.open(Path100 + '51678/Product.aspx','_parent');
                                break;
                            default:
                                
                                if(transport.responseText != "" && transport.responseText != "0")
                                {
                                    window.open(Path100 + '51678/Product.aspx','_parent');
                                }
                                else alert('Can not insert this customer,please check your information again');
                                break;
                        		               
                       }
	                },   
                    onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
                });
            }
               	
	      OffPleaseWait("AdminDvWait");   	
        } 
        else
            OffPleaseWait("AdminDvWait");
    }
}
function UpdatePatientInfo(ParentControl,GroupName,GroupValidate,event)
{
    var object = $('grpPatient_tbx_ID_A5_005').value;
    if(object != "0" && object != "")
    {
        var validationResult=false;    
        validationResult = Page_ClientValidate(GroupValidate);
        if(validationResult==true)
        {
             var s_arrayvalue="",s_arraystyle="",s_name="",s_pass="",s_code="";              
             var arr = GetDataFormPatient(ParentControl,GroupName,GroupValidate,0);
             if(arr && arr.length >0)
              {
                    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
	                {
		                method			: "post", // Setup Method            
		                parameters		: 
		                {
			                cmd			    : 2017,
			                name            : arr[0],//s_name
			                sData           : arr[1],//s_arrayvalue
			                arraystyle      : arr[2],//s_arraystyle
			                id              : object
		                },
		                onSuccess		: function(transport)
		                { // Event Success --> do...		  
                            switch(transport.responseText)      
                            {
                                case "-1":         
                                    alert('Please,choose exactly item to update successfully');                                 
                                    break;
                                case "1":
                                    GetPatientInformation(object,ParentControl,'grpPatient',event) ;
                                    GetPatientList(event,'pnl_A5_L4_X2_Y3_007');        
                                    alert('Update successfully!');               
                                    break;
                                default:
                                      break;                  
                            		               
                           }
		                },   
                        onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
	                 });
              }  	
		      OffPleaseWait("AdminDvWait");   	
        }
    }
    else
         alert('You forgot choose an item to update!!');
}

function DeletePatient(ParentControl,GroupName,event)
{
    var object = $('grpPatient_tbx_ID_A5_005').value;
    if(object != "0" && object != "")
    {
        if(confirm("Are you sure you want to delete"))
        {
            OnPleaseWait("AdminDvWait",event);
            var elem=document.getElementById(ParentControl);        
            new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
	               {
		                method			: "post", // Setup Method            
		                parameters		: 
		                {
			                cmd		       : 2018,
			                id             : object
		                },
		                onSuccess		: function(transport)
		                { // Event Success --> do...		  
                            switch(transport.responseText)      
                            {
                                case "0":   
                                    alert('Please,choose exactly item to delete successfully');                     
                                    break;
                                default:
                                      var object = transport.responseText ;
                                      GetPatientInformation(object,ParentControl,'grpPatient',event) ;
                                      GetPatientList(event,'pnl_A5_L4_X2_Y3_007');
                                      break;                  
                    	        	               
                           }
		                },   
                        onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
	                });
	           OffPleaseWait("AdminDvWait");
	   }
	   else
	      return false;
	}
	else
	{
	    alert('You forgot choose item to delete!!');
	} 
}



var savePagingPa = null;
var curParentControl = null;
var curPPatient = 1;
var curPPSIZE = 16;
var curSortP = '';
function GetPatientListCalled(event,curPage, pSize, sort, asc,ParentControl)
{
    OnPleaseWait("AdminDvWait",event);
    if (initPaging == false)
    {
	    pagingOptionsBottom1.InitPaging();
	    initPaging = true;
    }

    if (!curPage)	curPage = 1;
    if (!pSize)		pSize = 16;
    sort = curSortP;
    if(!asc) asc = '';
    asc = curAscOrder;
    
    curParentControl = (ParentControl!=null)? ParentControl :  curParentControl;
    ParentControl = (ParentControl==null)? curParentControl :  ParentControl;
    curPPatient = curPage;
    curPPSIZE = pSize;
    
    
    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
    {
        method			: "post", // Setup Method            
        parameters		: 
        {
	        cmd		    : 2020,
	        curPage		: curPage,
		    pSize		: pSize,
		    sort		: sort,
		    asc			: asc
	        
        },
        onSuccess		: function(transport)
        { // Event Success --> do...		  
                
            var response = transport.responseText ;
           
            if(response!='')
            {
                var pagingInfo	= response.substring(0, 19).split(";");
			    response		= response.substring(19);
                $(ParentControl).innerHTML = response; 
                if($('pnl_A5_L3_X2_Y9_010')) $('pnl_A5_L3_X2_Y9_010').style.display = '';
                savePagingPa = [curPage, pSize, sort, asc, pagingInfo[0] * 1, pagingInfo[1] * 1];
	            pagingOptionsBottom1.SetPaging(curPage, pSize, sort, asc, pagingInfo[0] * 1, pagingInfo[1] * 1);			
            }
            else
                if($('pnl_A5_L3_X2_Y9_010')) $('pnl_A5_L3_X2_Y9_010').style.display = 'none';
                
            OffPleaseWait("AdminDvWait");
        },   
        onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
    });         
    
}

function GetPatientList(event,ParentControl)
{
	pagingOptionsBottom1.onchange	= GetPatientListCalled;		
	GetPatientListCalled(event,null,null,null,null,ParentControl);
	
}




/*------------ End Patient Process---------------*/
var sSuSearch;
var CContinue = false;
var Suggest = function(textbox,divSuggest)
{
	this.tb = textbox;
	this.dvEntries = divSuggest;
	this.curpos = -1;
	this.userText = '';
	this.initialize();
}
Suggest.prototype = 
{
	initialize : function()
	{
	    
	    this.tb.onkeydown = this.SuggestKeyDown.handle(this);
	    this.tb.onkeyup = this.SuggestKeyUp.handle(this);
		this.dvEntries.onmouseover = this.handlleMouse.handle(this);
		this.dvEntries.onmouseup = this.handlleMouse.handle(this);
		this.dvEntries.onmousedown = this.handlleMouse.handle(this);
		this.tb.onblur = this.Onblur.bind(this);
		this.C = null;
		this.tb.setAttribute("autocomplete","off");
	},
	ShowSuggest :function()
    {
        if(this.tb.value == "")
        {
            this.HideSuggest();
            return false;
        }
        if(this.tb.id=='grpPatient_tbx_ID_A5_005')
            GetLikeCharacter(this.tb.value, this.createDropDown.handle(this));
        else
            GetLikeCharacterOfFormula(this.tb.value, this.createDropDown.handle(this));
    },
    createDropDown: function() {
        this.dvEntries.innerHTML = '';
        if(sSuSearch)
        {
	        this.dvEntries.style.width = this.tb.offsetWidth + "px";
	        this.dvEntries.style.display = '';
	        var dvEntry = null;
	        var arrEntries = sSuSearch.substr(0,sSuSearch.length-1).split(',');
	        var length = (arrEntries.length > 10)? 10 : arrEntries.length; 
	        for(var i=0;i<parseInt(length);i++)
	        {
		        dvEntry = create('div');
		        dvEntry.innerHTML = arrEntries[i];
		        dvEntry.className = 'dvContentSuggestItem';
		        this.dvEntries.appendChild(dvEntry);
	        }
        }
        else
           this.HideSuggest();
    },
    SuggestKeyDown: function(e)
    {
        if(!e) e = window.event;
		switch(e.keyCode) {
            case 38: //up arrow
                this.ScrollList(-1);
                break;
            case 40: //down arrow 
                this.ScrollList(1);
                break;
            case 27: //esc            
                this.tb.value = this.userText;
            case 13: //enter
                this.HideSuggest();
                if($('grpPatient_tbx_ID_A5_005')!=null)
			    {
		            GetPatientInformation(this.userText,'pnl_A5_L3_X2_Y7_010','grpPatient',null) ;   
		        }
		        else
		        {
		            InsertFormula('tbx_SpecialFormula_A5_005',60,e,'ddl_Chosen_A5_005','ddl_gram_A5_005','lbl_textformula_A5_005');
		            //LoadShortViewCart(20040,"pnl_A5_L6_X2_Y3_010");       
		        }                
                e.returnValue = false;
                if (e.preventDefault) {
                    e.preventDefault();
                }
                break;
         /* case 9: //tab            
                this.tb.value = this.userText;
                this.HideSuggest();
                this.tb.disabled = true;
                break;
         */
          }
    },
    SuggestKeyUp : function(e)
    {
		if(!e) e = window.event;
		var iKeyCode = e.keyCode;
		if ((iKeyCode != 16 && iKeyCode < 32) || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
            //vì các phím này là phím control
            return false;
        } else {
            //nếu là character bình thường 
            this.ShowSuggest(); 
        }
		
//		if((iKeyCode >95 && iKeyCode < 106)|| (iKeyCode > 47 && iKeyCode < 58) || (iKeyCode == 8) ) 
//        {
//            this.ShowSuggest(); 
//        }
//        else return false;	
    },
    handlleMouse :function (e)
    {
		if(!e) e = window.event;
		var curNode = (Event.element(e));
		if(e.type == "mouseover")
		{
			 this.HightLight(curNode);
		}
		else if(e.type == "mousedown" || e.type == "mouseup")
		{
			this.tb.value = curNode.firstChild.nodeValue;
			this.userText = curNode.firstChild.nodeValue;
			this.HideSuggest();
			if($('grpPatient_tbx_ID_A5_005')!=null)
			{
			    $('grpPatient_tbx_ID_A5_005').disabled = true;
		        GetPatientInformation(this.userText,'pnl_A5_L3_X2_Y7_010','grpPatient',null) ;   
		    }
		    else
		    {
		        InsertFormula('tbx_SpecialFormula_A5_005',60,e,'ddl_Chosen_A5_005','ddl_gram_A5_005','lbl_textformula_A5_005');
		        //LoadShortViewCart(20040,"pnl_A5_L6_X2_Y3_010");
		    }
		}
    },
    HightLight :function (curNode)
    {
        for(var i = 0;i<this.dvEntries.childNodes.length;i++)
		{
			var node = this.dvEntries.childNodes[i];
			if(curNode == node)
			{
				node.className = 'dvContentSuggestItemHighLight';
				node.style.Width = this.dvEntries.style.Width + "px";
				//alert(node.firstChild.nodeValue);
				this.tb.value = node.firstChild.nodeValue;
				this.userText = node.firstChild.nodeValue;
			}
			else
			{
				node.className = 'dvContentSuggestItem';
			}
		}
    },
    ScrollList : function(updown)
    {
		var nodes = this.dvEntries.childNodes;
		//alert(updown);
		if(nodes.length > 0)
		{
			var node = null;
			if(updown > 0) //down
			{
				if(this.curpos < nodes.length-1)
				{
					this.curpos = this.curpos + 1;
				}
				else
					this.curpos = 0;
			}
			else
			{
				if(this.curpos > 0)
				{
					this.curpos = this.curpos - 1;
				}
				else
					this.curpos = nodes.length - 1;
			}
			
			if(!node)
			{
			     //alert(this.curpos);
				node = nodes[this.curpos];
				  // alert(node);
				this.HightLight(node);
			}
		}
    },
    HideSuggest : function()
    {
		this.dvEntries.style.display = 'none';
    },
    Onblur: function () {
       if(this.tb.id=="grpPatient_tbx_ID_A5_005")
            this.tb.disabled = true;
       this.HideSuggest();
    }
}

function enableTb(obj)
{
    $(obj).disabled = false;
    $(obj).value = '';
}

function GetLikeCharacter(ssearch, func)
{
   new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
    {
        method: "post", // Setup Method            
        parameters: 
        {
            cmd      : 2021,
            search  : ssearch
        }, // Add Parameters
        onSuccess: function(transport)
        { // Event Success --> do...
            sSuSearch = transport.responseText;
            func();
        },   
        onFailure: function(){ alert(sError);return false;} // Event Failure --> do...     
        
    });
}

function GetLikeCharacterOfFormula(ssearch, func)
{
   new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
    {
        method: "post", // Setup Method            
        parameters: 
        {
            cmd      : 2021,
            search  : ssearch,
            formula : 1    
        }, // Add Parameters
        onSuccess: function(transport)
        { // Event Success --> do...
            sSuSearch = transport.responseText;
            func();
        },   
        onFailure: function(){ alert(sError);return false;} // Event Failure --> do...     
        
    });
}

function CleanFrom(ParentControl,GroupName) 
{ 
    var elem=document.getElementById(ParentControl);
    if(elem!=null)
    {
        var  childs=elem.getElementsByTagName("select");  
        for(i=0;i<childs.length;i++)
        {            
            if(childs[i].id.indexOf(GroupName)>=0)
            {
               
                 childs[i].options[0].selected = true;
            } 
        }

        childs=elem.getElementsByTagName("input");
        for(i=0;i<childs.length;i++)
        {            
            if(childs[i].id.indexOf(GroupName)>=0)
            {
                value =childs[i].getAttribute("att_DefineControl");
                childs[i].value = "";    
            } 
        }
     }
} 

function LoadOrderStatus(cbo)
{
    if($(cbo))
    {
         var Control = $(cbo);
         new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
         {
              method   : "post", // Setup Method            
              parameters  : 
              {
                cmd   : 2022
              },
              onSuccess  : function(transport)
              {
                    var TextXml = transport.responseXML;
                    var Nodes = TextXml.getElementsByTagName('option');
                    if(Nodes != null)               
                    {      
                        Control.options[0]= new Option( '--All Status--', '0');                        
                        Control.options[0].setAttribute('prop','27');
                        
                        for(var i=0;i<Nodes.length;i++)
                        {
                            var itemNode = Nodes[i];
                            Control.options[i+1]= new Option(itemNode.getAttribute('text'),itemNode.getAttribute('value'));
                            Control.options[i+1].setAttribute('prop',itemNode.getAttribute('prop'));                         
                        }                            
                    }
                    Control.onchange = this.GetAllOrderCustomer.handle(this,null);
              },
              onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait"); } // Event Failure --> do...     
          });   
    }
}

 
 
var myasc1 = 1;
var mmysort = 0;
function PatientSortAscDesc(mysort,img,event)
{
    var imgAsc = "../App_Themes/Skin1/images/img_FilterUp.jpg";
    var imgDesc = "../App_Themes/Skin1/images/img_FilterDown.jpg"; 
    var curPage = null;
    var pSize =  null;
    switch(mysort)
    {
        case '103796':
        case '103799':
            img = $('img_FilterDown_A5_005');
            break;
        case '104009':
        case '102011':
            img = $('img_FilterDown_A5_010');
            break;
        case '103701':
        case '103728':
             img = $('img_FilterDown_A5_015');
             break;
        case '104014':
        case '103729':
            img = $('img_FilterDown_A5_020');
            break;
        case '104034':
            img = $('img_FilterDown_A5_025');
            break;
        case '102017':
            img = $('img_FilterDown_A5_030');
            break;
    }
    var elems = $('pnl_A5_L4_X2_Y1_007');
    switch(mysort)
    {
        case '103796':
        case '104009':
        case '103701':
        case '104014':
        case '104034':
        case '102017':
            imgAsc = "../App_Themes/Skin1/images/img_OrderUp.jpg";
            imgDesc = "../App_Themes/Skin1/images/img_OrderDown.jpg"; 
            elems = $('pnl_A5_L7_X2_Y3_005');
            break;
    }    
    var  childs=elems.getElementsByTagName("img");  
    for(i=0;i<childs.length;i++)
    {
           childs[i].src = (childs[i]!=img)? imgDesc:imgAsc ;
    }
    
    if(mysort!=mmysort)
    {
        //if(mmysort)
        img.src = imgAsc; 
        myasc1 =0;
        mmysort = mysort;
    }
    else
    {
        
        if(myasc1== 1)
        {
            img.src = imgAsc; 
            myasc1 =0;
        }
        else
        {
            img.src = imgDesc; 
            myasc1 =1;
        }
        
    }
     curAscOrder = myasc1;
     curSortP = mysort;
     
     switch(mysort)
    {
        case '103796':
        case '104009':
        case '103701':
        case '104014':
        case '104034':
        case '102017':
            GetAllOrder(curPageorder, curPSIZEorder, mysort, myasc1, event);
            break;
        default:
            GetPatientListCalled(event,curPPatient,curPPSIZE, mysort, myasc1,$('pnl_A5_L4_X2_Y3_007'));                                
            break;
    }    
    
   // myasc = (myasc== 0 ) ? 1 : 0;

}


var saveDocMove = null;
var tooltipIsShowF = false;
var tooltipTimerF = null;
function disableselect(e)
{
    return false;
}

function reEnable()
{
    return true;
}

function showToolTipForm(o,e)
{
    //if (window.sidebar){
        //$("ToolTipContainer").onmousedown=disableselect;
        //$("ToolTipContainer").onclick=reEnable;
    //}
    
    var ID=o.id.split("_")[o.id.split("_").length-1];   
    if (!e) e = window.event;
    var tooltip = document.getElementById('ToolTipContainer');
    if (tooltipIsShowF)
    {
        document.onmousemove = saveDocMove;
        saveDocMove    = null;
        _hideToolTip();
    }
    if (tooltip && tooltipIsShowF==false)
    {
        tooltip.onmouseover = function(){window.clearTimeout(tooltipTimerF);}
        //tooltip.onmouseout = hideToolTip;
        tooltipIsShowF = true;
        new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
                {
                    method: "post", // Setup Method            
                    parameters: {cmd: 2031,pageID:73352}, // Add Parameters
                    onSuccess: function(transport)
                    { // Event Success --> do...
                        var response = transport.responseText || "";                        
                        if(response!="")
                        {
                            $("ToolTipContainer").innerHTML =response;
                            var dvClose = document.createElement("div");
                            dvClose.className = 'CssDivClose';
                            var imgClose = document.createElement("img");
                            imgClose.src = '../App_Themes/Skin1/images/close.jpg';
                            dvClose.appendChild(imgClose);
                            imgClose.width = '95';
                            imgClose.height = '29';
                            imgClose.onclick =  this._hideToolTip.handle(this);
                            $("ToolTipContainer").appendChild(dvClose);
                            $("ToolTipContainer").style.display="block";
                            $("ToolTipContainer").className = 'ToolTipForm';
                            OffPleaseWait("AdminDvWait");
                        }
                        else
                        {
                            $("ToolTipContainer").style.display="none";
                        }
                    }           
                }
            );  
        toolTipMoveF(e);
    }
   
}

function toolTipMoveF(event)
{
     if (!event) event = window.event;

     var tooltip = document.getElementById('ToolTipContainer');
     var doc = document.documentElement;
     var curX = event.clientX;
     var curY = event.clientY;


     var winwidth = doc.clientWidth;
     var winheight = doc.clientHeight;

     var rightedge = curX + tooltip.offsetWidth;
     var bottomedge = curY + tooltip.offsetHeight;

     if (rightedge > winwidth)
        curX -= tooltip.offsetWidth ;
     if (bottomedge > winheight)
        curY -= tooltip.offsetHeight;

     tooltip.style.top = curY + doc.scrollTop  + "px";
     tooltip.style.left = curX + doc.scrollLeft + 5 + "px";

     if (saveDocMove) saveDocMove(event);
    }

function _hideToolTip()
{
     window.clearTimeout(tooltipTimerF);
     if (tooltipIsShowF)
     {
      tooltipIsShowF = false;  
      var tooltip = document.getElementById('ToolTipContainer');
      if (tooltip) tooltip.style.display = 'none';
     }
}


function GetPatientInformation(object,ParentControl,GroupName,event)
{
    if($(ParentControl))
    {
       var value = (object.innerHTML) ? object.innerHTML : object ; 
       new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
        {
            method			: "post", // Setup Method            
            parameters		: 
            {
	            cmd		       : 2019,
	            id             : value
            },
            onSuccess		: function(transport)
            { // Event Success --> do...		  
                var response = transport.responseText ;
                var k = 0;
                if(response !='')
                {
                        var elem = $(ParentControl);
                        var childs = elem.getElementsByTagName('select');
                        for(var i=0;i<childs.length;i++)
                        {            
                            if(childs[i].id.indexOf(GroupName)>=0)
                            {
                                value =childs[i].getAttribute("att_DefineControl");
                                switch (value)
                                {
                                     case "103728"://Gender  
                                        var kk = 0;
                                        for(kk = 0;kk< childs[i].options.length;kk++)
                                        {
                                            if(childs[i].options[kk].value == response.split(',')[k])
                                            {
                                              childs[i].options.selectedIndex = kk;
                                              break;
                                            }
                                        }
                                        k++;
                                        
                                        break;
                                    case "102016"://Country                     
                                        
                                        for(kk = 0;kk< childs[i].options.length;kk++)
                                        {
                                            if(childs[i].options[kk].value == response.split(',')[k])
                                            {
                                              childs[i].options.selectedIndex = kk;
                                              break;
                                            }
                                        } 
                                        SelectCountry1('grpPatient_ddl_Country_A5_305','grpPatient_ddl_State_A5_305','grpPatient_tbx_State_A5_305',event,response.split(',')[k+1]);
                                        k++;               
                                        break;
                                    case "102017"://State                                           
                                        k++;
                                        break;
                                   
                                }
                            } 
                        }

                        childs=elem.getElementsByTagName("input");
                        for(i=0;i<childs.length;i++)
                        {            
                            if(childs[i].id.indexOf(GroupName)>=0)
                            {
                                value =childs[i].getAttribute("att_DefineControl");
                                if(value!=null)    
                                 {                
                                    switch (value)
                                    {
                                        case "102017"://State
                                           // childs[i].value = $('grpPatient_ddl_State_A5_305').options[$('grpPatient_ddl_State_A5_305').options.selectedIndex].text;
                                            break;
                                      
                                        default:
                                            childs[i].value =  response.split(',')[k++];
                                            break;
                                        
                                    }
                                 }
                            } 
                        }
                    OffPleaseWait("AdminDvWait");
                }
            },   
            onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
        });
    }
    else
    {
        OffPleaseWait("AdminDvWait");
        $("ToolTipContainer").style.display='none'; 
        showToolTipForm(object,event);
        GetPatientInformation2(object,'pnl_A5_L3_X2_Y7_0202','grpPatient',event);
    }
    
    
}

function GetPatientInformation2(object,ParentControl,GroupName,event)
{
   
       var value = (object.innerHTML) ? object.innerHTML : object ; 
       new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
        {
            method			: "post", // Setup Method            
            parameters		: 
            {
	            cmd		       : 2019,
	            id             : value
            },
            onSuccess		: function(transport)
            { // Event Success --> do...		  
                var response = transport.responseText ;
                var k = 0;
                if(response !='')
                {
                        var elem = $(ParentControl);
                        var childs = elem.getElementsByTagName('select');
                        for(var i=0;i<childs.length;i++)
                        {            
                            if(childs[i].id.indexOf(GroupName)>=0)
                            {
                                value =childs[i].getAttribute("att_DefineControl");
                                switch (value)
                                {
                                     case "103728"://Gender  
                                        var kk = 0;
                                        for(kk = 0;kk< childs[i].options.length;kk++)
                                        {
                                            if(childs[i].options[kk].value == response.split(',')[k])
                                            {
                                              childs[i].options.selectedIndex = kk;
                                              break;
                                            }
                                        }
                                        k++;
                                        
                                        break;
                                    case "102016"://Country                     
                                        
                                        for(kk = 0;kk< childs[i].options.length;kk++)
                                        {
                                            if(childs[i].options[kk].value == response.split(',')[k])
                                            {
                                              childs[i].options.selectedIndex = kk;
                                              break;
                                            }
                                        } 
                                        SelectCountry1('grpPatient_ddl_Country_A5_305','grpPatient_ddl_State_A5_305','grpPatient_tbx_State_A5_305',event,response.split(',')[k+1]);
                                        k++;               
                                        break;
                                    case "102017"://State                                           
                                        k++;
                                        break;
                                   
                                }
                            } 
                        }

                        childs=elem.getElementsByTagName("input");
                        for(i=0;i<childs.length;i++)
                        {            
                            if(childs[i].id.indexOf(GroupName)>=0)
                            {
                                value =childs[i].getAttribute("att_DefineControl");
                                if(value!=null)    
                                 {                
                                    switch (value)
                                    {
                                        case "102017"://State
                                           // childs[i].value = $('grpPatient_ddl_State_A5_305').options[$('grpPatient_ddl_State_A5_305').options.selectedIndex].text;
                                            break;
                                      
                                        default:
                                            childs[i].value =  response.split(',')[k++];
                                            break;
                                        
                                    }
                                 }
                            } 
                        }
                    OffPleaseWait("AdminDvWait");
                }
            },   
            onFailure: function(){ alert(sError);OffPleaseWait("AdminDvWait");return false; } // Event Failure --> do...     
        });
       
    
}
//============= Captcha=========================

function RefreshCaptcha()
{

    var control = $('img_SpecificCode_A5_005');
    new Ajax.Request("../VNVN_Web/VNVN_19_Server.aspx",
    {
        method: "post", // Setup Method            
        parameters: 
        {
            cmd     : 2030
        }, // Add Parameters
        onSuccess: function(transport)
        {            
            control.src = transport.responseText; 
        },   
        onFailure: function(){ alert(sError);return false;} // Event Failure --> do...     
        
    });
      
}
function SetCaptcha(id)
{
    if($(id))
        $(id).onclick = this.RefreshCaptcha.handle(this,$(id));
}
//=============End Captcha=========================
//=============Suggest=========================

function LoadSuggest()
{
    if($('grpPatient_tbx_ID_A5_005'))
        var obj = new Suggest($('grpPatient_tbx_ID_A5_005'),$('pnl_Suggest_Onpage'));
    else if($('tbx_SpecialFormula_A5_005'))
        var obj = new Suggest($('tbx_SpecialFormula_A5_005'),$('pnl_Suggest_Onpage'));
}
function setDateOrderForm()
{
    var mydate = new Date();
    if($('tbx_Month_A5_005'))
    {
        $('tbx_Day').disabled = true;
        $('tbx_Day').value = mydate.getDate();
        $('tbx_Month_A5_005').disabled = true;
        $('tbx_Month_A5_005').value = mydate.getMonth() + 1;
        $('tbx_Year_A5_005').disabled = true;
        $('tbx_Year_A5_005').value = mydate.getFullYear();
    }
}

//=============End Suggest=========================