/* Img pre caching */
var pic00 = new Image();var pic01 = new Image();var pic02 = new Image();var pic03 = new Image();var pic04 = new Image();  
var pic05 = new Image();var pic06 = new Image();var pic07 = new Image();var pic08 = new Image();
var pic09 = new Image();var pic10 = new Image();var pic11 = new Image();
var pic12 = new Image();var pic13 = new Image();var pic14= new Image();
pic00.src = "/Images/vote-clear-shuffle.jpg";pic01.src = "/Images/shuffle-top.jpg";pic02.src = "/Images/shuffle-up.jpg";pic03.src = "/Images/shuffle-down.jpg";pic04.src = "/Images/shuffle-bottom.jpg";
pic05.src = "/Images/vote-up10.jpg";pic06.src = "/Images/vote-down10.jpg";pic07.src = "/Images/vote-remain10.jpg";pic08.src = "/Images/vote-clear.jpg";   
pic09.src = "/Images/novote-up.jpg";pic10.src = "/Images/novote-down.jpg";pic11.src = "/Images/novote-remain.jpg";
pic12.src = "/Images/Icons/icon-arrowloadrightdark.png";pic13.src = "/Images/Icons/icon-arrowloadleftdark.png";pic14.src = "/Images/Icons/icon-arrowloadupdark.png";

var pictmp00 = new Image();var pictmp01 = new Image();var pictmp02 = new Image();var pictmp03 = new Image();
pictmp00.src = "/Images/alttt100additem.png";pictmp01.src = "/Images/alttt100blogo.png";pictmp02.src = "/Images/alttt100startgrp180x50.png";pictmp03.src = "/Images/alttt100startlist.png";



var JSPanelCurrentlyVisible = false;
var JSWarningsCleared = false;

// Begin main menu
var hidemenu = false;
var mtimer;
function fnHoverMainMenuItem(elm, width, marginleft) {

  window.clearInterval(mtimer);
  
  $(".mainmenuPopup").fadeOut('fast', function() {
    $(".mainmenuPopup").removeShadow();
  });
  $(".mainmenuOuterItemHovered").removeClass('mainmenuOuterItemHovered');
  $(".mainmenuexpanderHovered").removeClass('mainmenuexpanderHovered'); 

  $(elm).next("div").css('width', width + "px");
  
  if(marginleft == null) {
    var leftPos = $(elm).prev("a").position().left;
    
    $(elm).next("div").css('left', (leftPos+10) + "px");
  } else {
    $(elm).next("div").css('margin-left', marginleft + "px");
  }
  

  $(elm).next("div").fadeIn('fast', function() {
    $(elm).next("div").dropShadow( {opacity:0.5,top:4,left:4,color:'#888888'});  
  });
  $(elm).prev("a").addClass('mainmenuOuterItemHovered');
  $(elm).addClass('mainmenuexpanderHovered');
  
  
  
  $(elm).next("div").mouseover(function() {
    hidemenu = false;
  });
  
  $(".mainmenuPopup a").css('width', (width-10) + "px");

  $(elm).next("div").mouseleave(function() {
     hidemenu = true;
     $(elm).next("div").removeShadow();
     $(elm).next("div").fadeOut('fast', function() {
     // Animation complete
     $(elm).prev("a").removeClass('mainmenuOuterItemHovered');
     $(elm).removeClass('mainmenuexpanderHovered');
     }); ;
  });

}

function fnLeaveMainMenuItem(elm) {
   hidemenu = true;
      
   mtimer = window.setTimeout(function() { 

      if(hidemenu) {
          
          $(".mainmenuPopup").fadeOut('fast', function() {
            $(".mainmenuPopup").removeShadow();  
          });
          $(".mainmenuOuterItemHovered").removeClass('mainmenuOuterItemHovered');
          $(".mainmenuexpanderHovered").removeClass('mainmenuexpanderHovered'); 
      }
      
      hidemenu = false;    
   
   }, 300);
}
// End main menu

// Star rating

function setStarRating(storeElm, idx, amount) {

    var rating = 0;

    if(amount == "half") {
        rating = idx-.5;
    } else {
        rating = idx;
    }
    
    $("#" + storeElm)[0].value = rating;

}

