var intdays = 1000;
var now = new Date();
now.setTime(now.getTime() + intdays * 24 * 60 * 60 * 1000);

function SetCookie(name, value, expires, path, domain, secure) {

  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}



function validateform(chk)
{
	var tempval;
	var uid;
	var pwd;
	var manage;
	uid = window.document.ssoform.Userid.value;
	pwd = window.document.ssoform.Pword.value;
	
tempval = document.ssoform.manage.options[document.ssoform.manage.options.selectedIndex].value;
	if(tempval=="advisor")
	{
		loginNow(tempval);
		return false;
	}
	if ((uid =="" |  pwd=="") & tempval !="" )
	{
		alert('Please fill in both the "User ID" and "Password" fields to Log In to your account successfully.');
		if(chk==2){return false;}
	}
	else if ( uid !="" & pwd !="" & tempval =="")
	{
		alert('Please select an account to Log In.');
		if(chk==2){return false;}
	}
	else if ((uid =="" | pwd=="") & tempval =="")
	{
		alert('To Log In successfully, please fill in both the "User ID" and "Password" fields and select an account.');
		if(chk==2){return false;}
	}
	else if (uid =="" & pwd=="" & tempval =="")
	{
		alert('To Log In successfully, please fill in both the "User ID" and "Password" fields and select an account.');
		if(chk==2){return false;}
	}
	else if (uid.length < 4)
	{
		alert('The User ID you entered is invalid.');
		if(chk==2){return false;}
	}
	else if ((pwd.length < 5) || (pwd.length > 8))
	{
		alert('The password you entered is invalid.');
		if(chk==2){return false;}
	}
	else
	{
                manage = window.document.ssoform.manage.value;
                SetCookie("Manage",manage,now,"/",".www.citizensbanknc.com");	
	        loginNow(tempval);
	}
}

function loginNow(tempval)
{
	var dc=window.document.ssoform;
	if(tempval == "cards")
	{
         dc.Face.value="en_US";
	dc.UserID.value = dc.Userid.value;
	dc.Password.value = dc.Pword.value;
	dc.DestPage.value = "";
	dc.action="";
	dc.submit();	
        }
	if(tempval == "sbdashboard")
	{
		dc.UserID.value = dc.Userid.value;
		dc.PWD.value = dc.Pword.value;
		dc.brandname.value = "sbsdashboard";
		dc.TARGET.value = '';
		dc.action = "";
		dc.submit();
	}
	if(tempval == "retirement")
	{
		dc.USERID.value = dc.Userid.value;
		dc.PWD.value = dc.Pword.value;
		dc.brandname.value = "401k_blue";
		dc.TARGET.value = '';
		dc.action = "";
		dc.submit();
	}
	if(tempval == "brokerage")
	{
		dc.USERID.value = dc.Userid.value;
		dc.PWD.value = dc.Pword.value;
		dc.brandname.value = "brokerage";
		dc.TARGET.value = '';
		dc.action = "";
		dc.submit();
	}
}
function Help() {
window.open ("/homepage/include/help.html", "help", "width=470,height=460,scrollbars=no,location=no,dependent=yes,resizable=no top=20,left=300");
}
function SecurityHelp() {
window.open ("/security.php", "sechelp", "width=470,height=460,scrollbars=no,location=no,dependent=yes,resizable=no top=20,left=300");
}
function MapHelp() {
window.open ("/map.php", "maphelp", "width=900,height=660,scrollbars=yes,location=no,dependent=yes,resizable=yes top=20,left=300");
}
function PasswordHelp() {
window.open ("/password.php", "passhelp", "width=470,height=460,scrollbars=no,location=no,dependent=yes,resizable=no top=20,left=300");
}
function PassmarkPassword() {
window.open ("/passmark.php", "passhelp", "width=470,height=460,scrollbars=no,location=no,dependent=yes,resizable=no top=20,left=300");
}
function clearElements(){
	window.document.ssoform.Userid.focus();
	window.document.ssoform.Pword.value="";	
	window.document.ssoform.Userid.value="";
	
	//window.document.ssoform.Userid.value = ReadCookie("UserID");
	
	// retain the manage drop down value
	var mng = ReadCookie("Manage");
	if (mng!='')
	{
		var lstManage = window.document.ssoform.manage;
		for(i=0;i<lstManage.options.length;i++)
		{
			if (lstManage.options[i].value == mng)
			{
				lstManage.options[i].selected = true;				
			}
		}
	}
	
}

