
function ShowHelp()
{
	var div;
	
	div = document.getElementById("HelpCenter");
	if (div)
		div.style.display="block";
	div = document.getElementById("HelpCenterIF");
	if (div)
		div.style.display="block";

	div = document.getElementById("SelfRegPanel");
	if (div)
	{
		div.style.position="absolute";
		div.style.left="180px";
		div.style.top="90px";
	}
	
	return false;
}

function HideHelp()
{
	var div;
	
	div = document.getElementById("HelpCenter");
	if (div)
		div.style.display="none";
	div = document.getElementById("HelpCenterIF");
	if (div)
		div.style.display="none";
		
	div = document.getElementById("SelfRegPanel");
	if (div)
		div.style.position="static";
}



var PopUpHelpContent = new Object();


function findPos(obj) 
{
    var curleft = curtop = 0;
    var curwidth = obj.offsetWidth;
    var curheight = obj.offsetHeight;
    if (obj.offsetParent) 
    {
	    curleft = obj.offsetLeft
	    curtop = obj.offsetTop
	    while (obj = obj.offsetParent) 
	    {
		    curleft += obj.offsetLeft
		    curtop += obj.offsetTop
	    }
    }
    return [curleft,curtop, curwidth, curheight];
}


function HidePopUpHelp()
{
    var div;
    
    div = document.getElementById("divPopUp");
    if (div != null)
        div.style.display="none";
    div = document.getElementById("divPopUpIF");
    if (div != null)
        div.style.display="none";
}


function ShowPopUpHelp(id)
{
    PopUpHelpContent["MLEPassword"] =  "<center><b>Please Choose A Secure Password :</b>"+
                                    "<p>minimum 8 characters long"+
                                    "<br/>.<br/>must not contain your name or username"+
                                    "<br/>.<br/>must not contain 3 or more repeated characters"+
                                    "<br/>.<br/>do not use a common english word</center>";
                                    
    PopUpHelpContent["EMail"] =  "<center><b>Please Enter Your Secure (.pnn) EMail Address</b>"+
                                "<p>For %1 your secure email will be in the format:</p>" +
                                "<p>xxxxx@%2</p>" +
                                "<p>If you are unsure please contact your local IT Department</p></center>"
    

    PopUpHelpContent["EmploymentNumber"] =  "<center><b>Please Enter Your Employment Number</b>"+
                                "<p>This may be your warrant number, shoulder number, pay number or similar.</p></center>"

    PopUpHelpContent["EmploymentNumberMPS"] =  "<center><b>Your Employment Number</b>"+
                                "<p>Please enter your warrant or pay number</p>" +
                                "<p>Hint: For MPS staff, this will be C, P, S, X or Z and the 6 digits of your AWARE login / username</p></center>"

    PopUpHelpContent["NPRNumber"] =  "<center><p>This can be found on your Police SEARCH Assessment Center Candidate Feedback Report.  The number is formatted as <br/>nn/nn/nnnnn<br/> OR<br/> nnnnnnn.</p>" +
                                "<p>If you do not have this number at present, please continue with this form but you should supply it next time you login to the MLE.</p></center>" 


    HidePopUpHelp();
    var coords = findPos(document.getElementById(id));
    var divPopUp = document.getElementById("divPopUp");
    var divPopUpIF = document.getElementById("divPopUpIF");
    
    if (divPopUp != null)
    {
        if (PopUpHelpContent[id] != null)
        {
            divPopUpIF.style.left = coords[0]+10;
            divPopUpIF.style.top = coords[1]+coords[3]+1;
            divPopUpIF.style.width = coords[2]-9;
            divPopUpIF.style.display="block";

            divPopUp.style.left = coords[0]+10;
            divPopUp.style.top = coords[1]+coords[3]+1;
            divPopUp.style.width = coords[2]-9;
            divPopUp.style.display="block";

            divPopUp.style.height = divPopUpIF.offsetHeight;

            if (id=="EmploymentNumber" && ShowPopUpHelp.arguments[1].indexOf("Metropolitan Police") == 0)
                id = "EmploymentNumberMPS";
                
            divPopUp.innerHTML = ReplaceArgs(PopUpHelpContent[id],ShowPopUpHelp.arguments);

        }
    }
}
function ReplaceArgs (str)
{
    for (i=1; i<ReplaceArgs.arguments[1].length; i++)
    {
        var regEx = new RegExp ('%'+i, 'gi');
        var s = ReplaceArgs.arguments[1][i];
        if (s == null || s=='undefined')
            s = '';
        str = str.replace(regEx, s);
    }

return str;
}

/// Self Registration Client Scripts - BEGIN

