/*
'*************************************************************************************************************
' Copyright (C) 2001, The Hartford Steam Boiler Inspection and Insurance Company.  All Rights Reserved.
'*************************************************************************************************************
*/
function validateCredential(ctrlString)
{
	var isValid = true;
	var msg = "";
	var checkInval = false; 
	var MIN_LEN = 4;
	var MAX_LEN = 12;
	if(ctrlString.length < MIN_LEN || ctrlString.length > MAX_LEN)
	{
		msg = msg + "Your login name and password must each be at least " + MIN_LEN + " characters, \nand no more than " + MAX_LEN + " characters in length with no special characters or spaces. \n";
		isValid = false;	
	}
	//alert(ctrlString.);
	checkInval =  checkInvalidChars(arrInvalidChars,ctrlString);
	if (checkInval != true)
	{
		msg = msg + checkInval + "\n" ;
		isValid = false;
	}
	if(isValid == false)
	{
		alert(msg);
	}
	return isValid;
}
function submitForm(objForm,objDataForm,command)
{
	doSubmit(objForm,objDataForm,command);
}

function validate(cmd)
{
	var log = document.forms['default'].stt_logonid.value;
	var pwd = document.forms['default'].txt_password.value;
	var log = document.MEM_ID.MEMBER_ID.value;
	var pwd = document.MEM_PWD.MEMBER_PWD.value;	
	if(validateCredential(log) && validateCredential(pwd))
	{
		reqSubmit(cmd);
	}
}

function checkInvalidChars(invalArray,ctrl){
	var msg = "";
	for (var i=0; i< invalArray.length; i++){
		if (ctrl.search(invalArray[i]) >-1){
			msg = msg +  invalArray[i] + " is an invalid character \n";
		}	
	}
	if (msg !=""){
		return msg ;
	}else{
		return true;
	}
}
function submitReq(cmd){	
	if(cmd == "CmdEmailMeAccountInfo"){
		var log = document.MEM_ID.MEMBER_ID.value;
		if(log.length < 1){
			alert("Please enter your login name and your login information will be emailed to you.");
		}else{
			reqSubmit(cmd);			
		}
	}else if (cmd == "CmdDisplayMyPasswordHint"){
		var log = document.MEM_ID.MEMBER_ID.value;
		if(log.length < 1){
			alert("Please enter your login name and your password hint will be displayed on the screen.");
		}else{
			reqSubmit(cmd);			
		}	
	}else if (cmd == "cmdEmailAccountToEmail"){
		reqSubmit(cmd);			
	}else{	
		var log = document.MEM_ID.MEMBER_ID.value;
		if(validateCredential(log)){
			reqSubmit(cmd);
		}
	}	
}

function reqSubmit(cmd){
	if(cmd != "cmdEmailAccountToEmail"){
		document.forms['default'].stt_logonid.value = document.MEM_ID.MEMBER_ID.value;
		document.forms['default'].txt_password.value = document.MEM_PWD.MEMBER_PWD.value;
	}
	submitForm(document.forms['default'], document.forms['default'], cmd);
}
