/*
All product filtering pages have been modified to /resolve the back button issue.
//The product filtering controls pages have been replaced with the normal href redirect 
//to use a javascript function which is invoked on click event instead of the normal href redirect
// The javascript method "RedirectFilterPage" will create a cookie for
//each page and will direct to the the product filtering pages
//This cookie is a flag to let us know when the user click on hyperlink or click on the backbutton.
//If user clicked on backbutton it will retrieve the information from ReadFromHistoryPoint() c# method,
//otherwise it will retrieve information from  FilterExpressionSession var. 
*/
function RedirectFilterPage(redirectURL, thisID)
 {
       //delete all cookies
      delete_cookie("cookieproductlistClickMF");
      delete_cookie("cookieAnnualizedMFClick");
      delete_cookie("cookieCalendarMFClick");
      delete_cookie("cookieMorningstarMFClick");
      delete_cookie("cookieLipperMFClick");
      delete_cookie("cookieSMAClick");
      delete_cookie("cookieVarInvClick");
      delete_cookie("cookieMonthlySMAPerfClick");
      delete_cookie("cookieQuarterlySMAPerfClick");
      delete_cookie("cookieCalendarSMAPerfClick");
      delete_cookie("cookieAnnualizedSMAPerfClick");
     
      // CREATE COOKIE
       setCookie('cookie' + thisID,'true',1);
       
       // Redirect to URL
       var virtual_dir = base_path ? base_path : '/';
       location.href = virtual_dir + redirectURL;
 
 }
 
 
 
 function setCookie(c_name,value,expiredays)
{
   // alert('setCookie:: ' + c_name);
    var path = "/";
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+ expiredays);
    //document.cookie = c_name+ "=" + escape(value);
    document.cookie = c_name+ "=" + escape(value)+   ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ((path) ? "; path=" + path : "");
     
  //checkCookie (c_name);
}
 
function delete_cookie ( cookie_name )
{
     var path = "/";
 // alert('delete_cookie:: ' + cookie_name);
    var cookie_date = new Date ( );  // current date & time
   cookie_date.setTime ( cookie_date.getTime() - 11 );
  //document.cookie = cookie_name +=  "=; expires=" + cookie_date.toGMTString();
   document.cookie = cookie_name+ "=" + escape('true')+ "=; expires=" + cookie_date.toGMTString() + ((path) ? "; path=" + path : "");
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function checkCookie(c_name)
{
username=getCookie(c_name);
if (username!=null && username!="")
  {
  alert('Welcome again '+username+'!' + 'c_name:: ' + c_name);
  }
else
  {
  username=prompt('Please enter your name:',"");
  if (username!=null && username!="")
    {
    setCookie('username',username,365);
    }
  }
}