function InitSelfRegistration()
{
    // Display 1st wizard page
    document.all.GettingStarted.style.display = "inline";
    document.all.PersonalDetails.style.display = "none";
    document.all.EmploymentDetails.style.display = "none";
    document.all.Diversity.style.display = "none";
    document.all.LoginDetails.style.display = "none";

    // Disable / Hide various elements
	document.all.NPRNumber.style.display='none';
	document.all.DisabilityDesc.disabled=true;
	document.all.BirthDate.style.display='none';
	document.all.StartDate.style.display='none';

    // Reset back/next/finish buttons
    document.all.back.style.display = "none";
    document.all.next.style.display = "none";
    document.all.nextorg.style.display = "inline";
    document.all.finish.style.display = "none";
	document.all.back.disabled = true;
	document.all.next.disabled = true;
	document.all.nextorg.disabled = true;
	document.all.finish.disabled = true;

	if (document.all.PrimaryDomainID.value!="0" || document.all.AcceptTerms.checked == true)
    	document.all.next.disabled = false;
    	document.all.nextorg.disabled = false;

    // Populate the ranks
    PopulateRanks(document.all.EmploymentType.value);
    divHandler(document.all.currentdiv.value, 0)
        	
}

function InitProfile()
{
    PopulateRanks(document.all.EmploymentType.value);
    ValidateProfile(5);        	
    /*if (!MetEmploymentNumberValidation(document.all.PrimaryDomainID.value))
        {
            document.all.finish.disabled = true;
        }
    */
}

function InitAdminRegistration()
{
    ValidateAdminRegistration(3);
}

function InitProfileLogin()
{
    PopulateRanks(document.all.EmploymentType.value);
    ValidateProfileLogin(5);        	
    /*if (!MetEmploymentNumberValidation(document.all.PrimaryDomainID.value))
        {
            document.all.finish.disabled = true;
        }
    */
}

function removeBlankSpaces(fld) 
{
    var res = "";
    var c = 0;
    for (i=0; i<fld.length; i++) 
	{
	if (fld.charAt(i) != " " || c > 0) 
		{
			res+= fld.charAt(i);
			if (fld.charAt(i) != " ") c = res.length;
		}
	}
	
	//alert(res.substr(0,c))
    return res.substr(0,c);
}


function divHandler(showDiv, movedirection)
{
	//Function handles the navigation between Div tags.
	//Set all the div to hidden
	document.all.GettingStarted.style.display = "none";
	document.all.PersonalDetails.style.display = "none";
	document.all.EmploymentDetails.style.display = "none";
	document.all.Diversity.style.display = "none";
	document.all.LoginDetails.style.display = "none";

    //Set back/next/finish disabled and invisible
    document.all.back.style.display = "none";
    document.all.next.style.display = "none";
    document.all.nextorg.style.display = "none";
    document.all.finish.style.display = "none";

	document.all.back.disabled = true;
	document.all.next.disabled = true;
	document.all.nextorg.disabled = true;
	document.all.finish.disabled = true;

	//reset the tab colours
	document.all.spanGettingStarted.style.color = "Gray";
	document.all.spanPersonalDetails.style.color = "Gray";
	document.all.spanEmploymentDetails.style.color = "Gray";
	document.all.spanDiversity.style.color = "Gray";
	document.all.spanLoginDetails.style.color = "Gray";
	
	//Determines which way we are moving. Next=+1 or Back=-1
	showDiv = parseInt(showDiv)+parseInt(movedirection);
	
	//Populate the hidden field that keeps track which div is visible.
	document.all.currentdiv.value=showDiv
			
	if (showDiv==1)
	{
		//Display the current div and hide the back button.
		document.all.GettingStarted.style.display = "inline";
		showNextBack(showDiv);
    	document.all.spanGettingStarted.style.color = "DarkSalmon";
		
	}
	else if (showDiv==2)
	{
		//Display the current div and show the back button.
		document.all.PersonalDetails.style.display = "inline";
		showNextBack(showDiv,1,0);
    	document.all.spanPersonalDetails.style.color = "DarkSalmon";
	}
	else if (showDiv==3)
	{
		//Display the current div.
		document.all.EmploymentDetails.style.display = "inline";
		showNextBack(showDiv);
    	document.all.spanEmploymentDetails.style.color = "DarkSalmon";
	}
	else if (showDiv==4)
	{
		//Display the current div and show the next button.
		document.all.Diversity.style.display = "inline";
		showNextBack(showDiv);
    	document.all.spanDiversity.style.color = "DarkSalmon";
	}
	else if (showDiv==5)
	{
		//Display the current div and hide the next button.
		document.all.LoginDetails.style.display = "inline";
		showNextBack(showDiv,1);
    	document.all.spanLoginDetails.style.color = "DarkSalmon";
	}
	disabilityEnable(document.all.Disability.options[document.all.Disability.selectedIndex].text);
}


