/*Change History*/
/*************************************************************************************************************************
  Date          Marker      By          Issue Description
 -------------------------------------------------------------------------------------------------------------------------
 03/08/2006     [001]       HS          Impact2 ISSUE Before Live.xls(#109):Sales Rep Receiver
 01/09/2006     [002]       HS          Impact2 Issue Maintainence log (#19) 
 11/11/2006     [003]       MM          Remove non consecutive Duplicate Words 
 01/01/2007     [004]       MM          Copack Client
 01/01/2007     [005]       MM          TBA to be allowed typing in Phone FAX text boxes
 
 21/01/2009     [007]       HS          Check implemented in Ajex code for user list screen. 
 12/05/2009	    [008]	    HS	  	    Packcentre Material Checkbox should be added when selected Co-Pack client.
 13/07/2009     [009]       HS          If you run a report for a selected item code , and the item code have space the report generate blank.
 20/11/2009     [010]       HS          Browser Related Issues.
***************************************************************************************************************************/

var strClientErrors = "";
var screenname = new String();
screenname=document.location.href.substring(document.location.href.lastIndexOf('/')+1,document.location.href.lastIndexOf('.'))
screenname=screenname + '.aspx';
 
function setJavascriptError(tdObject, errorText)
{  
    var strErrorText = new String(); 

    if (errorText == null || errorText == undefined  ) 
        errorText ='';    
        
    strErrorText= errorText;

    if (strErrorText.length >= 6)
    {        
        var intPos = new Number();    
        intPos = -1;
        strErrorText = strErrorText.substring(strErrorText.length-6,strErrorText.length);
        intPos = strErrorText.lastIndexOf("<BR>");
        strErrorText = errorText;
        
        if (intPos > -1)
        {
            intPos = strErrorText.lastIndexOf("<BR>");
            strErrorText = strErrorText.substring(0,intPos);
        }
    }
            
    objTD = document.getElementById(tdObject);
    objTD.className = "errorcolor";
    objTD.innerHTML = strErrorText;
}
 
function setJavascriptInfo(tdObject, errorText)
{  
    var strErrorText = new String(); 

    if (errorText == null || errorText == undefined  ) 
        errorText ='';    
        
    strErrorText= errorText;

    if (strErrorText.length >= 6)
    {        
        var intPos = new Number();    
        intPos = -1;
        strErrorText = strErrorText.substring(strErrorText.length-6,strErrorText.length);
        intPos = strErrorText.lastIndexOf("<BR>");
        strErrorText = errorText;
        
        if (intPos > -1)
        {
            intPos = strErrorText.lastIndexOf("<BR>");
            strErrorText = strErrorText.substring(0,intPos);
        }
    }
            
    objTD = document.getElementById(tdObject);
    objTD.className = "informationcolor";
    objTD.innerHTML = strErrorText;
}
 