function displayStarRatingStoredVals(storeElm, srcElm) {
    try {
        var val =  $("#" + storeElm)[0].value;
        var $objPar = $("#" + srcElm);
        var $objStars = $objPar.find("div img");
                    
        for(var i=0; i<5; i++) { $objStars[i].src = '/images/stars/dimstar.gif'; }   

        if(val >= .5) $objStars[0].src = '/images/stars/halfstar.jpg';  
        if(val >= 1) $objStars[0].src = '/images/stars/Star-1.0.jpg';  

        if(val >= 1.5) $objStars[1].src = '/images/stars/halfstar.jpg';  
        if(val >= 2) $objStars[1].src = '/images/stars/Star-1.0.jpg';  

        if(val >= 2.5) $objStars[2].src = '/images/stars/halfstar.jpg';  
        if(val >= 3) $objStars[2].src = '/images/stars/Star-1.0.jpg';  

        if(val >= 3.5) $objStars[3].src = '/images/stars/halfstar.jpg';  
        if(val >= 4) $objStars[3].src = '/images/stars/Star-1.0.jpg';  

        if(val >= 4.5) $objStars[4].src = '/images/stars/halfstar.jpg';  
        if(val >= 5) $objStars[4].src = '/images/stars/Star-1.0.jpg';    
    } catch(e) {
    } 
}

function starRatingHover(storeElm, srcElm, idx, mode, amount) {
    var $objPar = $("#" + srcElm);
    var $objStars = $objPar.find("div img");
        
    switch(mode) {
        case "over":
            if($("#" + storeElm)[0].value != "") {
                for(var i=0; i<5; i++) { $objStars[i].src = '/images/stars/dimstar.gif'; }     
            }
            
            for(var i=0; i<idx; i++) {

                if(i==idx-1 && amount=="half") {
                    $objStars[i].src = '/images/stars/halfstar.jpg';  
                }
                else {
                    $objStars[i].src = '/images/stars/Star-1.0.jpg';    
                }
            }   
            break;
        
        case "out":
            for(var i=0; i<5; i++) {
                if(i >= idx) {
                    if(i==idx-1 && amount=="half") {
                        $objStars[i].src = '/images/stars/halfstar.jpg';    
                    }
                    else {
                        $objStars[i].src = '/images/stars/dimstar.gif';    
                    }        
                } else {
                
                    $objStars[i].src = '/images/stars/dimstar.gif';          
                }
            }    
            break;        
    }
}

function createTriggerWarningOnAllNavigateAwayElements() {
   var objElms = document.body.getElementsByTagName("a");
   for(var i=0; i < objElms.length; i++) {
   
   
      objElms[i].newFunc = function() {
        return objElms[i].onclick;
      }   
     
      objElms[i].onclick = function() {
         return confirm("You will lose the Item you are about to add. Navigate away?");
      }
   }         
}
function clearTriggerWarningOnAllNavigateAwayElements() {
   var objElms = document.body.getElementsByTagName("a");
   for(var i=0; i < objElms.length; i++) {  

      if (objElms[i].newFunc != null) {
       objElms[i].onclick = objElms[i].newFunc;
      }

   }         
}

function hideReOrderElms(hide) {
  if(hide) {
      $(".moveup").css("display", "none");
      $(".movedown").css("display", "none");
      $(".delete").css("display", "none");
  } else {
      $(".moveup").css("display", "block");
      $(".movedown").css("display", "block");
      $(".delete").css("display", "block");  
  }
}

function createWarningAsyncPostbackOnAllNavigateAwayElements(message, senderObject, disableSenderObject, bypassValidation, ValidationGroup) {
    
    var oForm =  document.getElementById("aspnetForm");
    var PagePassedValidation = true;
    
    if (!bypassValidation) PagePassedValidation= Page_ClientValidate(ValidationGroup);

    if (disableSenderObject) {

        oForm.onsubmit = function() {

            if (PagePassedValidation) {

                document.body.style.cursor = "wait";

                try {
                    disableElement(senderObject);
                } catch(e) {
                //alert(e.message);
                }
                                
                var objElms = document.body.getElementsByTagName("a");
                for(var i=0; i < objElms.length; i++) {  

                    objElms[i].setAttribute("orighref", objElms[i].href);      
                    objElms[i].href = null;

                    objElms[i].newFunc = function() {
                        return objElms[i].onclick;
                    }

                    objElms[i].onclick = function() {
                        alert(message);
                        return false;
                    }
                }
            }
        }
        JSWarningsCleared = false;

    }   

    return PagePassedValidation;
}

