﻿
function register(OnlySignIn)
{
    var theForm = document.Registration;
    var FormType = theForm.FormType;
    
    /*--------------------------------*\
    |   basic registration values
    \*--------------------------------*/
    
    var JSEmail = theForm.JSEmail;
    var JSPassword = theForm.JSPassword;
    var JSFName = theForm.JSFName;
    var JSLName = theForm.JSLName;
     var NoSpam = theForm.NoSpam;
      var SpamCookie = theForm.SpamCookie;
    
    /*--------------------------------*\
    |   job seeker profile
    \*--------------------------------*/
   
    var JSAddress1 = theForm.JSAddress1;
    var JSCity = theForm.JSCity;
    var JSST = theForm.JSST;
    var JSZip = theForm.JSZip;
    var JSCountry = theForm.JSCountry;
    var JSPhone1Type = theForm.JSPhone1Type;
    var JSPhone1 = theForm.JSPhone1;
    var JSExperience = theForm.JSExperience;
    var JSEducationId = theForm.JSEducationId;
    var JSSchool = theForm.JSSchool;
    var JSUSAAuth = theForm.JSUSAAuth;
    var JSLatestEmployer = theForm.JSLatestEmployer;
    var JSLatestJobTitle = theForm.JSLatestJobTitle;
    var JSJobCategory1 = theForm.JSJobCategory1;
    var JSJobCategory2 = theForm.JSJobCategory2;
    var JSPositionType = theForm.JSPositionType;
    var JSTravel = theForm.JSTravel;

    var JSProfileComplete = theForm.JSProfileComplete;
    
    
    var ResumeID = theForm.ResumeId;
    var JobseekerId = theForm.JobseekerId;
    var ResumeName= theForm.ResumeName;
    var ResPublic= theForm.ResPublic;
    var ResSearchable= theForm.ResSearchable;
    var ResCompleted= theForm.ResCompleted;
    var ResMethod= theForm.ResMethod;
    var ResDisplay= theForm.ResDisplay;
    var ResEducation= theForm.ResEducation;
    var ResExperience= theForm.ResExperience;
    var ResSkills= theForm.ResSkills;
    var ResOther= theForm.ResOther;
    var ResBodyHTML= theForm.ResBodyHTML;
    
    
    //==========================================================
    //  Trim all
    //==========================================================

        JSEmail.value        = trim(JSEmail.value);
        JSPassword.value     = trim(JSPassword.value);
        JSFName.value        = trim(JSFName.value);
        JSLName.value        = trim(JSLName.value);
        

        
        
    //==========================================================
    //  Validate Registration
    //==========================================================
//    if (ResumeID == 0)
//    {
        if ( (FormType.value == "Register") || (FormType.value == "Update"))
        {
         if (!validateTextFieldMinLength(JSFName,2,"Please provide your first name")) { return; }
        if (!validateTextFieldMinLength(JSLName,2,"Please provide your last name")) { return; }
            if (!validateTextFieldNotNull(JSEmail,"Please provide an email address")) { return; }
            if (!validEmailField(JSEmail,"Please provide a valid email address")) { return; }
            if (!validatePassword(JSPassword,"Your password must:\n\n  --Be at least six charaters in length\n  --Contain at least one number\n  --Contain only letters and numbers")) { return; }
            if (FormType.value == "Register")
            {
        if (!validateTextFieldNotNull(NoSpam,"Please enter the security code that you see in the box at the bottom left")) { return; }
        }
    }
    
    if (OnlySignIn != undefined) // if users want to only register for sign in for now
    {   
        JSProfileComplete.value = "1";
        theForm.submit();
    }
    else
    {
    //==========================================================
    //  Moved these from Trim above
    //==========================================================
        JSAddress1.value        = trim(JSAddress1.value);
        JSCity.value            = trim(JSCity.value);
        JSZip.value             = trim(JSZip.value);
        JSPhone1.value          = trim(JSPhone1.value);
        JSSchool.value          = trim(JSSchool.value);
        JSLatestEmployer.value  = trim(JSLatestEmployer.value);
        JSLatestJobTitle.value  = trim(JSLatestJobTitle.value);
    
    
        var V = new validateJobSeekerProfile(); // create instance of class validateJobSeekerProfile
        
        V.ResetRequired();
        V.compare("Contact Information",JSAddress1,"Address 1",!fieldHasLength(JSAddress1,5));
        V.compare("Contact Information",JSCity,"City Name",!fieldHasLength(JSCity,5));
        V.compare("Contact Information",JSZip,"Zip Code",(!fieldHasLength(JSZip,5) || !IsNumeric(JSZip.value)));
        V.compare("Contact Information",JSST,"State",!selectedIndexNotZero(JSST));
        V.compare("Contact Information",JSCountry,"Country",!selectedIndexNotZero(JSCountry));
        V.compare("Contact Information",JSPhone1Type,"Phone 1 Type",!selectedIndexNotZero(JSPhone1Type));
        V.compare("Contact Information",JSPhone1,"Phone 1",!fieldHasLength(JSPhone1,10));
        
        V.compare("Background & Experience",JSExperience,"Experience",!selectedIndexNotZero(JSExperience));
        V.compare("Background & Experience",JSEducationId,"Education Level",!selectedIndexNotZero(JSEducationId));
        V.compare("Background & Experience",JSSchool,"School",!fieldHasLength(JSSchool,3));
        V.compare("Background & Experience",JSUSAAuth,"US Work Authorization",!radioSelected(JSUSAAuth));
        V.compare("Background & Experience",JSLatestEmployer,"Latest Employer",!fieldHasLength(JSLatestEmployer,3));
        V.compare("Background & Experience",JSLatestJobTitle,"Latest Job Title",!fieldHasLength(JSLatestJobTitle,3));

        V.compare("Job Specifics",JSJobCategory1,"Job Category",!selectedIndexNotZero(JSJobCategory1));
        V.compare("Job Specifics",JSPositionType,"Position Type",!selectedIndexNotZero(JSPositionType));
        V.compare("Job Specifics",JSTravel,"Desired Travel",!selectedIndexNotZero(JSTravel));

        if (V.returnMessage().length > 0)
        {
            var myAnswer = window.confirm(V.returnMessage());
            if (myAnswer)
            {
                JSProfileComplete.value = "1";
                theForm.submit();
            }
        }
        else
        {
            JSProfileComplete.value = "1";
            theForm.submit();
        }

    }

        //==========================================================
        //  validateJobSeekerProfile Class
        //==========================================================
        //
        //  JS Class that handles response message and 
        //  "incomplete" arrows
        //  --------------------------------------------------------
        //  If condition is false, build string to alert user that
        //  they need to complete their profile in order to post
        //  a resume. If all is true, complete Job Seeker Profile
        //  Validation occurs on edit also, so users cannot fill out
        //  informaion and change after posting.
        //
        //==========================================================
        
        function validateJobSeekerProfile()
        {
            this.CurrentHeader = null;
            this.UserAlertMessage = "";
            /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
            validateJobSeekerProfile.prototype.compare = function(NewHeader,Field,FieldName,condition)
            {
                var newline = "\n";
                var hline = "-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-";
                if (condition==true)
                {
                    if (NewHeader != this.CurrentHeader)
                    {
                        this.CurrentHeader = NewHeader;
                        if (this.UserAlertMessage != "")
                        {
                            this.UserAlertMessage += newline
                        }
                        this.UserAlertMessage += hline + newline + NewHeader.toUpperCase() + newline;
                    }
                    this.UserAlertMessage += FieldName + newline;
                    var thisName = "";
                    if (Field.length)
                    {
                        if (Field[0].type == "radio") // bug with Radio - no true DOM collection
                        {
                            thisName = Field[0].name;
                        }
                        else
                        {
                            thisName = Field.name; // works OK with Selects
                        }
                    }
                    else
                    {
                        thisName = Field.name;
                    }
                    if (thisName=="JSPhone1Type" || thisName=="JSPhone1")
                    {
                        thisName = "JSPhone1";
                    }
                        document.getElementById(thisName + "required").innerHTML = "<IMG alt='Incomplete' SRC='../Images/incomplete.gif' BORDER=0 />";
                }
            }
            /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            reset all "required" DIVS to bullet
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
            validateJobSeekerProfile.prototype.ResetRequired = function()
            {
                var DIVs = document.getElementsByTagName("DIV");
                for (var x=0;x<DIVs.length;x++)
                {
                    if (DIVs[x].id.indexOf("required") > -1)
                    {
                        DIVs[x].innerHTML = "&#8226;";
                    }
                }
            }
            /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
            validateJobSeekerProfile.prototype.returnMessage = function()
            {
                var newline = "\n";
                var returnMessage = "";
                if (this.UserAlertMessage.length > 0)
                {
                    returnMessage = "In order appear in an employer search," + newline + 
                                    "you will need to complete the following fields." + newline + 
                                    newline + newline +
                                    this.UserAlertMessage + 
                                    newline + newline +
                                    "Click OK to submit the form and complete your " + newline + 
                                    "Job Seeker Profile at a later time,"+ newline + 
                                    "Cancel to complete the form now.";
                }
                return returnMessage;
            }
        }
    }

function YN(ele)
{
    if (ele.type == "checkbox")
    {
        if (ele.checked)
        {
            return "True";
        }
        else
        {
            return "False";
        }
    }
    else
    {
        if (ele.value == "T" || ele.value == "True" || ele.value == "true")
        {
            return "True";
        }
        else if (ele.value == "F" || ele.value == "False" || ele.value == "false")
        {
            return "False";
        }
        else
        {
            return "False";
        }
    }
}

