


// ******************************* Remember Me Cookie ******************************* //

function newCookie(name, value, days) {
    // Note: Variable days reflects for how long the cookie will last 
	// modify it according to your needs
	if (days) {																	//	If you set the number of days to 0 the cookie is trashed when the user closes the browser
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));			//	set date in time format 
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
	//	used escape/unescape to encode/decode string
    document.cookie = name + "=" + escape(value) + expires + "; path=/";	//	path : to maintain cookie within dowmain and if not mentioned expire cookie on browser close
}

/*	Old code to read cookie - reduce code complexity in new function
function readCookie(name) {
    var nameSG = name + "=";
    var nuller = '';
    if (document.cookie.indexOf(nameSG) == -1)
        return nuller;

    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];																//ca[i].replace(/^\s+|\s+$/g,"")	//remove white spaces
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);					//ca[i].substr(0,ca[i].indexOf("="));
        if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length, c.length);	//ca[i].substr(ca[i].indexOf("=")+1);
    }
    return null;
}	*/

/* New code to read cookie - reduce code complexity in this function*/
function readCookie(c_name)
{
	//If cookie doesnot exists
	 if (document.cookie.indexOf(c_name + "=") == -1)
        return '';
	var i,x,y,ARRcookies = document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)
		{
			//used escape/unescape to encode/decode string
			return unescape(y);
		}
	}
	return null;
}


function eraseCookie(name) {
	//If you don't specify the expiry date the cookie is trashed when you close the browser 
    newCookie(name, "", -1);
}

function toMem(a) {
	// Note: Days set to '10' reflects the cookie will last for 10 days
    newCookie('_userName', $(document,'#login_form').find('input[id="pw"]').val(), 10);     // add a new cookie as shown at left for every
    newCookie('_passWord', $(document,'#login_form').find('input[id="new_pw"]').val(), 10);   // field you wish to have the script remember
}

function delMem(a) {
	// make sure to add the eraseCookie function for every field
    eraseCookie('_userName');   
    eraseCookie('_passWord');

    $(document,'#login_form').find('input[id="pw"]').val('');   // add a line for every field
    $(document,'#login_form').find('input[id="new_pw"]').val('');
}
function remCookie() {
    $(document,'#login_form').find('input[id="pw"]').val(readCookie("_userName"))
    $(document,'#login_form').find('input[id="new_pw"]').val(readCookie("_passWord"));
}


// ******************************* Remember Me Cookie ******************************* //