function clearWarningAsyncPostbackOnAllNavigateAwayElements() {

   if(JSWarningsCleared) return; // Only clear once!

   var oForm =  document.getElementById("aspnetForm");
   oForm.onsubmit = null;
   
   document.body.style.cursor = "default";
   var objElms = document.body.getElementsByTagName("a");
   for(var i=0; i < objElms.length; i++) { 
    try {
        if (objElms[i].getAttribute("orighref") != null && objElms[i].getAttribute("orighref") != "")  {
            objElms[i].href = objElms[i].getAttribute("orighref");      
        }
    } catch(e) { }

     if (objElms[i].newFunc != null) {
        objElms[i].onclick = objElms[i].newFunc;
     }
   }  
   JSWarningsCleared = true;       
}

function disableElement(senderObject) {

    var pos;
    
    if (JSPanelCurrentlyVisible) {
        pos = $(senderObject).position();
    } else {
    
        pos = $(senderObject).offset();
    }

    var maskElm = document.createElement("div");                                
    maskElm.style.position = "absolute";
    maskElm.style.left = pos.left + "px";
    maskElm.style.top = pos.top + "px";
    maskElm.style.width = senderObject.offsetWidth + "px";
    maskElm.style.height = senderObject.offsetHeight + "px";
    maskElm.style.cursor = "wait";
    maskElm.style.backgroundColor = "#FFFFFF";
    maskElm.style.zIndex = "20000";
    maskElm.className  = "opacity1"; 
    maskElm.id = "dynaButtonMask"; 
    
    senderObject.parentNode.insertBefore(maskElm, senderObject);

    $(senderObject).fadeTo('slow', 0.45, function() {
         // Animation complete.
    });
    return true;
}

function ConfirmListSettingsUpdate()
{
   var txtUpdateStatus = 
         $("[id$=txtUpdateStatus]")[0]   
   if(txtUpdateStatus.value!=""){
      window.alert('List settings have been saved')
   }
}

function checkTextFieldDngr(elm, alertIfFound) {
   var booFound = false;

   if (String(elm.value).indexOf("<") > -1 || String(elm.value).indexOf(">") > -1) {
      elm.value = String(elm.value).replace(/</g, "&lt;");
      elm.value = String(elm.value).replace(/>/g, "&gt;");
      booFound = true;
   }

   if (booFound && alertIfFound) {
      alert("Some characters you have entered have been encoded.");
   }  
}
function htmlDecode(elm) {

   if (String(elm.value).indexOf("&lt;") > -1 || String(elm.value).indexOf("&gt;") > -1 || String(elm.value).indexOf("&quot;") > -1) {
      elm.value = String(elm.value).replace(/&lt;/g,"<");
      elm.value = String(elm.value).replace(/&gt;/g, ">");
      elm.value = String(elm.value).replace(/&quot;/g, "\"");
   }

}
function closePanel(emlId) {  

   JSPanelCurrentlyVisible = false;

   document.body.onresize = null;
   var objFilterbox = document.getElementById("divPanelBG_" + emlId);
   var objFloatbox = document.getElementById("divPanel_" + emlId);
   var objFloatboxIframe = document.getElementById("divPanelIfr_" + emlId);

   if (objFilterbox != null) {
      $(objFloatbox).removeShadow();   
      objFilterbox.style.display = "none";
      objFloatbox.style.display = "none";
      if (objFloatboxIframe != null) objFloatboxIframe.style.display = "none";
   }

   var oFncall = "panel"+emlId+"StoreState('invisible')";
   var ret = eval(oFncall);   
}

function showPanelRelative(emlId) {
   var oFncallGetWidth = "panel"+emlId+"GetWidth()";
   var boxWidth;
   
   try {
      boxWidth = eval(oFncallGetWidth); 
   } catch(e) {
      //alert("Unable to show panel. Cannot find function: " + oFncallGetWidth);
   }   
   
   var objFilterbox = document.getElementById("divPanelBG_" + emlId);
   var objFloatbox = document.getElementById("divPanel_" + emlId);
   var objFloatboxHeader = document.getElementById("divPanelHeader_" + emlId);      
   
   objFloatbox.style.width = String(boxWidth) + "px";  
   objFloatboxHeader.style.width = String(boxWidth-20) + "px";     
   
   objFloatbox.style.display="block";
   objFilterbox.style.display="block";
   
   var oFncall = "panel"+emlId+"StoreState('visible')";
   var ret = eval(oFncall); 
}