function showNextBack(divId, mode, objectName)
{
	if (divId==1)
	{
        document.all.back.style.display = "none";
        document.all.next.style.display = "none";
        document.all.nextorg.style.display = "inline";
        document.all.finish.style.display = "none";
	
		document.all.back.disabled = true;
		document.all.next.disabled = false;
		document.all.nextorg.disabled = false;
		if (document.all.PrimaryDomainID.value=="0" || document.all.AcceptTerms.checked == false)
		{
			document.all.next.disabled = true;
			document.all.nextorg.disabled = true;
		}
		if (mode==4)
		{
		    document.all.DivisionCode.value = '';
		}
	}
	else if (divId==2)
	{
        document.all.back.style.display = "inline";
        document.all.next.style.display = "inline";
        document.all.nextorg.style.display = "none";
        document.all.finish.style.display = "none";

		if (document.all.FirstName.value.length==0 || document.all.LastName.value.length==0 || !(emailCheck(document.all.EMail.value,1)))//document.all.EMail.value.length==0 || 
		{
			document.all.next.disabled = true;
		}
		else
		{
			document.all.next.disabled = false;
		}
		if (emailArray[0]!=undefined && document.all.FirstName.value.length!=0 && document.all.LastName.value.length!=0)//&& mode==4
		{
		
// Commented Out - DO NOT Auto Pouplate the EMail now.
//			if (objectName==1 || objectName==2)
//			{
//    			document.all.EMail.value = document.all.FirstName.value + '.' + document.all.LastName.value + '@' + emailArray[0];
//			}
//			else if (objectName==0)
//			{
//			    w = document.all.EMail.value.split('@');
//			    FrontEmail = w[0];
//			    document.all.EMail.value = FrontEmail + '@' + emailArray[0];
//			}
		}
		else
		{
			if (emailArray[0]==undefined)
			{
			    document.all.spanErrPersonalDetails.innerHTML = 'You are not able to self register please call your domain administrator.';
			    document.all.spanErrPersonalDetails.style.color = "Red";
			}
		}
		if (document.all.FirstName.value.length==0 || document.all.LastName.value.length==0 || !(emailCheck(document.all.EMail.value,1)))//document.all.EMail.value.length==0 || 
		{
			document.all.next.disabled = true;
		}
		else
		{
			document.all.next.disabled = false;
		}
		document.all.back.disabled = false;
	}
	else if (divId==3)
	{
	    document.all.back.style.display = "inline";
        document.all.next.style.display = "inline";
        document.all.nextorg.style.display = "none";
        document.all.finish.style.display = "none";
		document.all.back.disabled = false;
		document.all.next.disabled = false;
		if (MetEmploymentNumberValidation(document.all.PrimaryDomainID.value) || (document.all.NPRNumber.value.length!=0 && ValidateNPRNumber(document.all.NPRNumber.value, 1)))
        {
            document.all.next.disabled = true;
        }
        
	}
	else if (divId==4)
	{
        document.all.back.style.display = "inline";
        document.all.next.style.display = "inline";
        document.all.nextorg.style.display = "none";
        document.all.finish.style.display = "none";
		document.all.back.disabled = false;
		document.all.next.disabled = false;
	}
	else if (divId==5)
	{
        document.all.back.style.display = "inline";
        document.all.next.style.display = "none";
        document.all.nextorg.style.display = "none";
        document.all.finish.style.display = "inline";

		document.all.back.disabled = false;
        document.all.finish.disabled = true;
        
		if (mode==1) //Mode 1 is onkeyup
		{
			if (document.all.MLEUserName.value.length>0)
    		{
	    		document.all.MLEUserName.value = removeBlankSpaces(document.all.MLEUserName.value);
			}
			if (document.all.MLEPassword.value.length>0)
			{
		    	document.all.MLEPassword.value = removeBlankSpaces(document.all.MLEPassword.value);
			}
			if (document.all.confMLEPassword.value.length>0)
			{
			    document.all.confMLEPassword.value = removeBlankSpaces(document.all.confMLEPassword.value);
			}
			if (document.all.SecurityAnswer.value.length>0)
			{
			    document.all.SecurityAnswer.value = removeBlankSpaces(document.all.SecurityAnswer.value);
			}
		}
		if (document.all.MLEUserName.value.length==0 || (document.all.MLEPassword.value.length==0 || document.all.confMLEPassword.value.length==0 || passwordCheck(1, mode)) || document.all.SecurityQuestionID.value.length==0 || document.all.SecurityAnswer.value.length==0 
			|| document.all.drpDOBDay.value==0 || document.all.drpDOBMonth.value==0 || document.all.drpDOBYear.value==0 || document.all.drpEmpDay.value==0 || document.all.drpEmpMonth.value==0 || document.all.drpEmpYear.value==0)
		{
			document.all.next.style.display = "none";
			document.all.next.disabled = false;
			document.all.finish.style.display = "inline";
			document.all.finish.disabled = true;
		}
		else
		{
			document.all.next.style.display = "none";
			document.all.next.disabled = false;
			document.all.finish.style.display = "inline";
			document.all.finish.disabled = false;
			
		}
	}
}
	
