/**
* @object: button
* @use: control all button in resume;
* @location: openResume_th.php, openResume_en.php;
* @status: in progress about 99%;
*/
var button = {    
    editors:'',
    varObjective:'',
    educateId:'',
    objEducation:'',
    sourceButton:'',
    control:'',
    lang:'',
    defaultTip:'',
    resume_lang:'',
    member_type:'',    
    loadReady:function(){     
        button.buttonIndex();       
    },
    control_button:function (){
            var btnSection = new Array();           
            var total = $('span.btn').length;
            for(var i=0;i<total;i++){
                var btn = $('span.btn:eq('+i+') [type=button]');    
                var display = "span.btn:eq("+i+")";               
               var span = $('span.btn:eq('+i+') span.show_hand');
               span.eq(0).click(function(){
                    var path = $(this).parent().parent();
                    var language = $(this).attr("id");
                    var langSection = language.split("-");
                    var data = '';
                    var popup = '';
                   
                    if(langSection[0] == 'th'){
                        data = path.siblings(".hidden-example-Th").val();
                        popup = 'ตัวอย่าง';
                        $('#dialog').empty().attr('title', popup).append('<p style="text-align:left;">'+data+'</p>');
                        $('#dialog').dialog({
                                            bgiframe: true,
                                            resizable: false,
                                            width:400,
                                            height:400,
                                            modal: true,
                                            overlay: {
                                                backgroundColor: '#000',
                                                opacity: 0.5
                                            },
                                            close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                            buttons: {                                       
                                            'ตกลง': function() {
                                            $(this).dialog( 'destroy' );
                                        }
                                    }
                        });
                    }else{
                        data = path.siblings(".hidden-example").val();
                        popup = 'Example';
                        $('#dialog').empty().attr('title', popup).append('<p style="text-align:left;">'+data+'</p>');
                        $('#dialog').dialog({
                                            bgiframe: true,
                                            resizable: false,
                                            width:400,
                                            height:400,
                                            modal: true,
                                            overlay: {
                                                backgroundColor: '#000',
                                                opacity: 0.5
                                            },
                                            close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                            buttons: {                                       
                                            'OK': function() {
                                            $(this).dialog( 'destroy' );
                                        }
                                    }
                        });
                    }
                                           
               });
                var icon = $('span.btn:eq('+i+') img');
                $('span.btn:eq('+i+') .save-section').click(function(){//save button
                    var sectionId = $(this).siblings(".hidden-section").attr("value");
                    $(this).siblings("div.mainsection").find(".sectionInput").css('display','none');
                    var details = btnSection[sectionId].getData();
                    /*alert(details);*/
                    var test = details.replace(/<\/?[^>]+(>|$)/g, "");                                       
                    var data = '';
                    var dataSplit = details.split('</li>');                    
                    var pattern = /[&nbsp;&nbsp;]/g;
                    if(dataSplit.length != 1){                                                                    
                        var newstr = '';                                                                 
                        for(var i=0;i<dataSplit.length;i++){
                                   newstr += dataSplit[i];                          
                            if(i !=(dataSplit.length-1) ){
                                newstr += "</li>";                              
                            }                                                      
                        }
                        data += newstr;
                     }else{
                         data = details;
                     }                                                                                               
                    $(this).siblings("div.mainsection").find(".sectionInput").empty();
                    $(this).siblings("div:eq(0)").find("[name=x_button]").css('display','none');
                    $(this).siblings("hr").css('display','none');
					$(this).siblings(".short").css('display','none');
                    $(this).css('display','none');
                    $(this).siblings("div:eq(6)").css('display','none');
                    $(this).siblings("div:eq(7)").css('display','none');
                    $(this).siblings("div:eq(8)").css('display','block');
                    $(this).siblings("div:eq(9)").css('display','block');
                    $.ajax({
                                url:'modules/section/removeSectionSub.php',
                                cache: false,
                                data:{'source':'save','resumeId':$("#resId").val(),'sectionId':sectionId,'details':data},
                                type:'POST',
                                success:function(data){
                                /*alert(data);*/
                                btnSection[sectionId]  = null;
                                    $.ajax({
                                            url:'modules/resume/openResume.php',
                                            cache: false,
                                            data:{'resumeId':$("#resId").val()},
                                            type:'POST',
                                            success:function(data){
                                               $("#main").empty().append(data);
                                               button.control_button();
                                               button.buttonEducation();
                                               $("#education_section [name=close_button]").click(button.cancel_education);
                                            }

                                    });
                                }
                    });
                    $(this).siblings("div.mainsection").find(".sectionText").css('display','block').empty().append(data);
                    button.refreshTip();
                });
                 //icon.eq(0).click(function(){ //close button
                 $('span.btn:eq('+i+') .close-section').click(function(){ //close button
				
				//$("#preview_button").bind('click');
                    $(this).siblings("div.mainsection").find(".sectionText").css('display','block').empty().html(button.varObjective);
                    var sectionId = $(this).siblings(".hidden-section").attr("value");
                    $(this).siblings("div.mainsection").find(".sectionInput").empty().css('display','none');
                    $(this).siblings("div:eq(0)").find("[name=x_button]").css('display','none');
                    $(this).siblings("hr").css('display','none');
					$(this).siblings(".short").css('display','none');
                    $(this).css('display','none');
                    $(this).siblings("div:eq(7)").css('display','none');
                    $(this).siblings("div:eq(6)").css('display','none');
                    $(this).siblings("div:eq(8)").css('display','block');
                    $(this).siblings("div:eq(9)").css('display','block');
                    btnSection[sectionId] = null;
                    button.refreshTip();
                    button.editMode(1);
                });
               
                //icon.eq(2).click(function(){//edit button
                $('span.btn:eq('+i+') .edit-section').click(function(){//edit button
				//$('span.show_hand').hide();
				
					button.editMode(0);
					$(".account").hide();
					$(".tbme").show();
					$("#menutab1, #menutab2").show();
                    $("#menutab1").click();                                      
                    var head = $(this).siblings(".sectionHead").text();                    
                    switch(session_lang){
                        case'th':
                            var advice = $(this).siblings(".hidden-advice-Th").val();
                            var hint = $(this).siblings(".hidden-hint-Th").val();
                            var tip = $(this).siblings(".hidden-tip-Th").val();   
                        break;
                        
                        case'en':
                            var advice = $(this).siblings(".hidden-advice").val();
                            var hint = $(this).siblings(".hidden-hint").val();
                            var tip = $(this).siblings(".hidden-tip").val();
                        break;
                    } 
                    $(this).siblings("div.mainsection").find(".sectionText").css('display','none');                    
                    var print = $(this).siblings("div.mainsection").find(".sectionInput").attr("id");                                      
                    var oldText = $(this).siblings("div.mainsection").find(".sectionText").attr("id");
                    var sectionId = $(this).siblings(".hidden-section").attr("value");
                    var html = $('#'+oldText).html();                    
                    button.varObjective = html;
                    btnSection[sectionId] = CKEDITOR.appendTo(print);
                    //CKEDITOR.replace( 'textarea', {  enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_BR } );
                    CKEDITOR.on( 'instanceReady', function( ev )
                        {
                         ev.editor.dataProcessor.writer.setRules( 'br',
                         {
                            indent : false,
                            breakBeforeOpen : false,
                            breakAfterOpen : false,
                            breakBeforeClose : false,
                            breakAfterClose : false
                         });
                   });                                   
                    btnSection[sectionId].setData(html);                                                          
                    $(this).siblings("div.mainsection").find(".sectionInput").css('display','block');
					$(this).siblings("hr").css('display','block');  
                    $(this).siblings(".short").css('display','block');                   
                    $(this).css('display','none');
					$(this).siblings("div:eq(8)").css('display','block');
                    $(this).siblings("div:eq(7)").css('display','block');
                    $(this).siblings("div:eq(6)").css('display','block');
                    $(this).siblings("div:eq(10)").find(".mytextbox").css('display','none');                   
                    $('#tab1 li:eq(0)').empty().append(head);
                    $('#tab2 li:eq(0)').empty().append(head);
                    $('#tab3 li:eq(0)').empty().append(head);
                    //console.log($('#mycarouselAdvice').length);
                    var dataAdvice = advice.split("<br />");
                    var dataHint = hint.split("<br />");
                    var dataTip = tip.split("<br />");
                    var total = dataAdvice.length;
                    var totalHint = dataHint.length;
                    var totalTip = dataTip.length;
                    $('#mycarouselAdvice li').empty();
                    if($('#mycarouselAdvice li').length > total){
                        $('#mycarouselAdvice li:gt('+(total-1)+')').remove();
                    }
                    $('#mycarouselHint li').empty();
                    if($('#mycarouselHint li').length > totalHint){
                        $('#mycarouselHint li:gt('+(totalHint-1)+')').remove();
                    }
                    $('#mycarouselTip li').empty();                   
                                    for(var k=0;k<total;k++){
                                        $('#mycarouselAdvice li:eq('+k+')').empty().append(dataAdvice[k]).css('display', 'block');
                                    }                                  
                                        $('#mycarouselAdvice').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                                   for(var m=0;m<totalHint;m++){
                                        $('#mycarouselHint li:eq('+m+')').empty().append(dataHint[m]).css('display', 'block');
                                    }
                                        $('#mycarouselHint').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                                    for(var n=0;n<totalTip;n++){
                                                $('#mycarouselTip li:eq('+n+')').empty().append(dataTip[n]).css('display', 'block');
                                    }
                                        $('#mycarouselTip').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                });
                
            }
            
            /**
            * @function: close button, save button, remove button, edit button.
            * @location: openResume_th.php, openResume_en.php in section id 4, 13, 25, 29, 36;
            * @status: in progress about 70%;
            * @problem: replace edit button with add new button;
            */
             var tot = $("span.special").length;
             var btnExp = new Array();
             for(var j=0;j<tot;j++){
                    var buttons = $('span.special:eq('+j+') img');
                    $('span.special:eq('+j+') .close-button').click(function(){ //close button
                        var sectionId = $(this).parent().siblings(".hidden-section").attr("value");
                        $(this).siblings(".mainmenu").find(".subMenu").css("display","none");
                        $(this).siblings(".mainmenu").find(".inputTextArea").css("display","none");
                        $(this).siblings(".mainmenu").find('.experText').css('display','block'); 
                        $(this).siblings('hr').css('display','none');
						$(this).siblings('.short').css('display','none');
                        $(this).css('display','none');
                        $(this).siblings(".experienceEdit").not('.can-not-click').css('display','block');
                        $(this).siblings(".experienceRemove").not('.can-not-click').css('display','block');
                        $(this).siblings(".experienceAdd").css('display','block');
                        $(this).siblings(".save-button, .close-button").css('display','none');
                        $(this).siblings(".mainmenu").find(".subMenu").find(".start").attr("value", " ");   
                        $(this).siblings(".mainmenu").find(".subMenu").find(".end").attr("value", "Present");
                        $(this).siblings(".mainmenu").find(".subMenu").find("[name=company_text]").attr("value", " ");
                        $(this).siblings(".mainmenu").find(".subMenu").find("[name=position_text]").attr("value", " ");
                        $(this).siblings(".mainmenu").find(".subMenu").find("[name=selectCountry]").attr("value", " ");
                        $(this).siblings(".mainmenu").find(".subMenu").find("[name=province_text]").attr("value", " ");
                        $(this).siblings(".mainmenu").find(".subMenu").find("[name=city_text]").attr("value", " ");
                        $("#mainOptionText"+sectionId).hide();
                        btnExp[sectionId] = null;
                        button.refreshTip();
						button.editMode(1);                                              
                    });//End Close Buttons
                    
                    //buttons.eq(1).click(function(){//save button
                    $('span.special:eq('+j+') .save-button').click(function(){//save button
						button.editMode(1);
                        var sectionId = $(this).siblings(".hidden-section").attr("value");
                        var expId = $("[name=check_exp"+sectionId+"]:checked").val();
                        var currentTime = new Date();
                        var month = currentTime.getMonth() + 1;
                        var day = currentTime.getDate();                         
                        var startMonth = $(this).siblings(".mainmenu").find(".subMenu").find("#startMonth"+sectionId).attr("value");
                        var startYear = $(this).siblings(".mainmenu").find(".subMenu").find("#startYear"+sectionId).attr("value");
                        var endMonth = $(this).siblings(".mainmenu").find(".subMenu").find("#endMonth"+sectionId).attr("value");
                        var endYear = $(this).siblings(".mainmenu").find(".subMenu").find("#endYear"+sectionId).attr("value");                        
                        var company = $(this).siblings(".mainmenu").find(".subMenu").find("[name=company_text]").attr("value");
                        var position = $(this).siblings(".mainmenu").find(".subMenu").find("[name=position_text]").attr("value");
                        switch(button.control){
                            case'add':
                                    var country = $('#selectCountryExp'+sectionId).val();
                                    var flagId = sectionId;
                            break;
                            
                            case'edit':
                                    var country = $('#selectCountryExp'+expId).val();
                                    var flagId = expId;
                            break;
                        }
                        if(country == 226){
                            var city = $(this).siblings(".mainmenu").find(".subMenu").find("#city_exp"+sectionId).val();
                            var province = '';
                            var state = $(this).siblings(".mainmenu").find(".subMenu").find("#selectStateExp"+flagId).val();
                            var other = '';
                        }else if(country == 211){
                            var city = '';
                            var province = $(this).siblings(".mainmenu").find(".subMenu").find("#selectProvinceExp"+flagId).val();
                            var state = '';
                            var other = '';
                        }else{
                            var city = $(this).siblings(".mainmenu").find(".subMenu").find("[name=city_exp"+sectionId+"]").attr("value");              
                            var province = '';
                            var state = '';
                            var other =  $(this).siblings(".mainmenu").find(".subMenu").find("#stateOther"+sectionId).val();
                        }

                    var descript = btnExp[sectionId].getData(); 
                    var data = '';
                    var dataSplit = descript.split('</li>');
                    var pattern = /[&nbsp;&nbsp;]/g;

                    if(dataSplit.length != 1){                                                                    
                        var newstr = '';                                                                 
                        for(var i=0;i<dataSplit.length;i++){
                                newstr += dataSplit[i];                                                            
                            if(i !=(dataSplit.length-1) ){
                                newstr += "</li>";
                                
                            }                                                      
                        }
                        data += newstr;
                     }else{
                         data = descript;
                     }            
                      $.ajax({
                                url:'modules/experience/experienceSub.php',
                                cache: false,
                                data:{'resumeId':$("#resId").val(), 'sectionId':sectionId, 'expId':expId,
                                      'startMonth':startMonth, 'startYear':startYear, 'endMonth':endMonth,  'endYear':endYear, 'company':company, 
                                      'position':position, 'country':country,'province':province, 'other':other, 'state':state, 'city':city, 'desc':data, 'option':button.control},
                                type:'POST',
                                success:function(data){
                                       $.ajax({
                                                url:'modules/resume/openResume.php',
                                                cache: false,
                                                data:{'resumeId':$("#resId").val()},
                                                type:'POST',
                                                success:function(data){
                                                   $("#main").empty().append(data);
                                                   button.control_button();
                                                   button.buttonEducation();
                                                   $("#education_section [name=close_button]").click(button.cancel_education);  
                                                }

                                        });                                               
                                }

                        });
                        button.refreshTip();                            
                    });//End Save Buttons
                    
                    //buttons.eq(2).click(function(){ //remove button
                    $('span.special:eq('+j+') .experienceRemove').click(function(){ //remove button
                        var sectionId = $(this).siblings(".hidden-section").attr("value");
                        var expId = $("[name=check_exp"+sectionId+"]:checked").val();
                        var delPath = $("[name=check_exp"+sectionId+"]:checked").parent().parent().parent();
                        var head = $(this).siblings(".content-head").find("h3").text();
                        switch(session_lang){
                               case'th':
                                    var delete_word = 'คุณต้องการลบส่วนของ'+head+'ใช่หรือไม่?';
                                    var delete_title = 'ลบ';
                               break;
                               
                               default:
                                    var delete_word = 'Do you want to delete '+head+'?';
                                    var delete_title = 'Delete';
                               break;
                        }                       
                        $('#dialog').empty().attr('title',''+delete_title+'').append('<p>'+delete_word+'</p>');
                        utils.dialogData('dialog', delPath, 'experience', expId);                                      
                    });//End Remove Buttons
                                        
                    //buttons.eq(4).click(function(){ //Add New button
                    $('span.special:eq('+j+') .experienceAdd').click(function(){ //Add New button
							 button.editMode(0);
							 
                             var sectionId = $(this).siblings(".hidden-section").attr("value");
                             var start = $(this).siblings(".mainmenu").find(".subMenu").find(".start-exp").attr("id");
                             var end = $(this).siblings(".mainmenu").find(".subMenu").find(".end").attr("id");
                             $("#endMonth"+sectionId).change(function(){
                                 if($("#endMonth"+sectionId).val() != 0){
                                     $("#endYear"+sectionId).show();
                                 }else{
                                     $("#endYear"+sectionId).hide();
                                 }
                             })
                            $(this).siblings(".mainmenu").find(".subMenu").css("display","block");
                            $(this).siblings(".mainmenu").find(".inputTextArea").empty().css("display","block");
                            var ui = $(this).siblings(".mainmenu").find(".inputTextArea").attr("id");                                   
                            btnExp[sectionId] = CKEDITOR.appendTo(ui);
                            $(this).siblings(".mainmenu").find('.experText').css('display','none'); 
                            $(this).siblings('hr').css('display','block');
							$(this).siblings('.short').css('display','block');
                            $(this).css('display','none');
                            $(this).siblings(".experienceRemove").css('display','none');
                            $(this).siblings(".experienceAdd").css('display','none');
                            $(this).siblings(".experienceEdit").css('display','none');
                            $(this).siblings(".save-button, .close-button").css('display','block'); 
                            button.control = 'add';
                            $(this).siblings(".mainmenu").find(".start-exp").empty().val("");
                            $(this).siblings(".mainmenu").find(".end").empty().val("Present");
                            $(this).siblings(".mainmenu").find(".company-exp").empty().val("");
                            $(this).siblings(".mainmenu").find(".city-exp").empty().val("");
                            $(this).siblings(".mainmenu").find(".province-exp").empty().val("");
                            $(this).siblings(".mainmenu").find(".company-exp").focus();
                            $(this).siblings(".mainmenu").find(".position-exp").empty().val("");
                            var head = $(this).siblings(".content-head").text();
                            
                            switch(session_lang){
                                case'th':
                                    var advice = $(this).siblings(".hidden-advice-Th").val();
                                    var hint = $(this).siblings(".hidden-hint-Th").val();
                                    var tip  = $(this).siblings(".hidden-tip-Th").val();
                                    var stateName = 'รัฐ:';
                                    var province_prefix = 'จังหวัด:';  
                                break;
                                
                                case'en':
                                    var advice = $(this).siblings(".hidden-advice").val();
                                    var hint = $(this).siblings(".hidden-hint").val();
                                    var tip  = $(this).siblings(".hidden-tip").val();
                                    var stateName = 'State:';
                                    var province_prefix = 'Province:';    
                                break;
                            }
							$(".account").hide();
							$(".tbme").show();
							$("#menutab1, #menutab2").show();
                            $('#menutab1').click();
                            $.ajax({
                                    url:'modules/resume/createTools.php',
                                    cache: false,
                                    data:{'id':'1', 'cId':'226', 'option':'experience', 'name':'Exp'+sectionId+''},
                                    type:'POST',
                                    success:function(data){
                                       var html = data.split(":");
                                       $("#mainOption"+sectionId).empty().append(html[0]);
                                       $("#city_exp"+sectionId).hide();                                                                            
                                       $("#optionCountry"+sectionId).empty().append(html[1]);
                                       var selectCountry = $(html[1]).attr("id");
                                       
                                      $("[name="+selectCountry+"]").change(function(){
                                            if($("#"+selectCountry).val() == 226){    // us resident
                                                $("#mainOption"+sectionId).empty().append(html[2]).show();
                                                $("#city_exp"+sectionId).show();
                                                $("#cityName"+sectionId).show();
                                                $("#mainOptionText"+sectionId).text(stateName);
                                            } else if($("#"+selectCountry).val() == 211){    // thailand
                                                $("#mainOption"+sectionId).empty().append(html[0]).show();
                                                $("#city_exp"+sectionId).hide();
                                                $("#cityName"+sectionId).hide();
                                                $("#mainOptionText"+sectionId).text(province_prefix);                 
                                            }else{
                                                $("#city_exp"+sectionId).show();
                                                $("#cityName"+sectionId).show();
                                                $("#mainOptionText"+sectionId).text(stateName);
                                                 $("#mainOption"+sectionId).empty().append('<input type="text" id="stateOther'+sectionId+'" name="stateOther'+sectionId+'" value="" />');          
                                            }
                                      });
                                      
                                        if($("#"+selectCountry).val() == 226){    // us resident
                                                    $("#mainOptionText"+sectionId).text(stateName);
                                                    $("#mainOption"+sectionId).empty().append(html[2]).show();
                                                    $("#city_exp"+sectionId).show();
                                                    $("#cityName"+sectionId).show(); 
                                        } else if($("#"+selectCountry).val() == 211){    // thailand
                                                    $("#mainOption"+sectionId).empty().append(html[0]).show();
                                                    $("#city_exp"+sectionId).hide();
                                                    $("#cityName"+sectionId).hide();                  
                                        }else{
                                                    $("#city_exp"+sectionId).show();
                                                    $("#cityName"+sectionId).show();
                                                 $("#mainOption"+sectionId).empty().append('<input type="text" id="stateOther'+sectionId+'" name="stateOther'+sectionId+'" value="'+other+'" />');           
                                        }                                     
                                    }                                                                       
                            });
                            $('#tab1 li:eq(0)').empty().append(head);
                            $('#tab2 li:eq(0)').empty().append(head);
                            $('#tab3 li:eq(0)').empty().append(head);
                            var dataAdvice = advice.split("<br />");
                            var dataHint = hint.split("<br />");
                            var dataTip = tip.split("<br />");
                            var total = dataAdvice.length;
                            var totalHint = dataHint.length;
                            var totalTip = dataTip.length; 
                            $('#mycarouselAdvice li').empty();
                            if($('#mycarouselAdvice li').length > total){
                                $('#mycarouselAdvice li:gt('+(total-1)+')').remove();
                            }
                            $('#mycarouselHint li').empty();
                            if($('#mycarouselHint li').length > totalHint){
                                $('#mycarouselHint li:gt('+(totalHint-1)+')').remove();
                            }
                            $('#mycarouselTip li').empty();
                                var flag = true;                                
                                    for(var k=0;k<total;k++){
                                        $('#mycarouselAdvice li:eq('+k+')').empty().append(dataAdvice[k]).css('display', 'block');
                                    }                                  
                                    $('#mycarouselAdvice').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                                   for(var m=0;m<totalHint;m++){
                                        $('#mycarouselHint li:eq('+m+')').empty().append(dataHint[m]).css('display', 'block');
                                    }                                
                                    $('#mycarouselHint').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                                    
                                    for(var n=0;n<totalTip;n++){
                                                $('#mycarouselTip li:eq('+n+')').empty().append(dataTip[n]).css('display', 'block');
                                    }                              
                                    $('#mycarouselTip').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                    }); //End Add New Buttons
                    
                    //buttons.eq(3).click(function(){//Edit buttons
                    $('span.special:eq('+j+') .experienceEdit').click(function(){
							button.control = 'edit'; 
							button.editMode(0);
							$(".account").hide();
							$(".tbme").show();
							$("#menutab1, #menutab2").show();
                            $("#menutab1").click();
                            var head = $(this).parent().siblings(".content-head").text();
                            switch(session_lang){
                                case'th':
                                    var advice = $(this).siblings(".hidden-advice-Th").val();
                                    var hint = $(this).siblings(".hidden-hint-Th").val();
                                    var tip =  $(this).siblings(".hidden-tip-Th").val();                                      
                                break;
                                
                                case'en':
                                    var advice = $(this).siblings(".hidden-advice").val();
                                    var hint = $(this).siblings(".hidden-hint").val();
                                    var tip = $(this).siblings(".hidden-tip").val();                                    
                                break;
                            }
                            switch(button.resume_lang){
                                case'th':
                                    var stateName = 'รัฐ:';
                                    var province_prefix = 'จังหวัด:';
                                break;
                                case'en':
                                    var stateName = 'State:';
                                    var province_prefix = 'Province:';
                                break;
                            }
                            var sectionId = $(this).siblings(".hidden-section").attr("value");
                            var path = $("[name=check_exp"+sectionId+"]:checked").parent().parent().parent();                                           
                            var expId = $("[name=check_exp"+sectionId+"]:checked").val();                           
                            path.find('.experText').css('display','none'); 
                            path.siblings('hr').css('display','block');
							path.siblings('.short').css('display','block');
							$(this).siblings('.short').css('display','block');
                            path.siblings(".experienceEdit").css('display','none');
                            path.siblings(".experienceRemove").css('display','none');
                            path.siblings(".experienceAdd").css('display','none');
                            path.siblings(".save-button, .close-button").css('display','block');                                         
                            path.find(".subMenu").css("display","block");
                            path.find(".inputTextArea").empty().css("display","block");
                            var startMonthYear = $("#startMonthYear"+expId).val();
                            var month = startMonthYear.split(':');
                            $("#startMonth"+sectionId).val(month[0]);
                            $("#startYear"+sectionId).val(month[1]);
                            var endMonthYear = $("#endMonthYear"+expId).val();
                            
                            var year = endMonthYear.split(':');
                            $("#endMonth"+sectionId).val(year[0]);
                            $("#endYear"+sectionId).val(year[1]);
							
							if($("#endMonth"+sectionId).val() != 0){
								$("#endYear"+sectionId).show();
							}else{
								$("#endYear"+sectionId).hide();
							}							
							
                            $("#endMonth"+sectionId).change(function(){
                                 if($("#endMonth"+sectionId).val() != 0){
                                     $("#endYear"+sectionId).show();
                                 }else{
                                     $("#endYear"+sectionId).hide();
                                 }
                             })                    
                            var ui = path.find(".inputTextArea").attr("id");                               
                            btnExp[sectionId] = CKEDITOR.appendTo(ui);
                            var html = path.find("#description"+expId+"").html();                                                                          
                            btnExp[sectionId].setData(html);
                             var miniPath = $("[name=check_exp"+sectionId+"]:checked").parent();                    
                             var co = miniPath.siblings("div").find("#company-experience"+expId+"").text();
                             var start = miniPath.siblings("div").find("#start-experience"+expId+"").text();
                             var end = miniPath.siblings("div").find("#end-experience"+expId+"").text();
                             var position = miniPath.siblings("div").find("#position-experience"+expId+"").text();
                             var city = miniPath.siblings("div").find("#city-experience"+expId+"").text();
                             var province = miniPath.siblings("div").find("#provinceExpId"+expId+"").val();
                             var country = miniPath.siblings("div").find("#countryExpId"+expId+"").val();
                             var other = $("#stateother-experience"+expId+"").text();                       
                             $.ajax({
                                    url:'modules/resume/createTools.php',
                                    cache: false,
                                    data:{'id':province, 'cId':country, 'option':'experience', 'name':'Exp'+expId+''},
                                    type:'POST',
                                    success:function(data){
                                       var html = data.split(":");
                                       
                                       if(country == 211){
                                           $("#mainOption"+sectionId).empty().append(html[0]);                                           
                                           $("#city_exp"+sectionId).hide();
                                           $("#cityName"+sectionId).hide();
                                           $("#mainOptionText"+sectionId).text(province_prefix);
                                       }else if(country == 226){
                                           $("#mainOption"+sectionId).empty().append(html[2]);
                                           var selectState = $(html[2]).attr("id");
                                           $("#"+selectState).val($("#stateExpId"+expId).val());
                                           $("#city_exp"+sectionId).show();
                                           $("#cityName"+sectionId).show();
                                           $("#mainOptionText"+sectionId).text(stateName);
                                       }else{
                                           $("#city_exp"+sectionId).show();
                                           $("#cityName"+sectionId).show();
                                           $("#mainOptionText"+sectionId).text(stateName+':');
                                           $("#mainOption"+sectionId).empty().append('<input type="text" id="stateOther'+sectionId+'" name="stateOther'+sectionId+'" value="'+other+'" />');
                                       }                                      
                                       $("#optionCountry"+sectionId).empty().append(html[1]);
                                       var selectCountry = $(html[1]).attr("id");
                                      $("[name="+selectCountry+"]").change(function(){
                                            if($("#"+selectCountry).val() == 226){    // us resident
                                                $("#mainOption"+sectionId).empty().append(html[2]).show();
                                                var selectState = $(html[2]).attr("id");
                                                $("#"+selectState).val($("#stateExpId"+expId).val());
                                                $("#city_exp"+sectionId).show();
                                                $("#cityName"+sectionId).show();
                                                $("#mainOptionText"+sectionId).text(stateName).show();
                                            } else if($("#"+selectCountry).val() == 211){    // thailand
                                                $("#mainOption"+sectionId).empty().append(html[0]).show();
                                                $("#city_exp"+sectionId).hide();
                                                $("#cityName"+sectionId).hide();
                                                $("#mainOptionText"+sectionId).text(province_prefix).show();                 
                                            }else{
                                                $("#mainOption"+sectionId).empty().append('<input type="text" id="stateOther'+sectionId+'" name="stateOther'+sectionId+'" value="'+other+'" />');
                                                $("#city_exp"+sectionId).show();
                                                $("#cityName"+sectionId).show();
                                                $("#mainOptionText"+sectionId).text(stateName).show();         
                                            }
                                      });                                     
                                    }
                            });
                            $(this).siblings(".mainmenu").find(".start-exp").empty().val(start);                            
                            $(this).siblings(".mainmenu").find(".end").empty().val(end);
                            $(this).siblings(".mainmenu").find(".company-exp").empty().val(co);
                            $(this).siblings(".mainmenu").find(".city-exp").empty().val(city);
                            $(this).siblings(".mainmenu").find(".province-exp").empty().val(province);
                            $(this).siblings(".mainmenu").find("[name=selectCountryExp"+sectionId+"]").val(country);
                            $(this).siblings(".mainmenu").find(".position-exp").empty().val(position);
                            $("#stateOtherExpId"+expId).val(other);
                            var head = $(this).siblings(".content-head").text();

                            $('#tab1 li:eq(0)').empty().append(head);
                            $('#tab2 li:eq(0)').empty().append(head);
                            $('#tab3 li:eq(0)').empty().append(head);
                            var dataAdvice = advice.split("<br />");
                            var dataHint = hint.split("<br />");
                            var dataTip = tip.split("<br />");
                            var total = dataAdvice.length;
                            var totalHint = dataHint.length;
                            var totalTip = dataTip.length;

                            $('#mycarouselAdvice li').empty();
                            if($('#mycarouselAdvice li').length > total){
                                $('#mycarouselAdvice li:gt('+(total-1)+')').remove();
                            }
                            $('#mycarouselHint li').empty();
                            if($('#mycarouselHint li').length > totalHint){
                                $('#mycarouselHint li:gt('+(totalHint-1)+')').remove();
                            }
                            $('#mycarouselTip li').empty();          
                                    for(var k=0;k<total;k++){
                                        $('#mycarouselAdvice li:eq('+k+')').empty().append(dataAdvice[k]).css('display', 'block');
                                    }                                 
                                    $('#mycarouselAdvice').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                                   for(var m=0;m<totalHint;m++){
                                        $('#mycarouselHint li:eq('+m+')').empty().append(dataHint[m]).css('display', 'block');
                                    }                                  
                                    $('#mycarouselHint').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});                                    
                                    for(var n=0;n<totalTip;n++){
                                                $('#mycarouselTip li:eq('+n+')').empty().append(dataTip[n]).css('display', 'block');
                                    }                                  
                                    $('#mycarouselTip').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                    }); //End Edit Buttons
                                        
                $('span.special:eq('+j+') .editExperience').each(function(){
                   /**
                    * @function: Edit button;
                    * @location: openResume_th.php, openResume_en.php in section id 4, 13, 25, 29, 36;
                    * @status: in progress about 80%;
                    */
                     $(this).click(function(){
                            button.control = 'edit';
                            var path = $(this).parent().parent().parent().parent().parent();                            
                            var sectionId = path.parent().siblings(".hidden-section").attr("value");                           
                            var start = path.parent().find(".start").attr("id");
                            var end = path.parent().find(".end").attr("id");
                            $("#"+start).datepicker({dateFormat:'yy-mm-dd'});
                            $("#"+end).datepicker({dateFormat:'yy-mm-dd'});
                            path.parent().find(".subMenu").css("display","block");
                            path.parent().find(".inputTextArea").empty().css("display","block");
                            var ui = path.parent().find(".inputTextArea").attr("id");        
                            button.editors = CKEDITOR.appendTo(ui);
                            path.parent().find('.experText').css('display','none'); 
                            path.parent().siblings('hr').css('display','block');
							 path.parent().siblings('.short').css('display','block');
                            path.parent().siblings(".experienceEdit").find(".mytextbox").css('display','none');
                            path.parent().siblings(".experienceRemove").find(".mytextbox").css('display','none');
                            path.parent().siblings(".save-button, .close-button").find(".mytextbox").css('display','block');                                
                             var miniPath = $(this).parent();
                             var co = miniPath.siblings("th:eq(0)").text();
                             var start = miniPath.siblings("th:eq(1)").text();
                             var end = miniPath.siblings("th:eq(2)").text();
                             var position = miniPath.siblings("th:eq(3)").text();
                             var address = miniPath.siblings("th:eq(4)").text();
                             var id = miniPath.siblings("th:eq(5)").find(".hidden-experience").attr("value");
                             situation = address.split(",");
                             $('#city_exp').empty().val(situation[0]);
                             $('#province_exp').empty().val(situation[1].substr(1));
                             $('#selectCountryExp').val(situation[2].split(" "));
                             $('#company_text').empty().val(co);
                             $('.start').empty().val(start);
                             $('.end').empty().val(end);
                             $('#position_text').empty().val(position);                             
                     });
             });
				$('span.special:eq('+j+') .deleteExperience').each(function(){
                 /**
                    * @function: Remove button;
                    * @location: openResume_th.php, openResume_en.php in section id 4, 13, 25, 29, 36;
                    * @status: in progress about 80%;
                    */
                 $(this).click(function(){
                       var path = $(this).parent().parent().parent().parent().parent();
                       var expId = $(this).siblings(".hidden-experience").attr("value");
                       var delPath = $(this).parent().parent();                      
                       var head = path.parent().siblings(".content-head").find("h3").text();
                       $('#dialog').empty().attr('title','Delete').append('<p>คุณต้องการลบส่วนของ '+head+' ใช่หรือไม่?</p>');
                       utils.dialogData('dialog', delPath, 'experience', expId);                       
                 });
             });
             
			 var span = $('span.special:eq('+j+') span.show_hand');
               span.eq(0).click(function(){
                    var path = $(this).parent().parent();
                    var language = $(this).attr("id");
                    var langSection = language.split("-");
                    var data = '';
                    var popup = '';
                   
                    if(langSection[0] == 'th'){
                        data = path.siblings(".hidden-example-Th").val();
                        popup = 'ตัวอย่าง';
                        $('#dialog').empty().attr('title', popup).append('<p style="text-align:left;">'+data+'</p>');
                        $('#dialog').dialog({
                                            bgiframe: true,
                                            resizable: false,
                                            width:400,
                                            height:400,
                                            modal: true,
                                            overlay: {
                                                backgroundColor: '#000',
                                                opacity: 0.5
                                            },
                                            close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                            buttons: {                                       
                                            'ตกลง': function() {
                                            $(this).dialog( 'destroy' );
                                        }
                                    }
                        });
                    }else{
                        data = path.siblings(".hidden-example").val();
                        popup = 'Example';
                        $('#dialog').empty().attr('title', popup).append('<p style="text-align:left;">'+data+'</p>');
                        $('#dialog').dialog({
                                            bgiframe: true,
                                            resizable: false,
                                            width:400,
                                            height:400,
                                            modal: true,
                                            overlay: {
                                                backgroundColor: '#000',
                                                opacity: 0.5
                                            },
                                            close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                            buttons: {                                       
                                            'OK': function() {
                                            $(this).dialog( 'destroy' );
                                        }
                                    }
                        });
                    }
                                           
               });
             }             
    },
    
    /**
    * @function: buttonIndex
    * @location: modules/resume/index.phpp
    * @uses: control all button in this file
    */   
    buttonIndex:function(){
        var total = $(".td-button").length;
        for(var i=0;i<total;i++){
            $(".td-button:eq("+i+") .open_class").each(function(){//OPEN RESUME BUTTTON
                $(this).click(function(){
				
                    var id = $(this).parent().siblings("td").find(".hidden-resume").attr("value");
                    var lang = $(this).parent().siblings("td").find(".lang-img").attr("value");
					//var lang = session_lang;
                    switch(session_lang){
                        case'th':
                            var tip_word = 'คลิกที่ "รูปแบบ" เพื่อเลือกสไตล์ของเรซูเม่และฟอนต์ที่ต้องการ <br/><br/>คลิกที่ "หมวดหมู่" เพื่อ เพิ่ม/ลบ/จัดลำดับ ของหัวข้อในเรซูเม่ <br/><br/>คลิกที่ "บันทึกเป็น Word" และ "บันทึกเป็น PDF" เพื่อดาวน์โหลดเรซูเม่เป็น Word  และ PDF';
                            button.defaultTip = 'คลิกที่ "รูปแบบ" เพื่อเลือกสไตล์ของเรซูเม่และฟอนต์ที่ต้องการ <br/><br/>คลิกที่ "หมวดหมู่" เพื่อ เพิ่ม/ลบ/จัดลำดับ ของหัวข้อในเรซูเม่ <br/><br/>คลิกที่ "บันทึกเป็น Word" และ "บันทึกเป็น PDF" เพื่อดาวน์โหลดเรซูเม่เป็น Word  และ PDF';
                        break;
                        
                        default:
                            var tip_word = 'Click "Layout" to choose resume template and font style.<br/><br/> Click "Section" to add/remove/re-order sections.<br/><br/> Click "Export PDF" and "Export Word" to download resume in PDF and Word format.';
                            button.defaultTip = 'Click "Layout" to choose resume template and font style.<br/><br/> Click "Section" to add/remove/re-order sections.<br/><br/> Click "Export PDF" and "Export Word" to download resume in PDF and Word format.';
                        break;
                    }
                    button.lang = lang;
                    $('#dialog').empty().append('<div align="center" style="padding-top:20px;"><img src="images/loading.gif" border="0" /></div>');
                                   $('#dialog').dialog({
                                        bgiframe: true,
                                        resizable: false,
                                        width:100,
                                        height:100,
                                        modal: true,
                                        overlay: {
                                            backgroundColor: '#000',
                                            opacity: 0.5
                                        }
                                    });
                                    $("div.ui-widget-content").css({"background":"none", "border":"0px"}); 
                                    $("div.ui-dialog-titlebar").css("display","none"); 
                    $.ajax({
                            url:'modules/resume/openResume.php',
                            cache: false,
                            data:{'resumeId':id, 'lang':lang},
                            type:'POST',
                            success:function(data){
                                $('#dialog').dialog("destroy");
                               $("#main").empty().append(data);                    
                               button.control_button();
                               button.buttonEducation();
                               $("#education_section [name=close_button]").click(button.cancel_education);
                               $(".account h2").empty().append('My Resume');
								$(".account p").empty().append(tip_word);
							   /*$("ul#tab1").css({'display':'none'});
                               $("#menutab3").click();
                               $('#mycarouselTip li:eq(1)') .empty()
                                                                        .append(tip_word)
                                                                        .css('display', 'block');
                                $("#menutab1, #menutab2").hide(); */                      
                            }
                    });
                })
            })
            
            $(".td-button:eq("+i+") .preview_class").each(function(){//PREVIEW RESUME BUTTON
                $(this).click(function(){
                    var id = $(this).parent().siblings("td").find(".hidden-resume").attr("value");
                    var language = $(this).parent().siblings("td").find(".lang-img").attr("value");
                    $('#dialog').empty().append('<div align="center" style="padding-top:20px;"><img src="images/loading.gif" border="0" /></div>');
                                   $('#dialog').dialog({
                                        bgiframe: true,
                                        resizable: false,
                                        width:100,
                                        height:100,
                                        modal: true,
                                        overlay: {
                                            backgroundColor: '#000',
                                            opacity: 0.5
                                        }
                                    });
                                    $("div.ui-widget-content").css({"background":"none", "border":"0px"}); 
                                    $("div.ui-dialog-titlebar").css("display","none");
                    $.ajax({
                                                    url:'modules/resume/createPriview.php',
                                                    cache: false,
                                                    data:{'resumeId':id, 'language':language},
                                                    type:'POST',
                                                    success:function(data){
                                                            $('#dialog').dialog("destroy");
                                                             previwe = window.open('', '_blank', 'width=800,height=900,toolbar=no,location=no,menubar=no,scrollbars=1,titlebar=no,resizable=yes');
															 previwe.document.write(''+data+'');
															previwe.focus();
                                                    }  
                                       });
                })
            })
            
            $(".td-button:eq("+i+") .delete_class").each(function(){//DELETE RESUME BUTTON
                $(this).click(function(){
                    var id = $(this).parent().siblings("td").find(".hidden-resume").attr("value");
                    var resume_name = $(this).parent().siblings("td").eq(1).text();
                    switch(session_lang){
                        case'th':
                            var data = 'คุณต้องการลบใบประวัติ <b>'+ resume_name +'</b> ใช่หรือไม่';
                            var div = $(this).parent().parent();
                            var table = div.parent().parent();
                            $('#dialog').empty().attr('title','Delete').append('<p class="delete" style="padding-top:20px;">'+data+'</p>');
                            $('#dialog').dialog({
                                bgiframe: true,
                                resizable: false,
                                width:350,
                                height:200,
                                modal: true,
                                overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                                },
                                close: function(ev, ui) { $(this).dialog( 'destroy' ); },
                                buttons: {
                                    'ยกเลิก':function(){
                                        $(this).dialog( 'destroy' );
                                    },
                                    'ตกลง': function() {
                                        $(this).dialog( 'destroy' );                              
                                        $.ajax({
                                                url:'modules/resume/deleteResumeSub.php',
                                                cache: false,
                                                data:{'resumeId':id},
                                                type:'POST',
                                                success:function(data){
                                                    window.location.reload();                                              
                                                }
                                        });                                         
                                    }
                                }
                            });                                                       
                        break;
                        
                        default:
                            var data = 'Do you want to delete <b>'+ resume_name +'</b> resume?';
                            var div = $(this).parent().parent();
                            var table = div.parent().parent();
                            $('#dialog').empty().attr('title','Delete').append('<p class="delete" style="padding-top:20px;">'+data+'</p>');
                            $('#dialog').dialog({
                                bgiframe: true,
                                resizable: false,
                                width:350,
                                height:200,
                                modal: true,
                                overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                                },
                                close: function(ev, ui) { $(this).dialog( 'destroy' ); },
                                buttons: {
                                    'Cancel':function(){
                                        $(this).dialog( 'destroy' );
                                    },
                                    'OK': function() {
                                        $(this).dialog( 'destroy' );                              
                                        $.ajax({
                                                url:'modules/resume/deleteResumeSub.php',
                                                cache: false,
                                                data:{'resumeId':id},
                                                type:'POST',
                                                success:function(data){
                                                    window.location.reload();                                                
                                                }
                                        });
                                    }
                                }
                            });
                            
                        break;
                    }
                    
                })
            })
            
           $(".td-title:eq("+i+")").each(function(){//OPEN RESUME VIA CLICK RESUME TITLE
                $(this).click(function(){
                    
                    var id = $(this).siblings("td").find(".hidden-resume").attr("value");
                    var lang = $(this).siblings("td").find(".lang-img").attr("value");
                    //var lang = session_lang;
                    switch(session_lang){
                        case'th':
                            var tip_word = 'คลิกที่ "รูปแบบ" เพื่อเลือกสไตล์ของเรซูเม่และฟอนต์ที่ต้องการ <br/><br/>คลิกที่ "หมวดหมู่" เพื่อ เพิ่ม/ลบ/จัดลำดับ ของหัวข้อในเรซูเม่ <br/><br/>คลิกที่ "บันทึกเป็น Word" และ "บันทึกเป็น PDF" เพื่อดาวน์โหลดเรซูเม่เป็น Word  และ PDF';
                            button.defaultTip = 'คลิกที่ "รูปแบบ" เพื่อเลือกสไตล์ของเรซูเม่และฟอนต์ที่ต้องการ <br/><br/>คลิกที่ "หมวดหมู่" เพื่อ เพิ่ม/ลบ/จัดลำดับ ของหัวข้อในเรซูเม่ <br/><br/>คลิกที่ "บันทึกเป็น Word" และ "บันทึกเป็น PDF" เพื่อดาวน์โหลดเรซูเม่เป็น Word  และ PDF';
                        break;
                        
                        default:
                            var tip_word = 'Click "Layout" to choose resume template and font style.<br/><br/> Click "Section" to add/remove/re-order sections.<br/><br/> Click "Export PDF" and "Export Word" to download resume in PDF and Word format.';
                            button.defaultTip = 'Click "Layout" to choose resume template and font style.<br/><br/> Click "Section" to add/remove/re-order sections.<br/><br/> Click "Export PDF" and "Export Word" to download resume in PDF and Word format.';
                        break;                        
                    }
                    button.lang = lang;
                    $('#dialog').empty().append('<div align="center" style="padding-top:20px;"><img src="images/loading.gif" border="0" /></div>');
                    $('#dialog').dialog({
                                        bgiframe: true,
                                        resizable: false,
                                        width:100,
                                        height:100,
                                        modal: true,
                                        overlay: {
                                            backgroundColor: '#000',
                                            opacity: 0.5
                                        }
                                    });                 
                                    $("div.ui-widget-content").css({"background":"none", "border":"0px"}); 
                                    $("div.ui-dialog-titlebar").css("display","none");

                   $.ajax({
                            url:'modules/resume/openResume.php',
                            cache: false,
                            data:{'resumeId':id, 'lang':lang},
                            type:'POST',
                            success:function(data){
                               $('#dialog').dialog("destroy");
                               $("#main").empty().append(data);
                               button.control_button();
                               button.buttonEducation();
                               $("#education_section [name=close_button]").click(button.cancel_education);
                              $(".account").show();
							  $(".tbme").hide();
							  $(".account h2").empty().append('My Resume');
								$(".account p").empty().append(tip_word);
							  /* $("#menutab3").click();
                               $("ul#tab1").css({'display':'none'});
                               $('#mycarouselTip li:eq(1)') .empty()
                                                                        .append(tip_word)
                                                                        .css('display', 'block');
                               $("#menutab1, #menutab2").show();  */                                                               
                            }
                    });
                                                          
                })               
            })
            
            $(".td-button:eq("+i+") .weblink_class").each(function(){//WEB LINK BUTTTON
                $(this).click(function(){
                    var id = $(this).parent().siblings("td").find(".hidden-resume").attr("value");
                    var lang = $(this).parent().siblings("td").find(".lang-img").attr("value");
					//var lang = session_lang;
                    button.lang = lang;
                    switch(session_lang){
                        case'th':
                            var warning = 'การนำเว็บลิ้งค์ไปใช้งาน อาจจะทำให้ผู้อื่นเห็นข้อมูลส่วนตัวของท่าน';
                        break;
                        
                        case'en':
                            var warning = 'Everybody can see your private data when you post this link';
                        break;
                    }         
					
                    $.ajax({
                        url:'modules/resume/createLink.php',
                        cache: false,
                        data:{'resumeId':id, 'lang':lang},
                        type:'POST',
                        success:function(data){
                            alert(warning);
                            $('#dialog2').empty().append('<p>'+data+'</p>');
                                                               $('#dialog').empty().attr('title','Resume Link')
                                                                                            .append('<script type="text/javascript" src="js/jquery.copy.min.js"><\/script><div align="center" style="margin-top:20px;"><input type="text" id="url" name="url" value="'+data+'" readonly="readonly" style="width:400px;" /></div>');
                                                               $('#dialog').dialog({
                                                                    bgiframe: true,
                                                                    resizable: false,
                                                                    width:500,
                                                                    height:200,
                                                                    modal: true,
                                                                    overlay: {
                                                                        backgroundColor: '#000',
                                                                        opacity: 0.5
                                                                    },
                                                                    close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                                                    buttons: {
                                                                              'close': function() {
                                                                                $(this).dialog( 'destroy' );
                                                                              }
                                                                    },
                                                                    open:function(ev, ui) { $("#url").focus().select();}
                                                                });                              
                                                            }  
                                                        });
                                                    })
                                                })
                                            }
                                        },
    
    buttonEducation:function(){                       
        $('[name=editeducation_button], span.education-edit').click(function(){ //Edit Education Buttons
                /*$('#education').animate({scrollTop: '100px'}, 800);*/
               $(".account").hide();
			   $("#menutab1, #menutab2").show();
			   $(".tbme").show();
			   $("#menutab1").click();
				button.editMode(0);
                var head = $(this).parent().siblings("div").find("#education_header").text();
                switch(session_lang){
                    case'th':
                        var advice = $(this).parent().siblings(".hidden-advice-Th").val();
                        var hint = $(this).parent().siblings(".hidden-hint-Th").val();
                        var tip =  $(this).parent().siblings(".hidden-tip-Th").val();  
                    break;
                                
                    case'en':
                        var advice = $(this).parent().siblings(".hidden-advice").val();
                        var hint = $(this).parent().siblings(".hidden-hint").val();
                        var tip =  $(this).parent().siblings(".hidden-tip").val(); 
                    break;
                }
                 $('#tab1 li:eq(0)').empty().append(head);
                 $('#tab2 li:eq(0)').empty().append(head);
                 $('#tab3 li:eq(0)').empty().append(head); 
                 var dataAdvice = advice.split("<br />");
                 var dataHint = hint.split("<br />");
                 var dataTip = tip.split("<br />");
                 var total = dataAdvice.length;
                 var totalHint = dataHint.length;
                 var totalTip = dataTip.length;
                  $('#mycarouselAdvice li').empty();
                            if($('#mycarouselAdvice li').length > total){
                                $('#mycarouselAdvice li:gt('+(total-1)+')').remove();
                            }
                            $('#mycarouselHint li').empty();
                            if($('#mycarouselHint li').length > totalHint){
                                $('#mycarouselHint li:gt('+(totalHint-1)+')').remove();
                            }
                            $('#mycarouselTip li').empty();             
                                    for(var k=0;k<total;k++){
                                        $('#mycarouselAdvice li:eq('+k+')').empty().append(dataAdvice[k]).css('display', 'block');
                                    }                                 
                                    $('#mycarouselAdvice').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
                                   for(var m=0;m<totalHint;m++){
                                        $('#mycarouselHint li:eq('+m+')').empty().append(dataHint[m]).css('display', 'block');
                                    }                              
                                    $('#mycarouselHint').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});                                    
                                    for(var n=0;n<totalTip;n++){
                                                $('#mycarouselTip li:eq('+n+')').empty().append(dataTip[n]).css('display', 'block');
                                    }                                 
                                    $('#mycarouselTip').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});      
                 var path = $('[name=check_edu]:checked').parent().siblings("div");
                 var eduId = $('[name=check_edu]:checked').val();           
                 button.sourceButton = 'Edit';
                 var city = path.find("#city"+eduId+"").text();
                 var degree = path.find("#degree"+eduId+"").text();
                 var field = path.find("#field"+eduId+"").text();
                 var university = path.find("#school"+eduId+"").text();
                 var start = path.find("#start"+eduId+"").text();
                 var end = path.find("#end"+eduId+"").text();
                 var gpa = path.find("#gpa"+eduId+"").text();
                 var province = path.find("#provinceId"+eduId+"").val();
                 var country = path.find("#countryId"+eduId+"").val();
                 var state = path.find("#stateId"+eduId+"").val();
                 var other = $("#otherState"+eduId+"").text();
                               
                 if(country == 226){                                               
                        $("#educationState, #showOptionState, #educationOther, #educationOtherText").show();
                        $("#showOptionState").focus();
                        $("#educationProvince, #showOptionProvince, #showOtherState").hide();
                        $("#selectStateEducation").val(state);
                 }else if(country == 211){
                        $("#educationOther, #educationOtherText").hide();
                        $("#educationState, #showOptionState, #showOtherState").hide();
                        $("#educationProvince, #showOptionProvince").show();
                        $("#selectProvinceEducate").val(province);
                 }else{
                        $(" #showOptionState").hide();
                        $("#educationProvince, #showOptionProvince").hide();
                        $("#selectProvinceEducate").val(province);
                        $("#otherStateEducate").val(other);
                        $("#educationState, #showOtherState").show();
                 }
                 button.educateId = $('[name=check_edu]:checked').val();
                 $('#city_text').val(city);
                 $("#selectDegree").val(degree)
                 $('#field_text').val(field);
                 $('#school_text').val(university);
                 $('#selectStartYear').val(start);
                 $('#selectEndYear').val(end);
                 $('#gpa_text').val(gpa);
                 $('#province_text').val(province);
                 $('#selectCountryEducate').val(country);
                 var oldText = '';
                            
                $('#educationText').css('display','none');
                $('#educationInput').css('display','block');
                $('.submenux').css('display','block');
                $('#education_textarea').empty().val(oldText);
                $('#education_section hr').css('display','block');
				$('.short_e').css('display','block');
                $('#educationDelete').hide();
                $("#educationEdit").hide();
                $('#educationAdd').hide();
                $('#educationSave').show();
                $("#educationClose").show();              
                var print = $(this).parent().siblings("div").find(".education-input").attr("id");                                               
                var html = path.find('#description'+eduId+'').html();                   
                button.varObjective = html;
                button.editors_education = CKEDITOR.appendTo(print);                
                button.editors_education.setData(html);                               
                $("#selectCountryEducate").change(function(){
                    if($("#selectCountryEducate").val() == 226){    // us resident
                        $("#educationState, #showOptionState, #educationOther, #educationOtherText").show();
                        $("#showOptionState").focus();
                        $("#educationProvince, #showOptionProvince, #showOtherState").hide();
                        $("#selectStateEducation").val(state);
                    } else if($("#selectCountryEducate").val() == 211){  // thailand
                        $("#educationOther, #educationOtherText").hide();
                        $("#educationState, #showOptionState, #showOtherState").hide();
                        $("#educationProvince, #showOptionProvince").show();
                        $("#selectProvinceEducate").val(province);                   
                    }else{ // other 
                        $(" #showOptionState").hide();
                        $("#educationProvince, #showOptionProvince").hide();
                        $("#selectProvinceEducate").val(province);
                        $("#otherStateEducate").val(other);
                        $("#educationState, #showOtherState, #educationOther, #educationOtherText").show();            
                    }
              });
        }); //End Edit Education Buttons
        
        $('[name=deleteeducation_button], span.education-delete').click(function(){ //Delete Education Buttons
           switch(session_lang){
               case'th':
               var word = 'คุณต้องการลบระดับการศึกษานี้ ใช่หรือไม่?';
               var title = 'ลบ';
               break;
               
               case'en':
               var word = 'Do you want to delete this sub section?';
               var title = 'Delete';
               break;
           }
            var path = $('[name=check_edu]:checked').parent().parent();
            var expId = $('[name=check_edu]:checked').val();       
            var delPath = $('[name=check_edu]:checked').parent().parent();                      
            $('#dialog').empty().attr('title',''+title+'').append('<p>'+word+'</p>');
            utils.dialogData('dialog', delPath, 'education', expId);
        }); //End Delete Education Buttons
        
        $('[name=saveeducation_button], span.education-save').click(function(){ //Save Education Buttons
            var option = button.sourceButton;
			button.editMode(1);
            switch(option){
                case'Add':               
                    var degree = $('#selectDegree').val();
                    var field = $('#field_text').val();
                    var university = $('#school_text').val();
                    var start = $('#selectStartYear').val();
                    var end = $('#selectEndYear').val();
                    var gpa = $('#gpa_text').val();
                    var province = $('#selectProvinceEducate').val();
                    var country = $('#selectCountryEducate').val();
                    var city = $('#city_text').val();
                    var state = $('#selectStateEducation').val();
                    var other = $("#otherStateEducate").val();
                    var descript = button.editors.getData();
                    var data = '';
                    var dataSplit = descript.split('</li>');
                    var pattern = /[&nbsp;&nbsp;]/g;
                    if(dataSplit.length != 1){                                                                    
                        var newstr = '';                                                                 
                        for(var i=0;i<dataSplit.length;i++){
                                newstr += dataSplit[i];                          
                            if(i !=(dataSplit.length-1) ){
                                newstr += "</li>";                               
                            }                                                      
                        }
                        data += newstr;
                     }else{
                         data = descript;
                     }
                   $.ajax({
                            url:'modules/education/saveEducationSub.php',
                            cache: false,
                            data:{'degree':degree, 'field':field, 'university':university, 'start':start, 'end':end, 
                                     'gpa':gpa, 'province':province, 'other':other, 'state':state, 'country':country, 'city':city, 'descript':data},
                            type:'POST',
                            success:function(data){
                              $.ajax({
                                        url:'modules/resume/openResume.php',
                                        cache: false,
                                        data:{'resumeId':$("#resId").val()},
                                        type:'POST',
                                        success:function(data){
                                           $("#main").empty().append(data);
                                           button.control_button();
                                           button.buttonEducation();
                                           $("#education_section [name=close_button]").click(button.cancel_education);
                                        }
                                });
                            }
                    });                    
                break;
                
                case'Edit':                    
                    var educateId = button.educateId;
                    var degree = $('#selectDegree').val();
                    var field = $('#field_text').val();
                    var university = $('#school_text').val();
                    var start = $('#selectStartYear').val();
                    var end = $('#selectEndYear').val();
                    var gpa = $('#gpa_text').val();
                    var city = $('#city_text').val();
                    var province = $('#selectProvinceEducate').val();
                    var country = $('#selectCountryEducate').val();
                    var state = $('#selectStateEducation').val();
                    var other = $("#otherStateEducate").val();
                    var descript = button.editors_education.getData();                                 
                   var data = '';
                    var dataSplit = descript.split('</li>');
                    var pattern = /[&nbsp;&nbsp;]/g;

                    if(dataSplit.length != 1){                                                                    
                        var newstr = '';                                                                 
                        for(var i=0;i<dataSplit.length;i++){
                                newstr += dataSplit[i];                                                                                            
                            if(i !=(dataSplit.length-1) ){
                                newstr += "</li>";
                                
                            }                                                      
                        }
                        data += newstr;

                     }else{
                         data = descript;
                     }
                   $.ajax({
                            url:'modules/education/editEducationSub.php',
                            cache: false,
                            data:{'option':'edit','educateId':educateId, 'degree':degree, 'field':field, 'city':city,'university':university, 'start':start, 'end':end, 
                                     'gpa':gpa, 'province':province, 'other':other, 'state':state, 'country':country, 'descript':data},
                            type:'POST',
                            success:function(data){
                               $.ajax({
                                        url:'modules/resume/openResume.php',
                                        cache: false,
                                        data:{'resumeId':$("#resId").val()},
                                        type:'POST',
                                        success:function(data){
                                           $("#main").empty().append(data);
                                           button.control_button();
                                           button.buttonEducation();
                                           $("#education_section [name=close_button]").click(button.cancel_education);
                                        }

                                });
                            }

                    });
                    
                break;
            }
            button.refreshTip();
			button.editMode(1);
        }); //End Save Education Buttons f.apply(g || this, arguments);
        
        $('[name=addeducation_button], span.education-add').click(function(){  //Add New Education Buttons 
				$(".account").hide();
				$(".tbme").show();
				$("#menutab1, #menutab2").show();
				$("#menutab1").click();           
                button.sourceButton = 'Add';
				button.editMode(0);
                var oldText = '';
                $('#educationText').css("display","none"); 
                $('#educationInput').css("display",'block');
                $('.submenux').css("display","block");
                $('#education_textarea').empty().val(oldText);
                $('#education_section hr').css("display","block");
				 $('.short_e').css("display","block");
                $('#education_section #subMenu').find("input:text").empty().attr("value", "");
                $('#selectStartYear').val('1999');
                $('#selectEndYear').val('1999');
                $('#educationDelete').hide();
                $("#educationEdit").hide();
                $('#educationAdd').hide();
                $('#educationSave').show();
                $("#educationClose").show();
                $("#selectCountryEducate").val(226);
                $("#selectCountryEducate").change(function(){
                    if($("#selectCountryEducate").val() == 226){    // us resident
                        $("#educationState, #showOptionState, #educationOther, #educationOtherText").show();
                        $("#showOptionState").focus();
                        $("#educationProvince, #showOptionProvince, #showOtherState").hide();
                    } else if($("#selectCountryEducate").val() == 211){    // thailand
                        $("#educationState, #showOptionState, #educationOther, #educationOtherText, #showOtherState").hide();
                        $("#educationProvince, #showOptionProvince").show();                    
                    }else{ //other
                        $("#educationState, #educationOther, #educationOtherText, #showOtherState").show(); 
                        $("#showOptionState").hide();
                        $("#educationProvince, #showOptionProvince").hide();               
                    }
              });
               if($("#selectCountryEducate").val() == 226){    // us resident
                        $("#educationState, #showOptionState, #educationOther, #educationOtherText").show();
                        $("#showOptionState").focus();
                        $("#educationProvince, #showOptionProvince, #showOtherState").hide();
                    } else if($("#selectCountryEducate").val() == 211){    // thailand
                        $("#educationState, #showOptionState, #educationOther, #educationOtherText, #showOtherState").hide();
                        $("#educationProvince, #showOptionProvince").show();                    
                    }else{ //other
                        $("#educationState, #educationOther, #educationOtherText, #showOtherState").show(); 
                        $("#showOptionState").hide();
                        $("#educationProvince, #showOptionProvince").hide();               
               }
			    button.editors = CKEDITOR.appendTo("educationInput");     
                var head = $(this).parent().siblings("div").find("#education_header").text();
                switch(session_lang){
                    case'th':
                        var advice = $(this).parent().siblings(".hidden-advice-Th").val();
                        var hint = $(this).parent().siblings(".hidden-hint-Th").val();
                        var tip = $(this).parent().siblings(".hidden-tip-Th").val();   
                    break;
                                
                    case'en':
                        var advice = $(this).parent().siblings(".hidden-advice").val();
                        var hint = $(this).parent().siblings(".hidden-hint").val();
                        var tip = $(this).parent().siblings(".hidden-tip").val();
                    break;
                }
                 $('#tab1 li:eq(0)').empty().append(head);
                 $('#tab2 li:eq(0)').empty().append(head);
                 $('#tab3 li:eq(0)').empty().append(head);
                 var dataAdvice = advice.split("<br />");
                 var dataHint = hint.split("<br />");
                 var dataTip = tip.split("<br />");
                 var total = dataAdvice.length;
                 var totalHint = dataHint.length;
                 var totalTip = dataTip.length;
                  $('#mycarouselAdvice li').empty();
                            if($('#mycarouselAdvice li').length > total){
                                $('#mycarouselAdvice li:gt('+(total-1)+')').remove();
                            }
                            $('#mycarouselHint li').empty();
                            if($('#mycarouselHint li').length > totalHint){
                                $('#mycarouselHint li:gt('+(totalHint-1)+')').remove();
                            }
                            $('#mycarouselTip li').empty()
                                    for(var k=0;k<total;k++){
                                        $('#mycarouselAdvice li:eq('+k+')').empty().append(dataAdvice[k]).css('display', 'block');
                                    }
                                        $('#mycarouselAdvice').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
										
                                   for(var m=0;m<totalHint;m++){
                                        $('#mycarouselHint li:eq('+m+')').empty().append(dataHint[m]).css('display', 'block');
                                    }                                  
                                        $('#mycarouselHint').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});                                   
                                    for(var n=0;n<totalTip;n++){
                                                $('#mycarouselTip li:eq('+n+')').empty().append(dataTip[n]).css('display', 'block');
                                    }
                                    $('#mycarouselTip').css({'width':'210px', 'height':'250px', 'overflow-y': 'auto','font-weight':'normal'});
        });//End Add New Buttons                       
        
		$('[name=closeEducate_button], span.education-close').click(function(){
				button.editMode(1);
                $('#educationText').css('display','block'); 
                $('#educationInput').empty().css('display','none');
                $('.submenux').css('display','none');
                $('#education_section hr').css('display','none'); 
				$('.short_e').css('display','none'); 				
                $('#educationSave').hide();
                $("#educationClose").hide();
                $('#educationDelete').not('.can-not-click').show();
                $("#educationEdit").not('.can-not-click').show();
                $('#educationAdd').show();
                $("#educationState, #showOptionState").hide();
                $("#educationProvince, #showOptionProvince").show();
                button.refreshTip();
        });       
        
		var span = $('[name=example_education]');
        span.click(function(){
                    var path = $(this).parent().parent().parent();
                    var language = $(this).attr("id");
                    var langSection = language.split("-");
                    var data = '';
                    var popup = '';
                   
                    if(langSection[0] == 'th'){
                        data = path.siblings(".hidden-example-Th").val();
                        popup = 'ตัวอย่าง';
                        $('#dialog').empty().attr('title', popup).append('<p style="text-align:left;">'+data+'</p>');
                        $('#dialog').dialog({
                                            bgiframe: true,
                                            resizable: false,
                                            width:400,
                                            height:400,
                                            modal: true,
                                            overlay: {
                                                backgroundColor: '#000',
                                                opacity: 0.5
                                            },
                                            close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                            buttons: {                                       
                                            'ตกลง': function() {
                                            $(this).dialog( 'destroy' );
                                        }
                                    }
                        });
                    }else{
                        data = path.siblings(".hidden-example").val();
                        popup = 'Example';
                        $('#dialog').empty().attr('title', popup).append('<p style="text-align:left;">'+data+'</p>');
                        $('#dialog').dialog({
                                            bgiframe: true,
                                            resizable: false,
                                            width:400,
                                            height:400,
                                            modal: true,
                                            overlay: {
                                                backgroundColor: '#000',
                                                opacity: 0.5
                                            },
                                            close: function(ev, ui) { $(this).dialog( 'destroy' );},
                                            buttons: {                                       
                                            'OK': function() {
                                            $(this).dialog( 'destroy' );
                                        }
                                    }
                        });
                    }
                                           
               });
    },
    
   refreshTip:function(){
	
       var ul1   = '<ul id="mycarouselAdvice" class="jcarousel jcarousel-skin-tango">';
                          ul1 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul1 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul1 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul1 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul1 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul1 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul1 += '</ul>';
                    
        var ul2   = '<ul id="mycarouselHint" class="jcarousel jcarousel-skin-tango">';
                          ul2 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul2 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul2 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul2 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul2 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul2 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul2 += '</ul>';
        var ul3   = '<ul id="mycarouselTip" class="jcarousel jcarousel-skin-tango">';
                          ul3 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul3 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul3 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul3 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul3 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul3 += '<li style="display: none;padding-top:20px; font-weight:normal;">1</li>';
                          ul3 += '</ul>';
                    $('#tab1 li:eq(1)').empty().html(ul1);
                    $('#tab2 li:eq(1)').empty().html(ul2);
                    $('#tab3 li:eq(1)').empty().html(ul3);
                    /* $('#menutab3').click();
					$("#menutab1, #menutab2").hide();
					$('#tab3 li:eq(0)').empty().html('');
					$('#mycarouselTip li:eq(1)').empty().html(button.defaultTip).css({'font-weight':'normal','display':'block'});
					*/
					$(".tbme").hide();
					$(".account").show();
					$(".account h2").empty().append('My Resume');
					$(".account p").empty().append(button.defaultTip);
    },
	editMode:function(x){
		
		//x = 0 : hide all button
		//x = 1 : show all button
		
		var total = $('span.btn').length;		
		for(var i=0;i<total;i++){
			if(x == 0){
				$('span.btn:eq('+i+') .edit-section').css('display','none');
			}else if(x == 1){
				$('span.btn:eq('+i+') .edit-section').css('display','block');
			}
		}//end for
		
		var tot = $("span.special").length;
		for(var j=0;j<tot;j++){
			if(x == 0){
				$('span.special:eq('+j+') .edit-section').css('display','none');
				
				$("#educationDelete").css('display','none');
				$("#educationEdit").css('display','none');
				$("#educationAdd").css('display','none');
				
                $('span.special:eq('+j+') .experienceAdd').siblings(".experienceRemove").css('display','none');
                $('span.special:eq('+j+') .experienceAdd').siblings(".experienceAdd").css('display','none');
                $('span.special:eq('+j+') .experienceAdd').siblings(".experienceEdit").css('display','none');
				$('span.special:eq('+j+') .close-button').siblings(".experienceAdd").css('display','none');
				
				$("#labelBtn").css('display','none');
															
			}else if(x == 1){
				$('span.special:eq('+j+') .edit-section').css('display','block');
				if($('#check_edu').is(":visible")){
				$("#educationDelete").css('display','block');
				$("#educationEdit").css('display','block');
				}
				$("#educationAdd").css('display','block');
				if($('#check_exp25').is(":visible")){				
                $('span.special:eq('+j+') .experienceAdd').siblings(".experienceRemove").css('display','block');
                $('span.special:eq('+j+') .experienceAdd').siblings(".experienceEdit").css('display','block');	
				}
				$('span.special:eq('+j+') .close-button').siblings(".experienceAdd").css('display','block');
				 $('span.special:eq('+j+') .experienceAdd').siblings(".experienceAdd").css('display','block');
				$("#labelBtn").css('display','block');								
				
			} 			                                            
		}//end fo
				
	}// end editmode
	
}