function showPanel(emlId,scrollToWinTop) {

   JSPanelCurrentlyVisible = true;
   document.body.onresize = function() { showPanel(emlId,scrollToWinTop); }


   var oFncallGetWidth = "panel"+emlId+"GetWidth()";
   var boxWidth;
   
   try {
      boxWidth = eval(oFncallGetWidth); 
   } catch(e) {
      //alert("Unable to show panel. Cannot find function: " + oFncallGetWidth);
   }
      
   var objFilterbox = document.getElementById("divPanelBG_" + emlId);
   var objFloatbox = document.getElementById("divPanel_" + emlId);
   var objFloatboxHeader = document.getElementById("divPanelHeader_" + emlId);

   
   var scrollTop = 0;
      
   if(!scrollToWinTop) {   
       scrollTop = document.body.scrollTop;
       if (scrollTop == 0) scrollTop = document.body.parentNode.scrollTop;   
   } else {
         $('html, body').stop().animate({ scrollTop: 0 }, 'slow');
   }
   
   // This is to  solve an error happening when a Javascript panel has been shown but on closing it still
   // is being called by Javascriptpanel.ShowPanel() On load before JavascriptPanel.ClosePanel() is closed
   if(objFilterbox == null) 
        return;


   var offsetLeft = 0; var offsetTop = 0;
   // IE 7 FIX TO MAKE/MOVE THE PANELS ALWAYS ON "THE OUTSIDE"
   if (getInternetExplorerVersion != undefined && getInternetExplorerVersion() >= 7 && getInternetExplorerVersion() < 8) {

       if (emlId != 'LoginPopup') {
           offsetLeft = $(".container-tab-content").offset().left;
           offsetTop = $(".container-tab-content").offset().top;

           objFilterbox.style.top = "-" + String(offsetTop) + "px";
           objFilterbox.style.left = "-" + String(offsetLeft) + "px";
       }

   }

   
   var bodyHeight = document.body.parentNode.scrollHeight;
   if (bodyHeight < document.body.parentNode.clientHeight) bodyHeight = document.body.parentNode.clientHeight;

   var bodyWidth = document.body.scrollWidth;
   if (bodyWidth < document.body.parentNode.clientWidth) bodyWidth = document.body.parentNode.clientWidth;

   objFilterbox.style.height = (bodyHeight) + "px";
   objFilterbox.style.width = (bodyWidth) + "px";

   objFloatbox.style.top = (scrollTop + 50 - offsetTop) + "px";
   objFloatbox.style.left = String((document.body.parentNode.clientWidth / 2) - (boxWidth / 2) - offsetLeft) + "px";
   objFloatbox.style.width = String(boxWidth) + "px";  
   
   objFloatboxHeader.style.width = String(boxWidth-20) + "px";  
   
   objFloatbox.style.display="block";
   objFilterbox.style.display = "block";

   
   $(objFloatbox).removeShadow();   
   
   if (document.getElementById("divPanelIfr_" + emlId) != null) {
      var objFloatboxIframe = document.getElementById("divPanelIfr_" + emlId);

      if (getInternetExplorerVersion != undefined && getInternetExplorerVersion() >= 7 && getInternetExplorerVersion() < 8) {
          objFloatboxIframe.style.top = objFloatbox.style.top;
      } else {
          objFloatboxIframe.style.top = ($(objFloatbox).offset().top + 10) + "px";      
      }
      
      objFloatboxIframe.style.left = objFloatbox.style.left;
      objFloatboxIframe.style.width= (objFloatbox.offsetWidth-10) + "px";
      objFloatboxIframe.style.height = (objFloatbox.offsetHeight-10) + "px";
      objFloatboxIframe.style.display ="block";
      
   } 
   
   if(scrollToWinTop) {
       if(typeof(ScrollToTopOfPageAfterPostback) == 'undefined') {
       // We are not on list page - scroll manually...
       $('html, body').stop().animate({ scrollTop: 0 }, 'slow');
       }
   }    
   var oFncall = "panel"+emlId+"StoreState('visible')";
   var ret = eval(oFncall + ";$(objFloatbox).dropShadow( {opacity:0.9,top:8,left:8,color:'#999999'});"); 
   
   
    
}

function toggleGraph(sGraphId) {
   var oGraph =
      document.getElementById(sGraphId);
   if (oGraph.style.display=='none')
      oGraph.style.display='block';
   else
      oGraph.style.display='none';
}

var CONST_SEARCHBOX_MASK = "...";

function searchBoxFocus(elm) {
   if (elm.value==CONST_SEARCHBOX_MASK) {
   elm.value='';
   }
}

function searchBoxLostFocus(elm) {
   if(elm.value=='') elm.value=CONST_SEARCHBOX_MASK;
}