function PopulateRanks(empTypeID)
{
    //NPR Number will be displayed if the empTypeID = SO. Student officer.
	if (empTypeID=="SO" || empTypeID=="so" || document.all.NPRNumber.value.length != 0)
	{
	    document.all.txtNPRNumber.style.visibility="visible";
		document.all.NPRNumber.style.display = "inline";
		if (empTypeID=="SO" || empTypeID=="so")
		{
		    document.all.NPRNumber.readOnly = false;
		}
		else
		{
		    document.all.NPRNumber.readOnly = true;
		}
	}
	else
	{
		document.all.txtNPRNumber.style.visibility = "hidden";
		document.all.NPRNumber.style.display = "none";
	}
	RankOptionsLength = document.all.drpRankCode.options.length;
	
	for (j=document.all.drpRankCode.options.length-1;j>= 0;j--)
	{
		document.all.drpRankCode.remove(j);
	}
	
	var w; 
	var RankCode;
	var EmpType;
	var RankName;
	if (rankArray.length)
	{
		RankName = '-Select-';
		
		if (empTypeID == null || empTypeID == '')
		    RankCode = "Default_NS";
		else
		    RankCode = "Default_" + empTypeID.toUpperCase();
		
		addOption(document.all.drpRankCode,RankName,RankCode);
	}
	for (var i=0;i< rankArray.length;i++)
	{
		RankCode = rankArray[i][1];
		EmpType = rankArray[i][2];
		RankName = rankArray[i][3];
		if (EmpType == empTypeID)
		{
			addOption(document.all.drpRankCode,RankName,RankCode);
		}
	}

	document.all.RankCode.value = document.all.drpRankCode.value;
}


function PopulateRanksText(rankCode)
{
	document.all.RankCode.value = rankCode;
}
		
function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	
	selectbox.options.add(optn);
	if (value.toLowerCase()==document.all.RankCode.value.toLowerCase())
	{
	    optn.selected = true;
	}
}
		
//Validate email address supplied
function emailCheck (emailStr,mode) 
{

    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    //var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var knownDomsPat=/^(police.uk)$/;

    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */

    var emailPat=/^(.+)@(.+)$/;

    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ] */

    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed.*/

    var validChars="\[^\\s" + specialChars + "\]";

    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */

    var quotedUser="(\"[^\"]*\")";

    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */

    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* The following string represents an atom (basically a series of non-special characters.) */

    var atom=validChars + '+';

    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */

    var word="(" + atom + "|" + quotedUser + ")";

    // The following pattern describes the structure of the user

    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */

    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) 
    {
        /* Too many/few @'s or something; basically, this address doesn't
        even fit the general mould of a valid e-mail address. */

        //alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }

    var user=matchArray[1];
    var domain=matchArray[2];
    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) 
    {
        if (user.charCodeAt(i)>127) 
        {
            //alert("Ths username contains invalid characters.");
            return false;
        }
    }
    
    for (i=0; i<domain.length; i++) 
    {
        if (domain.charCodeAt(i)>127) 
        {
            //alert("Ths domain name contains invalid characters.");
            return false;
        }
    }

    // See if "user" is valid 

    if (user.match(userPat)==null) 
    {
        // user is not valid
        //alert("The username doesn't seem to be valid.");
        return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) 
    {
        // this is an IP address
        for (var i=1;i<=4;i++) 
        {
            if (IPArray[i]>255) 
            {
                //alert("Destination IP address is invalid!");
                return false;
            }
        }
        return true;
    }

    // Domain is symbolic name.  Check if it's valid.
     
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) 
    {
        if (domArr[i].search(atomPat)==-1) 
        {
            //alert("The domain name does not seem to be valid.");
            return false;
        }
    }

    //Added this so that it checks for the secure email address that should be supplied anything else you cannot go any further.
    if (mode==1)
    {
        var count = 0;
        for (i=0;i<emailArray.length;i++)
        {
            
            if (domain.toLowerCase()==emailArray[i].toLowerCase())
            {
                count = count + 1;
            }
            else
            {
                count = count + 0;
            }
        }
        if (count==0)
        {
            return false;
        }
    }

    // Make sure there's a host name preceding the domain.
    if (len<2) 
    {
        //alert("This address is missing a hostname!");
        return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}


