var post_state;
var bolEmpty = 1;
var sStringLeft = "";
var sStringRight = "";
var intCustomRow = 0;
var strTemplateIndex = "";
var strRowId = 0;
var rowWritten = 0;
var intFields = 0;
var intActiveID = 0;
var intPageNumber = 0;
var intTYCBalance = 0;
var intNNBalance = 0;
var intTYCChecked = 0;
var intNNChecked = 0;
var intPromoChecked = 0;
//intActiveID = Current customer ID being updated
var intUpdate = 0;
//intUpdate = 0 means a save operation can occur. If it is a number greater than 0, an update operation is occurring.

//img.prototype.oheight=null;
//img.prototype.owidth=null;

function GetXmlHttpObject(handler){

            var objXmlHttp=null; 

            if (navigator.userAgent.indexOf("Opera") >= 0)
            {
                        alert("This example doesn't work in Opera");
                        return;
            }

            if (navigator.userAgent.indexOf("MSIE") >= 0)
            {
                        var strName="Msxml2.XMLHTTP";
                        if(navigator.appVersion.indexOf("MSIE 5.5") >= 0)
                        {
                                    strName = "Microsoft.XMLHTTP"
                        }
                        try
                        {
                                    objXmlHttp = new ActiveXObject(strName);
                                    objXmlHttp.onreadystatechange = handler;
                                    return objXmlHttp;
                        }
                        catch(e)
                        {
                                    alert("Error. Scripting for ActiveX might be disabled");
                                    return;
                        }
            }
            if (navigator.userAgent.indexOf("Mozilla") >= 0)
            {
                        objXmlHttp = new XMLHttpRequest();
                        objXmlHttp.onload = handler;
                        objXmlHttp.onerror = handler;
                        return objXmlHttp;
            }
}
 
// All functions will return a string separated by | (pipe) characters. The first three (indices 0 thru 2) are standard, and contain the info we need to look for
//and act upon. arResults[0] = activity identifier; arResults[1] = condition (True/False); arResults[2] = info the activity needs to continue. Further indices are optional