var CONST_SEARCHBOXMAIN_MASK = "";

function searchBoxMainFocus(elm) {
   if (elm.value==CONST_SEARCHBOXMAIN_MASK) {
   elm.value='';
   }
}

function searchBoxMainLostFocus(elm) {
   if(elm.value=='') elm.value=CONST_SEARCHBOXMAIN_MASK;
}

function getY( oElement )
{
   var iReturnValue = 0;
   while( oElement != null ) {
      iReturnValue += oElement.offsetTop;
      iReturnValue -= oElement.offsetParent ? oElement.scrollTop : 0;
      
      oElement = oElement.offsetParent;
   }
   return iReturnValue ;
}

function getX( oElement )
{
   var iReturnValue = 0;
   while( oElement != null ) {
      iReturnValue += oElement.offsetLeft;
      oElement = oElement.offsetParent;
   }
   return iReturnValue;
}

function isValidDate(dateStr) {

    // Checks for the following valid date formats:
    // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY 
    if(dateStr=="" || dateStr==null)
    return true

    //var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
    var datePat = /^(\d{1,2}|[A-Za-z]+)(\/|-|\s|,|\\)(\d{1,2}|[A-Za-z]+)\2(\d{4})$/; // requires 4 digit year

    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
    //alert(lblDate +" is not a valid date, Please enter in MM/DD/YYYY format.")
    return false;
    }
    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[4];

    if (month < 1 || month > 12) { // check month range
    //alert(lblDate +":Month must be between 1 and 12.");
    return false;
    }
    if (day < 1 || day > 31) {
    //alert("Day must be between 1 and 31.");
    return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    //alert("Month "+month+" doesn't have 31 days!")
    return false;
    }
    if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day>29 || (day==29 && !isleap)) {
    //alert("February " + year + " doesn't have " + day + " days!");
    return false;
       }
    }
return true;
}