//Create the date and populate the appropriate text box.
function dateCheck (drpDay, drpMonth, drpYear,txtBox)
{
	txtBox.value = drpYear.value + "-" + drpMonth.value + "-" + drpDay.value
}

//Check that password and confirm password are the same.
function passwordCheck(mode, onevent)
{

    //This is for the Admin Registration page
    //onevent 5 = onblur
    var bresult = false;
    if (mode==3)
    {
        if (onevent==5)
        {
            if (document.all.MLEPassword.value.length<8)
            {
	            document.all.spanErrLoginDetails.className = "infotexterror";
	            document.all.spanErrLoginDetails.innerHTML = "Your password must be at least 8 characters.";
	            //document.all.btnSubmit.disabled = true;
	            bresult=true;
            }
            else //if (document.all.txtPassword.value.length>7 && document.all.confpassword.value.length>7)
            {
	            document.all.spanErrLoginDetails.className = "infotext";
	            document.all.spanErrLoginDetails.innerHTML = "Use this form to create a new MLE user account<br/>Fields marked in <span style='color:red;'>red</span> are required.<br/>Click the submit button to create the account.";
	            if (document.all.confMLEPassword.value.length>0 && document.all.MLEPassword.value != document.all.confMLEPassword.value)
	            {	
		            document.all.spanErrLoginDetails.className = "infotexterror";
		            document.all.spanErrLoginDetails.innerHTML = "Confirm password must be the same as password.";
		            //document.all.btnSubmit.disabled = true;
		            bresult=true;
	            }
            }
        }
        else
        {
            bresult=true;
            if (document.all.MLEPassword.value.length>7 && document.all.confMLEPassword.value.length>7 && document.all.MLEPassword.value==document.all.confMLEPassword.value)
            {
                //document.all.btnSubmit.disabled = false;
                bresult=false;
            }
        }
    }
    else if (mode==2)
    {
        //This checks for the profile page.
        if (onevent==5)
        {
            if (document.all.MLEPassword.value.length<8)
            {
	            document.all.spanErrLoginDetails.className = "infotexterror";
	            document.all.spanErrLoginDetails.innerHTML = "Your password must be at least 8 characters.";
	            bresult=true;
	            //document.all.finish.disabled = true;
	            //document.all.finish1.disabled = true;
            }
            else //if (document.all.txtPassword.value.length>7 && document.all.confpassword.value.length>7)
            {
	            document.all.spanErrLoginDetails.className = "infotext";
	            //document.all.spanErrLoginDetails.innerHTML = "Use this form to view or modify your MLE account details<br/>Fields marked in <span style='color:red;'>red</span> are required.<br/>Click the submit button to update your details.";
	            if (document.all.confMLEPassword.value.length>0 && document.all.MLEPassword.value != document.all.confMLEPassword.value)
	            {	
		            document.all.spanErrLoginDetails.className = "infotexterror";
		            document.all.spanErrLoginDetails.innerHTML = "Confirm password must be the same as password.";
		            //document.all.finish.disabled = true;
		            //document.all.finish1.disabled = true;
		            bresult=true;
	            }
            }
        }
        else
        {
            //document.all.finish.disabled = true;
		    //document.all.finish1.disabled = true;
		    bresult=true;
            if (document.all.MLEPassword.value.length>7 && document.all.confMLEPassword.value.length>7 && document.all.MLEPassword.value==document.all.confMLEPassword.value)
            {
                //document.all.finish.disabled = false;
		        //document.all.finish1.disabled = false;
		        bresult=false;
            }
        }   
    }
    else
    {

        //this checks for Self reg
        if (onevent==5)
        {
            if (document.all.MLEPassword.value.length<8)
            {
	            document.all.spanErrLoginDetails.className = "infotexterror";
	            document.all.spanErrLoginDetails.innerHTML = "Your password must be at least 8 characters.";
	            //document.all.finish.disabled = true;
	            bresult=true;
            }
            else //if (document.all.txtPassword.value.length>7 && document.all.confpassword.value.length>7)
            {
	            document.all.spanErrLoginDetails.className = "infotext";
	            document.all.spanErrLoginDetails.innerHTML = "Please enter your login details.";
	            if (document.all.confMLEPassword.value.length>0 && document.all.MLEPassword.value != document.all.confMLEPassword.value)
	            {	
		            document.all.spanErrLoginDetails.className = "infotexterror";
		            document.all.spanErrLoginDetails.innerHTML = "Confirm password must be the same as password.";
		            //document.all.finish.disabled = true;
		            bresult=true;
	            }
            }
        }
        else
        {
            bresult=true;
            if (document.all.MLEPassword.value.length>7 && document.all.confMLEPassword.value.length>7 && document.all.MLEPassword.value==document.all.confMLEPassword.value)
            {
                //document.all.finish.disabled = false;
                bresult=false;
            }
        }
        
    }
    return bresult;
}

