/*
Custom Validation Level7 16 Jan 2008
*/
/*********EMPLOYMENT**********************/
function EmploymentValidation()
{
    this.displayErrorMessage = false;
    this.validationSuccessful = true;
    this.validationMessage = "";
}
EmploymentValidation.prototype.ValidateMinimumPasswordLength = function(source)
{
  var sourcePath = source.id.substring(0,source.id.lastIndexOf("_"));
  var password = this.GetThisFormControl(sourcePath,"txtPassword").value;
  if(password.length<8)
  {
    this.validationSuccessful = false;
  }
}
EmploymentValidation.prototype.ValidateEmploymentDuration = function(source)
{
    var sourcePath = source.id.substring(0,source.id.lastIndexOf("_"));
    var fromMonth = this.GetThisFormControl(sourcePath,"ddDurationFromMonth").value;
    var fromYear = this.GetThisFormControl(sourcePath,"ddDurationFromYear").value;
    var toMonth = this.GetThisFormControl(sourcePath,"ddDurationToMonth").value;
    var toYear = this.GetThisFormControl(sourcePath,"ddDurationToYear").value;
    
    if(("-1" == fromMonth) || ("-1" == fromYear))
    {
        this.validationSuccessful = false;
    }    
    else
    {
        if(("-2" == toMonth))   
        {
            this.validationSuccessful = true;
        }
        else
        {
            
            if(("-1" == toMonth) || ("-1" == toYear))
            {
                this.validationSuccessful = false;
            }
            else
            {
                var durationDates = new DateUtil();        
                durationDates.SetDateFrom(01,parseInt(fromMonth),parseInt(fromYear));
                
                durationDates.SetDateTo(01,parseInt(toMonth),parseInt(toYear));
                
                if(durationDates.DateDiff("DAYS")<0)
                {
                    this.validationSuccessful = false;    
                }
            }
        }
    }    
}
EmploymentValidation.prototype.ValidateCurrentEmploymentDuration = function(source)
{
    var sourcePath = source.id.substring(0,source.id.lastIndexOf("_"));
    var fromMonth = this.GetThisFormControl(sourcePath,"ddlCurrentDurationFromMonth").value;
    var fromYear = this.GetThisFormControl(sourcePath,"ddlCurrentDurationFromYear").value;
    var toMonth = this.GetThisFormControl(sourcePath,"ddlCurrentDurationToMonth").value;
    var toYear = this.GetThisFormControl(sourcePath,"ddlCurrentDurationToYear").value;
   if(("-1" == fromMonth) || ("-1" == fromYear))
    {
        this.validationSuccessful = false;
    }    
    else
    {
        if(("-2" == toMonth))   
        {
            this.validationSuccessful = true;
        }
        else
        {
            
            if(("-1" == toMonth) || ("-1" == toYear))
            {
                this.validationSuccessful = false
            }
            else
            {
                var durationDates = new DateUtil();        
                durationDates.SetDateFrom(01,parseInt(fromMonth),parseInt(fromYear));
                durationDates.SetDateTo(01,parseInt(toMonth),parseInt(toYear));
                
                if(durationDates.DateDiff("DAYS")<0)
                {
                    this.validationSuccessful = false;    
                }
            }
        }
    }    
}
EmploymentValidation.prototype.GetThisFormControl = function(sourcePath,control) 
{
    return document.getElementById(sourcePath + "_" + control);
}

EmploymentValidation.prototype.ValidateKeySkills = function(source)
{
    var sourcePath = source.id.substring(0,source.id.lastIndexOf("_"));
    var keySkillsText = this.GetThisFormControl(sourcePath,"txtKeySkills").innerText;
   
    //keySkills set on Change Event of control.. Event Handler
    if("" == keySkills)
    {
        //Check Current Value
        if("" == keySkillsText)
        {
            this.validationSuccessful = false;
        }
        
    }
}
EmploymentValidation.prototype.CheckIfLegal = function(source)
{
    var sourcePath = source.id.substring(0,source.id.lastIndexOf("_"));
    var legalCheckBox = this.GetThisFormControl(sourcePath,"chkLegal").checked;    
    if(false == legalCheckBox)
    {
        this.validationSuccessful =false;
    } 
    
}
///////////////Object Reference//////////////////////
function validateEmploymentDuration(source, arguments)
{
    var empVal = new EmploymentValidation();
    empVal.ValidateEmploymentDuration(source); 
    
    if(!empVal.validationSuccessful)
    {
        if(empVal.displayErrorMessage)
        {
            alert(empVal.validationMessage);
        }
    }
    arguments.IsValid = empVal.validationSuccessful;
}

function validateCurrentEmploymentDuration(source,arguments)
{
    var empVal = new EmploymentValidation();
    empVal.ValidateCurrentEmploymentDuration(source); 
    
    if(!empVal.validationSuccessful)
    {
        if(empVal.displayErrorMessage)
        {
            alert(empVal.validationMessage);
        }
    }
    arguments.IsValid = empVal.validationSuccessful;
}

function validateKeySkills(source,arguments)
{
    
    var empVal = new EmploymentValidation();
    empVal.ValidateKeySkills(source);
    arguments.IsValid = empVal.validationSuccessful;
}
function validatePasswordLength(source,arguments)
{
    var empVal = new EmploymentValidation();
    empVal.ValidateMinimumPasswordLength(source);
    arguments.IsValid = empVal.validationSuccessful;
    
}
function checkLegal(source,arguments)
{
    var empVal = new EmploymentValidation();
    empVal.CheckIfLegal(source);
    arguments.IsValid = empVal.validationSuccessful;

}
function showHideAdvancedOptions()
{
    var labelTitle = document.getElementById('MainPage_MainContent_divShowAdvanced');
    var advanced = document.getElementById('MainPage_MainContent_pnlAdvancedOptions');
    if(advanced.style.display == 'none')
    {
        advanced.style.display = '';
        
        labelTitle.innerText = 'Hide Advanced Options';
    }  
    else
    {
        advanced.style.display = 'none';
        labelTitle.innerText = 'Show Advanced Options';
    }  
}
function showAdvanced()
{
    var labelTitle = document.getElementById('MainPage_MainContent_divShowAdvanced');
    var advanced = document.getElementById('MainPage_MainContent_pnlAdvancedOptions');
    advanced.style.display = '';    
    labelTitle.innerText = 'Hide Advanced Options';

}