function post_state_changed()
{  
            var arResults = new Array();
            if(post_state.readyState == 4 || post_state.readyState == "complete") {                   
             arResults = post_state.responseText.split("|");   
             //alert( post_state.responseText);    

         //This starts the area where we look for feedback from the posts up to the server   
         //Adding corrected records to the iif file...
           if (arResults[0] == 'writeRecordtoFile' && arResults[1] == "True"){            
               rowWritten = 1;           
             }
             if (arResults[0] == 'writeRecordtoFile' && arResults[1] == "False"){
               alert("An error occurred processing your import. Please contact the Advantage helpdesk for assistance. Thank you.");               
             }          

                // update pending Reminders 
               if (arResults[0] == 'getRCount' && arResults[1] == "True"){                   
               //alert(arResults[2]);                     
               //document.getElementById("reminder1").innerHTML="<B>Approve "+arResults[2]+" pending Reminders</B>";
               document.getElementById("reminder2").innerHTML="<B>Approve "+arResults[2]+" pending Reminders</B>";
              }   

	     // getTYCCount 
               if (arResults[0] == 'getTYCCount' && arResults[1] == "True"){    
               //alert(arResults[3]);                     
               intTYCChecked = arResults[3];
              }    

	     // getNNCount 
               if (arResults[0] == 'getNNCount' && arResults[1] == "True"){      
               //alert(arResults[4]);      
               intNNChecked = arResults[4];
              }   

	     // getPromoCount 
               if (arResults[0] == 'getPromoCount' && arResults[1] == "True"){      
               //alert(arResults[4]);      
               intPromoChecked = arResults[4];
              }   
 
         // getTYCBalance    
               if (arResults[0] == 'getTYCBalance' && arResults[1] == "True"){            
               document.getElementById("1_tyc_lpagedlr").innerHTML = "<strong>You may send up to <font color=\"blue\">" + arResults[2] + "</font> Thank You cards.</strong>";             
              }

         // getNNBalance    
             if (arResults[0] == 'getNNBalance' && arResults[1] == "True"){            
               document.getElementById("1_nn_lpagedlr").innerHTML = "<strong>You may send up to <font color=\"blue\">" + arResults[2] + "</font>  Neighbor Network cards.</strong>"; 
              }

         // getRemBalance    
             if (arResults[0] == 'getRemBalance' && arResults[1] == "True"){            
               document.getElementById("1_rm_lpagedlr").innerHTML = "<strong>You may send up to <font color=\"blue\">" + arResults[2] + "</font> Reminder cards.</strong>";    
              }

         // getPromoBalance    
             if (arResults[0] == 'getPromoBalance' && arResults[1] == "True"){     
             //alert(arResults[2]);       
               if( document.getElementById("1_promo_lpagedlr")){
               document.getElementById("1_promo_lpagedlr").innerHTML = "<strong>You may send up to <font color=\"blue\">" + arResults[2] + "</font> Promo cards.</strong>";  
                }
              }
 
         // Login    
             if (arResults[0] == 'Login' && arResults[1] == "True"){            
               location.href = arResults[2];             
             }
             if (arResults[0] == 'Login' && arResults[1] == "False"){
               alert("The userid and/or password does not match any of our records. Please try again.");
               document.getElementById("userid").focus();
             }               
            
            // LoginClient    
             if (arResults[0] == 'LoginClient' && arResults[1] == "True"){            
               location.href = arResults[2];             
             }
             if (arResults[0] == 'LoginClient' && arResults[1] == "False"){
               alert("The userid and/or password does not match any of our records. Please try again.");
               document.getElementById("userid").focus();
             }        
          
              // showDlrLogo   
             if (arResults[0] == 'showDlrLogo' && arResults[1] == "True"){           
               document.getElementById("divLogoMessage").innerHTML = "";   
               document.getElementById("divLogoMessage").innerHTML = arResults[2];             
             }
             if (arResults[0] == 'showDlrLogo' && arResults[1] == "False"){
               alert("A problem occurred updating the dealer logo status.");               
             }           

             // deleteDlrLogo   
             if (arResults[0] == 'deleteDlrLogo' && arResults[1] == "True"){
               ajaxcalls("showDlrLogo");              
             }  
             if (arResults[0] == 'deleteDlrLogo' && arResults[1] == "False"){
               alert("A problem occurred deleting your current logo file. The file was not removed.");               
             }     


         //Loads up the "ThankYouCards" select box on the thankyou.asp page
            if (arResults[0] == "Thank You Cards" && arResults[1] == "True"){  	
            //alert(arResults[2]);
             document.getElementById("ThankYouCards").options[0].text = "--Select Thank You Card Type--";
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as text value::id of template in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");   
                // alert(s.substr(0,ind));           
                 document.getElementById("ThankYouCards").options[document.getElementById("ThankYouCards").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);                
              }                                  
             } 

              //Loads up the "NN" select box on the thankyou.asp page
            if (arResults[0] == "NN Cards" && arResults[1] == "True"){  	
             document.getElementById("NN").options[0].text = "--Select Neighbor Network Card Type--";
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as text value::id of template in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");   
                // alert(s.substr(0,ind));           
                 document.getElementById("NN").options[document.getElementById("NN").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);                
              }                                  
             } 

             if (arResults[0] == 'NN Cards' && arResults[1] == "False"){
               document.getElementById("NN").option[0].text = "--Sorry No Neighbor Network Cards Available--";
             }     

      /*         //Loads up the "MR" select box on the thankyou.asp page
            if (arResults[0] == "MR Cards" && arResults[1] == "True"){  
             document.getElementById("MR").options.length = 0;
             document.getElementById("MR").options[0].text = "--Select Reminder Card Type--";
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as text value::id of template in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");   
                // alert(s.substr(0,ind));           
                 document.getElementById("MR").options[document.getElementById("MR").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);                
              }                                  
             } 

             if (arResults[0] == 'MR Cards' && arResults[1] == "False"){
               document.getElementById("MR").option[0].text = "--Sorry No Reminder Cards Available--";
             }     */
                                     



             //fills Option Select 
            if (arResults[0] == 'Option1' && arResults[1] == "True"){    
               document.getElementById("Option1").options[0].text = "--"+arResults[2]+" graphics loaded in Option 1--";
               document.getElementById("Option1").options[0].value = 1;               
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as filepath::description of option graphic in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");          
                //alert("text="+s.substr(ind +2)+" value="+s.substr(0,ind));
                document.getElementById("Option1").options[document.getElementById("Option1").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);    
                document.getElementById("imgoption1").className="drag";                                     
              }                                  
             }
            if (arResults[0] == 'Option1' && arResults[1] == "False"){  
               document.getElementById("imgoption1").className="";    
               //Nothing to do...              
             }     


              //fills Option Select 
            if (arResults[0] == 'Option2' && arResults[1] == "True"){  
               document.getElementById("Option2").options[0].text = "--"+arResults[2]+" graphics loaded in Option 2--";
               document.getElementById("Option2").options[0].value = 1;
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as filepath::description of option graphic in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");                            
                document.getElementById("Option2").options[document.getElementById("Option2").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);      
	  document.getElementById("imgoption2").className="drag";                              
              }                                  
             }
            if (arResults[0] == 'Option2' && arResults[1] == "False"){  
               document.getElementById("imgoption2").className="";    
               //Nothing to do..             
             }     



              //fills Option Select 
            if (arResults[0] == 'Option3' && arResults[1] == "True"){  
               document.getElementById("Option3").options[0].text = "--"+arResults[2]+" graphics loaded in Option 3--";
               document.getElementById("Option3").options[0].value = 1;
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as filepath::description of option graphic in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");                            
                document.getElementById("Option3").options[document.getElementById("Option3").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);      
                document.getElementById("imgoption3").className="drag";                             
              }                                  
             }
            if (arResults[0] == 'Option3' && arResults[1] == "False"){  
               document.getElementById("imgoption3").className="";    
               //Nothing to do...              
             }     


              //fills Option Select 
            if (arResults[0] == 'Option4' && arResults[1] == "True"){  
               document.getElementById("Option4").options[0].text = "--"+arResults[2]+" graphics loaded in Option 4--";
               document.getElementById("Option4").options[0].value = 1;
             for ( i = 1; i <= arResults[2]; i++ )
              {
               //The returned string is set up as filepath::description of option graphic in featureData table...
               var s = "";
                s = arResults[i+2];                         
               var ind = 0;
                ind = s.indexOf("::");                            
                document.getElementById("Option4").options[document.getElementById("Option4").options.length] = new Option(s.substr(ind +2),s.substr(0,ind),false,false);   
                document.getElementById("imgoption4").className="drag";                                       
              }                                  
             }
            if (arResults[0] == 'Option4' && arResults[1] == "False"){  
                document.getElementById("imgoption4").className="";    
               //Nothing to do...              
             }     


            //template for ajax based activities...copy this first - don't overwrite this
            if (arResults[0] == 'ChangeTemplate' && arResults[1] == "True"){  
              //Do stuff..
             setTimeout("ajaxcalls('Option1')",1000);
             setTimeout("ajaxcalls('Option2')",2000);
             setTimeout("ajaxcalls('Option3')",3000);
             setTimeout("ajaxcalls('Option4')",4000);
             }
            if (arResults[0] == '[something]' && arResults[1] == "False"){  
               //Do other stuff..
             }     


            //template for ajax based activities...copy this first - don't overwrite this
            if (arResults[0] == 'RemoveTemplate' && arResults[1] == "True"){                
               if (arResults[2] =="t"){
              location.href="thankyouadmin.asp";}
              if (arResults[2] =="n"){
              location.href="nnadmin.asp";}       
              if (arResults[2] =="r"){
              location.href="mradmin.asp";}        
             }
            if (arResults[0] == 'RemoveTemplate' && arResults[1] == "False"){  
               //Do other stuff...like nothing
             }     

            // Queue Up ad    
             if (arResults[0] == 'QueueUpTYC' && arResults[1] == "True"){  
               document.getElementById("loading").style.display="none";          
               alert("Thank You card saved successfully!");                  
               window.close();        
             }
             if (arResults[0] == 'QueueUpTYC' && arResults[1] == "False"){
               document.getElementById("loading").style.display="none";  
               alert("A technical problem has occurred. The system has alerted the system administrator. Sorry for the inconvenience!");               
             }     

             // Queue Up ad    
             if (arResults[0] == 'QueueUpNN' && arResults[1] == "True"){     
               document.getElementById("loading").style.display="none";                
               window.close();        
             }
             if (arResults[0] == 'QueueUpNN' && arResults[1] == "False"){
               document.getElementById("loading").style.display="none";  
               alert("A technical problem has occurred. The system has alerted the system administrator. Sorry for the inconvenience!");               
             }     

             // Queue Up ad    
             if (arResults[0] == 'QueueUpMR' && arResults[1] == "True"){           
               document.getElementById("loading").style.display="none";                  
               window.close();        
             }
             if (arResults[0] == 'QueueUpMR' && arResults[1] == "False"){
               document.getElementById("loading").style.display="none";  
               alert("A technical problem has occurred. The system has alerted the system administrator. Sorry for the inconvenience!");               
             }     

            // Queue Up ad    
            if (arResults[0] == 'QueueUpPromo' && arResults[1] == "True"){  
               document.getElementById("loading").style.display="none";          
               alert("Promo card saved successfully!");                  
               window.close();        
             }
             if (arResults[0] == 'QueueUpPromo' && arResults[1] == "False"){
               document.getElementById("loading").style.display="none";  
               alert("A technical problem has occurred. The system has alerted the system administrator. Sorry for the inconvenience!");               
             }     


             //Get user data 
            if (arResults[0] == 'getUserInfo' && arResults[1] == "True"){      
             //alert(arResults[2]);         
             document.getElementById("divClient").innerHTML = "";           
             document.getElementById("divClient").innerHTML = arResults[2];     
             document.getElementById("divClient").style.display="block";                          
             }
            if (arResults[0] == 'getUserInfo' && arResults[1] == "False"){  
               alert("A technical problem has occurred. We apologize for the inconvenience. Please come back later and try again.");
             }     

                // tycUncheckAll    
             if (arResults[0] == 'tycUncheckAll' && arResults[1] == "True"){              
                 if(arResults[2] == 'cl') {                    
                    ajaxcalls('CustomerList&page=1');
                 }
                if(arResults[2] == 'ty') {
                    ajaxcalls('TYCCustomerList&page=1');            
                 }
                if(arResults[2] != 'cl' && arResults[2] != 'ty') {
                    ajaxcalls('NNCustomerList2&page=1');            
                 }
           
             }

             if (arResults[0] == 'tycUncheckAll' && arResults[1] == "False"){
                  ajaxcalls('NNCustomerList2&page=1');
             } 

                // tycCheckAll    
             if (arResults[0] == 'tycCheckAll' && arResults[1] == "True"){                
               if(arResults[2] == 'cl') {                    
                    ajaxcalls('CustomerList&page=1');
                 }
                if(arResults[2] == 'ty') {
                    ajaxcalls('TYCCustomerList&page=1');            
                 }
                if(arResults[2] != 'cl' && arResults[2] != 'ty') {
                    ajaxcalls('NNCustomerList2&page=1');            
                 }

             }

             if (arResults[0] == 'tycCheckAll' && arResults[1] == "False"){
                  ajaxcalls('NNCustomerList2&page=1');
             } 

                // promoUncheckAll    
             if (arResults[0] == 'promoUncheckAll' && arResults[1] == "True"){               
                  ajaxcalls('PromoCustomerList&page=1');                  
             }

             if (arResults[0] == 'promoUncheckAll' && arResults[1] == "False"){
                  ajaxcalls('PromoCustomerList&page=1');
             } 

                // promoCheckAll    
             if (arResults[0] == 'promoCheckAll' && arResults[1] == "True"){               
                  ajaxcalls('PromoCustomerList&page=1');                  
             }

             if (arResults[0] == 'promoCheckAll' && arResults[1] == "False"){
                  ajaxcalls('PromoCustomerList&page=1');
             } 

               //Get user data 
            if (arResults[0] == 'updateClient' && arResults[1] == "True"){         
               alert("Your profile has been updated!");        
               ajaxcalls('getUserInfo');          
             }
            if (arResults[0] == 'updateClient' && arResults[1] == "False"){  
               alert("A technical problem has occurred that should never happen.\nWe are pretty sure this means the machines have taken over,\n and we are all toast!");
             }     

        /*  //update customer data
            if (arResults[0] == 'UpdateCustomer' && (arResults[1] == 'True')){             
             alert("The address you entered may have been modified to match what the US Postal Service has on record. \nThe modified address will include Zip+4 zip code.");
             //document.getElementById("divCustomers").style.display="block";
             //document.getElementById("divCustomers").innerHTML = "";
             //alert(arResults.length);
             if(arResults.length > 4){
             document.getElementById("divCustomers").innerHTML = arResults[4]; 
             document.getElementById("divCustomer").innerHTML = arResults[5]; 
             document.getElementById("divCustomer").style.display="none"; 
             document.getElementById("content").style.display="block";
             document.getElementById("divCustomers").style.display="block"; 
             } else {             
             document.getElementById("divCustomers").innerHTML = arResults[2]; 
             document.getElementById("divCustomer").innerHTML = arResults[3]; 
             document.getElementById("divCustomer").style.display="none";
             document.getElementById("content").style.display="block";
             document.getElementById("divCustomers").style.display="block";
              }                               
             }

            if (arResults[0] == 'UpdateCustomer' && (arResults[1] == 'False' || arResults[1] == 'Canada')){   
               if(arResults[1] == 'False'){
               alert("Your customer's address could not be verified by the United States Postal Service. The address has been added to your customer list, but you will be unable to send Neighbor Network cards from this address until it can be verified.\n\n Please note: Each time an address is added to the system or updated, the system tries to verify it with the USPS to make sure it is correct. This reduces the chance that the post card will be returned as 'undeliverable'. When time permits, please correct this address in order to permit it to be verified.");  
               }
               //document.getElementById("divCustomers").style.display="block";                
               //document.getElementById("divCustomers").innerHTML = "";
               //alert(arResults.length);
               if(arResults.length > 4){
               alert("Your customer's address could not be verified by the AdVantage Address database. The address has been added to your customer list, but you will be unable to send Neighbor Network cards from this address until it can be verified.\n\n Please note: Each time an address is added to the system or updated, the system tries to verify the address to make sure it is correct. This reduces the chance that the post card will be returned as 'undeliverable'. When time permits, please correct this address so it may be verified.");  
               document.getElementById("divCustomers").innerHTML = arResults[4]; 
               document.getElementById("divCustomer").innerHTML = "";
               document.getElementById("divCustomer").innerHTML = arResults[5]; 
               document.getElementById("divCustomer").style.display="none";   
               document.getElementById("content").style.display="block";
	 document.getElementById("divCustomers").style.display="block";
               } else {
               //alert("Your customer's address could not be verified by Canadian Address database. The address has been added to your customer list, but you will be unable to send Neighbor Network cards from this address until it can be verified.\n\n Please note: Each time an address is added to the system or updated, the system tries to verify the address to make sure it is correct. This reduces the chance that the post card will be returned as 'undeliverable'. When time permits, please correct this address so it may be verified.");  
               document.getElementById("divCustomers").innerHTML = arResults[2]; 
               document.getElementById("divCustomer").innerHTML = "";
               document.getElementById("divCustomer").innerHTML = arResults[3]; 
               document.getElementById("divCustomer").style.display="none";   
               document.getElementById("content").style.display="block";
   	 document.getElementById("divCustomers").style.display="block";
               }                  
             }   
	    

              //reset clientinfotable
            if (arResults[0] == 'resetClientInfoTable' && arResults[1] == "True"){  
               document.getElementById("divCustomer").innerHTML = "";
               document.getElementById("divCustomer").innerHTML = arResults[2];    
               document.getElementById("divCustomer").style.display="none";   
             }
            if (arResults[0] == 'resetClientInfoTable' && arResults[1] == "False"){  
               alert("A technical problem has occurred. The system has alerted the system administrator. Sorry for the inconvenience!");
             }     

             //save customer data
            if (arResults[0] == 'SaveCustomers' && arResults[1] == "True"){               
             alert("The address you entered may have been modified to match what the US Postal Service has on record. \nThe modified adddress will include Zip+4 zip code.");
             document.getElementById("divCustomers").style.display="block";
             document.getElementById("divCustomers").innerHTML = "";
             //alert(arResults.length);
             if(arResults.length > 4){
             document.getElementById("divCustomers").innerHTML = arResults[4]; 
             document.getElementById("divCustomer").innerHTML = "";
             document.getElementById("divCustomer").innerHTML = arResults[5]; 
             document.getElementById("divCustomer").style.display="none";
             document.getElementById("content").style.display="block";
             document.getElementById("divCustomers").style.display="block";
             } else {
             //alert("aj_java='"+arResults[2]);
             document.getElementById("divCustomers").innerHTML = arResults[2]; 
             document.getElementById("divCustomer").innerHTML = "";
             document.getElementById("divCustomer").innerHTML = arResults[3]; 
             document.getElementById("divCustomer").style.display="none";
             document.getElementById("content").style.display="block";
             document.getElementById("divCustomers").style.display="block";
             }
             //document.getElementById("divCustomer").style.display="none";          
             }

            if (arResults[0] == 'SaveCustomers' && (arResults[1] == 'False' || arResults[1] == 'Canada')){  
               if(arResults[1] == 'False'){
               alert("Your customer's address could not be verified by the United States Postal Service. The address has been added to your customer list, but you will be unable to send Neighbor Network cards from this address until it can be verified.\n\n Please note: Each time an address is added to the system or updated, the system tries to verify it with the USPS to make sure it is correct. This reduces the chance that the post card will be returned as 'undeliverable'. When time permits, please correct this address in order to permit it to be verified.");  
               }
               //document.getElementById("divCustomers").style.display="block"; 
               //document.getElementById("divCustomers").style.display="block";
               //document.getElementById("divCustomers").innerHTML = "";
               //alert(arResults.length);
               if(arResults.length > 4){
               document.getElementById("divCustomers").innerHTML = arResults[4]; 
               document.getElementById("divCustomer").innerHTML = "";
               document.getElementById("divCustomer").innerHTML = arResults[5]; 
               document.getElementById("divCustomer").style.display="none";
               document.getElementById("content").style.display="block";
               document.getElementById("divCustomers").style.display="block";

               } else {
               document.getElementById("divCustomers").innerHTML = arResults[2]; 
               document.getElementById("divCustomer").innerHTML = "";
               document.getElementById("divCustomer").innerHTML = arResults[3]; 
               document.getElementById("divCustomer").style.display="none";
               document.getElementById("content").style.display="block";
               document.getElementById("divCustomers").style.display="block";

               }              
             }     */	     


            //Loads up the "CustomerList" table on the thankyou.asp page and sets the innerHTML of divCustomers
              if (arResults[0] == "CustomerList" && arResults[1] == "True"  && arResults[2] != "bad search"){  	
               document.getElementById("divCustomers").innerHTML = "";
               document.getElementById("divCustomers").innerHTML = arResults[2]; 
               document.getElementById("divCustomers").style.display="block";                           
               } 
             if (arResults[0] == "CustomerList" && arResults[1] == "True" && arResults[2] == "bad search"){  	
               document.getElementById("results").style.display="block";                           
               } 

             if (arResults[0] == 'CustomerList' && arResults[1] == "False"){
               document.getElementById("divCustomers").innerHTML= "<b><center>--Sorry! You have no customers in your online customer listing. Please add some!--</center></b>";
             }     

             //Loads up the "NNCustomerList" table on the nn.asp page and sets the innerHTML of divCustomers
            if (arResults[0] == "NNCustomerList" && arResults[1] == "True"  && arResults[2] != "bad search"){  	             
             document.getElementById("divCustomers").innerHTML = "";
             document.getElementById("divCustomers").innerHTML = arResults[2];  
             document.getElementById("divCustomers").style.display="block";                                      
             } 
            if (arResults[0] == "NNCustomerList" && arResults[1] == "True" && arResults[2] == "bad search"){  	
             document.getElementById("results").style.display="block";                           
             } 

             if (arResults[0] == 'NNCustomerList' && arResults[1] == "False"){
               document.getElementById("divCustomers").innerHTML= "<b><center>--Sorry! You have no customers in your online customer listing. Please add some!--</center></b>";
             }     

              //Loads up the "TYCCustomerList" table on the thankyou.asp page and sets the innerHTML of divCustomers
             if (arResults[0] == "TYCCustomerList" && arResults[1] == "True" && arResults[2] != "bad search"){  	
              //alert(arResults[2]);             
              document.getElementById("divCustomers").innerHTML = "";
              document.getElementById("divCustomers").innerHTML = arResults[2];  
              document.getElementById("divCustomers").style.display="block";                                      
             } 
            if (arResults[0] == "TYCCustomerList" && arResults[1] == "True" && arResults[2] == "bad search"){  	
              document.getElementById("results").style.display="block";                                         
             } 

             if (arResults[0] == 'TYCCustomerList' && arResults[1] == "False"){
               document.getElementById("divCustomers").innerHTML= "<b><center>--Sorry! You have no customers in your online customer listing. Please add some!--</center></b>";
             }              

              //Loads up the "PromoCustomerList" table on the promo.asp page and sets the innerHTML of divCustomers
             if (arResults[0] == "PromoCustomerList" && arResults[1] == "True" && arResults[2] != "bad search"){  	
              //alert(arResults[2]);             
              document.getElementById("divCustomers").innerHTML = "";
              document.getElementById("divCustomers").innerHTML = arResults[2];  
              document.getElementById("divCustomers").style.display="block";                                      
             } 
            if (arResults[0] == "PromoCustomerList" && arResults[1] == "True" && arResults[2] == "bad search"){  	
              document.getElementById("results").style.display="block";                                         
             } 

             if (arResults[0] == 'PromoCustomerList' && arResults[1] == "False"){
               document.getElementById("divCustomers").innerHTML= "<b><center>--Sorry! You have no customers in your online customer listing. Please add some!--</center></b>";
             }        


               //Loads up the "MRCustomerList" table on the mr.asp page and sets the innerHTML of divCustomers
            if (arResults[0] == "MRCustomerList" && arResults[1] == "True" && arResults[2] != "bad search"){  	   
             //alert("MRCustomerList Results: "+arResults[3]);         
             document.getElementById("divCustomers").innerHTML = "";
             document.getElementById("divCustomers").innerHTML = arResults[2];     
             document.getElementById("divCustomers").style.display="block";      
             if(arResults[3]=="help"){                
             document.getElementById("multitr").style.display="none"; 
              } 
            }
  
      
            if (arResults[0] == "MRCustomerList" && arResults[1] == "True" && arResults[2] == "bad search"){  	
              document.getElementById("results").style.display="block";                           
             } 

             if (arResults[0] == 'MRCustomerList' && arResults[1] == "False"){
             //alert("false");
               document.getElementById("divCustomers").innerHTML= arResults[2]+"<br /><b><center>--Sorry! There are no customers set up to receive this type of reminder. Please add some!--</center></b>";
             }     



             //ChangeData
            if (arResults[0] == "ChangeData" && arResults[1] == "True"){  	
            // alert("Please make any changes you would you like to make to the customer information that you have selected.\nWhen you are finished, please click the button marked 'Add to or Update My Client List Now'. Thank you!");
             document.getElementById("divCustomer").innerHTML = "";
             document.getElementById("divCustomer").innerHTML = arResults[2];              
             } 

             if (arResults[0] == 'ChangeData' && arResults[1] == "False"){
               document.getElementById("divCustomer").innerHTML= "<b><center>--Sorry! An error has occurred. Please close your browser and log in again. Thank you!--</center></b>";
             }     


             //delete customer data
            if (arResults[0] == 'DeleteCustomer' && arResults[1] == "True"){  
              ajaxcalls("CustomerList");                
             }
            if (arResults[0] == 'DeleteCustomer' && arResults[1] == "False"){  
               alert("A technical problem has occurred. The system has alerted the system administrator. Sorry for the inconvenience!");
             }     

              //set reminder data
            if (arResults[0] == 'setReminder' && arResults[1] == "True"){ 
             //alert(arResults[3]);              
             ajaxcalls('MRCustomerList&page='+arResults[3]+'&r='+arResults[2]);             
             }
            if (arResults[0] == 'setReminder' && arResults[1] == "False"){  
               alert("A problem occurred when the system tried to update the reminder date. The system has alerted the administrator to this problem. Please try again. Thank you!");
             }                 

                //set PromoSendFlag data
            if (arResults[0] == 'setPromoSendFlag' && arResults[1] == "True"){  
             if(arResults[2] == 'customerlist'){
             //ajaxcalls('CustomerList');
             }else{
             //ajaxcalls('PromoCustomerList'); 
              }            
             }
            if (arResults[0] == 'setPromoSendFlag' && arResults[1] == "False"){  
               alert("A problem has occurred. The system has alerted the administrator regarding this issue. Please try again. Thank you!");
             }     

                //set PromoMultiSendFlag data
            if (arResults[0] == 'setPromoMultiSendFlag' && arResults[1] == "True"){  
             if(arResults[2] == 'customerlist'){
             //ajaxcalls('CustomerList');
             }else{
             //ajaxcalls('PromoCustomerList'); 
              }            
             }
            if (arResults[0] == 'setPromoMultiSendFlag' && arResults[1] == "False"){  
               alert("A problem has occurred. The system has alerted the administrator regarding this issue. Please try again. Thank you!");
             }     

                 //set PromoQuantity data
            if (arResults[0] == 'setPromoQuantity' && arResults[1] == "True"){  
             if(arResults[2] == 'customerlist'){
             //ajaxcalls('CustomerList');
             }else{
               //alert(arResults[3]);
               intNNChecked = arResults[3];
             //ajaxcalls('PromoCustomerList'); 
              }                       
             }
            if (arResults[0] == 'setPromoQuantity' && arResults[1] == "False"){  
               alert("A problem has occurred. The system has alerted the administrator regarding this issue. Please try again. Thank you!");
             }     
               

	        

                //set NNSendFlag data
            if (arResults[0] == 'setNNSendFlag' && arResults[1] == "True"){  
             if(arResults[2] == 'customerlist'){
             //ajaxcalls('CustomerList');
             }else{
             //ajaxcalls('NNCustomerList'); 
              }            
             }
            if (arResults[0] == 'setNNSendFlag' && arResults[1] == "False"){  
               alert("A problem has occurred. The system has alerted the administrator regarding this issue. Please try again. Thank you!");
             }     

                 //set NNQuantity data
            if (arResults[0] == 'setNNQuantity' && arResults[1] == "True"){  
             if(arResults[2] == 'customerlist'){
             //ajaxcalls('CustomerList');
             }else{
               intNNChecked = arResults[3];
             //ajaxcalls('NNCustomerList'); 
              }                       
             }
            if (arResults[0] == 'setNNQuantity' && arResults[1] == "False"){  
               alert("A problem has occurred. The system has alerted the administrator regarding this issue. Please try again. Thank you!");
             }     



            //template for ajax based activities...copy this first - don't overwrite this
            if (arResults[0] == '[something]' && arResults[1] == "True"){  
              //Do stuff..
             }
            if (arResults[0] == '[something]' && arResults[1] == "False"){  
               //Do other stuff..
             }     


             


           //Leave the brackets below alone! Do not remove!          
            } 
}

 