function Logout()
{
    window.location.href="../ThankYou.aspx";
}
/*************************************************************
 * Function         : fnSelectAll(obj)
 * Purpose          : This function is used to check or uncheck all the checkbox into list screen. 
 *                    This function is called when user check/click the SelectAll checkbox. 
 *                    Where chkSelect is control array of checkboxes.
 * Input Parameters : checkbox Contol
 * Return           : Return nothing. 
 * Author			:	
 * Creation Date	: 28-Dec-2005 
 * How to Call [E.g]:
            Call on Selelect All checkbox: 
            onclick="javascript:fnSelectAll(this);"            
/*************************************************************/
 function fnSelectAll(obj)
 { 
    var strChecked = obj.checked;     
    if(document.forms[0].chkSelect == undefined)
    {
       return false;
    }
    else if(document.forms[0].chkSelect.length == undefined)
    {
        document.forms[0].chkSelect.checked = strChecked;
        return true;
    }
    for (var i=0; i<document.forms[0].chkSelect.length; i++)
    {       
        document.forms[0].chkSelect[i].checked=strChecked;                           
    }  
 } 
 
 /*************************************************************
 * Function         : fnGetIdsOfCheckBoxes()
 * Purpose          : This function is used to get name of all selected checkboxes as coma separated.
 *                    Where name contain the database column value (like Id of row). 
 *                    These ids can be used for either delete or print operation.  
 * Input Parameters : none
 * Return           : String of ids with coma separated. E.g. "100,101,102"
 * Author			:	
 * Creation Date	: 28-Dec-2005             
/*************************************************************/
 function fnGetIdsOfCheckBoxes()
 {
    var strSelectedIds = new String();
    
    strSelectedIds = "";
    if(document.forms[0].chkSelect != undefined)
    {
        if (document.forms[0].chkSelect.length == undefined)
        {
            if ((document.forms[0].chkSelect.checked == true) 
                && (document.forms[0].chkSelect.name != 'chkSelect'))
            {          
                strSelectedIds = document.forms[0].chkSelect.name;
            } 
        }  
        else
        {  
            for (var i=0; i<document.forms[0].chkSelect.length; i++)
            { 
                if ((document.forms[0].chkSelect[i].checked == true) 
                    && (document.forms[0].chkSelect[i].name != 'chkSelect'))
                {          
                    strSelectedIds = strSelectedIds + document.forms[0].chkSelect[i].name + ',';                           
                }        
            }
            
            if (strSelectedIds!="")
            {
                strSelectedIds = strSelectedIds.substring(0,strSelectedIds.length-1);
            }
        }  
    }
    return strSelectedIds;
 }
 
 /*************************************************************
 * Function         : fnGetCodeIdsOfCheckBoxes()
 * Purpose          : This function is used to get name of all selected checkboxes as coma separated.
 *                    Where name contain the database column value (like Code and Id of row). 
 *                    These ids can be used for either delete or print operation.  
 * Input Parameters : none
 * Return           : String of ids with coma separated. E.g. "100,101,102~^~ca234,ca345,px34" 
 * Author			:	
 * Creation Date	: 02-MAR-2006             
/*************************************************************/
 function fnGetCodeIdsOfCheckBoxes()
 {
    var strSelectedIds  = new String();
    var strSelectedCodes= new String();
    var arrCodeIds      = new Array();
    var strCurrentValue = new String();                
    
    strSelectedIds  = "";
    strSelectedCodes= "";
    
    if(document.forms[0].chkSelect != undefined)
    {
        if (document.forms[0].chkSelect.length == undefined)
        {
            if ((document.forms[0].chkSelect.checked == true) 
                && (document.forms[0].chkSelect.name != 'chkSelect'))
            {   
                strCurrentValue = "";
                strCurrentValue = document.forms[0].chkSelect.name;
                arrCodeIds = strCurrentValue.split("~^~");                
                strSelectedIds = arrCodeIds[0];
                strSelectedCodes = arrCodeIds[1];                
            } 
        }  
        else
        {  
            for (var i=0; i<document.forms[0].chkSelect.length; i++)
            { 
                if ((document.forms[0].chkSelect[i].checked == true) 
                    && (document.forms[0].chkSelect[i].name != 'chkSelect'))
                { 
                    arrCodeIds      = new Array();
                    strCurrentValue = "";
                    strCurrentValue = document.forms[0].chkSelect[i].name;                    
                    arrCodeIds      = strCurrentValue.split("~^~");
                    strSelectedIds  = strSelectedIds + arrCodeIds[0] + ',';
                    strSelectedCodes= strSelectedCodes + arrCodeIds[1] + ', ';
                }        
            }
            
            if (strSelectedIds!="")
            {
                strSelectedIds = strSelectedIds.substring(0,strSelectedIds.length-1);
                strSelectedCodes = strSelectedCodes.substring(0,strSelectedCodes.length-2);
            }
        }  
    }
    return strSelectedIds + "~^~" + strSelectedCodes;
 }
 
 //[001] START
 /*************************************************************
 * Function         : fnGetIdCodeNamesOfCheckBoxes()
 * Purpose          : This function is used to get name of all selected checkboxes as coma separated.
 *                    Where name contain the database column value (like Name ,Code and Id of row). 
 *                    These ids can be used for either delete or print operation.  
 * Input Parameters : none
 * Return           : String of ids with coma separated. E.g. "100,101,102~^~ca234,ca345,px34~^~Name1,Name2,Name3" 
 * Author			:	
 * Creation Date	:             
/*************************************************************/
 function fnGetIdCodeNamesOfCheckBoxes()
 {
    var strSelectedIds  = new String();
    var strSelectedCodes= new String();
    var strSelectedNames= new String();
    var arrCodeIds      = new Array();
    var strCurrentValue = new String();                
    
    strSelectedIds  = "";
    strSelectedCodes= "";
    strSelectedNames = "";
    
    if(document.forms[0].chkSelect != undefined)
    {
        if (document.forms[0].chkSelect.length == undefined)
        {
            if ((document.forms[0].chkSelect.checked == true) 
                && (document.forms[0].chkSelect.name != 'chkSelect'))
            {   
                strCurrentValue = "";
                strCurrentValue = document.forms[0].chkSelect.name;
                arrCodeIds = strCurrentValue.split("~^~");                
                strSelectedIds = arrCodeIds[0];
                strSelectedCodes = arrCodeIds[1];  
                strSelectedNames = arrCodeIds[2];               
            } 
        }  
        else
        {  
            for (var i=0; i<document.forms[0].chkSelect.length; i++)
            { 
                if ((document.forms[0].chkSelect[i].checked == true) 
                    && (document.forms[0].chkSelect[i].name != 'chkSelect'))
                { 
                    arrCodeIds      = new Array();
                    strCurrentValue = "";
                    strCurrentValue = document.forms[0].chkSelect[i].name;                    
                    arrCodeIds      = strCurrentValue.split("~^~");
                    strSelectedIds  = strSelectedIds + arrCodeIds[0] + ',';                 
                    //[002]strSelectedCodes= strSelectedCodes + arrCodeIds[1] + ',';
                    strSelectedCodes= strSelectedCodes + arrCodeIds[1] + ', ';   //[002]
                    strSelectedNames= strSelectedNames + arrCodeIds[2] + ',';
                }        
            }
            
            if (strSelectedIds!="")
            {   
                strSelectedIds = strSelectedIds.substring(0,strSelectedIds.length-1);
                //[002]strSelectedCodes = strSelectedCodes.substring(0,strSelectedCodes.length-1);
                strSelectedCodes = strSelectedCodes.substring(0,strSelectedCodes.length-2);       //[002] 
                strSelectedNames = strSelectedNames.substring(0,strSelectedNames.length-1);
            }
        }  
    }
    return strSelectedIds + "~^~" + strSelectedCodes + "~^~" + strSelectedNames;
 }
 //[001] END
 
 
 /*************************************************************
 * Function         : fnGetIdsOfTextBoxes()
 * Purpose          : This function is used to get name of all selected TextBoxes as coma separated.
 *                    Where name contain the database column value (like Id of row). 
 *                    These ids can be used for either delete or print operation.  
 * Input Parameters : none
 * Return           : String of ids with comma separated. E.g. "100,101,102"
 * Author			:	
 * Creation Date	: 28-Dec-2005             
/*************************************************************/
 function fnGetIdsOfTextBoxes()
 {
    var strSelectedIds = new String();
    
    strSelectedIds = "";
    if(document.forms[0].txtSelect != undefined)
    {
        if (document.forms[0].txtSelect.length == undefined)
        {
            if ((document.forms[0].txtSelect.checked == true) 
                && (document.forms[0].txtSelect.name != 'txtSelect'))
            {          
                strSelectedIds = document.forms[0].txtSelect.name;
            } 
        }  
        else
        {  
            for (var i=0; i<document.forms[0].txtSelect.length; i++)
            { 
                if ((document.forms[0].txtSelect[i].checked == true) 
                    && (document.forms[0].txtSelect[i].name != 'txtSelect'))
                {          
                    strSelectedIds = strSelectedIds + document.forms[0].txtSelect[i].name + ',';                           
                }        
            }
            
            if (strSelectedIds!="")
            {
                strSelectedIds = strSelectedIds.substring(0,strSelectedIds.length-1);
            }
        }  
    }
    return strSelectedIds;
 }
 
 
 function openNewWindow(url)
 {    
    var intX = 750;
	var intY = 450;	
	var leftPos = 140;
	var topPos = 100;
    window.open(url,'','left='+leftPos+',top='+topPos+',leftmargin=0,topmargin=0,width='+intX+',height='+intY+',status=yes,resizable=yes,scrollbars=yes,titlebar=yes,menubar=yes,toolbar=yes,location=yes');
 }
  
 function openPopUp(url,width,height,windowname)
 {
		var intX = width;
		var intY = height;
		var w = 1024;
		var h = 768;
		var leftPos = (w-intX)/2;
		var topPos = (h-intY)/2;		
		window.open(url,windowname,'left='+leftPos+',top='+topPos+',leftmargin=0,topmargin=0,width='+intX+',height='+intY+',status=yes,resizable=no,scrollbars=yes,titlebar=no,menubar=no');						
		
}

    //[010]function fn_textbox_onkeyup(obj,ampersand,underscore,small,caps,number,dash,fslash,bslash,comma,colon,attherate,space,dot,apostrophe) 
    function fn_textbox_onkeyup(obj,ampersand,underscore,small,caps,number,dash,fslash,bslash,comma,colon,attherate,space,dot,apostrophe,e)     //[010]
    {     
//        var str = obj.value;   
//        var str1 ='';
//           
//        for (var i = 0; i < str.length; i++)
//        {     
//             var ch = str.substring(i, i + 1);  
//             if ( (ch == '_') && underscore=='Y')                             {   str1= str1 +ch;     }             
//             else if ( (ch =='&' ) && ampersand=='Y')                         {   str1= str1 +ch;     } 
//             else if ( (ch >= "a" &&  ch <= "z" )    && small=="Y")           {   str1= str1 +ch;     } 
//             else if ( (ch >= "A" && ch  <= "Z")     && caps=='Y')            {   str1= str1 +ch;     }  
//             else if ( (parseInt(ch)== ch)           && number=='Y')          {   str1= str1 +ch;     }  
//             else if ( (ch == '-') && dash=='Y')                              {   str1= str1 +ch;     }                 
//             else if ( (ch == '-') && fslash=='Y')                            {   str1= str1 +ch;     }       
//             else if ( (ch == '\/') && bslash=='Y')                           {   str1= str1 +ch;     }                        
//             else if ( (ch == ',') && comma=='Y')                             {   str1= str1 +ch;     }  
//             else if ( (ch == ':') && colon=='Y')                             {   str1= str1 +ch;     }                   
//             else if ( (ch == '@') && attherate=='Y')                         {   str1= str1 +ch;     } 
//             else if ( (ch == ' ') && space=='Y')                             {   str1= str1 +ch;     }             
//             else if ( (ch == '.') && dot=='Y')                               {   str1= str1 +ch;     }             
//             
//             else { str1= str1; }
//             obj.value=str1;
//        }  
            //[005]  
            //[010]start
            //alert(obj.name);            
            if (window.navigator.appVersion.indexOf("MSIE")==-1)
            { 
                if  (obj.name.toUpperCase().indexOf("FAX") >= 0 || obj.name.toUpperCase().indexOf("PHONE") >=0 ) 
                {            
                    if 
                    (  e.keyCode==84 || e.keyCode==66 || e.keyCode==65
                    || e.keyCode==116 || e.keyCode==97 || e.keyCode==98
                    || e.keyCode==96 || e.keyCode==99 || e.keyCode==100
                    || e.keyCode==101 || e.keyCode==102 || e.keyCode==103
                    || e.keyCode==104 || e.keyCode==105 || e.keyCode==110
                    ) 
                    {     
                       obj.Value = obj.Value +e.returnValue;      
                       return;                  
                    }
                    else if (  e.keyCode==8 || e.keyCode==46 )
                    {
                        // do nothing 
                    } 
                    else if (e.keyCode>64)
                    {                     
                        e.preventDefault();
                        return;  
                    }
                }    
            
                if  (obj.name.toUpperCase().indexOf("MAIL") >= 0 ) 
                { 
                    ampersand   ='N';   underscore  ='Y';   number      ='Y';   colon       ='Y';
                    dash        ='Y';   fslash      ='Y';   bslash      ='Y';   comma       ='N';   
                    attherate   ='Y';   space       ='Y';   dot         ='Y';   apostrophe  ='Y';
                }
                if  (obj.name.toUpperCase().indexOf("WEB") >= 0 ) 
                { 
                    ampersand   ='N';   underscore  ='Y';   number      ='Y';   colon       ='Y';
                    dash        ='Y';   fslash      ='Y';   bslash      ='Y';   comma       ='N';   
                    attherate   ='N';   space       ='Y';   dot         ='Y';   apostrophe  ='Y';
                }
                        
                 var blnShiftKey = new Boolean;
                 blnShiftKey=false;
                 
                 var blnCtrlKey = new Boolean;
                 blnCtrlKey=false;
                 
                 var blnAltKey = new Boolean;
                 blnAltKey=false;
             
                 if(e.shiftKey)
                 {
			        //set variable that shift key has been pressed
				    blnShiftKey=true;				    
                 }
			     if(e.ctrlKey)
			     {
			        //set variable that ctrl key has been pressed
			        blnCtrlKey=true; 
                 }			 
			     if(e.altKey)
			     {
			        //set variable that alt key has been pressed
			        blnAltKey=true; 
                 }                
			    			    
                 var key = e.keyCode;
                 //alert(key);
                 if (dash == undefined) { dash ='N';}
                 if (fslash == undefined) { fslash ='N';}   
                 if (bslash == undefined) { bslash ='N';}
                 if (comma == undefined) { comma ='N';}
                 if (colon == undefined) { colon     ='N';}
                 if (attherate == undefined) { attherate ='N';}
                 if (space == undefined) { space ='N';}
                 if (number == undefined) { number ='N';}
                 if (apostrophe == undefined) { apostrophe ='N';}
                 if (dot == undefined) { dot ='N';}
                 if (small == undefined) { small ='N';}
                 if (caps == undefined) { caps ='N';}
                 if (ampersand == undefined) { ampersand ='N';}
                 if (underscore == undefined) { underscore ='N';}
             
              	if(AgntUsr.indexOf('safari')!=-1)
		        {		         
		            if ((key==189 && blnShiftKey && underscore=='N')                      
                        || (key==55 && blnShiftKey && ampersand=='N')                      
                        || ( (key >= 65 &&  key <= 90 )    && (small=="N" && caps=="N") && !blnAltKey && !blnCtrlKey)           
                        || ( ((key >= 48 &&  key <= 57 ) || ( key >= 96 &&  key <= 105 ))    && number=='N')          
                        || ((key==189 || key==109) && !blnShiftKey && dash=='N')                              
                        || ((key==191 || key==111) && !blnShiftKey && fslash=='N')                                                  
                        || (key==220 && !blnShiftKey && bslash=='N')                                                                      
                        || (key==188 && !blnShiftKey && comma=='N')                                                                                          
                        || (key==186 && blnShiftKey && colon=='N')                                                                                          
                        || (key==50 && blnShiftKey && attherate=='N')                                                                                          
                        || (key==32 && !blnShiftKey && space=='N')
                        || (key==222 && !blnShiftKey && apostrophe=='N' )
                        || ((key==190 || key==110) && !blnShiftKey && dot=='N'))
                        {                                             
                            e.stopPropagation();
		                    e.preventDefault();
		                } 
    		      
		              //if it is a decimal field then allow only one decimal and 2 places of decimal
                        else if (ampersand=='N' && underscore=='N' && small=='N' && caps=='N' && number=='Y' && dash=='N' && fslash=='N' && bslash=='N' && comma=='N' && colon=='N' && attherate=='N' && space=='N' && dot=='Y' &&  apostrophe=='Y')
                        {                       
                            if (obj.value.indexOf(".") >= 0)
                            {
                                if (key==190 || key==110)
                                {
                                    e.stopPropagation();
                                    e.preventDefault();
                                }
                            }
                        } 
		        }
		        else
		        {   		        
                    if ((key==109 && blnShiftKey && underscore=='N')                      
                    || (key==55 && blnShiftKey && ampersand=='N')                      
                    || ( (key >= 65 &&  key <= 90 )    && (small=="N" && caps=="N") && !blnAltKey && !blnCtrlKey)           
                    || ( ((key >= 48 &&  key <= 57 ) || ( key >= 96 &&  key <= 105 ))    && number=='N')          
                    || ((key==189 || key==109) && !blnShiftKey && dash=='N')                              
                    || ((key==191 || key==111) && !blnShiftKey && fslash=='N')                                                  
                    || (key==220 && !blnShiftKey && bslash=='N')                                                                      
                    || (key==188 && !blnShiftKey && comma=='N')                                                                                          
                    || (key==59 && blnShiftKey && colon=='N')                                                                                          
                    || (key==50 && blnShiftKey && attherate=='N')                                                                                          
                    || (key==32 && !blnShiftKey && space=='N')
                    || (key==222 && !blnShiftKey && apostrophe=='N' )
                    || ((key==190 || key==110) && !blnShiftKey && dot=='N'))
                    {                                             
                        e.stopPropagation();
		                e.preventDefault();
		            } 
		      
		          //if it is a decimal field then allow only one decimal and 2 places of decimal
                    else if (ampersand=='N' && underscore=='N' && small=='N' && caps=='N' && number=='Y' && dash=='N' && fslash=='N' && bslash=='N' && comma=='N' && colon=='N' && attherate=='N' && space=='N' && dot=='Y' &&  apostrophe=='Y')
                    {                       
                        if (obj.value.indexOf(".") >= 0)
                        {
                            if (key==190 || key==110)
                            {
                                e.stopPropagation();
                                e.preventDefault();
                            }
                        }
                    } 
                    
                 }              
            }
            else
            {
            //[010]end 
            
            if  (obj.name.toUpperCase().indexOf("FAX") >= 0 || obj.name.toUpperCase().indexOf("PHONE") >=0 ) 
            {                      
                if 
                (  window.event.keyCode==84 || window.event.keyCode==66 || window.event.keyCode==65
                || window.event.keyCode==116 || window.event.keyCode==97 || window.event.keyCode==98
                || window.event.keyCode==96 || window.event.keyCode==99 || window.event.keyCode==100
                || window.event.keyCode==101 || window.event.keyCode==102 || window.event.keyCode==103
                || window.event.keyCode==104 || window.event.keyCode==105 || window.event.keyCode==110
                ) 
                {     
                   obj.Value = obj.Value +window.event.returnValue;      
                   return;                  
                }
                else if (  window.event.keyCode==8 || window.event.keyCode==46 )
                {
                    // do nothing 
                } 
                else if (  window.event.keyCode>64  )
                { 
                    window.event.returnValue = false;
                    return;  
                }
            }    
            
            if  (obj.name.toUpperCase().indexOf("MAIL") >= 0 ) 
            { 
                ampersand   ='N';   underscore  ='Y';   number      ='Y';   colon       ='Y';
                dash        ='Y';   fslash      ='Y';   bslash      ='Y';   comma       ='N';   
                attherate   ='Y';   space       ='Y';   dot         ='Y';   apostrophe  ='Y';
            }
            if  (obj.name.toUpperCase().indexOf("WEB") >= 0 ) 
            { 
                ampersand   ='N';   underscore  ='Y';   number      ='Y';   colon       ='Y';
                dash        ='Y';   fslash      ='Y';   bslash      ='Y';   comma       ='N';   
                attherate   ='N';   space       ='Y';   dot         ='Y';   apostrophe  ='Y';
            }
                        
            //[005]
        
             var blnShiftKey = new Boolean;
             blnShiftKey=false;
             
             var blnCtrlKey = new Boolean;
             blnCtrlKey=false;
             
             var blnAltKey = new Boolean;
             blnAltKey=false;
             
             if(window.event.shiftKey)
             {
			    //set variable that shift key has been pressed
				blnShiftKey=true; 
             }
			 if(window.event.ctrlKey)
			 {
			    //set variable that ctrl key has been pressed
			    blnCtrlKey=true; 
             }			 
			 if(window.event.altKey)
			 {
			    //set variable that alt key has been pressed
			    blnAltKey=true; 
             }                
			    
             var key = window.event.keyCode;             
             //var ch = unescape('%' + key.toString(16));
             //alert(key);
              
             if (dash == undefined) { dash ='N';}
             if (fslash == undefined) { fslash ='N';}   
             if (bslash == undefined) { bslash ='N';}
             if (comma == undefined) { comma ='N';}
             if (colon == undefined) { colon     ='N';}
             if (attherate == undefined) { attherate ='N';}
             if (space == undefined) { space ='N';}
             if (number == undefined) { number ='N';}
             if (apostrophe == undefined) { apostrophe ='N';}
             if (dot == undefined) { dot ='N';}
             if (small == undefined) { small ='N';}
             if (caps == undefined) { caps ='N';}
             if (ampersand == undefined) { ampersand ='N';}
             if (underscore == undefined) { underscore ='N';}
             
             
             
             if ((key==189 && blnShiftKey && underscore=='N')                      
                    || (key==55 && blnShiftKey && ampersand=='N')                      
                    || ( (key >= 65 &&  key <= 90 )    && (small=="N" && caps=="N") && !blnAltKey && !blnCtrlKey)           
                    || ( ((key >= 48 &&  key <= 57 ) || ( key >= 96 &&  key <= 105 ))    && number=='N')          
                    || ((key==189 || key==109) && !blnShiftKey && dash=='N')                              
                    || ((key==191 || key==111) && !blnShiftKey && fslash=='N')                                                  
                    || (key==220 && !blnShiftKey && bslash=='N')                                                                      
                    || (key==188 && !blnShiftKey && comma=='N')                                                                                          
                    || (key==186 && blnShiftKey && colon=='N')                                                                                          
                    || (key==50 && blnShiftKey && attherate=='N')                                                                                          
                    || (key==32 && !blnShiftKey && space=='N')
                    || (key==222 && !blnShiftKey && apostrophe=='N' )
                    || ((key==190 || key==110) && !blnShiftKey && dot=='N'))
              {
                window.event.cancelBubble = true;
		        window.event.returnValue = false;
		      } 
		      
		      //if it is a decimal field then allow only one decimal and 2 places of decimal
		      else if (ampersand=='N' && underscore=='N' && small=='N' && caps=='N' && number=='Y' && dash=='N' && fslash=='N' && bslash=='N' && comma=='N' && colon=='N' && attherate=='N' && space=='N' && dot=='Y' &&  apostrophe=='Y')
		      {
		        
	            if (obj.value.indexOf(".") >= 0)
		        {
		            if (key==190 || key==110)
		            {
		                window.event.cancelBubble = true;
		                window.event.returnValue = false;
		            }
//		            else if ((key >= 48 &&  key <= 57 ) || ( key >= 96 &&  key <= 105 ))
//		            {
//		                var strNumber = new String;
//		                strNumber = obj.value.substring(obj.value.indexOf(".")+1,obj.value.length)
//		                if (strNumber.length==2)
//		                {
//	                        window.event.cancelBubble = true;
//	                        window.event.returnValue = false;
//	                    }   
//		                
//		            }
		             
		        }
		        
		      }
		    
		 }   //[010]  
    }
			


 function openPopUpWithLoc(url,width,height,windowname,xpos,ypos)
 {
		var intX = width;
		var intY = height;
		var w = 1024;
		var h = 768;
		var leftPos = xpos;
		var topPos = ypos;		
		window.open(url,windowname,'left='+leftPos+',top='+topPos+',leftmargin=0,topmargin=0,width='+intX+',height='+intY+',status=yes,resizable=yes,scrollbars=yes,titlebar=no,menubar=no');						
		
}