//Disability and disability description enable
function disabilityEnable(disability)
{
	document.all.DisabilityDesc.disabled=true;
	if (disability=='Yes')
	{
		document.all.DisabilityDesc.disabled=false;
	}
}


/// Pop-Up Dialog for NPRN Check - BEGIN
function callModalDialog()
{
	var answer = 0;
	var argsArray = new Array("Do you have your National Police Recruitment Number? If so please enter it.","National Police Recruitment Number");
	answer = showModalDialog("MessageModalDialog.htm",argsArray,"dialogWidth:20em;dialogHeight:10em;dialogLeft:center;dialogTop:center");
	return answer;
}

function onInit()
{
	if (window.dialogArguments != null)
	{
		window.document.all.spanQuestion.innerHTML = window.dialogArguments[0];
		document.title = window.dialogArguments[1];
	}
}

function doYes() 
{
    window.returnValue = 3;
    window.close();
}

function doNo() 
{
    window.returnValue = 4;
    window.close();
}
/// Pop-Up Dialog for NPRN Check - END

///NPRN Formating - START

function NPRNumberFormatting(NPRNumberFormat)
{
    //Display the accepted formatting in NPRNumber
    

    if (document.all.NPRNumber.value == ""){
	            document.all.NPRNumber.value = NPRNumberFormat;
	            document.all.NPRNumber.title = document.all.NPRNumber.title + " " + NPRNumberFormat;
            }
}

function ValidateNPRNumber(NPRNumber, mode)
{
//Mode 1 = Self reg
//Mode 2 = Profile page.
    var bresult = false ;
    
    if (mode==1)
    {
        document.all.next.disabled = false;
        document.all.spanErrEmploymentDetails.innerHTML = "Please enter details about your employment.";
        document.all.spanErrEmploymentDetails.style.color = "Black";
    }
    else
    {
        document.all.finish.disabled = false;
        document.all.finish1.disabled = false;
        //document.all.spanErrLoginDetails.innerHTML = "Use this form to view or modify your MLE account details<br/>Fields marked in <span style='color:red;'>red</span> are required.<br/>Click the submit button to update your details.";
        document.all.spanErrLoginDetails.style.color = "Black";
    }
    
    var r;
    var pattern = "[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9][0-9]";
    var pattern2 = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9]";
    re = new RegExp(pattern);
    re2 = new RegExp(pattern2);
    
    if (NPRNumber.length==7)
    {
        if (NPRNumber.match(re2)==null)
        {
            if (mode==1)
            {
                if (NPRNumber.length==7)
                {
                //document.all.spanErrEmploymentDetails.innerHTML = "Please format the National Police Recruitment Number as follows nnnnnnn.";
                //document.all.spanErrEmploymentDetails.style.color = "Red";
                }
                bresult = true;
                //document.all.next.disabled = true;
            }
            else
            {
                if (NPRNumber.length==7)
                {
                //document.all.spanErrLoginDetails.innerHTML = "Please format the National Police Recruitment Number as follows nnnnnnn.";
                //document.all.spanErrLoginDetails.style.color = "Red";
                }
                bresult = true;
                //document.all.finish.disabled = true;
                //document.all.finish1.disabled = true;
            }
        }
    }
    else
    {
        if (NPRNumber.match(re)==null)
        {
            if (mode==1)
            {
                if (NPRNumber.length==11)
                {
                document.all.spanErrEmploymentDetails.innerHTML = "Please format the National Police Recruitment Number as follows nn/nn/nnnnn.";
                document.all.spanErrEmploymentDetails.style.color = "Red";
                }
                bresult = true;
                //document.all.next.disabled = true;
            }
            else
            {
                if (NPRNumber.length==11)
                {
                document.all.spanErrLoginDetails.innerHTML = "Please format the National Police Recruitment Number as follows nn/nn/nnnnn.";
                document.all.spanErrLoginDetails.style.color = "Red";
                }
                bresult = true;
                //document.all.finish.disabled = true;
                //document.all.finish1.disabled = true;
            }
        }
    }
    return bresult;
    
}