function ajaxcalls(activity)
{  
          
          if (activity.indexOf("Login") == 0){
            url = "functions.asp?a="+activity+"&u=" + document.getElementById("userid").value + "&p="+document.getElementById("password").value;                              
           }

            if (activity.indexOf("LoginClient") == 0){      
            url = "functions.asp?a="+activity+"&u=" + document.getElementById("userid").value + "&p="+document.getElementById("password").value;    
            //alert("1. "+url); 
           }

          if (activity.indexOf("Thank You Cards") == 0 || activity.indexOf("NN Cards") == 0 || activity.indexOf("MR Cards") == 0){           
            url = "functions.asp?a="+activity;           
           }       
      
           if (activity.indexOf("RemoveTemplate") == 0){                
            url = "functions.asp?a="+activity+"&t="+strTemplateIndex+"&pag="+strType;     
            //alert(url);      
           }

           if (activity.indexOf("getUserInfo2") == 0){        
            alert(activity);        
                         
           }

           if (activity.indexOf("getUserInfo") == 0){        
            //alert(activity);        
            url = "functions.asp?a="+activity;                   
           }

            if (activity.indexOf("updateClient") ==0){        
            //prompt("",activity);        
            url = "functions.asp?a="+activity;                  
           }
  
           if (activity.indexOf("getTYCCount") == 0 || activity.indexOf("getNNCount") == 0 || activity.indexOf("getPromoCount") == 0){                
            url = "functions.asp?a="+activity;    
            //alert(url);      
           }           

          if (activity.indexOf("Option1") ==0 || activity.indexOf("Option2") ==0 || activity.indexOf("Option3") ==0 || activity.indexOf("Option4") ==0){                            
            url = "functions.asp?a="+activity;           
           }

          if (activity.indexOf("QueueUpPromo") ==0 || activity.indexOf("QueueUpNN") ==0){     
            document.getElementById("loading").style.display="block";  
            var obj = document.getElementById("senddate");
            var strSelected = "";
              for(var i=0; i < obj.options.length;i++){
                if(obj.options[i].selected){
                   strSelected = strSelected + obj.options[i].value+":"
                }
              }
            //alert(functions.asp?a="+activity+"&dates="+strSelected);            
            url = "functions.asp?a="+activity+"&dates="+strSelected;                  
          }

          if (activity.indexOf("QueueUpTYC") ==0 || activity.indexOf("QueueUpMR") ==0){     
            document.getElementById("loading").style.display="block";      
            url = "functions.asp?a="+activity+"&dates="+strSelected;                  
          }

           if (activity.indexOf("resetClientInfoTable") == 0){                                    
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("CustomerList") == 0){    
           //alert("functions.asp?a="+activity);                                
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("TYCCustomerList") == 0){    
           // alert("functions.asp?a="+activity);                                                 
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("NNCustomerList") == 0||activity.indexOf("NNCustomerList2") == 0){                                            
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("PromoCustomerList") == 0||activity.indexOf("PromoCustomerList2") == 0){                                            
            url = "functions.asp?a="+activity;           
           }


           if (activity.indexOf("tycUncheckAll") == 0||activity.indexOf("promoUncheckAll") == 0||activity.indexOf("tycCheckAll") == 0||activity.indexOf("promoCheckAll") == 0){
           //alert(activity);
            url = "functions.asp?a="+activity;
           }


           if (activity.indexOf("MRCustomerList") == 0){       
           //prompt('',activity);                                  
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("setFilter") == 0){       
           //prompt('',activity);                                  
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("setSendFlag") == 0){                                                              
            //alert(activity);            
            url = "functions.asp?a="+activity;           
           }


           if (activity.indexOf("setReminder") == 0){        
            //prompt("",activity);                                           
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("setNNSendFlag") == 0){   
            //alert(activity);                                                            
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("setNNQuantity") == 0){   
            //alert(activity);                                                            
            url = "functions.asp?a="+activity;           
           }


           if (activity.indexOf("setPromoSendFlag") == 0 || activity.indexOf("setPromoMultiSendFlag") == 0){                                                              
            //prompt('',activity);            
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("setPromoQuantity") == 0){   
            //alert(activity);                                                            
            url = "functions.asp?a="+activity;           
           }

           if (activity.indexOf("updateTYCCount") == 0 || activity.indexOf("updateNNCount") == 0||activity.indexOf("updateRemCount") == 0||activity.indexOf("updatePromoBalance") == 0){   
            //alert(activity);                                                            
            url = "functions.asp?a="+activity;           
           }          

           if (activity.indexOf("ChangeData") == 0){   
            //alert("this is it!     functions.asp?a="+activity);                                                
            url = "functions.asp?a="+activity;           
           }           

           if ((activity.indexOf("SaveCustomer") == 0)||(activity.indexOf("UpdateCustomer") == 0)||(activity.indexOf("DeleteCustomer") == 0)){    
            //prompt("",activity);                                                
            url = "functions.asp?a="+activity;           
           }      

           if (activity.indexOf("removeRecord") == 0 || activity.indexOf("removeRemRecord") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }    

           if (activity.indexOf("showDlrLogo") == 0 || activity.indexOf("deleteDlrLogo") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }    

            if (activity.indexOf("removeCustom") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }    

            if (activity.indexOf("writeRecordtoFile") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }    

             if (activity.indexOf("getTYCBalance") == 0||activity.indexOf("getNNBalance") == 0||activity.indexOf("getRemBalance") == 0||activity.indexOf("getPromoBalance") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }    

           if (activity.indexOf("updateDescription") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }    

           if (activity.indexOf("removeOptionRecord") == 0){   
           //prompt("",activity);                                                
            url = "functions.asp?a="+activity;           
           }    

           if (activity.indexOf("goCanadian") == 0||activity.indexOf("goAmerican") == 0){   
           //alert(activity);                                                
            url = "functions.asp?a="+activity;           
           }            

          if (activity.indexOf("getRCount") == 0){       
           //alert(activity);                                  
            url = "functions.asp?a="+activity;           
           }

          post_state = GetXmlHttpObject(post_state_changed);
          //alert("2. "+url);
          post_state.open("POST", url, true);
          post_state.send(null);      
}


