﻿function checkFileExtension()
 {
    var fileUploadIns = document.getElementById(fileUpload);
    var lblFileUploadErrorIns = document.getElementById(lblFileUploadError);
    
    var filePath = fileUploadIns.value;

    if(filePath.indexOf('.') == -1)
        return false;

    var validExtensions = new Array();
    var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

    validExtensions[0] = 'doc';
    validExtensions[1] = 'docx';
    validExtensions[2] = 'txt';
    validExtensions[3] = 'pdf';
    validExtensions[4] = 'rtx';  
    validExtensions[5] = 'html';  
    validExtensions[6] = 'htm';
    validExtensions[7] = 'mht';

    for(var i = 0; i < validExtensions.length; i++)
    {
        if(ext == validExtensions[i])
        {
        lblFileUploadErrorIns.innerHTML = "";
        return true;
        }
    }
    lblFileUploadErrorIns.innerHTML = 'The file extension ' + ext.toUpperCase() + ' is not allowed! </br> (Try Followings: .doc, .docx, .txt, .pdf, .rtx, .html, .htm and .mht)';
    return false;
 }
 
function SelectJobProfiles()
{   
    var rdoUSAIns = document.getElementById(rdoUSA);
    var rdoIndiaIns = document.getElementById(rdoIndia);
    var cboJobProfileIns = document.getElementById(cboJobProfile);
    
    if (rdoUSAIns.checked == true)
    {
        cboJobProfileIns.options.length = 2;
        cboJobProfileIns[0].text = "";
        cboJobProfileIns[0].value = "";
        cboJobProfileIns[1].text = "Sr. Business Analyst / Project Manager";
        cboJobProfileIns[1].value = "Sr. Business Analyst / Project Manager";
    }
    else if (rdoIndiaIns.checked == true)
    {
        cboJobProfileIns.options.length = 6;
        cboJobProfileIns[0].text = "";
        cboJobProfileIns[0].value = "";
        cboJobProfileIns[1].text = "Project Lead";
        cboJobProfileIns[1].value = "Project Lead";
        cboJobProfileIns[2].text = "Module Lead";
        cboJobProfileIns[2].value = "Module Lead";
        cboJobProfileIns[3].text = "Senior Software Engineer";
        cboJobProfileIns[3].value = "Senior Software Engineer";
        cboJobProfileIns[4].text = "Business Analyst / Senior Business Analyst";
        cboJobProfileIns[4].value = "Business Analyst / Senior Business Analyst";
        cboJobProfileIns[5].text = "Quality / Testing Engineer";
        cboJobProfileIns[5].value = "Quality / Testing Engineer";
    }
    else
    {
        cboJobProfileIns.options.length = 1;
        cboJobProfileIns[0].text = "Select a location to get the Job Profile List";
        cboJobProfileIns[0].value = ""; 
    }
}

function ValidationMandatoryFields()
{   var MessageBuilder = "";
    var rdoUSAIns = document.getElementById(rdoUSA);
    var rdoIndiaIns = document.getElementById(rdoIndia);
    var cboJobProfileIns = document.getElementById(cboJobProfile);
    var txtFirstNameIns = document.getElementById(txtFirstName);
    var txtLastNameIns = document.getElementById(txtLastName);
    var txtEmailIdIns = document.getElementById(txtEmailId);
    var txtContactNumberIns = document.getElementById(txtContactNumber);
    var fileUploadIns = document.getElementById(fileUpload);
    var chkAcceptedIns = document.getElementById(chkAccepted);
    var lblErrorMessageIns = document.getElementById(lblErrorMessage);
    if (cboJobProfileIns.selectedIndex <= 0 )
    {
        MessageBuilder += "Select a job profile.</br>"
    }
    if (txtFirstNameIns.value == "")
    {
        MessageBuilder += "First Name cannot be empty.</br>";
    }
    if (txtLastNameIns.value == "")
    {
        MessageBuilder += "Last Name cannot be empty.</br>";
    }
    if (txtEmailIdIns.value == "")
    {
        MessageBuilder += "Email cannot be empty.</br>";
    }
    if (txtContactNumberIns.value == "")
    {
        MessageBuilder +=  "Phone cannot be empty.</br>";
    }
    if (fileUploadIns.value == "")
    { 
        MessageBuilder +=  "Please upload your resume.</br>";
    }
    if (chkAcceptedIns.checked == false)
    {
        MessageBuilder += "Please accept the terms and conditions to complete the application process!";
    }
    if(MessageBuilder.length > 0)
    {
        lblErrorMessageIns.innerHTML = MessageBuilder;
        return false;
    }
    return true;
}

function SelectedJob()
{
    var cboJobProfileIns = document.getElementById(cboJobProfile);
    var hidJobProfileInc =  document.getElementById(hidJobProfile);
    var SelIndex = cboJobProfileIns.selectedIndex;
    hidJobProfileInc.value =  cboJobProfileIns[SelIndex].value;
}
function ClearForm()
{
    
    var rdoUSAIns = document.getElementById(rdoUSA);
    var rdoIndiaIns = document.getElementById(rdoIndia);
    var cboJobProfileIns = document.getElementById(cboJobProfile);
    var txtFirstNameIns = document.getElementById(txtFirstName);
    var txtLastNameIns = document.getElementById(txtLastName);
    var txtEmailIdIns = document.getElementById(txtEmailId);
    var txtContactNumberIns = document.getElementById(txtContactNumber);
    var fileUploadIns = document.getElementById(fileUpload);
    var chkAcceptedIns = document.getElementById(chkAccepted);
    var lblErrorMessageIns = document.getElementById(lblErrorMessage);

    txtFirstNameIns.value = "";
    txtLastNameIns.value = "";
    txtEmailIdIns.value = "";
    txtContactNumberIns.value = "";
    txtEmailIdIns.value = "";
    fileUploadIns.value = "";
    chkAcceptedIns.value = "";
    lblErrorMessageIns.innerHTML = "";
    SelectJobProfiles();
}

