// JavaScript Document
var usr;
var pw;
var sv;

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
//alert("inside setcookie");
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getme()
{
usr = document.frmlogin.txtemail;
pw = document.frmlogin.txtpwd;
sv = document.frmlogin.save;

	if (GetCookie('txtemail') != null)
	{
		usr.value = GetCookie('txtemail')
		pw.value = GetCookie('txtpwd')
		if (GetCookie('save') == 'true')
		{
			sv.checked = true;
		}
        if (GetCookie('save') == 'false')
		{
			sv.unchecked = true;
		}
	}
}


//Checking for valid email id
function checkemail(){
  var str=document.frmlogin.txtemail.value
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (filter.test(str))
  testresults=true
  else{
      alert("Please input a valid email address!");
  		document.frmlogin.txtemail.focus();
      testresults=false
  }
  return (testresults);
}
//Onclick of login button
function validate_login(pflag)
{
  var email = jQuery.trim(document.frmlogin.txtemail.value);
  var pwd = jQuery.trim(document.frmlogin.txtpwd.value);
     
  if(email == "")
  {
      alert("Please enter Email Address"); 
      document.frmlogin.txtemail.focus();
      return false;
  }
  else if(pwd == "")
  {
      alert("Please enter password");
      document.frmlogin.txtpwd.focus();
      return false;
  }
  var chkemail = true; //checkemail();
   if(chkemail == true)
   {
	 
    if(pflag=='1'){
		if(sv.checked)
		{
			expdate = new Date();
			expdate.setTime(expdate.getTime()+(365 * 24 * 60 * 60 * 1000));
			SetCookie('txtemail', usr.value, expdate);
			SetCookie('txtpwd', pw.value, expdate);
			SetCookie('save', 'true', expdate);
		}
	 document.frmlogin.action="?rt=login/chkLogin";
     document.frmlogin.submit();
	}
	else{
	 document.frmlogin.action="?rt=login/chkLogin1";
     document.frmlogin.submit();
	}
   }
}
//login val is -- 'n',inactive
function inactiveuser()
{
  msg=document.frminactive.message.value;
  if(msg == "")
  {
    	alert("Please write Message to Activate your account ");
	}
  else
  {
    document.frminactive.action ="?rt=login/inactiveUser";
    document.frminactive.submit();
  }
}
function logout()
{
  document.frmmain.action ="?rt=login/logoutAction";
  document.frmmain.submit();
}
//For Forgot password..,
function sub_rec()
{
	if(document.fpwd.txt_mail.value==''){
		alert("Please Enter the email-ID");
		return false();
	}
	else{
		document.fpwd.action ="?rt=login/send_mail";
		document.fpwd.submit();
	}
}
function cancel_rec()
{
	document.fpwd.action ="?rt=login/loginAction";
	document.fpwd.submit();
}

