    //This is for disable the document.write in the API render function
    var kasamba_EG_Disable_Render='1';          
    var resetLayoutControls =false ;
    var objLastPresses =null;
     //This param will keep the HTML controls states when user comes back to this page.                        
    var objCustomSizeLinkCommands ="";
    var objLayoutStateCommands="";   
    
    var rbMainTbl = "";
    var arrParams;
    var PageIsLoad=0;
    
    function getObject(objName,tagName)
    {
        var obj_tags = document.getElementsByTagName(tagName)
        
        for(i=0;i<obj_tags.length;i++)
        {              
            if(obj_tags[i].id.indexOf(objName) >= 0)           
            {           
                
                return obj_tags[i];
            }
         }       
    }    
     
    function customizeSize(customLink, divSizesToOpen,widthTextBox,widthValue,heightTextBox,heightValue)
    {        
       
       if (document.getElementById(divSizesToOpen).style.display=="none" || document.getElementById(divSizesToOpen).style.display=="")
       {
             document.getElementById(divSizesToOpen).style.display = "block";   
             customLink.innerHTML  = "Default Size" ;       
       }
       else
       {       
            rbSubClick(customLink.id,kasamba_EG_paramID)
            customLink.innerHTML  = "Customize Size" ;    
       }      
              
       document.getElementById(widthTextBox).value = widthValue;
       document.getElementById(heightTextBox).value = heightValue;        
    }    
    
    
    function closeControls(toDefaultCustom)
    {        
        closeRoots();       
        closeTextBoxesDivs();         
        closeChangeLinks();                 
        closeMessages();
        
        if (toDefaultCustom)
        {
           setCustomizeToDefault();  
        }   
    } 
    
  
    
    function setCustomizeToDefault()
    {
        //setting the controls as they appear when loading the page.                           
        arrBannersID =  firstBanners.split(",");
        
        var theTagName = new String(); 
        
        for(i=0;i<arrBannersID.length;i++)
        {
            obj = document.getElementById(arrBannersID[i]);            
            theTagName = obj.tagName;
           
            if (theTagName.toLowerCase() == "span")
            {
                obj.style.display = 'inline';
                obj.innerHTML = "Customize Size";
            }
            else if(theTagName.toLowerCase() == "input")
            {
                obj.checked = true;                
            }
        
        }  
    }   
    
    function CheckDimensions(txtBox,minVal,maxVal, defaultSize)
    {                  
        closeMessages();       
          
        kasamba_EG_changedSizeAndLayout = 1;             
        var txtValue  =txtBox.value;
        
        var objNotation = getObject("msgNoteChange" + kasamba_EG_paramID ,"span")
        //if (objNotation!=null)
        //{                    
         //   objNotation.style.display="none";
        //}
      
        if (txtValue!=null)
        {        
            if(isNaN(txtValue) || txtValue=="" )
            {                
                txtValue = "-1";
            }
            
            txtValue = parseInt(txtValue);       
           
            if ( txtValue>maxVal) //value is too big
            {                   
                txtBox.value = defaultSize;          
                
                if(txtBox.id.indexOf('Width') >= 0)
                {                           
                    kasamba_EG_width =  defaultSize            
                }  
                else if(txtBox.id.indexOf('Height') >= 0)
                {
                    kasamba_EG_height =  defaultSize         
                }            
            }       
            else if (txtValue<minVal) //value is too small
            {                                   
                if(txtBox.id.indexOf('Width') >= 0)
                {       
                    if ( parseInt(txtBox.value.length)==3)                        
                    {                       
                       txtBox.value = minVal;
                    }
                    kasamba_EG_width =  minVal;              
                }                      
                else if(txtBox.id.indexOf('Height') >= 0)
                {                   
                    kasamba_EG_height =  minVal;                 
                }       
            } 
            else// value is valid
            {
                if(txtBox.id.indexOf('Width') >= 0)
                {                               
                    kasamba_EG_width =  txtValue;              
                }                      
                else if(txtBox.id.indexOf('Height') >= 0)
                {
                    kasamba_EG_height =  txtValue;   
                }                 
                
                if (objNotation!=null)
                {                    
                    objNotation.style.display="block";
                }
                
                /*var itm = getParamItem(kasamba_EG_paramID);
               
                if (itm!=null)
                {
                    if (numExpertInPage>0 && (kasamba_EG_height != itm.BannerHeight || kasamba_EG_width != itm.BannerWidth) )
                    {
                        if (objNotation!=null)
                        {                    
                            objNotation.style.display="block";
                        }
                    }
                }*/
            }           
        }  
    
    }
    
    function closeChangeLinks()
    {
        var span_tags = document.getElementsByTagName("span") 
        for(i=0;i<span_tags.length;i++)
        {              
            if(span_tags[i].id.indexOf('lblCustomLink') >= 0)
            {                           
                span_tags[i].style.display = 'none'  
                span_tags[i].innerHTML ='Customize Size';            
            }
         }      
    
    }    
    function closeRoots()
    {
        var table_tags = document.getElementsByTagName("table") 
        for(i=0;i<table_tags.length;i++)
        {              
            if(table_tags[i].id.indexOf('tblRoot') >= 0)
            {                           
                table_tags[i].style.display = 'none'               
            }
         }        
    }
    
    function closeTextBoxesDivs()
    {
        var div_tags = document.getElementsByTagName("div")       
           
        for(i=0;i<div_tags.length;i++)
        {                
            if(div_tags[i].id.indexOf('TextBoxes') >= 0)
            {           
                div_tags[i].style.display = 'none';               
            }
         }                    
    }     
    
     function closeMessages()
    {
        var span_tags = document.getElementsByTagName("span") 
        for(i=0;i<span_tags.length;i++)
        {              
            if(span_tags[i].id.indexOf('msgMinExpert') >= 0 || span_tags[i].id.indexOf('msgNoteChange') >= 0 ||  span_tags[i].id.indexOf('msgNoExperts') >= 0  )
            {                           
                span_tags[i].style.display = 'none'               
            }
         }      
    }
    
    function checkSpecialClick()
    {  
        beforeRender();    
    }    
    
    function SaveSession()
    {   
        //number of expers in page(grid) is calculated inside the API javascript.        
        kasamba_EG_numExperts = numExpertInPage;
       
        try
        {   
            document.getElementById("hiddenParamID").value = kasamba_EG_paramID;
            document.getElementById("hiddenWidth").value = kasamba_EG_width;
            document.getElementById("hiddenHeight").value = kasamba_EG_height;
            document.getElementById("hiddenNumExperts").value = kasamba_EG_numExperts;
            document.getElementById("hiddenHeader").value = kasamba_EG_header;
            document.getElementById("hiddenFooter").value = kasamba_EG_footer;
            document.getElementById("hiddenPadding").value = kasamba_EG_padding;
            document.getElementById("hiddenSpecialOfferLayout").value = kasamba_EG_specialOfferLayout;
            document.getElementById("hiddenControlsStateCommands").value = kasamba_EG_controlsStateCommands;
            document.getElementById("hiddenChangedSizeAndLayout").value = kasamba_EG_changedSizeAndLayout;
            document.getElementById("hiddenTitleFontSize").value = kasamba_EG_titleFontSize;
            document.getElementById("hiddenSubtitleFontSize").value = kasamba_EG_subtitleFontSize;
            document.getElementById("hiddenFooterFontSize").value = kasamba_EG_footerFontSize;
            
            return true;
        }
        catch(e)
        {
            WriteErrorLog(e, "SaveSession");
        }
        return false;
    }
  
        
    function setDefaultLayout()
    {            
        
        switch(parseInt(kasamba_EG_paramID))
        {
        case 1 :                         
                setLayout(true,false,true,false,true,false,true,false,false,false,"block") ;
                break;
        case 2:
                setLayout(true,false,true,false,true,false,true,false,false,false,"block") ;
                break; 
        case 3:
               setLayout(false,true,false,true,false,true,false,true,false,true,"none") ;
                break;
        case 4:                 
                setLayout(false,false,false,true,false,false,true,false,false,true,"none") ; 
                break;
        case 5:
                setLayout(true,false,false,true,false,true,false,true,false,true,"none") ;
                break;
        case 6:
                setLayout(true,true,false,true,false,true,false,true,false,true,"none") ;
                break;
        case 7:
                setLayout(true,false,false,true,false,false,true,false,false,false,"none") ; 
                break;
        case 8:
                setLayout(false,true,false,true,false,true,false,true,false,true,"none") ;                      
                break;
        }
   }     
       
       
            
        function getLayoutType1(paramItm)
        {     
            
                       
            var objExpertChange, objNoteChange;
            var numberOfExperts = paramItm.NumberExperts;
             
            var chkheader = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader");
            var chkfooter = document.getElementById("ctl00_ContentPlaceHolderPage_chkFooter");
            var rbWithIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithIcon");          
            var rbWithoutIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithoutIcon");    
            var chkSpecialOffer= document.getElementById("ctl00_ContentPlaceHolderPage_chkSpecial"); 
            var tblIcon = document.getElementById("tblIcon")
            var noExpertsMsg = document.getElementById("ctl00_ContentPlaceHolderPage_msgNoExperts");
            var objNotation = getObject("msgNoteChange" + kasamba_EG_paramID ,"span")
            
            var specialOffer = getObject("chkSpecial",'input')            
            var iconClosed = "none";
           
            if (specialOffer!=null && tblIcon!=null) 
            {   
                                     
                if (specialOffer.checked)        
                {               
                    iconClosed = "block"; 
                              
                }
                else
                {                   
                    iconClosed ="none";                             
                }                
            }
           
            if (chkheader!=null)        
            {
                if (!resetLayoutControls)
                {
                    if (!chkheader.checked)               
                    {   
                        setLayout(null,null,null,null,null,null,null,true,true,null,iconClosed) ; 
                    }
                    else if (chkheader.checked)               
                    {                          
                        setLayout(true,false,null,null,null,false,null,false,null,false,iconClosed) ;                              
                       
                    }
                }                            
                else
                {
                    setLayout(true,false,true,false,null,false,null,false,null,null,iconClosed) ;                    
                    resetLayoutControls=false;                                  
                }                 
            }    
                           
            var headerFooterState = getHeaderFooterState();                        
                
            if (headerFooterState == 3 )
            {        
                kasamba_EG_header=2 // header will appear but with nothing inside.                                             
            } 
            else if (headerFooterState==1 || headerFooterState ==2)         
            {             
                if(rbWithIcon.checked &&  chkSpecialOffer.checked )
                {                               
                    kasamba_EG_header=4 // header will appear with text and icon.
                }
                else   
                {                                
                    kasamba_EG_header=3 // header will appear with text only. 
                }   
            }       
           
            if (headerFooterState==0)
            {
                kasamba_EG_header=1 // delete header completely - will not appear in any case.
                kasamba_EG_numExperts+=1;                
            }   
                 
            calcExperts();                  
            //alert(paramItm.BannerHeight!= kasamba_EG_height || paramItm.BannerWidth!= kasamba_EG_width)
            objNotation.style.display= "none";  
            if (numExpertInPage==0)
            {                                       
               var messageMinimalExpert = getObject("msgMinExpert" + kasamba_EG_paramID ,'span');                  
                
               if (messageMinimalExpert !=null && ( chkheader.checked==true || chkfooter.checked==true ) && noExpertsMsg.style.display=="none") 
               {                    
                    messageMinimalExpert.style.display ="block";                    
               }               
            }
            else if (numExpertInPage>0 && (paramItm.BannerHeight!= kasamba_EG_height || paramItm.BannerWidth!= kasamba_EG_width))
            {
                 objNotation.style.display= "block";           
            }
            
            switch(headerFooterState)
            { 
                case 0: //niether footer nor header are checked
                     kasamba_EG_footer = 4; 
                     break;         
                case 2: // header is checked. Therefor, show only                                              
                     kasamba_EG_footer = 2;
                     break;
                case 1:    // footer is checked      
                case 3:    // header & footer are checked                                             
                     kasamba_EG_footer = 3
                     break;
            }     
            return true; 
        }
        
        function getLayoutType2(paramItm)
        {                     
            var objExpertChange, objNoteChange;
            var numberOfExperts = paramItm.NumberExperts;                         
            var chkFooter= document.getElementById("ctl00_ContentPlaceHolderPage_chkFooter");
            var tblIcon = document.getElementById("tblIcon");   
            var chkheader = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader");
           
            if (chkheader.checked)     
            {
                kasamba_EG_header=3
            }
            else
            {
                 kasamba_EG_header=2
            }       
            
             setLayout(null,false,false,true,false,true,false,null,false,null,"none") ; 
             kasamba_EG_footer=4;                   
           
            return true;        
        }
        
        function setLayout(headerChecked, headerDisabled, footerChecked, footerDisabled, specialOfferChecked,specialOfferDisabled, withIconChecked,withIconDisabled, withoutIconChecked, withoutIconDisabled, tblIconDisplay)
        {
            var chkheader = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader")
            var chkSpecialOffer= document.getElementById("ctl00_ContentPlaceHolderPage_chkSpecial"); 
            var chkFooter= document.getElementById("ctl00_ContentPlaceHolderPage_chkFooter");
            var rbWithoutIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithoutIcon");  
            var rbWithIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithIcon");  
            var tblIcon = document.getElementById("tblIcon");              
             
            objLayoutStateCommands=""; 
            
            if (headerChecked != null) 
            {
                 chkheader.checked=headerChecked ;                
                 objLayoutStateCommands+= "document.getElementById('" + chkheader.id + "').checked = " + headerChecked + ";"
                  
            } 
            
            if (headerDisabled!=null)
            {
                chkheader.disabled=headerDisabled;
                objLayoutStateCommands+= "document.getElementById('" + chkheader.id + "').disabled = " + headerDisabled+ ";"
            }    
            
            if(footerChecked!=null)
            {
                chkFooter.checked=footerChecked;
                objLayoutStateCommands+= "document.getElementById('" + chkFooter.id + "').checked = " + footerChecked+ ";"
            }
           
            if(footerDisabled!=null)
            {
                chkFooter.disabled=footerDisabled;
                objLayoutStateCommands+= "document.getElementById('" + chkFooter.id + "').disabled = " + footerDisabled+ ";"
            }    
            
            if (specialOfferChecked!=null)
            {
                chkSpecialOffer.checked=specialOfferChecked;
                objLayoutStateCommands+= "document.getElementById('" + chkSpecialOffer.id + "').checked = " + specialOfferChecked+ ";"             
            }            
           
            if (specialOfferDisabled!=null)
            {
                chkSpecialOffer.disabled=specialOfferDisabled;
                objLayoutStateCommands+= "document.getElementById('" + chkSpecialOffer.id + "').disabled = " + specialOfferDisabled+ ";"             
            }    
            
            if(withIconChecked !=null)
            {
                rbWithIcon.checked = withIconChecked;
                objLayoutStateCommands+= "document.getElementById('" + rbWithIcon.id + "').checked = " + withIconChecked+ ";"             
            }    
            
            if (withIconDisabled!=null)
            {
                rbWithIcon.disabled = withIconDisabled
                objLayoutStateCommands+= "document.getElementById('" + rbWithIcon.id + "').disabled = " + withIconDisabled+ ";"             
            }      
            
            if (withoutIconChecked !=null)
            {
                rbWithoutIcon.checked=withoutIconChecked;
                objLayoutStateCommands+= "document.getElementById('" + rbWithoutIcon.id + "').checked = " + withoutIconChecked+ ";"             
            }
            
            if (withoutIconDisabled!=null)
            {
                rbWithoutIcon.disabled = withoutIconDisabled;
                objLayoutStateCommands+= "document.getElementById('" + rbWithoutIcon.id + "').disabled = " + withoutIconDisabled+ ";"             
            }                          
            
            if (tblIconDisplay!=null)
            {
                tblIcon.style.display = tblIconDisplay;
                objLayoutStateCommands+= "document.getElementById('" + tblIcon.id + "').style.display  = '" + tblIconDisplay+ "';"             
            }    
        }
        
        function markLayoutObject(obj)
        {
             if (obj.checked)  
                {                         
                    objLayoutStateCommands+= "document.getElementById('" + obj.id + "').checked =true;"
                }
                else
                {                
                    objLayoutStateCommands+= "document.getElementById('" + obj.id + "').checked = false;"
                }    
                
                if (obj.disabled)  
                {                         
                    objLayoutStateCommands+= "document.getElementById('" + obj.id + "').disabled =true;"
                }
                else
                {                
                    objLayoutStateCommands+= "document.getElementById('" + obj.id + "').disabled = false;"
                }    
        }
        
        
        function setLastLayoutControlsState()
        {
            var chkheader = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader")
            var chkSpecialOffer= document.getElementById("ctl00_ContentPlaceHolderPage_chkSpecial"); 
            var chkFooter= document.getElementById("ctl00_ContentPlaceHolderPage_chkFooter");
            var rbWithoutIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithoutIcon");  
            var rbWithIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithIcon");  
            var tblIcon = document.getElementById("tblIcon");              
             
            objLayoutStateCommands=""; 
            markLayoutObject(chkheader);
            markLayoutObject(chkSpecialOffer);
            markLayoutObject(chkFooter);
            markLayoutObject(rbWithoutIcon);
            markLayoutObject(rbWithIcon);            
           
            if (tblIcon.style.display == "block")
            {                         
                objLayoutStateCommands+= "document.getElementById('" + tblIcon.id + "').style.display ='block';"
            }
            else
            {                
                objLayoutStateCommands+= "document.getElementById('" + tblIcon.id + "').style.display ='block';"
            }             
            markLayoutObject(tblIcon);
            
            
            return (objLayoutStateCommands);
        }
        
        
        function getLayoutType3(paramItm)
        {  
           kasamba_EG_numExperts = paramItm.NumberExperts ;               
           kasamba_EG_header=1
           kasamba_EG_footer=6                    
           return true;        
        }
                
        function getLayoutType4(paramItm)
        {          
           switchHeaderAndSpecialOffer(6,5);           
           kasamba_EG_footer=5;   
           return true;   
        }
            
         function getLayoutType5(paramItm)
         {     
          
            var header = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader");
            if (header!=null)
            {
                if (header.checked)
                {
                     kasamba_EG_header=8;   
                }
                else
                {
                     kasamba_EG_header=9;  
                }
            }
               
           kasamba_EG_footer=1;                 
           kasamba_EG_numExperts = paramItm.NumberExperts ;   
           return true;   
         }
         
         function getLayoutType6(paramItm)
         {             
           kasamba_EG_footer=2;
           kasamba_EG_header=1;                               
           kasamba_EG_numExperts = paramItm.NumberExperts ;                                                                    
          
           return true;   
         }
         
         function getLayoutType7(paramItm)
         {     
           switchHeaderAndSpecialOffer(3,7);           
           kasamba_EG_footer = 4;  
           return true;   
         }
        
    
        function getParamItem(paramID)
        {          
            if (arrParams!=null)
            {
                for (i=0; i<arrParams.length; i++)
	            {	           
		            if (arrParams[i].ID == paramID)
		            {
		                return arrParams[i];			        
		            }
	            }
	        }
        }
    
        //check control and set all global variable before rendering 
        function beforeRender()
        {          
             kasamba_EG_padding = 0;                       
             var itm  = getParamItem(kasamba_EG_paramID);    
             
             if (itm!=null)
             {
                 kasamba_EG_paramID = itm.ID;
                 if (kasamba_EG_changedSizeAndLayout==0)
                 {
                    kasamba_EG_height = itm.BannerHeight;
                    kasamba_EG_width =  itm.BannerWidth;             
                 }
                              
                 kasamba_EG_bannerGridShape = itm.BannerGridShape
                 kasamba_EG_expertUnitHeight = itm.ExpertUnitHeight;
                 kasamba_EG_expertUnitWidth = itm.ExpertUnitWidth;
                 kasamba_EG_headerUnitHeight = itm.HeaderUnitHeight;
                 kasamba_EG_headerUnitWidth = itm.HeaderUnitWidth;
                 kasamba_EG_footerUnitHeight = itm.FooterUnitHeight;
                 kasamba_EG_navigationUnitHeight = itm.NavigationUnitHeight ;
                 kasamba_EG_navigationUnitWidth = itm.NavigationUnitWidth ;       
                 kasamba_EG_imageSpecialOffer = itm.ImageSpecialOffer;
                 kasamba_EG_imageDefaultExpert = itm.ImageDefaultExpert; 
                 kasamba_EG_layoutType = itm.LayoutType; 
                 kasamba_EG_titleFontSize = itm.TitleFontSizeDefault + "pt"; 
                 kasamba_EG_subtitleFontSize = itm.SubtitleFontSizeDefault + "pt";               
                 kasamba_EG_footerFontSize = itm.FooterFontSizeDefault + "pt";               
           
                 switch (itm.LayoutType)
                 {
                    case 1:
                        succeed = getLayoutType1(itm);
                        if (!succeed)
                            return;
                        break;
                     case 2:
                        succeed = getLayoutType2(itm);
                        if (!succeed)
                            return;
                        break;   
                     case 3:                                      
                        succeed = getLayoutType3(itm);
                        if (!succeed)
                            return;
                        break; 
                     case 4:
                        succeed = getLayoutType4(itm);
                        if (!succeed)
                            return;
                        break;     
                     case 5:
                        succeed = getLayoutType5(itm);
                        if (!succeed)
                            return;
                        break; 
                     case 6:
                        succeed = getLayoutType6(itm);
                        if (!succeed)
                            return;
                        break;   
                     case 7:
                        succeed = getLayoutType7(itm);
                        if (!succeed)
                            return;
                        break;            
                                      
                 }        
             
                EGrender();                        
            
                setInterval("WriteSize()",500);  
            }              
        }
        
        function WriteSize()
        { 
            var outputDiv = document.getElementById("output");
            var size = outputDiv.offsetWidth + " X " + outputDiv.offsetHeight;
            document.getElementById("BannerSizeTop").innerHTML = size;
            document.getElementById("BannerSizeDown").innerHTML = size;
        }   
        
        function getHeaderFooterState()
        {
            
            header = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader");
            footer = document.getElementById("ctl00_ContentPlaceHolderPage_chkFooter");           
            
           
            if (header.checked==false && footer.checked ==false)
            {
                //if footer and header are both unchecked
                return 0
            }
            
            else if(header.checked==true && footer.checked ==true)
            {
                //if footer and header are both checked
                return 1;
            }
            else  if(header.checked==true && footer.checked ==false)
            {
                //if header is checked only
                return 2;
            }
            else  if(header.checked==false && footer.checked ==true)
            {
                //if footer is checked only
                return 3;
            }       
        }       
        
        function switchHeaderAndSpecialOffer(header1, header2)
        {
           var specialOffer= document.getElementById("ctl00_ContentPlaceHolderPage_chkSpecial");           
           var header = document.getElementById("ctl00_ContentPlaceHolderPage_chkHeader");
            
           if (objLastPresses ==null)
           {
                objLastPresses = specialOffer; 
                specialOffer.checked=true;         
           }      
                 
           if ( (objLastPresses.id == specialOffer.id && specialOffer.checked ==true ) ||(objLastPresses.id == header.id && header.checked ==false ) )
           {
                
                 kasamba_EG_header=header2;
                 setLayout(false,false,false,true,true,false,true,false,false,true,"block") ;                   
           }
           else if ((objLastPresses.id == header.id && specialOffer.checked ==true ) ||(objLastPresses.id == specialOffer.id && header.checked ==false ) )
           {    
                
                 kasamba_EG_header=header1;
                 setLayout(true,false,false,true,false,false,true,false,false,true,"none") ;  
                 
           }        
        }
        
        function setSpecialOfferParam()
        {
            kasamba_EG_specialOfferLayout = 1; // None
            var chkSpecialOffer= document.getElementById("ctl00_ContentPlaceHolderPage_chkSpecial"); 
            var rbWithIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithIcon");          
            var rbWithoutIcon= document.getElementById("ctl00_ContentPlaceHolderPage_rbWithoutIcon");   
            
            if (chkSpecialOffer!=null && rbWithIcon!=null && rbWithoutIcon!=null)
            {            
               
               if (chkSpecialOffer.checked)
               {
                    if (rbWithIcon.checked)
                    {
                        kasamba_EG_specialOfferLayout = 3; // WithIcon
                    }    
                    else
                    {
                        kasamba_EG_specialOfferLayout = 2; // WithNotIcon
                    }      
                    
               } 
            }
        
        }
        
        function closeSpecialOffer(obj)
        {
            if (obj.checked==false)
            {
                document.getElementById("tblIcon").display="none";
            }  
        }
        
        function saveObjStateCommand()
        {          
            setSpecialOfferParam();      
            //saving the grid size section   
            kasamba_EG_controlsStateCommands+=reArrangeGridAndSize(); 
            
            //saving the layout section
            kasamba_EG_controlsStateCommands+=setLastLayoutControlsState();       
        }        
        
        function reArrangeGridAndSize()
        {
            var gridAndSize = "";
           
            gridAndSize=  " closeControls(false);"          
            var itm  = getParamItem(kasamba_EG_paramID); 
            
            if (itm!=null)
            {            
                var obj = getObject("rbSize" + kasamba_EG_paramID, 'input' );
                gridAndSize+="document.getElementById('" + obj.id + "').checked=true;" 
                
                switch (itm.BannerGridShape)
                {
                    case 1:
                    {
                        obj = getObject("tblRootSquare", 'table' );
                        gridAndSize+="document.getElementById('" + obj.id + "').style.display='block';";
                        
                        obj = getObject("rbSquare", 'input' );
                        gridAndSize+="document.getElementById('" + obj.id + "').checked=true;";
                        break;
                    }
                    case 2:
                    {
                        obj = getObject("tblRootHorizontal", 'table' );
                        gridAndSize+="document.getElementById('" + obj.id + "').style.display='block';";
                        
                        obj = getObject("rbHorizontal", 'input' );
                        gridAndSize+="document.getElementById('" + obj.id + "').checked=true;";
                        
                       
                        break;
                    }
                    case 3:
                    {
                        obj = getObject("tblRootVertical", 'table' );
                        gridAndSize+="document.getElementById('" + obj.id + "').style.display='block';";
                        
                        obj = getObject("rbVertical", 'input' );
                        gridAndSize+="document.getElementById('" + obj.id + "').checked=true;";                        
                        break;
                    }
                }   
                
                
                if (itm.DimensionCustomizable ==1)
                {
                    if (kasamba_EG_width!=itm.BannerWidth || kasamba_EG_height!=itm.BannerHeight )
                    {         
                        obj = getObject("lblCustomLink" + kasamba_EG_paramID ,'span' );
                        gridAndSize+="document.getElementById('" + obj.id + "').style.display='inline';";  
                        gridAndSize+="document.getElementById('" + obj.id + "').innerHTML ='Customize Size';";
                                                
                        obj = getObject("divTextBoxes" + kasamba_EG_paramID ,'div' );
                        gridAndSize+="document.getElementById('" + obj.id + "').style.display='block';";  
                         
                        obj = getObject("txtWidth" + kasamba_EG_paramID, 'input');
                        gridAndSize+="document.getElementById('" + obj.id + "').value = " +kasamba_EG_width + " ;";  
                                            
                        obj = getObject("txtHeight" + kasamba_EG_paramID, 'input' );
                        gridAndSize+="document.getElementById('" + obj.id + "').value = " +kasamba_EG_height + " ;";                                
                    }  
                    else  
                    {
                        obj = getObject("lblCustomLink" + kasamba_EG_paramID ,'span' );
                        gridAndSize+="document.getElementById('" + obj.id + "').style.display='inline';";                                       
                    }
                }     
            }           
                   
           return (gridAndSize)
        }
               
        function handleMainRadio(paramID,tbl,objID)
        {    
            
            if (objID!=null)
            {
                objMainRadio = getObject (objID, 'input');            
                objMainRadio.checked=true;            
            }
            
            objLinkChange = null;
            objDivTextBoxes = null;
            objSubRadio=null;
            objLastPresses=null;
            
            closeControls(true); 
            
            kasamba_EG_changedSizeAndLayout =0;
            resetLayoutControls =true;
             
            kasamba_EG_paramID= paramID;
             
            setDefaultLayout();          
                      
            if (tbl!=null)      
            {
                if(tbl!="")
                {                         
                    objRootShape = getObject(tbl,'table');                                     
                    document.getElementById(tbl).style.display = "block"  ;    
                }   
            }          
           
               
            beforeRender();
        }
        
        function handleSizeWithoutCustomization(paramID)
        {
            
            handleCommonSubRadio(paramID);
            //closeChangeLinks();
          //  objLastPresses = null; 
                   
        }
        
       
        
        function handleCommonSubRadio(paramID)
        {     
            
            objSubRadio = getObject("rbSize"+paramID,'input');
            kasamba_EG_changedSizeAndLayout = 0;        
            objLastPresses = null; 
            objLinkChange = null;
            objDivTextBoxes = null;
            objSubRadio = null;
            closeChangeLinks();  
            closeTextBoxesDivs(); 
            closeMessages();
            kasamba_EG_paramID= paramID;
            setDefaultLayout();
            beforeRender();  
        
        }
        
        function rbSubClick(link,paramID)
        {                 
             handleCommonSubRadio(paramID);            
             if (link!=null)
             {
                document.getElementById(link).style.display = "inline"; 
             }                   
        }
        
        function validatePage()
        {
            if (PageIsLoad != 1)
            {
                return false;
            }
                
             closeMessages();
             var message =getObject("msgNoExperts","span");
             if(numExpertInPage ==0)
             {
                message.style.display="block";
                return false;
             }
             return true;
        }
        
        
  // Callback function invoked on successful 
// completion of the page method.
function OnSucceeded(result, userContext, methodName) 
{
   if (methodName == "GetAffiliateParams")
   {
        arrParams = result;
        beforeRender();
   }
}

// Callback function invoked on failure 
// of the page method.
function OnFailed(error, userContext, methodName) 
{
    if(error !== null) 
    {
        alert(error.get_message());
    }
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


window.onload = function () 
{
    if (typeof(AffiliateWizard.Ajax.ProcessService.GetAffiliateParams)!= "undefined")
    {
        AffiliateWizard.Ajax.ProcessService.GetAffiliateParams(OnSucceeded, OnFailed);
        PageIsLoad = 1;
    }
}
    
