var utils = {
    option:'',
    
    checkChar:function(string){
            return string.replace(/<p>/g, " ").replace(/<\/p>/g," ").replace(/<br \/>/g," ");
    },
    
    /**
    * @function: dialogSection;
    * @location: Popup when click remove section;
    * @status: complete;
    */
    dialogSection:function(div, path, sectionId){       
        $("#"+div).dialog({
                            bgiframe: true,
                            resizable: false,
                            height:140,
                            modal: true,
                            overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                            },
                            buttons: {
                                'ยืนยัน': function() {
                                    $(this).dialog( 'destroy' );
                                    path.remove();                                   
                                },
                                'ยกเลิก': function() {
                                    $(this).dialog( 'destroy' );
                                }
                            }
        });         
    },
    
    
    /**
    * @function: dialogData;
    * @location: Popup when click remove data in section;
    * @status: complete;
    */
   dialogData:function(div, path, option, refId){
        switch(option){
            case'education':
                
                switch(button.lang){
                    case'th':
                        $("#"+div).dialog({
                            bgiframe: true,
                            resizable: false,
                            height:140,
                            modal: true,
                            overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                            },
                            buttons: {
                                 'ยกเลิก': function() {
                                    $(this).dialog( 'destroy' );
                                },
                                'ตกลง': function() {
                                    $(this).dialog( 'destroy' );                                    
                                    path.empty();
                                        $.ajax({
                                                url:'modules/education/editEducationSub.php',
                                                cache: false,
                                                data:{'option':'delete','educateId':refId},
                                                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;
                    
                    default:
                    $("#"+div).dialog({
                            bgiframe: true,
                            resizable: false,
                            height:140,
                            modal: true,
                            overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                            },
                            buttons: {
                                 'Cancel': function() {
                                    $(this).dialog( 'destroy' );
                                },
                                'OK': function() {
                                    $(this).dialog( 'destroy' );                                    
                                    path.empty();
                                        $.ajax({
                                                url:'modules/education/editEducationSub.php',
                                                cache: false,
                                                data:{'option':'delete','educateId':refId},
                                                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;
                }
            break;
            
            case'experience':               
                switch(button.lang){
                    case'th':
                    $("#"+div).dialog({
                            bgiframe: true,
                            resizable: false,
                            height:140,
                            modal: true,
                            overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                            },
                            buttons: {
                                'ยกเลิก': function() {
                                    $(this).dialog( 'destroy' );
                                },
                                'ตกลง': function() {
                                    $(this).dialog( 'destroy' );                                    
                                    path.empty();
                                    $.ajax({
                                                url:'modules/experience/deleteExperienceSub.php',
                                                cache: false,
                                                data:{'experienceId':refId},
                                                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;
                    
                    default:
                    $("#"+div).dialog({
                            bgiframe: true,
                            resizable: false,
                            height:140,
                            modal: true,
                            overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                            },
                            buttons: {
                                 'Cancel': function() {
                                    $(this).dialog( 'destroy' );
                                },
                                'OK': function() {
                                    $(this).dialog( 'destroy' );                                    
                                    path.empty();
                                    $.ajax({
                                                url:'modules/experience/deleteExperienceSub.php',
                                                cache: false,
                                                data:{'experienceId':refId},
                                                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;
                }
            break;
        }                       
    },
    
    upperChar:function(string){
        var total = string.length;
        newVal = '';
        val = string.split(" ");
        for(var c=0; c < val.length; c++) {
                /*test = val[c].substring(0,1);
                word = '<p>'+test.bold()+'</p>';
                console.log(word);*/
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
        }
        string = newVal.replace(/Of/g, "of").replace(/And/g, "and");
        //console.log(string);
        return(string);
    } 
}