function ComboItemsMoveWithSort(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}

}

function ComboItemsMove(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
//arrFbox.sort();
//arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}

}


function OpenReportPopup(strUrl)
{
	var strWindowProperties;
	var left;
	var top;
	var screenWidth, screenHeight;
	var urlLength;
	
	screenWidth = (screen.width) -	5;
	screenHeight = (screen.height) - 40;
	left = 0
	top = 0
	
	urlLength = strUrl.length
	if(urlLength <= 0)	
	{        
     	return false;
	}
	else
	{
		strWindowProperties = "left="+left +",top="+top+",width="+screenWidth+",height="+screenHeight		
		strWindowProperties = strWindowProperties + ",status=yes," + "scrollbars=auto," + "location=no," + "menubar=no," + "resizable=yes"      //[006]
		window.open(strUrl,"",strWindowProperties)
		return true;
	}
}

function getFirstPage()
{
	document.forms[0].hdnOperation.value = "SEARCH";
    document.forms[0].action= screenname + "?qstrPageAction=FIRST";
    document.forms[0].submit();
}			
function getPreviousPage()
{
	document.forms[0].hdnOperation.value = "SEARCH";
    document.forms[0].action= screenname + "?qstrPageAction=PREV";
    document.forms[0].submit();
}
function getNextPage()
{
	document.forms[0].hdnOperation.value = "SEARCH";
    document.forms[0].action= screenname + "?qstrPageAction=NEXT";
    document.forms[0].submit();
}
function getLastPage()
{
	document.forms[0].hdnOperation.value = "SEARCH";
    document.forms[0].action= screenname + "?qstrPageAction=LAST";
    document.forms[0].submit();
}


