﻿var v_flag;
var v_container;
var g_currentFontSize;

function f_setFontSize(p_size, p_portion) {
    var v_size = 'Normal';

    switch (p_size) {
        case '1':
            v_size = 'Normal';
            break;
        case '2':
            v_size = 'Large';
            break;
        case '3':
            v_size = 'Largest';
            break;
    }
    if (g_currentFontSize == null) {
        g_currentFontSize = 'Normal';
    }
    createCookie('font-size', p_size, 1);
    f_switchStyleSheet(g_currentFontSize, v_size);
    g_currentFontSize = v_size;


    if (g_langOpt == 1) {
        v_langOptDesc = 'en';
    } else if (g_langOpt == 2) {
        v_langOptDesc = 'tc';
    } else if (g_langOpt == 3) {
        v_langOptDesc = 'cn';
    }
    var v_imgPrefix = '';
    if (p_portion == 'js') {
    } else if (p_portion == 'emp') {
        v_imgPrefix = 'b';
    }
    
    switch (p_size) {
        case '1':
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1' + v_imgPrefix + '_f2.jpg';
            $('#smallestFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size1' + v_imgPrefix + '.jpg';

            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2' + v_imgPrefix + '.jpg';            
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3' + v_imgPrefix + '.jpg';
            break;
        case '2':
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1' + v_imgPrefix + '.jpg';

            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2' + v_imgPrefix + '_f2.jpg';
            $('#mediumFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size2' + v_imgPrefix + '.jpg';
            
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3' + v_imgPrefix + '.jpg';
            break;
        case '3':
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1' + v_imgPrefix + '.jpg';
            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2' + v_imgPrefix + '.jpg';
            
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3' + v_imgPrefix + '_f2.jpg';
            $('#largestFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size3' + v_imgPrefix + '.jpg';
            break;
        default:
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1' + v_imgPrefix + '.jpg';

            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2' + v_imgPrefix + '_f2.jpg';
            $('#mediumFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size2' + v_imgPrefix + '.jpg';
            
            
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3' + v_imgPrefix + '.jpg';
    }
}

function f_setInfoFontSize(p_size) {
    $('*').each(function() {
    $(this).css('font-size', '');
    });
    eraseCookie('font-size');
    if (p_size != '1') {
        f_setInfoFontSizeRecursive($('body'), p_size);
    }
    createCookie('font-size', p_size, 1);


    if (g_langOpt == 1) {
        v_langOptDesc = 'en';
    } else if (g_langOpt == 2) {
        v_langOptDesc = 'tc';
    } else if (g_langOpt == 3) {
        v_langOptDesc = 'cn';
    }

    switch (p_size) {
        case '1':
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1c_f2.jpg';
            $('#smallestFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size1c.jpg';
            
            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2c.jpg';
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3c.jpg';
            break;
        case '2':
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1c.jpg';

            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2c_f2.jpg';
            $('#mediumFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size2c.jpg';
            
            
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3c.jpg';
            break;
        case '3':
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1c.jpg';
            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2c.jpg';

            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3c_f2.jpg';
            $('#largestFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size3c.jpg';
            break;
        default:
            $('#smallestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size1c.jpg';

            $('#mediumFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size2c_f2.jpg';
            $('#mediumFontSize').get(0).oSrc = g_root + 'image/' + v_langOptDesc + '/size2c.jpg';
            
            
            $('#largestFontSize').get(0).src = g_root + 'image/' + v_langOptDesc + '/size3c.jpg';
    }
    
    
}
function f_setInfoFontSizeRecursive(p_obj, p_size) {

    p_obj.children().each(function() {
        f_setInfoFontSizeRecursive($(this), p_size);
    });
    var a = p_obj.css('font-size');
    var newSize = '';
    if (a != undefined) {
        p_obj.css('font-size', '');
        if ((a.toString().indexOf('px') >= 0) || (a.toString().indexOf('pt') >= 0)) {
            a = parseInt(a.toString().replace('px', '').replace('pt', ''), 10);
        } else {
            switch (a.toString()) {
                case "1":
                    a = 10;
                    break;
                case "2":
                    a = 13;
                    break;
                case "3":
                    a = 16;
                    break;
                case "4":
                    a = 18;
                    break;
                case "5" :
                    a = 24;
                    break;
                case "6":
                    a = 32;
                    break;
                case "7":
                    a = 48;
                    break;
                default :
                    a = 13;
            }
        }
        newSize = a + parseInt(p_size, 10) - 1;
        p_obj.css('font-size', newSize + 'PX');
    }

}
//function f_setInfoFontSize(p_size) {
//        var v_size = 0;

//        switch (p_size) {
//            case '1':
//                v_size = -1;
//                break;
//            case '2':
//                v_size = 15.5;
//                break;
//            case '3':
//                v_size = 18;
//                break;
//        }

//        if (v_size > 0) {

//            $('*').each(function() {
//                $(this).css('font-size', v_size);
//            });
//            
//            createCookie('font-size', p_size, 1);

//        } else {
//        $('*').each(function() {
//            $(this).css('font-size', '');
//        });

//            eraseCookie('font-size');
//            //location.reload();
//        }
//}

function f_switchStyleSheet(p_frSize, p_toSize) {
    if (p_frSize != p_toSize) {
        $("link[rel=stylesheet]").each(
            function() {
                $(this).attr('href', $(this).attr('href').replace('App_Themes/' + p_frSize + '/', 'App_Themes/' + p_toSize + '/'));
            }
        );
    }
}

function f_onError(arg) {
    alert(f_msgTxt('E092041') + ": " + arg._message); //error has occured
}

function f_showError(res) {

    if (typeof(v_container) == 'undefined') {
        v_container = '*';
    }
    v_flag = false;
    var result = res.d;

    if (result != null) {

        if (result.length == 0) {
            v_flag = true;
        }
        else {
            if (result[0][0] != '') {
                f_getFocus($(v_container).find('[id$=' + result[0][0] + ']').eq(parseInt(result[0][3])));
            }

            for (var i = 0; i < result.length; i++) {
                var v_rowno = parseInt(result[i][3]);
                switch (v_rowno) {
                    case -1:
                        f_fillMessage($('span[id$=uxGeneralError]'), result[i][2]);
                        break;
                    default:
                        f_fillMessage($(v_container).find('span[id$=' + result[i][1] + ']').eq(v_rowno), result[i][2]);
                        break;
                }
            }
        }

    } else {
        window.location = g_root + "WebForm/Default.aspx";
    }
}

function f_showMessage(res) {
    var result = res.d;    
    if (typeof(v_container) == 'undefined') {
       v_container = '*';
    }
     
    //alert('result: ' + result);   
    for (var i = 0; i < result.length; i++) {
        var v_rowno = parseInt(result[i][3]);
        switch (v_rowno) {
            case -1:
                f_fillMessage($('span[id$=uxGeneralError]'), result[i][2]);
                break;           
            default:
                f_fillMessage($(v_container).find('span[id$=' + result[i][1] + ']').eq(v_rowno), result[i][2]);
                break;
        }
    }    
}

function f_fillMessage(control, errorMsg) {
    $(control).hide().html(errorMsg).css({ filter: 'alpha(opacity=99.99)' }).customFadeIn('slow');
}

function f_getFocus(control) {
    $(control).focus();
}

function f_clearAllSpans() {
    $('span.error').each(function() {
        $(this).html('');
    });
}

function f_clearAllSpans(control) {
    $('[id$=uxGeneralError]').html('');
    $(control).find('span.error').each(function() {
        $(this).html('');
    });
}

function f_clearError(control) {   
    $(control).html('');    
}

function f_initDropDownList(control, type, val) {
//    this.v_target = control;
//    $.ajax({
//        type: "POST",
//        async: false,
//        url: g_root + "WebServices/RegProfileWS.asmx/F_GetCode",
//        contentType: "application/json; charset=utf-8",
//        data: "{p_codeType:'" + type + "',p_params:'" + val + "', p_langOpt:" + lang + "}",
//        dataType: "json",
//        success: f_initSubComboBox,
//        error: f_onError
//    });

    this.v_target = control;
    $.ajax({
        type: "POST",
        async: false,
        url: g_root + "WebServices/RegProfileWS.asmx/F_GetCode",
        contentType: "application/json; charset=utf-8",
        data: "{p_codeType:'" + type + "',p_params:'" + val + "', p_langOpt:" + g_langOpt + "}",
        dataType: "json",
        success: f_initSubComboBox,
        error: f_onError
    });
}

function f_initSubComboBox(res) {
    var result = res.d;
    var $x = $(v_target);
    var y = $x.get(0);
    while (y.hasChildNodes()) {
        y.removeChild(y.firstChild);
    }
    y.options[0] = new Option;
    y.options[0].text = '';
    y.options[0].value = '';
    //$(v_target).html('');
    //$(v_target).append($("<option></option>").attr("value", '').text(''));
    for (var i = 0; i < result.length; i++) {
        //$(v_target).append($("<option></option>").attr("value", result[i][0]).text(result[i][1]));               
        var z = $x.get(0) 
        z.options[i+1] = new Option;
        z.options[i+1].text = result[i][1];
        z.options[i+1].value = result[i][0];
    }    
}

(function($) {
    $.fn.customFadeIn = function(speed, callback) {
        $(this).fadeIn(speed, function() {
            if (jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
    $.fn.customFadeOut = function(speed, callback) {
        $(this).fadeOut(speed, function() {
            if (jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
})(jQuery); 
function f_initialVariable(p_commonCodeWSPage, p_langOpt) {

    g_commonCodeWSPage = p_commonCodeWSPage;
    g_langOpt = p_langOpt;

}
 function f_getQueryString(p_key)   
{  
    var AllVars = window.location.search.substring(1);  
    var Vars = AllVars.split("&");  

    for (i = 0; i < Vars.length; i++){  
       var Var = Vars[i].split("=");
        if (Var[0] == p_key) return Var[1];  

    }  
     return "";  
}  

function f_highlightKeyword() {
    //Highlight searched keyword after searching.
    //1. Keyword search (Simple and advanced search)
    //2. Job title search (Advanced search)    

    if (($('*[id$=uxSearchKeyword]').val() != undefined &&
         $('*[id$=uxSearchKeyword]').val() != NaN) ||
        ($('*[id$=uxSearchJobTitleKeyword]').val() != undefined &&
         $('*[id$=uxSearchJobTitleKeyword]').val() != NaN)) {
        
        if ($('*[id$=uxSearchKeyword]').val().trim() != '' ||
            $('*[id$=uxSearchJobTitleKeyword]').val().trim() != '') {

            var v_simpleSearchKeyword = $('*[id$=uxSearchKeyword]').val()
            var v_simpleSearchKeywordList = v_simpleSearchKeyword.split(',');

            var v_searchJobTitleKeyword = $('*[id$=uxSearchJobTitleKeyword]').val()
            var v_searchJobTitleKeywordList = v_searchJobTitleKeyword.split(',');

            for (i = 0; i < v_simpleSearchKeywordList.length; i++) {
                if (v_simpleSearchKeywordList[i] != '' &&
                    v_simpleSearchKeywordList[i] != undefined &&
                    v_simpleSearchKeywordList[i] != NaN) {
                    
                    $('*[id$=uxJobCardArea]').highlight(v_simpleSearchKeywordList[i], false);
                    $('*[id$=uxJobListArea]').highlight(v_simpleSearchKeywordList[i], false);
                    $('*[id$=uxJobListDetails]').highlight(v_simpleSearchKeywordList[i], false);
                    $('*[id$=uxJobCardPt2Note]').highlight(v_simpleSearchKeywordList[i], false);
                }
            }

            for (i = 0; i < v_searchJobTitleKeywordList.length; i++) {
                if (v_searchJobTitleKeywordList[i] != '' &&
                    v_searchJobTitleKeywordList[i] != undefined &&
                    v_searchJobTitleKeywordList[i] != NaN) {

                    $('*[id$=uxJobTitleDiv]').highlight(v_searchJobTitleKeywordList[i], true);
                }
            }
        }
    }   
}