function refreshDiv(divName)
{
  if(divName=="1_tyc_lpagedlr")
  {    
    ajaxcalls("getTYCBalance");
  }

  if(divName=="1_nn_lpagedlr")
  {
    ajaxcalls("getNNBalance");
  }

  if(divName=="1_rm_lpagedlr")
  {
    ajaxcalls("getRemBalance");
  }

  if(divName=="1_promo_lpagedlr")
  {
    //alert("1_promo_lpagedlr");
    ajaxcalls("getPromoBalance");
  }
}


function validatePromo(id,ftr){
if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == true){
  //alert("setPromoMultiSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  ajaxcalls("setPromoMultiSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
}
else{
 if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == false){
  //alert("Please remember to put a check in the checkbox to allow the cards to be sent out to " + document.getElementById(id).options[document.getElementById(id).selectedIndex].value + " of your customer's neighbors. Thank you!"); 
   ajaxcalls("setPromoMultiSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  }
 if(document.getElementById(id).selectedIndex == 0 && document.getElementById("chkNN"+id).checked == true){
  //alert("Please select the quantity to send and then check the box to allow the cards to be sent out to your customer's neighbors.");
   document.getElementById("chkNN"+id).checked=false;
   }  
 }
}

function validatePromoQuantity(id,ftr){
if(document.getElementById(id).selectedIndex > 0 && document.getElementById(id).options[document.getElementById(id).selectedIndex].value==id){
    
  tempX = event.clientX + document.body.scrollLeft;
  tempY = event.clientY + document.body.scrollTop - 150;
  
  document.getElementById("customQty").style.left=tempX;
  document.getElementById("customQty").style.top=tempY;
  document.getElementById("customQty").style.display="block";
  document.getElementById("hdncustomQty").value=id+":"+ftr;
  return;
}

if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == true){
  ajaxcalls("setPromoQuantity&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
}
else{
 if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == false){
  //alert("Please remember to put a check in the checkbox to allow the cards to be sent out to " + document.getElementById(id).options[document.getElementById(id).selectedIndex].value + " of your customer's neighbors. Thank you!"); 
  }
 if(document.getElementById(id).selectedIndex == 0 && document.getElementById("chkNN"+id).checked == true){
  ajaxcalls("setPromoMultiSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  alert("You have set the card quantity to zero, so no cards will be sent to your customer's neighbors.");  
  return;
  }
 if(document.getElementById(id).selectedIndex == 0 && document.getElementById("chkNN"+id).checked == false){
  ajaxcalls("setPromoQuantity&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  alert("You have set the card quantity to zero, so no cards will be sent to your customer's neighbors.");  
  return;
  }
 }
}


function validateNN(id,ftr){
if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == true){
  //alert("setNNSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  ajaxcalls("setNNSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
}
else{
 if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == false){
  //alert("Please remember to put a check in the checkbox to allow the cards to be sent out to " + document.getElementById(id).options[document.getElementById(id).selectedIndex].value + " of your customer's neighbors. Thank you!"); 
   ajaxcalls("setNNSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  }
 if(document.getElementById(id).selectedIndex == 0 && document.getElementById("chkNN"+id).checked == true){
  //alert("Please select the quantity to send and then check the box to allow the cards to be sent out to your customer's neighbors.");
   document.getElementById("chkNN"+id).checked=false;
   }  
 }
}

function valCustomQty(ctype){
 var obj = document.getElementById("tbcustomQty");
 var id = document.getElementById("hdncustomQty").value.split(":");
 if(obj.value=="" || obj.value <25){
   alert("You MUST enter a number into the \"Custom Quantity\" field and it must be 25 or greater.");
   obj.focus();
   return (false);
 }else{
  var checkOK = "0123456789";
  var checkStr = obj.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
       break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only numbers in the \"Custom Quantity\" field.");
    obj.focus();
    return (false);
  }
 }
    document.getElementById("customQty").style.display="none";
    
    if(ctype=="nn"){
      ajaxcalls("setNNQuantity&id="+id[0]+"&m="+obj.value+"&ftr="+id[1]);
      ajaxcalls("NNCustomerList2&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
    }else{
      ajaxcalls("setPromoQuantity&id="+id[0]+"&m="+obj.value+"&ftr="+id[1]);
      ajaxcalls("PromoCustomerList&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
    }
}
    

function validateNNQuantity(id,ftr){
//alert("validateNNQuantity "+document.getElementById(id).options[document.getElementById(id).selectedIndex].value);
if(document.getElementById(id).selectedIndex > 0 && document.getElementById(id).options[document.getElementById(id).selectedIndex].value==id){
    
  tempX = event.clientX + document.body.scrollLeft;
  tempY = event.clientY + document.body.scrollTop - 150;
  
  document.getElementById("customQty").style.left=tempX;
  document.getElementById("customQty").style.top=tempY;
  document.getElementById("customQty").style.display="block";
  document.getElementById("hdncustomQty").value=id+":"+ftr;
  return;
}

if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == true){
  ajaxcalls("setNNQuantity&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
}
else{
 if(document.getElementById(id).selectedIndex > 0 && document.getElementById("chkNN"+id).checked == false){
  //alert("Please remember to put a check in the checkbox to allow the cards to be sent out to " + document.getElementById(id).options[document.getElementById(id).selectedIndex].value + " of your customer's neighbors. Thank you!"); 
  }
 if(document.getElementById(id).selectedIndex == 0 && document.getElementById("chkNN"+id).checked == true){
  ajaxcalls("setNNSendFlag&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  alert("You have set the card quantity to zero, so no cards will be sent to your customer's neighbors.");  
  return;
  }
 if(document.getElementById(id).selectedIndex == 0 && document.getElementById("chkNN"+id).checked == false){
  ajaxcalls("setNNQuantity&id="+id+"&m="+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"&ftr="+ftr);
  alert("You have set the card quantity to zero, so no cards will be sent to your customer's neighbors.");  
  return;
  }
 }
}


function replaceText(sId,intOffset)
{
var tbl = document.getElementById(sId);
createRow();
if (bolEmpty == 1){
  var lastRow = tbl.rows.length;  
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  row.id = "tr" + intCustomRow;
  var cellLeft = row.insertCell(0);  
  var cellMid = row.insertCell(1); 
  var cellRight = row.insertCell(2); 
  var textNode = document.createTextNode();  
  cellLeft.appendChild(textNode);
  cellMid.appendChild(textNode);
  cellRight.appendChild(textNode);
  cellLeft.innerHTML = sStringLeft;   
  cellLeft.className = "title";
  cellMid.innerHTML = "=";
  cellMid.align = "center";
  cellMid.className = "title";  
  cellRight.innerHTML = sStringRight;
  cellRight.align = "center";
  cellRight.className = "title";
  document.getElementById("cfLabel").value = "";
  } 
 }

function createRow()
{
var sTemp = "";
intCustomRow += 1;
sStringLeft = "<div align='center'>" + document.getElementById("cfLabel").value + "</div>";
sStringRight = document.getElementById("lstClientFields").options(document.getElementById("lstClientFields").selectedIndex).text + "&nbsp;&nbsp;&nbsp;<a href=Javascript:removeCustomRow('tr" + intCustomRow + "');>Remove field</a>"
}

//function getTYCCount(){
// return intTYCCount; 
//}
 
 function removeCustomRow(strRowId)
 {  
   var intDelRow = document.getElementById('tblMapClientFields').rows(strRowId).rowIndex;
  //alert(document.getElementById('tblNewClient').rows(strRowId).rowIndex);
  document.getElementById('tblMapClientFields').deleteRow(intDelRow);  
  document.getElementById("cfLabel").value = "";
 }

 function removeTemplate(strRow,tempIndex,page) {
 strRowId = strRow;
 strTemplateIndex = tempIndex;
 strType = page;
 ajaxcalls("RemoveTemplate");  
 }

 function updateClient(){  

  var strData = "";
  var x = 0;
       
  strData = document.getElementById("f1").value + "::"+ document.getElementById("f2").value + "::";  

  for (x=30;x <= 35;x++){       
    if(x!=32){
        strData = strData + document.getElementById("f" + x).value + "::";
    }else{
        strData = strData + document.getElementById("f32").value + "~~" + document.getElementById("f322").value + "::";
     }
    }   
  
  strData = strData + document.getElementById("f36a").value + "::" +  document.getElementById("f36p").value + "::"+ document.getElementById("f36suf").value + "::"+ document.getElementById("f36ext").value + "::";

  strData = strData + document.getElementById("f39a").value + "::" +  document.getElementById("f39p").value + "::"+ document.getElementById("f39suf").value + "::"+ document.getElementById("f39ext").value + "::";

  for (x=37;x <= 38;x++){         
        strData = strData + document.getElementById("f" + x).value + "::";
    } 

  strData = strData + document.getElementById("f40").value + "::";

  strData = strData + document.getElementById("f42a").value + "::" +  document.getElementById("f42p").value + "::"+ document.getElementById("f42suf").value + "::"+ document.getElementById("f42ext").value + "::";

  strData = strData + document.getElementById("f43").value;

  strData = strData.replace(/'/g,"''");  
  strData = strData.replace(/&/g,"%26");
  //alert(strData);
  ajaxcalls('updateClient&d='+strData);
}

function collectSelect(idNumber){
  var z = 0;
  var strSelect = "";
  if(document.getElementById("f" + idNumber).options.length == 1){
        return document.getElementById("f" + idNumber).options[0].text;
         }
  if(document.getElementById("f" + idNumber).options.length > 1){
        strSelect = document.getElementById("f" + idNumber).options[0].text;
       for (z=1;z < document.getElementById("f" + idNumber).options.length;z++){  
        strSelect = strSelect + "[!]" +  document.getElementById("f" + idNumber).options[z].text;       
         }
        //alert(strSelect);
        return strSelect;     
     }      
  if(document.getElementById("f" + idNumber).options.length == 0){
        return "NA";
         }
   }


/* function packageData(ftr,page){  
  var strData = "";
  var x = 0;  
  
  if(page == null || intPageNumber == 0)
     page = 1;
  if(intPageNumber > 0)
     page = intPageNumber; 
  if(ftr == null)
     ftr = "~";
  //alert("packageData ftr="+ftr+" page="+page);
  strData = document.getElementById("cName").value + "::" + document.getElementById("cAddress").value + "::" + document.getElementById("cCity").value + "::" + document.getElementById("cState").options[document.getElementById("cState").selectedIndex].value + "::" + document.getElementById("cZipCode").value + "::" + document.getElementById("cAreaCode").value + document.getElementById("cPhoneP").value+ document.getElementById("cPhoneS").value + document.getElementById("cPhoneExt").value + "::" + document.getElementById("cEmail").value;
 //alert(strData);
  if(intFields>0){
     for (x=7;x <= intFields;x++){   
      if(document.getElementById("f" + (x+1)).tag=="list"){
         strData = strData + "::" + collectSelect(x + 1);
        } else {        
        strData = strData + "::" + document.getElementById("f" + (x+1)).value;
      }      
     } //end of looping
    //alert(intActiveID);
    strData = strData.replace(/&/,"%26");
    if (intActiveID == 0){
   // alert("SaveCustomer");
   // prompt("","SaveCustomer&d=" + strData + "&ftr="+ftr);
    ajaxcalls("SaveCustomer&d=" + strData + "&ftr="+ftr);    
    }else{    
   // alert("UpdateCustomer");
   // prompt("","UpdateCustomer&d=" + strData + "&id=" + intActiveID + "&ftr="+ftr+"&page="+page);
    ajaxcalls("UpdateCustomer&d=" + strData + "&id=" + intActiveID + "&ftr="+ftr+"&page="+page);
    intActiveID = 0;
    //document.getElementById("divCustomer").style.display="none";
    return true;      
        }
      }
    } */



function showFullSize(imageURL){
  if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
    {
      winstyle = "dialogWidth=385px; dialogHeight:140px; center:yes";
      window.showModelessDialog(imageURL+'&b=IE',null,winstyle);
    }
    else
    {
      window.open(imageURL+'&b=NN','','width=370,height=115', true);
    }  
  return true;
}

 function checkboxclick(id){
  //alert(document.getElementById(id).checked);
  if(document.getElementById(id).checked ==true){
     document.getElementById(id).value="Y";
    }
  if(document.getElementById(id).checked ==false){
     document.getElementById(id).value="N";
    }
 }

 function Form_Validator()  
 {
  if (document.all.f30.value == "")
  {
    alert("Please enter a value for the \"Business Name\" field.");
    document.all.f30.focus();
    return (false);
  }

  if (document.all.f30.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Business Name\" field.");
    document.all.f30.focus();
    return (false);
  }

  if (document.all.f30.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Business Name\" field.");
    document.all.f30.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :()!,'.-/\\&";
  var checkStr = document.all.f30.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
       break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :()!,'.-/\\& characters in the \"Business Name\" field.");
    document.all.f30.focus();
    return (false);
  }


  if (document.all.f31.value == "")
  {
    alert("Please enter a value for the \"Contact\" field.");
    document.all.f31.focus();
    return (false);
  }

  if (document.all.f31.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Contact\" field.");
    document.all.f31.focus();
    return (false);
  }

  if (document.all.f31.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Contact\" field.");
    document.all.f31.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ :()!,'.-/\\&";
  var checkStr = document.all.f31.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, number and :()!,'.-/\\& characters in the \"Contact\" field.");
    document.all.f31.focus();
    return (false);
  }

    if (document.all.f32.value == "")
  {
    alert("Please enter a value for the \"Address #1\" field.");
    document.all.f32.focus();
    return (false);
  }

  if (document.all.f32.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Address #1\" field.");
    document.all.f32.focus();
    return (false);
  }

  if (document.all.f32.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Address #1\" field.");
    document.all.f32.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :()!,'.-/\\&";
  var checkStr = document.all.f32.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :()!,'.-/\\& characters in the \"Address #1\" field.");
    document.all.f32.focus();
    return (false);
  }

  if (document.all.f322.value!='' && document.all.f322.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Address #2\" field.");
    document.all.f322.focus();
    return (false);
  }

  if (document.all.f322.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Address #2\" field.");
    document.all.f322.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :()!,'.-/\\&";
  var checkStr = document.all.f322.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :()!,'.-/\\& characters in the \"Address #2\" field.");
    document.all.f322.focus();
    return (false);
  }


  if (document.all.f33.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    document.all.f33.focus();
    return (false);
  }

  if (document.all.f33.value.length = 0 )
  {
    alert("Please enter a city name in the \"City\" field.");
    document.all.f33.focus();
    return (false);
  }

  if (document.all.f33.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"City\" field.");
    document.all.f33.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ :()!,'.-/\\&";
  var checkStr = document.all.f33.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, number and :()!,'.-/\\& characters in the \"City\" field.");
    document.all.f33.focus();
    return (false);
  }
  

  if (document.all.f34.selectedIndex <= 0)
  {
    alert("Please select a State or Province.");
    document.all.f34.focus();
    return (false);
  }

  if (document.all.f34.selectedIndex >= 51)
  {
    ajaxcalls('goCanadian');
  } else {
    ajaxcalls('goAmerican');
  }

    if (document.all.f34.selectedIndex < 51){

    if (document.all.f35.value == "")
  {
    alert("Please enter a value for the \"Zip Code/Postal Code\" field.");
    document.all.f35.focus();
    return (false);
  }

  if (document.all.f35.value.length < 5 )
  {
    alert("Please enter your Zip Code into the \"Zip Code/Postal Code\" field.");
    document.all.f35.focus();
    return (false);
  }

  if (document.all.f35.value.length > 10)
  {
    alert("Please enter at most 7 characters for Canadian Postal Codes and a maximum of 10 characters for US Zip Codes in the \"Zip Code/Postal Code\" field.");
    document.all.f35.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = document.all.f35.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digits in the \"Zip Code\" field.");
    document.all.f35.focus();
    return (false);
   }
  }

  if (document.all.f36a.value.length > 3 || document.all.f36a.value.length < 3)
  {
    alert("Please enter no more or less than 3 digits in the \"Area Code\" field.");
    document.all.f36a.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = document.all.f36a.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Area Code\" field.");
    document.all.f36a.focus();
    return (false);
  }