function getPage(PageId)
{
    if (document.forms[0].cboPaging.value != PageId)
    {
	    document.forms[0].hdnOperation.value = "SEARCH";
        document.forms[0].action= screenname + "?qstrPageAction="+ document.forms[0].cboPaging.value;
        document.forms[0].submit();
    }
}

function fnTrim(strString)
{
	// white space consist of (blank,tab,newline)
	var intLeftIndex = 0; //Store position of first non-white space from leftmost side
	var intRightIndex = 0; //Store position of first non-white space from rightmost side
	var blnFound = false; //Check for any non-white space character
	var regExp = /\S+/; 
	var intCount;
	if (strString.search(regExp) == -1) //Check for non-white space character
	{
		//Valid character not found then return empty string
		strString = ""; 
		return(strString);
	}
	//If  atleast one non-white space character found.
	for (intCount=0;intCount < strString.length; intCount++)
	{
		// Checking for first non-white spaces from left side
		if (strString.charAt(intCount) != " ") 
		{
			intLeftIndex = intCount - 1;
			break;
		}
	}
	for (intCount=strString.length - 1;intCount >= 0; intCount--)
	{
		// Checking for first non-white spaces from Right most side
		if (strString.charAt(intCount) != " ") 
		{
			intRightIndex = intCount + 1;
			break;
		}
	}
	
	//Remove leading and trailing spaces
	strString=strString.substring(intLeftIndex+1,intRightIndex); 
	return (strString);
}

function SubmitMe(obj)
{
    obj.document.forms[0].hdnOperation.value="CHANGE";
    obj.document.forms[0].submit();
}

function setCombo(objCombo,strText)
{
 
    for (var intCount = 0; intCount < objCombo.options.length; intCount++)
    {
	    if (fnTrim(objCombo.options[intCount].innerHTML.toUpperCase()) == fnTrim(strText.toUpperCase()))
	    {
		    objCombo.selectedIndex = intCount;
		    break;
	    }
	}
}





/****************************************************************************
Method Name		:	OpenNewWindow
Parameters		:	http url
Return Type		:	Boolean
Functionality		:	Accepts http url and open it in a new browser window with maximize window size.
					
Author			:	
Creation Date		:	12-12-2005
*****************************************************************************/
function OpenNewWindow(strUrl)
{
	var strWindowProperties;
	var left;
	var top;
	var screenWidth, screenHeight;
	var urlLength;
	
	screenWidth = (screen.width) - 225 ;
	screenHeight = (screen.height)-110;
	left = 100;
	top = 20;
	
	urlLength = strUrl.length
	if(urlLength <= 0)	
	{        
     	return false;
	}
	else
	{
		strWindowProperties = "left="+left +",top="+top+",width="+screenWidth+",height="+screenHeight		
		strWindowProperties = strWindowProperties + ",status=no," + "scrollbars=yes," + "location=no," + "menubar=no," + "resizable=yes"      
		window.open(strUrl,"",strWindowProperties)
		return true;
	}
}



