﻿function RememberMe()
{
    var MyBox = document.getElementById('remember');
    
    if (MyBox.checked)
    { 
        var Day;
        var Month;
        var Year;
        var Gender;
        var Location;
        
        Day = document.getElementById('ctl00_TxtDay').value;
        Month = document.getElementById('ctl00_TxtMonth').value;
        Year = document.getElementById('ctl00_TxtYear').value;
        if (document.getElementById('gender-m').checked)
        {    
            Gender = 'Male';
        }
        else if (document.getElementById('gender-f').checked)
        {
            Gender = 'Female';
        }
        Location = document.getElementById('ctl00_DrpLocation').value;
      
        Set_Cookie( 'Day', Day);
        Set_Cookie( 'Month', Month);
        Set_Cookie( 'Year', Year);
        Set_Cookie( 'Gender', Gender);
        Set_Cookie( 'Location', Location);     
    }
}

function CheckCookie()
{
    try
    {        
        var CkDay = Get_Cookie('Day');
        var CkMonth = Get_Cookie('Month');
        var CkYear = Get_Cookie('Year');
        var CkGender = Get_Cookie('Gender');
        var CkLocation = Get_Cookie('Location');
        
        if(CkDay!=null)
        {
            document.getElementById('ctl00_TxtDay').value = CkDay;
        }
        if(CkMonth!=null)
        {
            document.getElementById('ctl00_TxtMonth').value = CkMonth;
        }
        if(CkYear!=null)
        {
            document.getElementById('ctl00_TxtYear').value = CkYear;
        }
        if(CkGender!=null)
        {     
            if(CkGender == 'Male')           
            {
                document.getElementById('gender-m').checked = true;
                document.getElementById('LblMale').className = 'checked';
                
            }
            else
            {
                document.getElementById('gender-f').checked = true;
                document.getElementById('LblFemale').className = 'checked';
            }
        }
        if(CkLocation!=null)
        {
            document.getElementById('ctl00_DrpLocation').value = CkLocation;
        }
        
    }
    catch(err)
    {
        alert(err);
    }
}

//Set the value for the cookie.
function Set_Cookie(name, value){
    document.cookie =name +'='+ value + '; expires=Thu, 2 Aug 2020 20:47:11 UTC; path=/';
}

//Set the value for the cookie.
function Set_TempCookie(name, value){
    document.cookie = name +'='+ value + '; path=/';
}

// Get the value stored in the cookie

    function Get_Cookie(name)
    {
    
	var dc=document.cookie;

	var prefix=name+'=';

	var s = dc.indexOf('; ' + prefix);

	if (s==-1){

		s=dc.indexOf(prefix);

		if (s != 0) return null;

	}

	else

		 s+=2;

	var e=dc.indexOf(';', s);

	if (e==-1)

		 e=dc.length;

	return unescape(dc.substring(s+prefix.length, e));

}


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



//Test if cookies is enabled
function TestCookie()
{
    var status = false;
    
    var MyBox = document.getElementById('remember');
    
    if (MyBox.checked)
    {    
        Set_Cookie( 'test', 'none');
        // if Get_Cookie succeeds, cookies are enabled, since
        //the cookie was successfully created.
        if ( Get_Cookie( 'test' ) )
        {
	        Delete_Cookie('test', '/', '');
	        status = true;
        }
        else
        {
	       status = false;
        }
        
        if (!status)
        {
            alert('Please enable cookies for this feature.');
        }
    }
}