if (document.all.f36p.value.length > 3 || document.all.f36p.value.length < 3)
  {
    alert("Please enter no more or less than 3 digits in the \"Prefix\" field.");
    document.all.f36p.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = document.all.f36p.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Prefix\" field.");
    document.all.f36p.focus();
    return (false);
  }
  
if (document.all.f36suf.value.length > 4 || document.all.f36suf.value.length < 4)
  {
    alert("Please enter no more or less than 4 digits in the \"Suffix\" field.");
    document.all.f36suf.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = document.all.f36suf.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Suffix\" field.");
    document.all.f36suf.focus();
    return (false);
  }


/*  if (document.all.f37.value == "")
  {
    alert("Please enter a value for the \"EmailAddress\" field.");
    document.all.EmailAddress.focus();
    return (false);
  }

  if (document.all.f37.value.length < 7)
  {
    alert("Please enter at least 7 characters in the \"Email Address\" field.");
    document.all.f37.focus();
    return (false);
  }

  if (document.all.f37.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Email Address\" field.");
    document.all.f37.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-_@.";
  var checkStr = document.all.f37.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit and \"@_.\" characters in the \"Email Address\" field.");
    document.all.f37.focus();
    return (false);
  }  
    
if (document.all.f40.value == "")
  {
    alert("Please enter a value for the \"Authorized Email Address\" field.");
    document.all.f40.focus();
    return (false);
  }

  if (document.all.f40.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Authorized Email Address\" field.");
    document.all.f40.focus();
    return (false);
  }

  if (document.all.f40.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Authorized Email Address\" field.");
    document.all.f40.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-_@.";
  var checkStr = document.all.f40.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit and \"@_.\" characters in the \"Email Address\" field.");
    document.all.f40.focus();
    return (false);
  } */

  updateClient();
}