/****************************************************************************
Method Name		:	OpenNewPopup
Parameters		:	http url
Return Type		:	Boolean
Functionality		:	Accepts http url and open it in a new browser window with maximize window size.
				Like "Report url to display report on browser"					
Author			:		
Creation Date		:	12-12-2005
*****************************************************************************/
function OpenNewPopup(strUrl)
{
	var strWindowProperties;
	var left;
	var top;
	var screenWidth, screenHeight;
	var urlLength;
	
	screenWidth = (screen.width) -	5;
	screenHeight = (screen.height) - 40;
	left = 0
	top = 0
	
	urlLength = strUrl.length
	if(urlLength <= 0)	
	{        
     	return false;
	}
	else
	{
		strWindowProperties = "left="+left +",top="+top+",width="+screenWidth+",height="+screenHeight		
		strWindowProperties = strWindowProperties + ",status=yes," + "scrollbars=auto," + "location=no," + "menubar=no," + "resizable=yes"     
		window.open(strUrl,"",strWindowProperties)
		return true;
	}
}

function OpenParamPopup(strUrl)
{
	var strWindowProperties;
	var left;
	var top;
	var screenWidth, screenHeight;
	var urlLength;
	
	screenWidth = 400;
	screenHeight = 400;
	left = 10
	top = 10
	
	urlLength = strUrl.length
	if(urlLength <= 0)	
	{        
     	return false;
	}
	else
	{
		strWindowProperties = "left="+left +",top="+top+",width="+screenWidth+",height="+screenHeight		
		strWindowProperties = strWindowProperties + ",status=yes," + "scrollbars=yes," + "location=no," + "menubar=no," + "resizable=yes"      
		window.open(strUrl,"OpenParamPopup",strWindowProperties)
		return true;
	}
}

function fnShowCalendar(strDateField)
{
	window.open("Calendar.aspx?strDateField="+strDateField,"Calendar","width=230,height=230,top=10,left=10");
}

 
/****************************************************************************
Method Name		:	fnGetMonth
Parameters		:	String
Return Type		:	int
Functionality		:	Accepts String month and convert the month with integer value.
					eg: jan with 01
Author			:	
Creation Date		:	12-12-2005
*****************************************************************************/

function fnGetMonth(strMonth)
{
	var l_intMonth;
	
	//alert(strMonth);
	switch(strMonth.toLowerCase())
	{
		case "jan":
			l_intMonth = 01;
			break;
		case "feb":
			l_intMonth = 02;
			break;
		case "mar":
			l_intMonth = 03;
			break;
		case "apr":
			l_intMonth = 04;
			break;
		case "may":
			l_intMonth = 05;
			break;
		case "jun":
			l_intMonth = 06;
			break;
		case "jul":
			l_intMonth = 07;
			break;
		case "aug":
			l_intMonth = 08;
			break;
		case "sep":
			l_intMonth = 09;
			break;
		case "oct":
			l_intMonth = 10;
			break;
		case "nov":
			l_intMonth = 11;
			break;
		case "dec":
			l_intMonth = 12;
			break;
		default:
			//alert("Invalid Month")
			l_intMonth = 0;						
	}	
	return l_intMonth;
}

 

/****************************************************************************
Method Name		:	fnCompareDate
Parameters		:	String (StartDate,EndDate)
Return Type		:	Boolean
Functionality		:	Accepts String 
Author			:	
Creation Date		:	12-12-2005
*****************************************************************************/
function fnCompareDate(strStartDate,strEndDate)
{
	strStartDate = fnTrim(strStartDate);
	strEndDate = fnTrim(strEndDate)

	var l_intStartDay
	var strStartMonth
	var l_intStartMonth
	var l_intStartYear

	var l_intEndDay
	var strEndMonth
	var l_intEndMonth
	var l_intEndYear

	l_intStartDay = strStartDate.charAt(0) + strStartDate.charAt(1)
	strStartMonth  = strStartDate.charAt(3) + strStartDate.charAt(4) + strStartDate.charAt(5)
	l_intStartYear = strStartDate.charAt(7) + strStartDate.charAt(8) + strStartDate.charAt(9) + strStartDate.charAt(10)


	l_intEndDay = strEndDate.charAt(0) + strEndDate.charAt(1)
	strEndMonth  = strEndDate.charAt(3) + strEndDate.charAt(4) + strEndDate.charAt(5)
	l_intEndYear = strEndDate.charAt(7) + strEndDate.charAt(8) + strEndDate.charAt(9) + strEndDate.charAt(10)
	
	l_intStartMonth = fnGetMonth(strStartMonth);
	if (l_intStartMonth == 0)
		return false;
	
	l_intEndMonth = fnGetMonth(strEndMonth);
	if (l_intEndMonth == 0)
		return false;

			
	
	if (l_intStartYear > l_intEndYear)
	{
		return false;
	}
	else if((l_intStartYear == l_intEndYear) && (l_intStartMonth > l_intEndMonth))
	{
		return false;
	}
	else if((l_intStartYear == l_intEndYear) && (l_intStartMonth == l_intEndMonth) && (l_intStartDay > l_intEndDay))
	{
		return false;
	}	
	else
	{
		return true;
	}
	
	
}


/****************************************************************************


/****************************************************************************
Method Name		:	fnEqualDate
Parameters		:	String (StartDate,EndDate)
Return Type		:	Boolean
Functionality		:	Compares the two dates and if they are equal return false else true.
Author			:	 
Creation Date		:	12-12-2005
*****************************************************************************/
function fnEqualDate(strStartDate,strEndDate)
{
	strStartDate = fnTrim(strStartDate);
	strEndDate = fnTrim(strEndDate)

	var l_intStartDay
	var strStartMonth
	var l_intStartMonth
	var l_intStartYear

	var l_intEndDay
	var strEndMonth
	var l_intEndMonth
	var l_intEndYear

	l_intStartDay = strStartDate.charAt(0) + strStartDate.charAt(1)
	strStartMonth  = strStartDate.charAt(3) + strStartDate.charAt(4)
	l_intStartYear = strStartDate.charAt(7) + strStartDate.charAt(8) + strStartDate.charAt(9) + strStartDate.charAt(10)


	l_intEndDay = strEndDate.charAt(0) + strEndDate.charAt(1)
	strEndMonth  = strEndDate.charAt(3) + strEndDate.charAt(4)
	l_intEndYear = strEndDate.charAt(7) + strEndDate.charAt(8) + strEndDate.charAt(9) + strEndDate.charAt(10)
	
	l_intStartMonth = strStartMonth;
	if (l_intStartMonth == 0)
		return false;
	
	l_intEndMonth = strEndMonth;
	if (l_intEndMonth == 0)
		return false;
			
	
	if((l_intStartYear == l_intEndYear) && (l_intStartMonth == l_intEndMonth) && (l_intStartDay == l_intEndDay))
	{
		return false;
	}
	else
	{
		return true;
	}	
	
}
/****************************************************************************


/****************************************************************************
Method Name		:	fnCPDate
Parameters		:	String (StartDate,EndDate)
Return Type		:	Boolean
Functionality		:	Accepts String 
Author			:	
Creation Date		:	12-12-2005
*****************************************************************************/
function fnCPDate(strStartDate,strEndDate)
{
	strStartDate = fnTrim(strStartDate);
	strEndDate = fnTrim(strEndDate)

	var l_intStartDay
	var strStartMonth
	var l_intStartMonth
	var l_intStartYear

	var l_intEndDay
	var strEndMonth
	var l_intEndMonth
	var l_intEndYear

	l_intStartDay = strStartDate.charAt(0) + strStartDate.charAt(1)
	l_intStartMonth  = strStartDate.charAt(3) + strStartDate.charAt(4) + strStartDate.charAt(5)
	l_intStartYear = strStartDate.charAt(7) + strStartDate.charAt(8) + strStartDate.charAt(9) + strStartDate.charAt(10)


	l_intEndDay = strEndDate.charAt(0) + strEndDate.charAt(1)
	l_intEndMonth= strEndDate.charAt(3) + strEndDate.charAt(4) + strEndDate.charAt(5)
	l_intEndYear = strEndDate.charAt(7) + strEndDate.charAt(8) + strEndDate.charAt(9) + strEndDate.charAt(10)
	
	
	if (l_intStartMonth == 0)
		return false;
	
	
	if (l_intEndMonth == 0)
		return false;

			
	
	if (l_intStartYear > l_intEndYear)
	{
		return false;
	}
	else if((l_intStartYear == l_intEndYear) && (l_intStartMonth > l_intEndMonth))
	{
		return false;
	}
	else if((l_intStartYear == l_intEndYear) && (l_intStartMonth == l_intEndMonth) && (l_intStartDay > l_intEndDay))
	{
		return false;
	}	
	else
	{
		return true;
	}
	
	
}


