J00028 = "Changes will be lost!\nAre you sure?";
strChgsLost = J00028;
J00030 = "Please Enter the User ID";
strUID = J00030;
J00031 = "Invalid User ID!";
strBadUID = J00031;
J00032 = "User ID cannot contain spaces!";
strSpacesUID = J00032;
J00033 = "Please Enter Your Password";
strPwd = J00033;
J00034 = "Invalid Password!";
strBadPwd = J00034;
J00086 = "Last Name";
strLastName = J00086
J00091 = "Password";
strPassword = J00091;
J00569 = "onlogout"
//J00570 = "We are not able to save your Password. Please make sure your new Password conforms to the requirements listed to the right of the field.";

//Rel 304, TrackIt 76916, sv, page text and popup has changed for invalid password entered by user(J00570)
J00570 = "\nThe password you have entered is invalid. Password must:\n\n•    Be at least 6 characters.\n•    Contain at least one letter.\n•    May contain letters, numbers, underscore (_), $, !, and # characters.\n•    May not contain any spaces or other special characters.\n\nPlease click OKAY to try again.";

strExtPwdMessage = J00570;

var PwdMinLength;
var PwdMinAlphas;
var PwdMinUpcase;
var PwdMinLwcase;
var PwdMinDigits;
var sJump;
var bAllow;

// Purpose : Alerts an error message to the user and sets the focus to  the appropriate form element.
function warnError(theObj, msg)
{
	alert(msg);
	theObj.focus();
	//theObj.select();
}

// Purpose : Alerts an error message to the user and sets the focus to the appropriate form element.(No focus!)
function warnError1(theObj, msg)
{
	alert(msg);
}

// Purpose : Checks whether the entered User ID is valid or not. Returns 'true' if valid, 'false' otherwise.
function validUserID(theObj)
{
	allTrim(theObj);
	var str = theObj.value;
	if(str.length < 1 || str.length > 30)
	{
		warnError(theObj, strUID);
		return false;
	}
	var indexOfSpace = str.indexOf(' ');
	if(indexOfSpace != -1)
	{
		warnError(theObj, strSpacesUID);
		return false;
	}

	return true;
}

// Purpose : Checks whether the entered Password is valid or not. Returns 'true' if valid, 'false' otherwise.
function validPwd(theObj, extMessage)
{
	var str = theObj.value;

	if(isEmpty(theObj.value))
	{
		warnError(theObj, strPwd);
		return false;
	}

	if ( ( str.indexOf(' ')!= -1 ) ||
		 ( str.length      < PwdMinLength ) ||
		 ( NoOfAlphas(str) < PwdMinAlphas ) ||
		 ( NoOfUpcase(str) < PwdMinUpcase ) ||
		 ( NoOfLwcase(str) < PwdMinLwcase ) ||
		 ( NoOfDigits(str) < PwdMinDigits ) )
	{
		if (extMessage)
			warnError(theObj, strExtPwdMessage);
		else
			warnError(theObj, strBadPwd);
		theObj.value = "";
		return false;
	}

	return true;
}


function getCurrentDate()
{
	var ClientDate = new Date();
	var m, d, y;
	var hh, mi, ss;

	if(ClientDate.getDate() < 10)
		d = "0" + ClientDate.getDate();
	else
		d = ClientDate.getDate();

	m = ClientDate.getMonth()+1;
	if (m < 10)
		m = "0" + m;

	y = ClientDate.getFullYear();

	if (ClientDate.getHours() < 10)
		hh = "0" + ClientDate.getHours();
	else
		hh = ClientDate.getHours();

	if (ClientDate.getMinutes() < 10)
		mi = "0" + ClientDate.getMinutes();
	else
		mi = ClientDate.getMinutes();

	if (ClientDate.getSeconds() < 10)
		ss = "0" + ClientDate.getSeconds();
	else
		ss = ClientDate.getSeconds();

	var formattedDate = d + "/" + m  + "/" + y + " " + hh + ":" + mi + ":" + ss;
	return formattedDate;
}

function onLogout(frmObj)
{
	var bLogout = false;
	var ClientDate = new Date();
	var m, d, y;
	var hh, mi, ss;
	var dt, tm;
	alert(J00569);
	if(ClientDate.getDate() < 10)
		d = "0" + ClientDate.getDate();
	else
		d = ClientDate.getDate();

	m = ClientDate.getMonth()+1;
	if (m < 10) m = "0" + m;

	y = ClientDate.getFullYear();

	if(ClientDate.getHours() < 10)
		hh = "0" + ClientDate.getHours();
	else
		hh = ClientDate.getHours();

	if (ClientDate.getMinutes() < 10)
		mi = "0" + ClientDate.getMinutes();
	else
		mi = ClientDate.getMinutes();

	if (ClientDate.getSeconds() < 10)
		ss = "0" + ClientDate.getSeconds();
	else
		ss = ClientDate.getSeconds();

	dt = d + "/" + m  + "/" + y;
	tm = hh + ":" + mi + ":" + ss;

	if (frmObj.hdnPageModified.value == "Yes") {
		if(confirm(strChgsLost)) bLogout = true;
	}
	else  bLogout = true;

	if (bLogout)
		parent.location.href = "../Asp/Logout.asp?DateOut=" + dt + "&TimeOut=" + tm;
}

