﻿// Disable right mouse click.
//window.document.oncontextmenu = new Function("return (document.activeElement.isTextEdit) ? true : false");
   
// Disable selection.
//window.document.onselectstart = new Function("return (document.activeElement.isTextEdit) ? true : false");

// Redraw main table on window resize.
window.onresize = SetMainTableSize;

// Redraw main table on window resize.
function SetMainTableSize()
{
    // Set width.
    // TODO:
//    if (document.getElementById("tabMain").style.height < 495)
//        document.getElementById("tabMain").style.height = 495;
        
    document.getElementById("tdPanel").style.height = document.body.clientHeight - 115;
    
    // Set news list style.
    if (document.getElementById("ctl00_ContentPlaceHolder1_gvNewsList") != null)
    {
        var pages = document.getElementById("ctl00_ContentPlaceHolder1_gvNewsList").getElementsByTagName("a");
        
        for (var i = 0; i < pages.length; i++)
        {
            if (pages[i].href.indexOf("javascript") != -1)
                pages[i].className = "newsHeader";
        }
        
        var numbers = document.getElementById("ctl00_ContentPlaceHolder1_gvNewsList").getElementsByTagName("span");
        
        for (var i = 0; i < numbers.length; i++)
            numbers[i].className = "newsHeader";
    }
}

// Toggle news item.
function ToggleNewsItem(item_id)
{
    if (document.getElementById(item_id).style.display == "none")
        document.getElementById(item_id).style.display = "block";
    else
        document.getElementById(item_id).style.display = "none";
}

// Registration form "Interview" validation.
function RegFormInterviewIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    return IsValid;
}

// Registration form "Online learning" validation.
function RegFormOnlineLearningIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    return IsValid;
}

// Registration form "Subscribe" validation.
function RegFormSubscribeIsValid()
{
    var IsValid = true;
    
    // Hide alert messages.
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_lblFullNameAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_lblMobileNumberAlert").style.display = "none";
    
    // Validate full name.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_txtFullName").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_lblFullNameAlert").style.display = "block";
    }
    
    // Validate mobile telephone number.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_txtMobileNumber").value) ||
        !IsPhone(document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_txtMobileNumber").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlSubscribeForm_lblMobileNumberAlert").style.display = "block";
    }
        
    return IsValid;
}

// Registration form "Questions" validation.
function RegFormQuestionsIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    return IsValid;
}

// Registration form "Exam" validation.
function RegFormExamIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    // Validate exam name.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ddlExamName").value) &&
        IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_txtExamName").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblExamNameAlert").style.display = "block";
    }
    
    // Validate exam date.
    if (!IsEUDate(document.getElementById("ctl00_ContentPlaceHolder1_txtExamDate").value) ||
        IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_txtExamDate").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblExamDateAlert").style.display = "block";
    }

    return IsValid;
}

// Registration form "Employment" validation.
function RegFormEmploymentIsValid()
{
    var IsValid = true;
    
    // Hide alert messages.
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblFullNameAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblMobileNumberAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblPhoneNumberAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblResumeAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblPhotoAlert").style.display = "none";
    
    // Validate full name.
    if (document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_txtFullName").value == "")
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblFullNameAlert").style.display = "block";
    }
    
    // Validate mobile telephone number.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_txtMobileNumber").value) ||
        !IsPhone(document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_txtMobileNumber").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblMobileNumberAlert").style.display = "block";
    }
    
    // Validate telephone number.
    if (!IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_txtPhoneNumber").value) &&
        !IsPhone(document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_txtPhoneNumber").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblPhoneNumberAlert").style.display = "block";
    }
    
    // Validate resume.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_fuResume").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblResumeAlert").style.display = "block";
    }
    
    // Validate photo.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_fuPhoto").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlEmploymentFormControl_lblPhotoAlert").style.display = "block";
    }

    return IsValid;
}

// Registration form "Contact" validation.
function RegFormContactIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    return IsValid;
}

// Registration form "Consultation" validation.
function RegFormConsultationIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    return IsValid;
}

// Registration form "Consulting" validation.
function RegFormConsultingIsValid()
{
    var IsValid;
    
    IsValid = RegFormIsValid();
    
    return IsValid;
}