/****************************************************************************
Method Name             :           fnIsNumeric
Parameters		:           Integer Value
Return Type        	:           Boolean (True if Numeric and false if non numeric)
Functionality      	:           This method will return if the value passed
                                                            is a valid numeric value
                                                            Functions Used
                                                            1. fnTrim(strValue)
Author            	:            
Creation Date    	:           12-12-2005
*****************************************************************************/

function fnIsNumeric(control)

{
            if ((control.value == "")||(control.value == null))

            {
                        return true;
            }

            var regExp = /^[\-\+]{0,1}\d{0,100}\.{0,1}\d{1,100}$/
            var strTrimCtrlValue
           
            strTrimCtrlValue = fnTrim(control.value);   

            if (regExp.test(strTrimCtrlValue)) //Validate Integer

            {
                        if (parseInt(strTrimCtrlValue)<0)

                        {
                                   return false;
                        }

                        return true;

            }

            return false; 

}

/****************************************************************************
Method Name        :           fnIsNumeric
Parameters         :           Integer Value
Return Type        :           Boolean (True if Numeric and false if non numeric)
Functionality      :           This method will return if the value passed
				    is a valid numeric value
				    Functions Used
				    1. fnTrim(strValue)
Author            :            
Creation Date     :           12-12-2005
*****************************************************************************/

function fnIsNumericWithoutDec(control)

{
            if ((control.value == "")||(control.value == null))

            {
                        return true;
            }
            var regExp = /^[\-\+]{0,1}\d{0,100}\d{1,100}$/
            var strTrimCtrlValue
            //Remove leading and trailing spaces

            strTrimCtrlValue = fnTrim(control.value);   

            if (regExp.test(strTrimCtrlValue)) //Validate Integer

            {
                        if (parseInt(strTrimCtrlValue)<0)

                        {
                                    //Not postive

                                    return false;
                        }
                        return true;
            }

            return false; //Not a valid integer

}
 
/****************************************************************************
Method Name 		:       fnTrim
Parameters		:       String
Return Type 		:	String
Functionality		:	Accepts String and removes any leading and trailing spaces
Author			: 
Creation Date    :           01/11/2002  
*****************************************************************************/

function fnTrim1(strString)
{
            // white space consist of (blank,tab,newline)
            var intLeftIndex = 0; //Store position of first non-white space from leftmost side
            var intRightIndex = 0; //Store position of first non-white space from rightmost side
            var blnFound = false; //Check for any non-white space character
            var regExp = /\S+/; 
            var intCount;

            if (strString.search(regExp) == -1) //Check for non-white space character
            {
                        //Valid character not found then return empty string
                        strString = ""; 
                        return(strString);

            }

            //If  atleast one non-white space character found.
            for (intCount=0;intCount < strString.length; intCount++)

            {           // Checking for first non-white spaces from left side
                        if (strString.charAt(intCount) != " ") 

                        {
                                    intLeftIndex = intCount - 1;
                                    break;
                        }
            }

            for (intCount=strString.length - 1;intCount >= 0; intCount--)

            {
                        // Checking for first non-white spaces from Right most side
                        if (strString.charAt(intCount) != " ") 
                        {
                                    intRightIndex = intCount + 1;
                                    break;
                        }

            }           
            //Remove leading and trailing spaces
            strString=strString.substring(intLeftIndex+1,intRightIndex); 
            return (strString);

}
/****************************************************************************
Method Name		:	fnCPDateNew
Parameters		:	String (StartDate,EndDate)
Return Type		:	Boolean
Functionality		:	Accepts String 
Author			:	 
Creation Date		:	12-12-2005 
*****************************************************************************/
function fnCPDateNew(strStartDate,strEndDate)
{
	strStartDate = fnTrim(strStartDate)
	strEndDate = fnTrim(strEndDate)
	var dtStDt
	var dtEnddt
	
	stStDt = strStartDate.split("/")
	dtEnddt = strEndDate.split("/")
	
	var dtStartDate = new Date() 
	var dtEndDate = new Date()
	 
	dtStartDate.setMonth(stStDt[1]-1)			 
	dtStartDate.setFullYear(stStDt[2])
	dtStartDate.setDate(stStDt[0])				 
	 
	dtEndDate.setMonth(dtEnddt[1]-1)			 
	dtEndDate.setFullYear(dtEnddt[2])
	dtEndDate.setDate(dtEnddt[0])				 
	//alert(dtStartDate);
	//alert(dtEndDate);
	
	if (dtStartDate <= dtEndDate)
		{
		 	return true;
		}
	else
		{
			return false;
		}		
}
 
/****************************************************************************
Method Name		:	fnCompareDateCheck
Parameters		:	String (StartDate,EndDate)
Return Type		:	Boolean
Functionality		:	Accepts String 
Author			:	 
Creation Date		:	12-12-2005 
*****************************************************************************/
function fnCompareDateCheck(strStartDate,strEndDate)
{
	strStartDate = fnTrim(strStartDate)
	strEndDate = fnTrim(strEndDate)
	var dtStDt
	var dtEnddt
	
	stStDt = strStartDate.split("/")
	dtEnddt = strEndDate.split("/")
	
	var dtStartDate = new Date() 
	var dtEndDate = new Date()
		
	var intMonth1 = new Number();
    var intMonth2 = new Number();        
    intMonth1 = stStDt[1].toString();
    intMonth2 = dtEnddt[1].toString();
    intMonth1 = intMonth1 - 1;
    intMonth2 = intMonth2 - 1;
	
	dtStartDate.setFullYear(stStDt[2].toString(), intMonth1, stStDt[0].toString());
	dtEndDate.setFullYear(dtEnddt[2].toString(), intMonth2, dtEnddt[0].toString());
		
	if (dtStartDate < dtEndDate)
		{
		 	return false;
		}
	else
		{
			return true;
		}		
}
 
/****************************************************************************
Method Name		:	fnDatediff
Parameters		:	String (StartDate,EndDate,strComparisonType)
Return Type		:	Boolean
Functionality	:	Accepts two dates to compare in mm/dd/yyyy format 
                    and strComparisonType String 
                    valid values are 'equal' (default), 'greater', 'smaller' 
Author			:	 
Creation Date		:	12-12-2005 
*****************************************************************************/

 
 function fnDatediff(strDate1, strDate2, strComparisonType)
{ 

    var _d1 = new Date(strDate1.substring(3,5) + '/'  + strDate1.substring(0,2)+ '/'  + strDate1.substring(6,10) );
    var _d2 = new Date(strDate2.substring(3,5) + '/'  + strDate2.substring(0,2)+ '/'  + strDate2.substring(6,10) );
  
 /*
	var _d1 = new Date();
	_d1.setMonth(strDate1.substring(3,5))
	_d1.setDate(strDate1.substring(0,2))
	_d1.setYear(strDate1.substring(6,10)) 
	var _d2 = new Date();
	_d2.setMonth(strDate2.substring(3,5))
	_d2.setDate(strDate2.substring(0,2))
	_d2.setYear(strDate2.substring(6,10)) 
     alert(strDate1 + ' ' + strDate2);
 	alert(strDate1.substring(3,5) + ' m1 ' )
	alert(strDate1.substring(0,2)+ ' d1 ' )
	alert(strDate1.substring(6,10)+ ' y1 ' ) 
	alert(strDate2.substring(3,5)+ ' m2' )
	alert(strDate2.substring(0,2)+ ' d2 ' )
	alert(strDate2.substring(6,10)+ ' y2 ' ) 	
     alert(_d1 + ' ' + _d2);
 */
 
    //var dayDiff = fnDaydiff(_d1,_d2);
    if (strComparisonType =='smaller')
	var dayDiff = fnDaydiff(_d1,_d2);	
	
	//var dayDiff = fnDaydiff(_d2,_d1);
	if (strComparisonType =='greater')
    var dayDiff = fnDaydiff(_d2,_d1);
     

//   alert(dayDiff);
    
    
        if (dayDiff < 0 )
	    {    
		    return false ;
        } 
	    
	    return true;
 
}