function redirectSearchResults(q) {
   if (q != CONST_SEARCHBOXMAIN_MASK) {
   window.location='/Results.aspx?q=' + q;
   }   
}
 
   
 function SelectUnSelectAll(AttributeId){  
   
  var objList = 
    $("[id$=chkList_"+ AttributeId + "]")[0]
    
   objList  =
     objList.getElementsByTagName("input");
     
     var booCheck = false;
     
    for(var i=0; i < objList.length; i++){
       objCheckBox = 
         objList[i];
       if(i==0 && objCheckBox.checked)
          booCheck= 
          true;
       else
        objCheckBox.checked = 
         booCheck                    
    }     
 }
   
 function RemoveSearchOptions(objLink, AttributeId){ 
      
      var objSpan =    
            objLink.parentElement.getElementsByTagName("span")[0];
            
       objSpan.title = ""     
       objSpan.innerText = ""        
       objLink.parentElement.style.display = "none"          
       //ShowHideImgSearchBtn();
             
      var objList = 
      $("[id$=chkList_"+ AttributeId + "]")[0]          
      
      var objTextBox = 
        $("[id$=txtSearchAttribute_"+ AttributeId + "]")[0]                     
         
      var txtFrom = 
           $("[id$=txtFrom_"+ AttributeId + "]")[0]
           
      var txtTo = 
          $("[id$=txtTo_"+ AttributeId + "]")[0]  
                 
      objList  =
         objList.getElementsByTagName("input");
     
     var booCheck = false;
     
       for(var i=0; i < objList.length; i++){
          objCheckBox = 
            objList[i];
                    
           objCheckBox.checked = 
            booCheck                    
       }
       
     objTextBox.value = 
         ""; 
         
      if(txtFrom!= null)
         txtFrom.value=""
                       
        if(txtTo!= null)
         txtTo.value=""     
 }
   
   function showHideAllFilters(booShow) {         
       
       var arryElm =
         document.getElementsByName("toggleFilterVis");
      
       var oTRFilters =
         $(".trFilters")[0];  
       
       var imgExpandAll =
            $(".imgExpandAll")[0]; 
       
       var imgHideAll =
         $(".imgHideAll")[0]; 
         
       var divButton = 
       $('[id="divButton"]')[0]       
                                             
       var btnImgSearch = 
       $("[id$=btnImgSearch]")[0]
      
      for (var i=0; i<arryElm.length; i++) {
         showHideFilters(arryElm[i], true, booShow,oTRFilters,imgExpandAll,imgHideAll,divButton,btnImgSearch);
      }                                   
   }
   
   function showHideFilters(oLink, booOverride, booOverrideVisibleValue,oTRFilters,imgExpandAll,imgHideAll,divButton,btnImgSearch) {
     if(oTRFilters==null)
       oTRFilters =
         $(".trFilters")[0];    
       //document.getElementById("ctl00_plcContentMain_ctl01_trFilters")      
     if(imgExpandAll==null)                   
      imgExpandAll =
            $(".imgExpandAll")[0];                                                 
            
     if(imgHideAll==null)      
      imgHideAll =
         $(".imgHideAll")[0];
     
     if(btnImgSearch==null)       
      divButton = 
       $('[id="divButton"]')[0]       
       
     if(btnImgSearch==null)                                         
       btnImgSearch = 
       $("[id$=btnImgSearch]")[0] 
                                   
                               
      if (oTRFilters) {       
         var iIndex =
            oLink.parentNode.parentNode.cellIndex;
         var oFilter =
            oTRFilters.cells[iIndex].getElementsByTagName('DIV')[0];
         
         if (booOverride) {
            if (booOverrideVisibleValue==true) {
               oFilter.style.display = '';
               oLink.getElementsByTagName('IMG')[0].src = '/images/down-black.gif';
            } else {
               oFilter.style.display = 'none';
               oLink.getElementsByTagName('IMG')[0].src = '/images/right-black.gif';            
            }
            
         } else {
         
            oFilter.style.display =
               oFilter.style.display == '' ?
                  'none' : '';
                  
            oLink.getElementsByTagName('IMG')[0].src =
               oFilter.style.display == '' ?
                  '/images/down-black.gif' :
                  '/images/right-black.gif';         
         }                  
         var bShowAny =
            false;           
            
         for (var iFilter=0; iFilter<oTRFilters.cells.length; iFilter++) {
            var sDisplay =
               //oTRFilters.cells[iFilter].style.display;
               oTRFilters.cells[iFilter].getElementsByTagName('DIV')[0].style.display;
            if (sDisplay == '') {
               bShowAny =
                  true;
               break;
            }
         }
         
            oTRFilters.style.display =
            bShowAny ? '' : 'none';
            
           divButton.style.display = 
            bShowAny ? '' : 'none';
                                            
                                                
            btnImgSearch.style.display = 
            bShowAny? "none" : "" 
             
           //ShowHideImgSearchBtn();             
            
         if(booOverride) {
            if (booOverrideVisibleValue) {
            
               imgExpandAll.style.display = 'none'
               imgHideAll.style.display = '';              
            
            } else {
            
               imgExpandAll.style.display = ''
               imgHideAll.style.display = 'none';                   
            }
         }
      }
      
      // In list.ascx
      ShowBubbleTail(null);

   }
      
   
   String.prototype.trim = function() {
   a = this.replace(/^\s+/, '');
   a = a.replace(/\s+$/, '');
   return a
   };
   
   function FilterList(objSender, AttributeId, Type){
          
     var objList = 
      $("[id$=chkList_"+ AttributeId + "]")[0]
     
     var txtSearch=
         $("[id$=txtSearchAttribute_"+ AttributeId + "]")[0]
                  
      objElementsList  =
         objList.getElementsByTagName("tr");
         
      objLabelList  =
         objList.getElementsByTagName("label");        
       
      var re= new RegExp("(^|\\s)+" + txtSearch.value, "i")
       
        var lstRangeOp=
           $("[id$=lstRangeOp_"+ AttributeId + "]")[0]
       
       //if(txtSearch.value.trim() != "")
       for(var i=1; i < objLabelList.length -1; i++){
           var txtValue = 
                     objLabelList[i].innerText                      
           if(txtSearch.value.trim() == "" || txtSearch.value.trim() == "...")
            objElementsList[i].style.display= ""  
           else{
              var booFound = 
              false;
              
              if(txtValue.match(re)!=null)
                 booFound= true;
              
              if(lstRangeOp!=null){               
                if(lstRangeOp.value!=""){
                  booFound= false;      
                              
                  if(Type=="date"){
                     var dtSearchDate = getDate(txtSearch.value);
                     var  valDate = getDate(txtValue)
                     if(dtSearchDate!= null && valDate != null)  
                      if((lstRangeOp.value==">=" &&  valDate >= dtSearchDate)
                       || (lstRangeOp.value=="<=" && valDate <= dtSearchDate))
                        booFound= true;
                   }                   
                   if(Type=="number" && !isNaN(txtSearch.value)){                                                           
                      if((lstRangeOp.value==">=" && parseFloat(txtValue) >= parseFloat(txtSearch.value))
                        || (lstRangeOp.value=="<=" && parseFloat(txtValue) <= parseFloat(txtSearch.value)))
                        booFound= true;
                   }
                }              
              }                                          
              if(booFound)
                objElementsList[i].style.display= ""
              else
               objElementsList[i].style.display= "none"  
            }                                     
       }     
   }
   
    var m_FilterListDBScript = null;
    var m_FilterListCurrentSearchStr = null;
    function FilterListDB(objSender, AttributeId, DestinationElm, HiddenValueElm) {
    
       // Load the script
       var headID = document.getElementsByTagName("head")[0];         
       
       if (m_FilterListDBScript != null) {
         headID.removeChild(m_FilterListDBScript);
       }
       
       var ftrTimer = setTimeout(function() {

           if(objSender.value == m_FilterListCurrentSearchStr) return;
           m_FilterListCurrentSearchStr = objSender.value;
           var d = new Date();
           ftrTimer = null;
           m_FilterListDBScript = document.createElement('script');
           m_FilterListDBScript.id="attributeFilterScript";
           m_FilterListDBScript.type = 'text/javascript';
           m_FilterListDBScript.onload = function() {   }           
           m_FilterListDBScript.src = '/Js/AttributeFilterData.aspx?attributeid=' + AttributeId + '&q=' + objSender.value + '&destElm=' + DestinationElm + '&hiddenValElm=' + HiddenValueElm + '&scrtime=' + d.getTime() ;
           headID.appendChild(m_FilterListDBScript);  
           m_FilterListCurrentSearchStr = null;
       }
       , 200);  
       
          
       //window.location = m_FilterListDBScript.src;
          
           
    }
   
   function getDate(strValue){
     if(strValue!= ""){
        var dt = strValue.split("/")
        if(dt.length==3){
            var strDate = dt[1] + "/" + dt[0] + "/" + dt[2]
            if(isValidDate(strDate))
               return new Date(strDate)
        }
     }
     return ""
   }
        
        
   function checkItemAddedToHiddenElmStoreValues(strCheckItem, strHiddenElmStoreValues) {
       if(strHiddenElmStoreValues.indexOf(strCheckItem+",", 0) > -1) {
        return true;
       } else {
        return false;
       }   
   }
    
   function BuildCaption(objSender,AttributeId,strHiddenElmStoreValues){
                                              
          var objCaptionCell = 
            $("[id$=tdSearchCaption_"+ AttributeId + "]")[0]                     
            
          var objList =   
            $("[id$=chkList_"+ AttributeId + "]")[0]
                               
          var objLabelList  =
            objList.getElementsByTagName("label");
            
          var txtFrom = 
           $("[id$=txtFrom_"+ AttributeId + "]")[0]
           
          var txtTo = 
           $("[id$=txtTo_"+ AttributeId + "]")[0]  
                
          var objCheckboxList  =
            objList.getElementsByTagName("input");  
                      
          var objSpan =    
            objCaptionCell.getElementsByTagName("span")[0];           
                    
          var objLink =    
            objCaptionCell.getElementsByTagName("a")[0]; 
          
                    
          var strCaption =                ""         
                 
          var itemSeparator = ",";
          var HiddenElmStoreValues = document.getElementById(strHiddenElmStoreValues);
          //if(HiddenElmStoreValues != null) HiddenElmStoreValues.value = "";
          
          for(var i=0; i < objCheckboxList.length; i++){
             objCheckBox = 
               objCheckboxList[i];
                                               
             if(objCheckBox.checked){
                strCaption += (strCaption==""? "" : ", ") + objLabelList[i].innerText;                     
                if(HiddenElmStoreValues != null && objCheckBox.getAttribute("attribvalid") != null && !checkItemAddedToHiddenElmStoreValues(objCheckBox.getAttribute("attribvalid"), HiddenElmStoreValues.value)) HiddenElmStoreValues.value+=objCheckBox.getAttribute("attribvalid") + itemSeparator;
             } else {
                if(HiddenElmStoreValues != null && objCheckBox.getAttribute("attribvalid") != null && checkItemAddedToHiddenElmStoreValues(objCheckBox.getAttribute("attribvalid"), HiddenElmStoreValues.value)) {
                    //alert(objCheckBox.getAttribute("attribvalid"));
                    HiddenElmStoreValues.value=String(HiddenElmStoreValues.value).replace(objCheckBox.getAttribute("attribvalid")+",", "");
                }
             }                        
          } 
          
          if(txtFrom!= null)
            if(txtFrom.value !="")
              strCaption += (strCaption==""? "" : ", ") + 
                  "From: " + txtFrom.value
                  
           if(txtTo!= null)
            if(txtTo.value !="")
              strCaption += (strCaption==""? "" : ", ") + 
                  "To: " + txtTo.value   
                      
           objSpan.title = 
            strCaption;
          
            objSpan.innerText = 
               strCaption.length > 50? strCaption.substr(0,50) + "..." : strCaption;                            
              
           if(strCaption.trim() != "")                 
             objLink.parentElement.style.display = ""                    
            else
            objLink.parentElement.style.display = "none"                                                                             
   }
   
   function ShowHideImgSearchBtn(){
   
     var btnImg = 
            $("[id$=btnImgSearch]")[0]   
            
        if( btnImg.style.display == "none" ){
           var arrCaptionCell = 
                  $("[id*=tdSearchCaption_]")    
                  
            var booSearchFilterFound = 
            false;
            
            for(var i=0; i < arrCaptionCell.length; i++){
              objSpan = 
                  arrCaptionCell[i].getElementsByTagName("span")[0];        
              if(objSpan.innerText.trim()!= ""){
                  booSearchFilterFound= 
                  true;
                  break;
              }        
            }
           
            var btnImg = 
                  $("[id$=btnImgSearch]")[0]      
            if(booSearchFilterFound)     
            btnImg.style.display = ""
            else
             btnImg.style.display = "none" 
       }              
   }
   