function removeSpaces(str)
{
	var lenStr = str.length;
	var cnt = 0;
	while(str.charAt(cnt) == ' ')
		cnt++;
	str = str.substring(cnt, lenStr);
	cnt = str.length - 1;
	while(str.charAt(cnt) == ' ')
		cnt--;
	str = str.substring(0, cnt+1);
	return str;
}


function onJump()
{
	var bLogout = false;
	var ClientDate = new Date();
	var m, d, y;
	var hh, mi, ss;
	var dt, tm;

	if(ClientDate.getDate() < 10)
		d = "0" + ClientDate.getDate();
	else
		d = ClientDate.getDate();

	m = ClientDate.getMonth()+1;
	if(m < 10)
		m = "0" + m;

	y = ClientDate.getFullYear();

	if(ClientDate.getHours() < 10)
		hh = "0" + ClientDate.getHours();
	else
		hh = ClientDate.getHours();

	if(ClientDate.getMinutes() < 10)
		mi = "0" + ClientDate.getMinutes();
	else
		mi = ClientDate.getMinutes();

	if(ClientDate.getSeconds() < 10)
		ss = "0" + ClientDate.getSeconds();
	else
		ss = ClientDate.getSeconds();

	dt = d + "/" + m  + "/" + y;
    tm = hh + ":" + mi + ":" + ss;
	if(confirm("You will be logged out of the Card Registry session and any changes done will be lost. Continue?"))
	{
	sJump = true;
		parent.location.href = "../Asp/Logout.asp?DateOut=" + dt + "&TimeOut=" + tm + "&Jump=Y";
	}
	else
	{
	sJump = false;
	return;
	}
}

function NoOfChar(CheckString, SearchString)
{
	var No = 0;
	for ( i = 0; i < SearchString.length; i++) {
		if ( CheckString.indexOf ( SearchString.substr(i,1) ) > -1 )
			No = No + 1;
	}
	return(No);
}

function NoOfAlphas ( objString )
{
	return ( NoOfUpcase ( objString ) + NoOfLwcase ( objString ) );
}

function NoOfUpcase ( objString )
{
	return ( NoOfChar ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', objString ) );
}

function NoOfLwcase ( objString )
{
	return ( NoOfChar ( 'abcdefghijklmnopqrstuvwxyz', objString ) );
}

function NoOfDigits ( objString )
{
	return ( NoOfChar ( '0123456789', objString ) );
}

function removeQuotes(frmObj)
{
	var noOfElements = frmObj.length;

	for(var cnt=0; cnt<noOfElements; cnt++)
	{
		if(frmObj.elements[cnt].type == "text")
		{
			var strVal = frmObj.elements[cnt].value;
			var newVal = '';
			for(var i=0; i<strVal.length; i++)
			{
				var chr = strVal.charAt(i);
				newVal = newVal + ((chr=='"')?"'":chr);
			}
			frmObj.elements[cnt].value = newVal;
		}
	}
}

// Purpose : Trims the leading and trailing spaces of a string.
function allTrim(theObj)
{
	var str = theObj.value;
	var lenStr = str.length;
	var cnt = 0;
	while(str.charAt(cnt) == ' ')
		cnt++;
	str = str.substring(cnt, lenStr);
	cnt = str.length - 1;
	while(str.charAt(cnt) == ' ')
		cnt--;
	str = str.substring(0, cnt+1);
	theObj.value = str;
}

// Purpose : Checks whether the form element is mandatory. If mandatory,
//           it checks for the emptiness of the element and displays an appropriate message.
function checkString1(theObj, fieldStr, reqField)
{
	if (isEmpty(theObj.value))
	{
		if (reqField == false) return true;
		else return false;
	}
	return true;
}

// Purpose : Returns 'true' if the string is empty, 'false' otherwise.
function isEmpty(TextValue)
{
	if ((TextValue == null) || (TextValue.length == 0 ))
		return true;
	return false;
}

function valueChanged(theObj, trimValue)
{
	var frmObj = theObj.form;
	frmObj.hdnPageModified.value = "Yes";
	if(trimValue) allTrim(theObj);
}