/****************************************************************************
Method Name		:	fnDaydiff
Parameters		:	String (StartDate,EndDate)
Return Type		:	Integer
Functionality	:	Accepts two dates to compare in mm/dd/yyyy format  
Author			:	 
Creation Date		:	12-12-2005 
*****************************************************************************/
function fnDaydiff(_v1,_v2) 
{
	var _delta = 0;
	var _a1 = _v1;
	var _a2 = _v2;
	//if (_v1.getTime()<_v2.getTime()) 
	//{
		_a1 = _v2;
		_a2 = _v1;
	//} 
	 
	_delta = _a1.getTime() - _a2.getTime();  
	 
	_delta /= (1000 * 60 * 60 * 24); 
 
return _delta;

}
/*****************************************************************************/

/*----AJEX Code----*/
var strCurrentOperation = "";
var arrFillComboName = new Array();  
    
/*************************************************************
 * Function         : AjaxComboChanged(control,strFillComboName,ClassName)
 * Purpose          : This function will use with on change event of combo. 
                      It will call the Code behind method PopulateCombo using the page class name. 
                      Ajax component library will take care of calling the code behind method 
                      and the method will returns the array list of data table collection 
                      with callback response object. This will automatically call the 
                      LoadCombo_CallBack function that will handle the array list and fill the 
                      combo with data table collections.
 * Input Parameters : control           : The Selected Combo/Drop Downlist Control. 
                      strFillComboName  : Collection of combo name with coma seperated for filling the values.
                      ClassName         : Your Ajax registerd class name without any quote.
 * Retrun           : Return ArrayList, which is DataTable Collection.
                      Return with CallBack response or calling LoadCombo_CallBack(response) function.
 * How to Call [E.g]:
            Call on Combo onchange event: 
            onchange="javascript: AjaxComboChanged(this,'cboClient',ImpactReports_WarehouseMovement);"
            onchange="javascript: AjaxComboChanged(this,'cboBillingGroup,cboItemCategory',ImpactReports_WarehouseMovement);"
/*************************************************************/                   
function AjaxComboChanged(control,strFillComboName,ClassName)
{
        //alert("ClassName");
        //alert(ClassName);
    arrFillComboName = strFillComboName.split(",");               
    strCurrentOperation = control.id + "_Change";                
    var strSelectedComboValue = control.options[control.selectedIndex].value;                
    
    //[007]start
    if(strFillComboName == "cboUserGroup" && fnTrim(strSelectedComboValue) == "")
    {
        strSelectedComboValue = "all";
    }
    //[007]end
    if (fnTrim(strSelectedComboValue) != "")
    {   
        //Class Name is defined by Ajax.Net because that's the name of the type we registered
        ClassName.PopulateCombo(strFillComboName, strSelectedComboValue, strCurrentOperation, LoadCombo_CallBack);        
    }   
    if (fnTrim(strSelectedComboValue) == "" || fnTrim(strSelectedComboValue) == '0' ||  strSelectedComboValue.toUpperCase  == "NONE"  )
    {   
        for(var arrIndex = 0; arrIndex < arrFillComboName.length; arrIndex++)
	    { 
            if ( document.getElementById(arrFillComboName[arrIndex])!=null) 
            { 
                var targetCombo = document.getElementById(arrFillComboName[arrIndex]);
                targetCombo.options.length = 0;                
                targetCombo.options[0]= new Option('None',''); 
            }       
        }
    }
}
//[004]
function AjaxComboChanged_New(control, strFillComboName, strParam, ClassName)
{
        //alert("ClassName");
        //alert(ClassName);
    arrFillComboName = strFillComboName.split(",");               
    strCurrentOperation = control.id + "_Change";                
    var strSelectedComboValue = control.options[control.selectedIndex].value;                
    
    if (fnTrim(strSelectedComboValue) != "")
    {   
        //Class Name is defined by Ajax.Net because that's the name of the type we registered
        ClassName.PopulateCombo_New(strFillComboName, strSelectedComboValue, strCurrentOperation, strParam, LoadCombo_CallBack);        
    }   
    if (fnTrim(strSelectedComboValue) == "" || fnTrim(strSelectedComboValue) == '0' ||  strSelectedComboValue.toUpperCase  == "NONE"  )
    {   
        for(var arrIndex = 0; arrIndex < arrFillComboName.length; arrIndex++)
	    { 
            if ( document.getElementById(arrFillComboName[arrIndex])!=null) 
            { 
                var targetCombo = document.getElementById(arrFillComboName[arrIndex]);
                targetCombo.options.length = 0;                
                targetCombo.options[0]= new Option('None',''); 
            }       
        }
    }
}
//[004]
/*************************************************************
 * Function         : LoadCombo_CallBack(response)
 * Purpose          : Using callback Ajax.Net pass the response. This function is Called from AjaxComboChanged function.
                      The function will handle the array list and fill the combo with data table collections.                      
 * Input Parameters : response (ArrayList of DataTable Collection.)
 * Retrun           : Fill the Given Combo.
/*************************************************************/                   
function LoadCombo_CallBack(response)
{
    //alert("1");    
    var cboControl = null; 
    for(var arrIndex = 0; arrIndex < arrFillComboName.length; arrIndex++)
	{ 
	    //alert(strCurrentOperation);
	    //alert(arrFillComboName[arrIndex]);
        if (arrFillComboName[arrIndex] != "")
        {          
            cboControl = eval('document.forms[0]["'+arrFillComboName[arrIndex]+'"]');
        }
            //alert(cboControl);                
        if (cboControl == null)
        {
            //alert("The Control Name is not Correct.");        
            return;
        }    
            //alert(cboControl);                
        //if the server side code threw an exception
        if (response.error != null)
        {    
            alert(response.error); //we should probably do better than this
            return;
        }  
        
        var drCboResponse = response.value; 
            //alert(drCboResponse);
        drCboResponse = drCboResponse[arrIndex]; 
            //alert(drCboResponse);               
        //if the response wasn't what we expected  
        if (drCboResponse == null || typeof(drCboResponse) != "object")
        {
            return;  
        }     
        cboControl.options.length = 0; //reset the  dropdown     
        //note that this is JavaScript casing and the L in length is lowercase for arrays                
        
        var intLength = drCboResponse.Rows.length;
        cboControl.options[cboControl.options.length] = new Option("None", "");
            //alert(drCboResponse.Rows.length);
        for (var i = 0; i < drCboResponse.Rows.length; ++i)
        {  
           cboControl.options[cboControl.options.length] = new Option(drCboResponse.Rows[i].AjaxColumn1, drCboResponse.Rows[i].AjaxColumn0);
        }
    }    
}

    
/*************************************************************
 * Function         : AjaxClientValidation()
 * Purpose          : This function will be used on page submit to validate page values
 * Input Parameters : none
 * Return           : Return nothing. 
 * How to Call [E.g]:
            Call on Form Submit: 
            onchange="javascript: AjaxComboChanged();" 
/*************************************************************/                   
function AjaxClientValidation(obj,ClassName,Validate_CallBack)
{           
        //Class Name is defined by Ajax.Net because that's the name of the type we registered
        ClassName.AjaxClientValidation(obj);        
}
function Validate_CallBack(response)
{
    //alert("1");    
}