function HoverImage_MouseOver(hoverImg, hoverDiv) {
    if (hoverDiv.style.display == "none") {
        hoverDiv.style.width = hoverImg.clientWidth + "px";
        hoverDiv.style.height = hoverImg.clientHeight + "px";
        hoverDiv.style.left = getX(hoverImg) + "px";
        hoverDiv.style.top  = getY(hoverImg) + "px";
        hoverDiv.style.display = "block";
    }
}


function HoverImage_MouseOut(hoverDiv) {
   hoverDiv.style.display = "none";
}   

function fnSystemInfoSetExpandedState() {
   var objPaneFacts = 
      document.getElementById("PaneFacts");
      
   var objSystemInfoExpander = 
      document.getElementById("systemInfoExpander");      
      
   var objSystemInfoExpanderInner = 
      document.getElementById("systemInfoExpanderInner");          

   if(objPaneFacts.style.display=="none") {
      objPaneFacts.style.display="block";
      objSystemInfoExpander.innerText="-";
      objSystemInfoExpanderInner.innerText="less info";
   } else {
      objPaneFacts.style.display="none";
      objSystemInfoExpander.innerText="+";
      objSystemInfoExpanderInner.innerText="more info";      
   }
}

function fnSetExpandedState(expandElementId, plusHrefId, textHrefId) {
   var objExpandElement = 
      document.getElementById(expandElementId);
      
   var plusHref = 
      document.getElementById(plusHrefId);      
      
   var textHref = 
      document.getElementById(textHrefId);          

   if(objExpandElement.style.display=="none") {
      objExpandElement.style.display="block";
      plusHref.innerText="-";
      textHref.innerText="less info";
   } else {
      objExpandElement.style.display="none";
      plusHref.innerText="+";
      textHref.innerText="more info";      
   }
}



function PageSizeChange(visibleElm, invisibleEml) {
visibleElm.style.display="block";
invisibleEml.style.display="none";
}
function RemoveAllEscapeCharacter(str){

    for(var i=0;i<=strPost.length-1;i++)
    {
        str= str.replace("`","'").replace('~','"').replace('^','\n').replace('¬','\r');    
    }

    return str;    
}

function ReplaceAllOriginalEscapeCharacter(str){

    for(var i=0;i<=str.length-1;i++)
    {
        str= str.replace("`","'").replace('~','"').replace('^','\n').replace('¬','\r');    
    }

    return str;    
}

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function encodeHtml(encodedHtml) {
 encodedHtml = escape(encodedHtml);
 encodedHtml = encodedHtml.replace(/\//g,"%2F");
 encodedHtml = encodedHtml.replace(/\?/g,"%3F");
 encodedHtml = encodedHtml.replace(/=/g,"%3D");
 encodedHtml = encodedHtml.replace(/&/g,"%26");
 encodedHtml = encodedHtml.replace(/@/g,"%40");
 return encodedHtml;
} 