// Registration form validation.
function RegFormIsValid()
{
    var IsValid = true;
    
    // Hide alert messages.
    HideAlertMessages();
    
    // Validate full name.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtFullName").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblFullNameAlert").style.display = "block";
    }
    
    // Validate telephone and mobile telephone numbers.
    if (IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtPhoneNumber").value) &&
        IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtMobileNumber").value))
    {
        IsValid = false;
            
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblEmptyContactAlert").style.display = "block";
    }
    else
    {
        // Validate telephone number.
        if (!IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtPhoneNumber").value) &&
            !IsPhone(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtPhoneNumber").value))
        {
            IsValid = false;
            
            // Show alert message.
            document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblPhoneNumberAlert").style.display = "block";
        }
            
        // Validate mobile telephone number.
        if (!IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtMobileNumber").value) &&
            !IsPhone(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtMobileNumber").value))
        {
            IsValid = false;
            
            // Show alert message.
            document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblMobileNumberAlert").style.display = "block";
        }
    }
    
    // Validate e-mail.
    if (!IsEmpty(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtEmail").value) &&
        !IsEmail(document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_txtEmail").value))
    {
        IsValid = false;
        
        // Show alert message.
        document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblEmailAlert").style.display = "block";
    }
    
    return IsValid;
}

// Hide alert messages.
function HideAlertMessages()
{
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblFullNameAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblEmptyContactAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblPhoneNumberAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblMobileNumberAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblEmailAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblExamNameAlert").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder1_ctrlRegForm_lblExamDateAlert").style.display = "none";
}

// Validates digital input.
function IsDigitalInput()
{
    if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) ||
         event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39)
        {
            event.returnValue = true;
        }
        else
            event.returnValue = false;
}

// Validates e-mail format.
function IsEmail(strValue)
{
    var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
    var isValid = false;
    
    if (objRegExp.test(strValue))
	    isValid = true;
	    
	return isValid;
}

// Validate phone number.
function IsPhone(strValue)
{
    var objRegExp  = /^([0-9\-\s]*)[0-9\s]$/;
    var isValid = false;
    
    strValue = trim(strValue);
    
    if (strValue.length >= 8)
    {
        if (strValue.substring(0, 1) == "+" || strValue.substring(0, 1) == "0")
        {
            if (objRegExp.test(strValue.substring(1, strValue.length)))
                isValid = true;
        }
    }
        
    return isValid;
}

// Validates integer format.
function IsInteger(strValue)
{
    var objRegExp  = /(^-?\d\d*$)/;
    var isValid = false;

    if (objRegExp.test(strValue))
        isValid = true;
        
    return isValid;
}

// Validates numeric format.
function IsNumeric(strValue)
{
    var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
    var isValid = false;
    
    if (objRegExp.test(strValue))
        isValid = true;
        
    return isValid;
}

// Validates Europe date format.
function IsEUDate(strValue)
{
    var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
    var isValid = false;
    var arrayDate;
    var intDay;
    var intYear;
    var intMonth;
    var arrayLookup;
    var booLeapYear;
 
    if (objRegExp.test(strValue))
    {
        arrayDate = strValue.split(RegExp.$1);
	    intDay = parseInt(arrayDate[0],10);
	    intYear = parseInt(arrayDate[2],10);
        intMonth = parseInt(arrayDate[1],10);
	
	    if (intMonth > 12 || intMonth < 1)
		    isValid = false;
		else
		{
            arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                            '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
  
            if (arrayLookup[arrayDate[1]] != null)
            {
                if (intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
                    isValid = true;
            }

            booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
            if (((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <= 28)) && intDay !=0)
                isValid = true;
        }
    }
    
    return isValid;
}

// Validates empty value.
function IsEmpty(strValue)
{
    var isValid = true;

    if (trim(strValue) != "")
	    isValid = false;
	
	return isValid;
}

// Trim string.
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g, "");
}

// Left trim string.
function ltrim(stringToTrim)
{
	return stringToTrim.replace(/^\s+/, "");
}

// Right trim string.
function rtrim(stringToTrim)
{
	return stringToTrim.replace(/\s+$/, "");
}