function checkFirstThree(){

  //alert("checking...");

  if (document.all.cName.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Name\" field.");
    document.all.cName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :'.()&!,";
  var checkStr = document.all.cName.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :'.()&!, characters in the \"Name\" field.");
    document.all.cName.focus();
    return (false);
  }


  if (document.all.cAddress.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Street Address\" field.");
    document.all.cAddress.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :'.-()&!,";
  var checkStr = document.all.cAddress.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :'.-()&!, characters in the \"Street Address\" field.");
    document.all.cAddress.focus();
    return (false);
  }

  if (document.all.cAddress2.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"Street Address 2\" field.");
    document.all.cAddress2.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :'.-()&!,";
  var checkStr = document.all.cAddress2.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :'.-()&!, characters in the \"Street Address 2\" field.");
    document.all.cAddress2.focus();
    return (false);
  }


  if (document.all.cCity.value.length > 80)
  {
    alert("Please enter at most 80 characters in the \"City\" field.");
    document.all.cCity.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 :-'.()&!,";
  var checkStr = document.all.cCity.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letters, numbers, and the :'.()&!, characters in the \"City\" field.");
    document.all.cCity.focus();
    return (false);
  }

 //added cState to this later - so now it really checks the first FOUR fields, not the first three!!!
  if (document.all.cState.selectedIndex == 0)
  {
    alert("Please select a state/province from the \"State/Province\" field.");
    document.all.cState.focus();    
    return (false);
  }
 //alert("intPageNumber="+intPageNumber);  
  return (true);
}