///NPRN Formating - END

/// Self Registration Client Scripts - END
/// User Profile Client Scripts - BEGIN
function ValidateProfile(mode)
{
/*Mode Key: mode 1 = onkeyup.
            mode 4 = onchange.
*/
		if (document.all.MLEUserName.value.length>0)
		{
    		document.all.MLEUserName.value = removeBlankSpaces(document.all.MLEUserName.value);
		}

    if (document.all.AcceptTerms.checked == false || document.all.FirstName.value.length==0 || document.all.LastName.value.length==0 || (document.all.EMail.value.length>0 && !(emailCheck(document.all.EMail.value,2))) || document.all.MLEUserName.value.length==0 || (document.all.MLEPassword.value.length==0 || document.all.confMLEPassword.value.length==0 || passwordCheck(2, mode)) || document.all.SecurityQuestionID.value.length==0 || document.all.SecurityAnswer.value.length==0 
			|| document.all.drpDOBDay.value==0 || document.all.drpDOBMonth.value==0 || document.all.drpDOBYear.value==0 || document.all.drpEmpDay.value==0 || document.all.drpEmpMonth.value==0 || document.all.drpEmpYear.value==0 || MetEmploymentNumberValidation(document.all.PrimaryDomainID.value) || (document.all.NPRNumber.value.length!=0 && ValidateNPRNumber(document.all.NPRNumber.value, 2)))
    {
        document.all.finish.disabled = true;
        document.all.finish.style.display = "none";
        document.all.finish1.disabled = true;
    }
    else
    {
        document.all.finish.disabled = false;
        document.all.finish.style.display = "none";
        document.all.finish1.disabled = false;
    }
    //if (mode==4 && document.all.confMLEPassword.value.length>0)
	//	{
	//		passwordCheck(2);
	//	}
    disabilityEnable(document.all.Disability.options[document.all.Disability.selectedIndex].text);
}
/* This is here for the new profile after login page, is now different to the profile page. */
function ValidateProfileLogin(mode)
{
/*Mode Key: mode 1 = onkeyup.
            mode 4 = onchange.
*/
		if (document.all.MLEUserName.value.length>0)
		{
    		document.all.MLEUserName.value = removeBlankSpaces(document.all.MLEUserName.value);
		}

    if (document.all.AcceptTerms.checked == false || document.all.FirstName.value.length==0 || document.all.LastName.value.length==0 || (document.all.EMail.value.length>0 && !(emailCheck(document.all.EMail.value,2))) || document.all.MLEUserName.value.length==0 || document.all.SecurityQuestionID.value.length==0 || document.all.SecurityAnswer.value.length==0 
			|| document.all.drpDOBDay.value==0 || document.all.drpDOBMonth.value==0 || document.all.drpDOBYear.value==0 || document.all.drpEmpDay.value==0 || document.all.drpEmpMonth.value==0 || document.all.drpEmpYear.value==0 || MetEmploymentNumberValidation(document.all.PrimaryDomainID.value) || (document.all.NPRNumber.value.length!=0 && ValidateNPRNumber(document.all.NPRNumber.value, 2)))
    {
        //document.all.finish.disabled = true;
        //document.all.finish.style.display = "none";
        document.all.finish1.disabled = true;
    }
    else
    {
        //document.all.finish.disabled = false;
        //document.all.finish.style.display = "none";
        document.all.finish1.disabled = false;
    }
    //if (mode==4 && document.all.confMLEPassword.value.length>0)
	//	{
	//		passwordCheck(2);
	//	}
    disabilityEnable(document.all.Disability.options[document.all.Disability.selectedIndex].text);
}

function PopulatePasswordFields(TempPassword)
    {
    document.all.MLEPassword.value=TempPassword;
    document.all.confMLEPassword.value=TempPassword;
    }

///User Profile Client Scripts - END
/// Admin Registration Client Scripts - BEGIN
function ValidateAdminRegistration(mode)
{
/*Mode Key: mode 1 = onkeyup.
            mode 4 = onchange.
*/
    document.all.btnSubmit.disabled = true;
    if (mode==1) //Mode 1 is onkeyup
	{
		if (document.all.MLEUserName.value.length>0)
		{
    		document.all.MLEUserName.value = removeBlankSpaces(document.all.MLEUserName.value);
		}
	}

    if (document.all.FirstName.value.length==0 || document.all.LastName.value.length==0 || document.all.MLEUserName.value.length==0 || (document.all.MLEPassword.value.length==0 || document.all.confMLEPassword.value.length==0 || passwordCheck(3, mode)))
    {
        document.all.btnSubmit.disabled = true;
    }
    else
    {
        document.all.btnSubmit.disabled = false;
    }
}
/// Admin Registration Client Scripts - END