function ToggleDisplay(div,iframe,objpos,pos)
{   
    var t=0;
    var l=0;
    var state=false;    
    var cNode = document.getElementById(objpos);
    while(cNode.tagName!='BODY'){ 
        l+=cNode.offsetLeft; 
        t+=cNode.offsetTop; 
        cNode=cNode.offsetParent; 
    }

    var DivRef = document.getElementById(div);
    var IfrRef = document.getElementById(iframe);
    var ObjPos = document.getElementById(objpos); 
    if (ObjPos.options.value == null || ObjPos.options.value == '')
    return false	;	

    //lblName.value=frmPDAEntry.cmbItemName.options[frmPDAEntry.cmbItemName.selectedIndex].text;
    lblName.innerText ="";
    lblName.innerText =" " + ObjPos.options[ObjPos.selectedIndex].text;
    var strComboValue = new String()
    strComboValue = lblName.innerText;

    if (DivRef.style.display=="none") {
        state=true;
    } else {
        state=false;
    }

    if(state)
    {        
        DivRef.style.display = "block";
        //IfrRef.style.width = DivRef.offsetWidth;
        //IfrRef.style.height = DivRef.offsetHeight;        
        //IfrRef.style.width = 300;
        IfrRef.style.width = strComboValue.length * 6.4;
        IfrRef.style.height =15;
        IfrRef.style.valign="middle";
            DivRef.style.valign="middle";

    switch (pos) {
        case "left": 
            DivRef.style.top = t;
            DivRef.style.left = (l-ObjPos.offsetWidth);
            IfrRef.style.top = t;
            IfrRef.style.left = (l-ObjPos.offsetWidth);
        break;
        case "right": 
            DivRef.style.top = t;
            DivRef.style.left = (l+ObjPos.offsetWidth);
            IfrRef.style.top = t;
            IfrRef.style.left = (l+ObjPos.offsetWidth);
            break;
        case "bottom": 
            DivRef.style.top = (t+ObjPos.offsetHeight);
            DivRef.style.left = l;
            IfrRef.style.top = (t+ObjPos.offsetHeight);
            IfrRef.style.left = l;
            break;
        case "top": 
            DivRef.style.top = (t-ObjPos.offsetHeight);
            DivRef.style.left = l;
            IfrRef.style.top = (t-ObjPos.offsetHeight);
            IfrRef.style.left = l;
            break;
        }


    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
    IfrRef.style.display = "block";
    DivRef.style.backgroundColor = "#516999";
    IfrRef.style.backgroundColor = "#516999";
    }
    else
    {
        DivRef.style.display = "none";
        IfrRef.style.display = "none";
    }

}	

function Export()
{
    document.forms[0].hdnOperation.value='SEARCH';
    
    var strAction = new String();
    strAction = document.forms[0].action;
    
    if (strAction.indexOf("?",0) == -1)
        document.forms[0].action= screenname + "?hdnExportCSV=Y";
    else
    {
        if (strAction.indexOf("hdnExportCSV",0)==-1)
            document.forms[0].action = strAction + "&hdnExportCSV=Y";
    }
    
    document.forms[0].submit();
}

function sub_days(adate,days) 
{
    return new Date(adate.getTime() - (days * 86400000));
}
function format_date(adate) 
{
    return adate.getDate() + '/' + (adate.getMonth()+1) + '/' + y2k(adate.getYear());
}
function y2k(number) 
{ 
    return (number < 1000) ? number + 1900 : number; 
}

function setFocus()
{       
	for(i=0;i<document.forms[0].length;i++)
	{
	    //if (document.forms[0].elements[i].name!='__VIEWSTATE')
	        //alert(document.forms[0].elements[i].id);
	    //status=typeof(document.forms[0].elements[i].type);

		if((document.forms[0].elements[i].type=="text") || (document.forms[0].elements[i].type=="select-one")) 
		{
//		    alert(document.forms[0].elements[i].id)
//		    alert(document.forms[0].elements[i].disabled)
//		    alert(document.forms[0].elements[i].readOnly)
		    
			if ((!document.forms[0].elements[i].disabled) && (!document.forms[0].elements[i].readOnly))// && (document.forms[0].elements[i].name!='__VIEWSTATE'))
			{
			    //status = status + ":" + document.forms[0].elements[i].name;
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}

}
/*************************************************************
 * Function         : ValidateExtension()
 * Purpose          : This function will be used to check if the file extension in 
                      fileUpload Control is one of the extensions provided in extArray
 * Input Parameters : 1. file (i.e. the file Upload Contorl)
                      2. extArray (A string array of the extensions to be checked)
 * Return           : Return true or false. 
 * How to Call [E.g]:
            extArray = new Array(".gif", ".jpg", ".jpeg", ".png");
            
            var isValidExtension=ValidateExtension(fileUploadCtrl, extArray);
/*************************************************************/                
//[010]start
/*
function ValidateExtension(file, extArray)
    {
    hasCorrectExtension = false;
    if (!file) return;
    while (file.indexOf("\\") != -1)
    { 
    file = file.slice(file.indexOf("\\") + 1);
    ext = file.slice(file.indexOf(".")).toLowerCase();
    
    }
    for (var i = 0; i < extArray.length; i++) 
    {
    if (extArray[i] == ext) 
    { 
        hasCorrectExtension = true; 
        break; 
    }
    }
    if(hasCorrectExtension==true)
    {
        return true;
    }
    else
    {
        return false;
    }
}
*/
function ValidateExtension(file, extArray)
{
    hasCorrectExtension = false;
    if (!file) return;
    
    if(file.indexOf("\\") != -1)
    {  
        while (file.indexOf("\\") != -1)
        { 
        file = file.slice(file.indexOf("\\") + 1);
        ext = file.slice(file.indexOf(".")).toLowerCase();
        }
    }
    else
    {
        ext = file.slice(file.indexOf(".")).toLowerCase(); 
    }   
    
    for (var i = 0; i < extArray.length; i++) 
    {
        if (extArray[i] == ext) 
        { 
            hasCorrectExtension = true; 
            break; 
        }
    }
    if(hasCorrectExtension==true)
    {
        return true;       
    }
    else
    {
        return false;
    }
}
//[010]end        
/*------------------------*/
//[003]
//Remove non consecutive duplicate words 

function removeDuplicates(field,delimiter)
{
    var strValue =  field.value;
    var arrValue = strValue.split(delimiter);
    var arrNewValue = [];
    var seenValue = {};
    
    for(var i=0;i<arrValue.length;i++) 
    {
        if (!seenValue[arrValue[i]]) 
        {
            seenValue[arrValue[i]]=true;
            arrNewValue.push(arrValue[i]);
        }
    }
    field.value = arrNewValue.join(delimiter);
}

function FNArrayGetSearchLinearRowI( searchS, arraySA ) 
{
     var I = 0;
     var minI = 0;
     var maxI = arraySA.length - 1;
     var s = "";     
     var foundB = false;
     
     I = minI - 1;
     while ( ( I <= maxI ) && ( !( foundB ) ) ) 
     {
      I = I + 1;
      s = arraySA[ I ];
      foundB = ( searchS == s );
     }
     
     if ( foundB ) 
     {
      return( I );
     }
     else 
     {
      return( -1 ); //indicating not found
     }
}

 //[003]
 
//[008]start 
//This function called from Item Detail screen, Warehouse Inventory Report, Warehouse Movement Report and Stock By Location Report.
function fnIsCoPackClient(strValue,ClassName)
{        
    ClassName.IsCoPackClient(strValue,LoadCoPack_CallBack);  
}        
function LoadCoPack_CallBack(response)
{   
    //if the server side code threw an exception
    if (response.error != null)
    {    
        alert(response.error); 
        return;
    }          
    m_IsCoPackClient = response.value.toString();
    
    if(m_IsCoPackClient =="Yes")
    {   
         document.getElementById("tr_PackMaterial").style.display = 'block';
         document.getElementById("hdnIsPackMaterial").value = 'Yes';                  
    }
    else
    {
         document.getElementById("tr_PackMaterial").style.display = 'none';             
         document.getElementById("hdnIsPackMaterial").value = 'No';
    }
}        
//[008]end
//[009]start
    function fnRemoveSpaces(strString)
    {
        var strSelectedItems = new String();
        var arrItem = new Array(); 
        arrItem = strString.split(",");
        if (arrItem.length > 1)
        {
            for (var i=0; i<arrItem.length; i++)
            {         
                if(i==0)
                {
                    strString = fnTrim(arrItem[i]);
                }
                else
                {
                    strString = strString + ',' + fnTrim(arrItem[i]);                     
                }                                        
            }            
        }
        return (strString);
    }
//[009]end