function searchForIt(cardType) {
if(document.getElementById('keyword').value!=""){
  if(document.getElementById('search').options[document.getElementById('search').selectedIndex].value==1 && document.getElementById('keyword').value.length == 1){
    alert("The Name field search requires two or more characters. Please enter another character to start your search.");
    document.getElementById('keyword').focus();
    return (false);
  }
   if(cardType=='tyc'){
   //alert("(tyc)looking for:"+ document.getElementById('keyword').value+" search #:"+ document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
   ajaxcalls("TYCCustomerList&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
  }
  if(cardType=='nnc'){
   //alert("(nnc)looking for:"+ document.getElementById('keyword').value);
   ajaxcalls("NNCustomerList2&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
  }
  if(cardType=='mr'){
   //alert("(mr)looking for:"+ document.getElementById('keyword').value);
   ajaxcalls("MRCustomerList&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
  }
  if(cardType=='pm'){
   //alert("(pm)looking for:"+ document.getElementById('keyword').value);
   ajaxcalls("PromoCustomerList&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
  }
  if(cardType=='cl'){
   //alert("(mr)looking for:"+ document.getElementById('keyword').value);
   ajaxcalls("CustomerList&page=1&keyword="+document.getElementById('keyword').value+"&search="+document.getElementById('search').options[document.getElementById('search').selectedIndex].value);
  }
} else {
  alert("Keyword is missing - please enter a keyword to search for.");
  document.getElementById('keyword').focus();
  return (false);
 }
}

function checkEnter(e,cardType) {
var keynum
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
if (keynum == 13){
  searchForIt(cardType)
  }
}

function searchClick(cardType){
if(cardType=='tyc' || cardType=='cl' || cardType=='pm'){
document.getElementById('btnAddClient').style.visibility = 'visible';
}
searchForIt(cardType);
}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {  
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}

// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

function checknMove(e,numchars,nextObj){
  if (event.srcElement.value.length < numchars){
     return true;
    }
   if (event.srcElement.value.length == numchars){
    document.getElementById(nextObj).focus();   
    return true;
   }
   return false;
}

function getMessage(feature,obj,id)  
 {
 //alert(feature);
  if (obj.checked==true){
  var r=confirm("You have sent a post card to this customer in the past 30 days. Are you sure you want to send another one so soon?")
  if (r==true && obj.checked==true)
    {
    //do nothing, let it happen
    }
  else
    {
    obj.checked=false;
    if (feature=="Neighbor Network card"){
    validateNN(id);
    }else{
    ajaxcalls('setSendFlag&id='+id)
    }
    return false;
    }
   }
  }

function fixImgs(whichId, maxW,maxH) {
var pix=document.getElementById(whichId);  
    w=pix.width;
    h=pix.height;
    pix.oheight=h;
    pix.owidth=w;
    if (w > maxW) {      
      pix.width=maxW;
      pix.height=h*maxW/w;
    //alert(pix.width);
    }  
    if (h > maxH) {      
      pix.height=maxH;
      pix.width=w*maxH/h;
    //alert(pix.width);
    }  
}

function updateDescription(cID,fields,position,gtype){
var strDescription = "";
if(fields=="f8"){
//prompt("","updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+document.getElementById('des1:'+position).value);
strDescription = document.getElementById('des1:'+position).value;
strDescription = strDescription.replace(/\&/g,"~");
strDescription = strDescription.replace(/\'/g,"''");
ajaxcalls("updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+strDescription);
}
if(fields=="f10"){
//prompt("","updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+document.getElementById('des2:'+position).value);
strDescription = document.getElementById('des2:'+position).value;
strDescription = strDescription.replace(/\&/g,"~");
strDescription = strDescription.replace(/\'/g,"''");
ajaxcalls("updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+strDescription);
}
if(fields=="f12"){
//prompt("","updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+document.getElementById('des3:'+position).value);
strDescription = document.getElementById('des3:'+position).value;
strDescription = strDescription.replace(/\&/g,"~");
strDescription = strDescription.replace(/\'/g,"''");
ajaxcalls("updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+strDescription);
}
if(fields=="f14"){
//prompt("","updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+document.getElementById('des4:'+position).value);
strDescription = document.getElementById('des4:'+position).value;
strDescription = strDescription.replace(/\&/g,"~");
strDescription = strDescription.replace(/\'/g,"''");
ajaxcalls("updateDescription&cid=" + cID + "&type=" + gtype + "&position=" + position + "&fields=" + fields + "&newDescription="+strDescription);
 }
}

function getRCount(){
 ajaxcalls("getRCount");
}

function setFilter(filter){
 ajaxcalls("setFilter&filter="+filter);
}


function test(){
alert("hi");
}

















