
window.onload = function() {
//  applyDefaultValue(document.getElementById('TxtUserNameT'), 'Email id');
//  applyDefaultValue(document.getElementById('TxtPasswordT'), 'Password');

}

function setCookie(usrnm,usrid)
{
//alert('hello!');
var c_name='username';
var c_id='userid';
var expiredays=365;
var val=usrnm;
var exdate=new Date();
 
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(val)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
 
    document.cookie=c_id+ "=" +escape(usrid)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    
        
    document.cookie=c_name+ "=" +escape(val)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/microsite/";
 
    document.cookie=c_id+ "=" +escape(usrid)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/microsite/";
    
    window.open("index.aspx", target="_self");
    //window.location.replace("http://198.106.21.89/index.aspx")
    //alert(usrid);
   //checkCookie();
}

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()
{
//alert('hELLO');
username=getCookie('username');
//alert(getCookie('userid'));
if (username!=null && username!="")
  {
        document.getElementById("Header1_LoginDiv").style.display="none";
        document.getElementById("Header1_WelComeDiv").innerHTML ="Welcome "+username;
        document.getElementById("Header1_LogutDiv").style.display="inline";
        if(document.getElementById("keyIconEC")!=null)
        {
            document.getElementById("keyIconEC").style.display="none";
        }
        if(document.getElementById("keyIconRR")!=null)
        {
            document.getElementById("keyIconRR").style.display="none";
        }
        //alert('Welcome '+username+'!');
  }
else
  {
        if(document.getElementById("keyIconEC")!=null)
        {
            document.getElementById("keyIconEC").style.display="inline";
        }
        if(document.getElementById("keyIconRR")!=null)
        {
            document.getElementById("keyIconRR").style.display="inline";
        }
        document.getElementById("Header1_LoginDiv").style.display="inline";
        document.getElementById("Header1_LogutDiv").style.display="none";
        document.getElementById("Header1_WelComeDiv").innerHTML ="Welcome Guest";
  }
}

function GetUserID()
{
    userID=getCookie('userid');
    if(userID!=null && userID!="" && userID!="undefined")
    {
        document.getElementById("TxtUserID").value=userID;
    }
    //alert(userID);
}
function Logout()
{
    //alert('logout');
    var cookie_date = new Date ( );  // current date & time
    var cookie_name='username';
    var cookie_Id='userid';
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
    document.cookie = cookie_Id += "=; expires=" + cookie_date.toGMTString();
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString()+"; path=/microsite/";
    document.cookie = cookie_Id += "=; expires=" + cookie_date.toGMTString()+"; path=/microsite/";
    
    window.open("index.aspx", target="_self");
    //window.location.replace("http://198.106.21.89/index.aspx")
    //alert('logout');
}

function validatePageOpen()
{
    username=getCookie('username');

    if (username!=null && username!="")
      {
        return true;
      }
    else
      {
      alert('Please login or signup for free to view the page.');
        return false;
      }
}


function applyDefaultValue(elem, val) {
  elem.style.color = '#222222';
  elem.value = val;
  elem.onfocus = function() {
    if(this.value == val) {
      this.style.color = '';
      this.value = '';
    }
  }
  elem.onblur = function() {
    if(this.value == '') {
      this.style.color = '#ff0012';
      this.value = val;
    }
  }
}