///Check multiline text box length - START
function CheckMultilineTextboxLength(widget, length, mode)
{
//Mode 1 is selfreg
//Mode 2 is profile
    if (widget.value.length > length)
    {
        widget.value = widget.value.substring(0,length);
        
        if (mode==1)
        {
        document.all.spanErrDiversity.innerHTML = "The field can only be " + length + " characters long.";
        document.all.spanErrDiversity.style.color = "Red";
        }
        else
        {
        document.all.spanErrLoginDetails.innerHTML = "The field can only be " + length + " characters long.";
        document.all.spanErrLoginDetails.style.color = "Red";
        }
    }
}

///Check multiline text box length - END

///Profile close button - START
function fn_MsgBoardClose()
    {
	    //This is the SumTotal generic "close" modal dialog box function
	    parent.SYS_ModalDialog_Close('',0);
	}
	

///Profile close button - END
///Check if it is the MET if so Employmentnumber is mandatory - START
function MetEmploymentNumberValidation(org, mode)
{
    //Mode 1 = Self reg
    //Mode 2 = Profile

    var bresult = false ;

    //document.all.spanEmploymentNumber.innerHTML = "Employment Number:";
    var e = document.getElementById("txtEmploymentNumber");
    e.setAttribute("class", "formtext", 0);
    e.setAttribute("className", "formtext", 0);

    if (org==27)
    {
        //document.all.spanEmploymentNumber.innerHTML = "Employment Number *:";
        
        
        var EmploymentNumber = document.all.EmploymentNumber.value;
        var r;
        var pattern = "[PpCcXxZzSs][Zz0-9][0-9][0-9][0-9][0-9][0-9]";
        re = new RegExp(pattern);
        if (EmploymentNumber.length == 0)
        {
            bresult = false;
        }
        else if (EmploymentNumber.match(re)==null || EmploymentNumber.length > 7)
        {
            e.setAttribute("class", "formtextreq", 0);
            e.setAttribute("className", "formtextreq", 0);
            if (mode==1)
            {
                document.all.spanErrEmploymentDetails.innerHTML = "Please enter a P, C, X, Z and the last 6 digits of your warrant number or employment number.";
                document.all.spanErrEmploymentDetails.style.color = "Red";
            }
            bresult = true; 
        }
    }
    return bresult;
                
}


///Check if it is the MET if so Employmentnumber is mandatory - END


function OpenDialog(url)
{
    window.showModalDialog(url,'','dialogHeight:600px;dialogWidth:800px;center:yes;status:no;scroll:yes;help:no;resizeable:yes;');
    return false;
}
	

function OpenDialogSmall(url)
{
    window.showModalDialog(url,'','dialogHeight:300px;dialogWidth:400px;center:yes;status:no;scroll:yes;help:no;resizeable:yes;');
    return false;
}

//Added the animation for the save process in userprofile and selfregistration.
function rdAnimate(page) 
{
    if (page=='self')
    {
        document.all.LoginDetails.style.display = 'none';
        document.all.footer.style.display = 'none';
        //document.all.finish.disabled=true
        //document.all.back.disabled=true
    }
    else
    {
        document.all.content1.style.display = 'none';
    }
    document.all.progress.style.display = 'inline';

   var img = document.getElementById("rdLogo")
   if (img.src.indexOf("images/rdWait01.gif")!=-1) {
    img.src="images/rdWait02.gif"
   } else if (img.src.indexOf("rdWait02.gif")!=-1) {
    img.src="images/rdWait03.gif"
   } else if (img.src.indexOf("rdWait03.gif")!=-1) {
    img.src="images/rdWait04.gif"
   } else if (img.src.indexOf("rdWait04.gif")!=-1) {
    img.src="images/rdWait05.gif"
   } 
   //else if (img.src.indexOf("rdWait05.gif")!=-1) {
   //img.src="rdTemplate/rdWait06.gif"}
    else {
    img.src="images/rdWait01.gif"
   }
   setTimeout("rdAnimate()",300);
  }
//End of animation

function SelfHelp ()
    {
        var location = parent.LocalURL.location.href;
        var locArr = location.split('SelfHelpBlank.htm');
        var len=locArr.length-1;
        if (len==0)
            {
                parent.SupportPage.history.back()
                parent.LocalURL.history.back()
            }
        else
            {
                parent.SupportPage.history.back();
            }
    }
	




