// JavaScript Document
//--- Create Organization -------------------------------------------------------------------
function createOrg_checkNoErr(){
var err_no = 0;
// out of focus, on blur
$('#create_org_form_social_table input, #create_org_form_social_table select').each(function(){
if(typeof($(this).attr('id')) != 'undefined'){
if($(this).is(":focus")){
$(this).blur();
} // if($(this).is(":focus")){
};
});
$('#create_org_form_social_table input, #create_org_form_social_table select').each(function(){
create_org_step_3_onFocus($(this));
create_org_step_3_onBlur($(this));
});
err_no = $('#create_org_form_social_table').find('div[id*="err"]').length;
if(err_no == 0){
return true;
}
return false;
}
var createOrgHandler = function(e) {
if(e != null){
if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
return;
} // if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
} // if(e != null){
ajax_form_show_topBarMessage(0);
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_finish_submitBtn"), function(){}, true);
ajax_submitBtn_setInProgress($("#create_org_finish_previous_submitBtn"), function(){}, true);
if(!createOrg_checkNoErr()){
// ---------------- scroll top --------------------
var pos_top = 0;
if($('#create_org_form_social_table').find('div[id*="err"]').length > 0){
if(typeof($(this).attr('id')) != 'undefined'){
var id = $('#create_org_form_social_table').find('div[id*="err"]').first().attr('id').replace('_err', '');
pos_top = $('#'+id+'').offset().top;
}
}
// filter err
pos_top -= 160;
$("html, body").animate({ scrollTop:pos_top }, "fast");
// --- END ----- scroll top ----------------------
// button
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_finish_submitBtn"), createOrgHandler, false);
ajax_submitBtn_setInProgress($("#create_org_finish_previous_submitBtn"), createOrg_prev_step_2_handler, false);
} else { // if(!createOrg_checkNoErr()){
$.ajax({
url: local_url+'lib/ajax/createorg/',
headers: { 'X-Etickets-Key': $('#h').val() },
data: $('#create_org_form').serialize(),
type:"POST",
dataType:'json',
beforeSend: function(msg){
ajax_show_loading_mask(true);
},
complete: function(msg){
setTimeout(function() {
ajax_show_loading_mask(false);
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_finish_submitBtn"), createOrgHandler, false);
ajax_submitBtn_setInProgress($("#create_org_finish_previous_submitBtn"), createOrg_prev_step_2_handler, false);
}, 500);
},
success: function(json_data){
setTimeout(function() {
if(json_data.status == 1){
$(location).attr('href', json_data.gurl);
} else {
if(json_data.status == -4003){
$(location).attr('href', local_url+'logout/');
} else if(json_data.status == -1001){
ajax_form_show_topBarMessage(1);
}
}
}, 500);
},
error:function(xhr, ajaxOptions, thrownError){
setTimeout(function() {
ajax_form_show_topBarMessage(1);
}, 500);
}
});
} // if(!createOrg_checkNoErr()){
};
function createOrg_step_1_checkNoErr(){
var err_no = 0;
// out of focus, on blur
$('#create_org_form_profile_table input').each(function(){
if(typeof($(this).attr('id')) != 'undefined'){
if($(this).is(":focus")){
$(this).blur();
} // if($(this).is(":focus")){
};
});
$('#create_org_form_profile_table input').each(function(){
create_org_step_1_onFocus($(this));
create_org_step_1_onBlur($(this));
});
err_no = $('#create_org_form_profile_table').find('div[id*="err"]').length;
if(err_no == 0){
return true;
}
return false;
}
var createOrg_step_1_handler = function(e){
if(e != null){
if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
return;
} // if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
}
ajax_form_show_topBarMessage(0);
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_profile_submitBtn"), function(){}, true);
if(!createOrg_step_1_checkNoErr()){
// ---------------- scroll top --------------------
var pos_top = 0;
if($('#create_org_form_profile_table').find('div[id*="err"]').length > 0){
if(typeof($(this).attr('id')) != 'undefined'){
var id = $('#create_org_form_profile_table').find('div[id*="err"]').first().attr('id').replace('_err', '');
id = ((id == 'create_org_display_fullname_eng' || id == 'create_org_display_fullname_chi')? 'create_org_display_fullname_tabs' : id);
pos_top = $('#'+id+'').offset().top;
}
}
// filter err
pos_top -= 160;
$("html, body").animate({ scrollTop:pos_top }, "fast");
// --- END ----- scroll top ----------------------
// button
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_profile_submitBtn"), createOrg_step_1_handler, false);
} else {
$("html, body").animate({ scrollTop: 0 }, "fast");
$('#create_org_form_profile_table').hide();
$('#create_org_form_contact_table').show();
$("#create_org_img_step_1").attr("src", local_url+"lib/img/form/form_steps_no_1.png");
$("#create_org_img_step_2").attr("src", local_url+"lib/img/form/form_steps_no_2_selected.png");
}
}
function createOrg_step_2_checkNoErr(){
var err_no = 0;
// out of focus, on blur
$('#create_org_form_contact_table input, #create_org_form_contact_table select, #create_org_form_contact_table textarea').each(function(){
if(typeof($(this).attr('id')) != 'undefined'){
if($(this).is(":focus")){
$(this).blur();
} // if($(this).is(":focus")){
};
});
$('#create_org_form_contact_table input, #create_org_form_contact_table select, #create_org_form_contact_table textarea').each(function(){
create_org_step_2_onFocus($(this));
create_org_step_2_onBlur($(this));
});
err_no = $('#create_org_form_contact_table').find('div[id*="err"]').length;
if(err_no == 0){
return true;
}
return false;
}
var createOrg_step_2_handler = function(e){
if(e != null){
if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
return;
} // if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
}
ajax_form_show_topBarMessage(0);
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_contact_submitBtn"), function(){}, true);
ajax_submitBtn_setInProgress($("#create_org_contact_previous_submitBtn"), function(){}, true);
if(!createOrg_step_2_checkNoErr()){
// ---------------- scroll top --------------------
var pos_top = 0;
if($('#create_org_form_contact_table').find('div[id*="err"]').length > 0){
if(typeof($(this).attr('id')) != 'undefined'){
var id = $('#create_org_form_contact_table').find('div[id*="err"]').first().attr('id').replace('_err', '');
id = (id == 'org_display_description_eng' || id == 'org_display_description_chi')? 'org_display_description_tabs' : id;
id = (id == 'org_display_address_eng' || id == 'org_display_address_chi')? 'org_display_address_tabs' : id;
id = (id == 'org_display_contact_person_eng' || id == 'org_display_contact_person_chi')? 'org_display_contact_person_tabs' : id;
pos_top = $('#'+id+'').offset().top;
}
}
// filter err
pos_top -= 160;
$("html, body").animate({ scrollTop:pos_top }, "fast");
// --- END ----- scroll top ----------------------
// button
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_contact_submitBtn"), createOrg_step_2_handler, false);
ajax_submitBtn_setInProgress($("#create_org_contact_previous_submitBtn"), createOrg_prev_step_1_handler, false);
} else { // if(!createOrg_step_2_checkNoErr()){
$("html, body").animate({ scrollTop: 0 }, "fast");
$('#create_org_form_contact_table').hide();
$('#create_org_form_social_table').show();
$("#create_org_img_step_2").attr("src", local_url+"lib/img/form/form_steps_no_2.png");
$("#create_org_img_step_3").attr("src", local_url+"lib/img/form/form_steps_no_3_selected.png");
} // if(!createOrg_step_2_checkNoErr()){
}
var createOrg_prev_step_1_handler = function(e){
$("html, body").animate({ scrollTop: 0 }, "fast");
$('#create_org_form_profile_table').show();
$('#create_org_form_contact_table').hide();
$("#create_org_img_step_1").attr("src", local_url+"lib/img/form/form_steps_no_1_selected.png");
$("#create_org_img_step_2").attr("src", local_url+"lib/img/form/form_steps_no_2.png");
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_profile_submitBtn"), createOrg_step_1_handler, false);
}
var createOrg_prev_step_2_handler = function(e){
$("html, body").animate({ scrollTop: 0 }, "fast");
$('#create_org_form_contact_table').show();
$('#create_org_form_social_table').hide();
$("#create_org_img_step_2").attr("src", local_url+"lib/img/form/form_steps_no_2_selected.png");
$("#create_org_img_step_3").attr("src", local_url+"lib/img/form/form_steps_no_3.png");
ajax_submitBtn_setInProgress_withLoadingBar($("#create_org_contact_submitBtn"), createOrg_step_2_handler, false);
ajax_submitBtn_setInProgress($("#create_org_contact_previous_submitBtn"), createOrg_prev_step_1_handler, false);
}
function create_org_step_3_onFocus(_target){
if(typeof($(_target).attr('id')) != 'undefined'){
_target.css("border", "1px solid #05D08F");
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
} // if(typeof(_target.attr('id')) != 'undefined'){
}
function create_org_step_2_onFocus(_target){
if(typeof($(_target).attr('id')) != 'undefined'){
_target.css("border", "1px solid #05D08F");
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
} // if(typeof(_target.attr('id')) != 'undefined'){
}
function create_org_step_1_onFocus(_target){
if(typeof($(_target).attr('id')) != 'undefined'){
// ENG, CHI
if( _target.attr('id') == 'org_display_fullname_eng' ||
_target.attr('id') == 'org_display_fullname_chi'){
$('#org_display_fullname_eng').css("border", "1px solid #ccc");
$('#org_display_fullname_eng_err').remove();
$('#org_display_fullname_chi').css("border", "1px solid #ccc");
$('#org_display_fullname_chi_err').remove();
}
_target.css("border", "1px solid #05D08F");
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
} // if(typeof(_target.attr('id')) != 'undefined'){
}
function create_org_step_3_onBlur(_target){
if( $("option:selected", _target).length){
if($("option:selected", _target).val() != 0){
$(_target).css("color", "#333333");
} else {
$(_target).css("color", "#999999");
}
}
_target.css("border", "1px solid #ccc");
if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if(_target.attr('id') == 'org_display_country'){
_target.css("border", "1px solid #FF8000");
if(!$('#'+_target.attr('id')+'_err').length){
_target.after('
'+ajax_showStatusMessage(-46)+'
');
}
}
} // if(typeof(_target.attr('id')) != 'undefined'){
} else { // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if( _target.attr('id') == 'org_display_website'){
var val = _target.val();
if (val && !val.match(/^http([s]?):\/\/.*/) &&
val != 'http://yourwebsite.com' ) {
_target.val('http://' + val);
}
if(!validateURL($.trim(_target.val()))){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-45)+'
');
}
} //if(!validateURL(_target.val())){
}
} //if(typeof(_target.attr('id')) != 'undefined'){
} // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
}
function create_org_step_2_onBlur(_target){
if( $("option:selected", _target).length){
if($("option:selected", _target).val() != 0){
$(_target).css("color", "#333333");
} else {
$(_target).css("color", "#999999");
}
}
_target.css("border", "1px solid #ccc");
if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(_target.attr('id') == 'org_display_tel_areacode' || _target.attr('id') == 'org_display_tel'){
if( ($('#org_display_tel_areacode').val() == '' && $('#org_display_tel').val() == '') ||
($('#org_display_tel_areacode').val() != '' && $('#org_display_tel').val() == '') ||
($('#org_display_tel_areacode').val() == '' && $('#org_display_tel').val() != '') ){
$('#org_display_tel_areacode').css("border", "1px solid #FF8000");
$('#org_display_tel').css("border", "1px solid #FF8000");
if($('#org_display_tel_err').length){
$('#org_display_tel_err').remove();
}
$('#org_display_tel').parent().parent().parent().parent().after(''+ajax_showStatusMessage(-46)+'
');
}
} else if(_target.attr('id') == 'org_display_email'){
_target.css("border", "1px solid #FF8000");
if(!$('#'+_target.attr('id')+'_err').length){
_target.after(''+ajax_showStatusMessage(-46)+'
');
}
}
} else { // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if( _target.attr('id') == 'org_display_email'){
if(!validateEmail($.trim(_target.val()))){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-44)+'
');
}
} //if(!validateURL(_target.val())){
} else if( _target.attr('id') == 'org_display_tel_areacode' ||
_target.attr('id') == 'org_display_tel'){
if(!$.isNumeric($('#org_display_tel_areacode').val()) || !$.isNumeric($('#org_display_tel').val()) ){
if(!$.isNumeric($('#org_display_tel_areacode').val())){
$('#org_display_tel_areacode').css("border", "1px solid #FF8000");
}
if(!$.isNumeric($('#org_display_tel').val())){
$('#org_display_tel').css("border", "1px solid #FF8000");
}
if($('#org_display_tel_err').length){
$('#org_display_tel_err').remove();
}
$('#org_display_tel').parent().parent().parent().parent().after(''+ajax_showStatusMessage(-56)+'
');
}
}
} //if(typeof(_target.attr('id')) != 'undefined'){
} // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
}
function create_org_step_1_onBlur(_target){
_target.css("border", "1px solid #ccc");
if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if(_target.attr('id') == 'org_display_fullname_eng'){
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
$("#createOrg_fullname_eng_loading_gif").stop().hide();
if($('#org_display_fullname_chi').val() == ''){
if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
$("#create_org_profile_submitBtn").css('cursor', 'not-allowed');
$("#create_org_profile_submitBtn").unbind();
$('#create_org_profile_submitBtn').stop().switchClass('form_submitBtn', 'form_submitBtn_grey_disabled', 0);
} // if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
} // if($('#org_display_fullname_chi').val() == ''){
} else if(_target.attr('id') == 'org_display_fullname_chi'){
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
$("#createOrg_fullname_chi_loading_gif").stop().hide();
if($('#org_display_fullname_eng').val() == ''){
if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
$("#create_org_profile_submitBtn").css('cursor', 'not-allowed');
$("#create_org_profile_submitBtn").unbind();
$('#create_org_profile_submitBtn').stop().switchClass('form_submitBtn', 'form_submitBtn_grey_disabled', 0);
} // if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
} // if($('#org_display_fullname_eng').val() == ''){
}
// * require field ------------
if( _target.attr('id') == 'org_display_fullname_eng' ||
_target.attr('id') == 'org_display_fullname_chi'){
if( _target.attr('id').indexOf('_eng') !=-1 ){
if( $.trim($('#'+_target.attr('id').replace('_eng', '_chi')).val()) == '' ){
if(!$('#'+_target.attr('id')+'_err').length){
//alert('sdfsdf'+_target.attr('id'));
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-46)+'
');
}
if(!$('#'+_target.attr('id').replace('_eng', '_chi')+'_err').length){
$('#'+_target.attr('id').replace('_eng', '_chi')).css("border", "1px solid #FF8000");
$('#'+_target.attr('id').replace('_eng', '_chi')).after(''+ajax_showStatusMessage(-46)+'
');
}
}
} else if( _target.attr('id').indexOf("_chi") !=-1 ){
if( $.trim($('#'+_target.attr('id').replace('_chi', '_eng')).val()) == '' ){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-46)+'
');
}
if(!$('#'+_target.attr('id').replace('_chi', '_eng')+'_err').length){
$('#'+_target.attr('id').replace('_chi', '_eng')).css("border", "1px solid #FF8000");
$('#'+_target.attr('id').replace('_chi', '_eng')).after(''+ajax_showStatusMessage(-46)+'
');
}
}
}
} else if( _target.attr('id') == 'org_display_fullname_eng_approved'){
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
$("#createOrg_fullname_eng_loading_gif").stop().hide();
if(!$('#org_display_fullname_eng_err').length){
$('#org_display_fullname_eng').css("border", "1px solid #FF8000");
$('#org_display_fullname_eng').after('
'+ajax_showStatusMessage(-32)+'
');
}
} else if( _target.attr('id') == 'org_display_fullname_chi_approved'){
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
$("#createOrg_fullname_chi_loading_gif").stop().hide();
if(!$('#org_display_fullname_chi_err').length){
$('#org_display_fullname_chi').css("border", "1px solid #FF8000");
$('#org_display_fullname_chi').after('
'+ajax_showStatusMessage(-36)+'
');
}
}
// ---- END * require field ------------
} // if(typeof(_target.attr('id')) != 'undefined'){
} else { // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if( _target.attr('id') == 'org_display_fullname_eng' ||
_target.attr('id') == 'org_display_fullname_chi'
){
if( (_target.attr('id') == 'org_display_fullname_eng' && $.trim($("#org_display_fullname_eng_approved").val()) == 0) ||
(_target.attr('id') == 'org_display_fullname_chi' && $.trim($("#org_display_fullname_chi_approved").val()) == 0)
){
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
if(!$('#'+_target.attr('id')+'_err').length){
var msg_no;
if(_target.attr('id') == 'org_display_fullname_eng'){
$("#createOrg_fullname_eng_loading_gif").stop().hide();
msg_no = -32;
} else if(_target.attr('id') == 'org_display_fullname_chi'){
$("#createOrg_fullname_chi_loading_gif").stop().hide();
msg_no = -36;
}
_target.css("border", "1px solid #FF8000");
_target.after('
'+ajax_showStatusMessage(msg_no).replace('
', ' ')+'
');
}
}
}
} //if(typeof(_target.attr('id')) != 'undefined'){
} // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0')
}
function create_org_step_1_onKeyUp(_target){
if(typeof(_target.attr('id')) != 'undefined'){
if(_target.attr('id') == 'org_display_fullname_eng'){
if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
$("#create_org_profile_submitBtn").css('cursor', 'not-allowed');
$("#create_org_profile_submitBtn").unbind();
$('#create_org_profile_submitBtn').stop().switchClass('form_submitBtn', 'form_submitBtn_grey_disabled', 0);
} // if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
if(!$('#createOrg_fullname_eng_loading_gif').is(':visible')){
$("#createOrg_fullname_eng_loading_gif").stop().css('opacity', '0');
$("#createOrg_fullname_eng_loading_gif").show().animate({"opacity": "1"}, "fast");
}
_target.css("border", "1px solid #CCCCCC");
//$("#org_display_fullname_eng_approved").val(0);
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
ajax_getJSON = $.ajax({
url: local_url+'lib/ajax/createorg_fullname/?n=0&lang=1',
headers: { 'X-Etickets-Key': $('#h').val() },
data: $("#create_org_form").serialize(),
type:"POST",
dataType:'json',
beforeSend: function(msg){
//
},
complete: function(msg){
ajax_getJSON = null;
},
success: function(json_data){
//alert(json_data.status);
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
if(!json_data.status){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after('
'+ajax_showStatusMessage(-32).replace('
', ' ')+'
');
}
$("#org_display_fullname_eng_approved").val(0);
} else {
$("#org_display_fullname_eng_approved").val(1);
if($('#org_display_fullname_chi').val() == '' || $('#org_display_fullname_chi').val() == '輸入資料'){
$("#org_display_fullname_chi_approved").val(1);
}
if($("#org_display_fullname_chi_approved").val() == 1 && $("#org_display_fullname_eng_approved").val() == 1){
$("#create_org_profile_submitBtn").css('cursor', 'pointer');
$("#create_org_profile_submitBtn").bind("click", createOrg_step_1_handler);
$('#create_org_profile_submitBtn').stop().switchClass('form_submitBtn_grey_disabled', 'form_submitBtn', 0);
}
}
$("#createOrg_fullname_eng_loading_gif").stop().hide();
},
error:function(xhr, ajaxOptions, thrownError){
//
}
});
} else if(_target.attr('id') == 'org_display_fullname_chi'){
if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
$("#create_org_profile_submitBtn").css('cursor', 'not-allowed');
$("#create_org_profile_submitBtn").unbind();
$('#create_org_profile_submitBtn').stop().switchClass('form_submitBtn', 'form_submitBtn_grey_disabled', 0);
} // if($('#create_org_profile_submitBtn').attr("class") != 'form_submitBtn_grey_disabled'){
if(!$('#createOrg_fullname_chi_loading_gif').is(':visible')){
$("#createOrg_fullname_chi_loading_gif").stop().css('opacity', '0');
$("#createOrg_fullname_chi_loading_gif").show().animate({"opacity": "1"}, "fast");
}
_target.css("border", "1px solid #ccc");
//$("#org_display_fullname_chi_approved").val(0);
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
ajax_getJSON = $.ajax({
url: local_url+'lib/ajax/createorg_fullname/?n=0&lang=2',
headers: { 'X-Etickets-Key': $('#h').val() },
data: $("#create_org_form").serialize(),
type:"POST",
dataType:'json',
beforeSend: function(msg){
//
},
complete: function(msg){
ajax_getJSON = null;
},
success: function(json_data){
//alert(json_data.status);
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
//alert(json_data.status);
if(!json_data.status){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after('
'+ajax_showStatusMessage(-36).replace('
', ' ')+'
');
}
_target.css("border", "1px solid #FF8000");
$("#org_display_fullname_chi_approved").val(0);
} else {
$("#org_display_fullname_chi_approved").val(1);
if($('#org_display_fullname_eng').val() == ''){
$("#org_display_fullname_eng_approved").val(1);
}
if($("#org_display_fullname_chi_approved").val() == 1 && $("#org_display_fullname_eng_approved").val() == 1){
$("#create_org_profile_submitBtn").css('cursor', 'pointer');
$("#create_org_profile_submitBtn").bind("click", createOrg_step_1_handler);
$('#create_org_profile_submitBtn').stop().switchClass('form_submitBtn_grey_disabled', 'form_submitBtn', 0);
}
}
$("#createOrg_fullname_chi_loading_gif").stop().hide();
ajax_getJSON = null;
},
error:function(xhr, ajaxOptions, thrownError){
//
}
});
}
} //if(typeof(_target.attr('id')) != 'undefined'){
}
function init_org_create_event(){
if($('#create_org_form').length){
// -- Step 3 --
$('#create_org_form_social_table input, #create_org_form_social_table select, #create_org_form_social_table textarea').each(function(){
if(typeof($(this).attr('type')) != 'undefined'){
if($(this).attr('type') == 'tel'){
$(this).numeric({decimal:false, negative:false});
}
}
$(this).focus(function(){
create_org_step_3_onFocus($(this));
});
$(this).blur(function(){
create_org_step_3_onBlur($(this));
});
});
// -- Step 2 --
$('#create_org_form_contact_table input, #create_org_form_contact_table select, #create_org_form_contact_table textarea').each(function(){
// -------- init --------
if( $("option:selected", this).length){
if($("option:selected", this).val() != 0){
$(this).css("color", "#333333");
} else {
$(this).css("color", "#999999");
}
} //if( $("option:selected", this).length){
// --- END ---- init -----
if(typeof($(this).attr('type')) != 'undefined'){
if($(this).attr('type') == 'tel'){
$(this).numeric({decimal:false, negative:false});
}
}
$(this).focus(function(){
create_org_step_2_onFocus($(this));
});
$(this).blur(function(){
create_org_step_2_onBlur($(this));
});
});
// -- Step 1 --
$('#create_org_form_profile_table input').each(function(){
if(typeof($(this).attr('type')) != 'undefined'){
if($(this).attr('type') == 'tel'){
$(this).numeric({decimal:false, negative:false});
}
}
$(this).focus(function(){
create_org_step_1_onFocus($(this));
});
$(this).blur(function(){
create_org_step_1_onBlur($(this));
});
if(typeof($(this).attr('id')) != 'undefined'){
if($(this).attr('id') == 'org_display_fullname_eng' || $(this).attr('id') == 'org_display_fullname_chi'){
$(this).keyup(function(){
create_org_step_1_onKeyUp($(this));
});
}
}// if(typeof($(this).attr('id')) != 'undefined'){
});
// -------------- tabs ---------------
// --- Step 1 ---
$("#org_display_fullname_tabs").tabs({ active: (Number(global_js_params.lang) != 1 ? 1 : 0) });
// --- Step 2 ---
$("#org_display_description_tabs").tabs({ active: (Number(global_js_params.lang) != 1 ? 1 : 0) });
$("#org_display_address_tabs").tabs({ active: (Number(global_js_params.lang) != 1 ? 1 : 0) });
$("#org_display_contact_person_tabs").tabs({ active: (Number(global_js_params.lang) != 1 ? 1 : 0) });
// -- END -------- tabs ----------------
// --- Step 1 ---
$("#create_org_form_profile_table input[type!='hidden']").each(function(){
$(this).bind("keypress", createOrg_step_1_handler);
});
$("#create_org_profile_submitBtn").css('cursor', 'not-allowed');
// --- Step 2 ---
$("#create_org_form_contact_table input[type!='hidden']").each(function(){
$(this).bind("keypress", createOrg_step_2_handler);
});
$("#create_org_contact_submitBtn").bind("click", createOrg_step_2_handler);
$("#create_org_contact_previous_submitBtn").bind("click", createOrg_prev_step_1_handler);
// --- Step 3 ---
$("#create_org_form_social_table input[type!='hidden']").each(function(){
$(this).bind("keypress", createOrgHandler);
});
$("#create_org_finish_previous_submitBtn").bind("click", createOrg_prev_step_2_handler);
$("#create_org_finish_submitBtn").bind("click", createOrgHandler);
} // if($('#create_org_form').length){
} // function init_org_create_event(){
//--- END Create Organization -------------------------------------------------------------------
//--- Update Organization -------------------------------------------------------------------
function updateOrg_checkNoErr(){
var err_no = 0;
// out of focus, on blur
$('#update_org_form input, #update_org_form select, #update_org_form textarea').each(function(){
if(typeof($(this).attr('id')) != 'undefined'){
if($(this).is(":focus")){
$(this).blur();
} // if($(this).is(":focus")){
};
});
// require image(s)
if($('#org_profile_err').length == 0){
profile_img_uploader_onFocus($('#org_profile'));
profile_img_uploader_onBlur($('#org_profile'));
profile_img_uploader_onHover($('#org_profile'));
} // if($('#org_profile_err').length){
// form
$('#update_org_form input, #update_org_form select, #update_org_form textarea').each(function(){
update_org_onFocus($(this));
update_org_onBlur($(this));
});
err_no = $('#update_org_form').find('div[id*="err"]').length;
if(err_no == 0){
return true;
}
return false;
}
var updateOrgHandler = function(e) {
if(e != null){
if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
return;
} // if(($(e.currentTarget).is('input') || $(e.currentTarget).is('textarea')) && e.which != 13){
}
ajax_form_show_topBarMessage(0);
ajax_show_loading_mask(true);
ajax_submitBtn_setInProgress_withLoadingBar($("#update_org_finish_submitBtn"), function(){}, true);
if(!updateOrg_checkNoErr()){
// ---------------- scroll top --------------------
var pos_top = 0;
if($('#update_org_form').find('div[id*="err"]').length > 0){
if(typeof($(this).attr('id')) != 'undefined'){
var id = $('#update_org_form').find('div[id*="err"]').first().attr('id').replace('_err', '');
id = (id == 'update_org_display_fullname_eng' || id == 'update_org_display_fullname_chi')? 'update_org_display_fullname_tabs' : id;
id = (id == 'update_org_display_description_eng' || id == 'update_org_display_description_chi')? 'update_org_display_description_tabs' : id;
id = (id == 'update_org_display_address_eng' || id == 'update_org_display_address_chi')? 'update_org_display_address_tabs' : id;
id = (id == 'update_org_display_contact_person_eng' || id == 'update_org_display_contact_person_chi')? 'update_org_display_contact_person_tabs' : id;
pos_top = $('#'+id+'').offset().top;
}
}
// filter err
pos_top -= 160;
$("html, body").animate({ scrollTop:pos_top }, "fast");
// --- END ----- scroll top ----------------------
// button
ajax_show_loading_mask(false);
ajax_submitBtn_setInProgress_withLoadingBar($("#update_org_finish_submitBtn"), updateOrgHandler, false);
} else { //if(!updateOrg_checkNoErr()){
$.ajax({
url: local_url+'lib/ajax/updateorg/?orid='+$('#orid').val(),
headers: { 'X-Etickets-Key': $('#h').val() },
data: $('#update_org_form').serialize(),
type:"POST",
dataType:'json',
beforeSend: function(msg){
},
complete: function(msg){
},
success: function(json_data){
//alert(json_data.status);
setTimeout(function() {
if(json_data.status == 1){
//$(location).attr('href', local_url+'org/profile/');
$(location).attr('href', json_data.gurl);
} else {
if(json_data.status == -4003){
$(location).attr('href', local_url+'logout/');
}
ajax_form_show_topBarMessage(1);
ajax_show_loading_mask(false);
ajax_submitBtn_setInProgress_withLoadingBar($("#update_org_finish_submitBtn"), updateOrgHandler, false);
} // if(json_data.status == 1){
}, 500);
},
error:function(xhr, ajaxOptions, thrownError){
setTimeout(function() {
ajax_form_show_topBarMessage(1);
ajax_show_loading_mask(false);
ajax_submitBtn_setInProgress_withLoadingBar($("#update_org_finish_submitBtn"), updateOrgHandler, false);
}, 500);
}
});
} //if(!updateOrg_checkNoErr()){
};
function update_org_onFocus(_target){
if(typeof($(_target).attr('id')) != 'undefined'){
// ENG, CHI
if( _target.attr('id') == 'update_org_display_fullname_eng' ||
_target.attr('id') == 'update_org_display_fullname_chi'){
$('#update_org_display_fullname_eng').css("border", "1px solid #ccc");
$('#update_org_display_fullname_eng_err').remove();
$('#update_org_display_fullname_chi').css("border", "1px solid #ccc");
$('#update_org_display_fullname_chi_err').remove();
} else if( _target.attr('id') == 'update_org_display_tel_areacode' ||
_target.attr('id') == 'update_org_display_tel'){
$('#update_org_display_tel_areacode').css("border", "1px solid #ccc");
$('#update_org_display_tel').css("border", "1px solid #ccc");
if($('#update_org_display_tel_err').length){
$('#update_org_display_tel_err').remove();
}
}
_target.css("border", "1px solid #05D08F");
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
} // if(typeof(_target.attr('id')) != 'undefined'){
}
function update_org_onBlur(_target){
_target.css("border", "1px solid #ccc");
if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if(_target.attr('id') == 'update_org_display_fullname_eng'){
$("#updateOrg_fullname_eng_loading_gif").stop().hide();
} else if(_target.attr('id') == 'update_org_display_fullname_chi'){
$("#updateOrg_fullname_chi_loading_gif").stop().hide();
}
// * require field ------------
if( _target.attr('id') == 'update_org_display_description_eng' ||
_target.attr('id') == 'update_org_display_description_chi' ||
_target.attr('id') == 'update_org_display_address_eng' ||
_target.attr('id') == 'update_org_display_address_chi' ||
_target.attr('id') == 'update_org_display_fullname_eng' ||
_target.attr('id') == 'update_org_display_fullname_chi'){
// copy create
if( _target.attr('id').indexOf('_eng') !=-1 ){
if( $.trim($('#'+_target.attr('id').replace('_eng', '_chi')).val()) == '' ){
if(!$('#'+_target.attr('id')+'_err').length){
//alert('sdfsdf'+_target.attr('id'));
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-46)+'
');
}
if(!$('#'+_target.attr('id').replace('_eng', '_chi')+'_err').length){
$('#'+_target.attr('id').replace('_eng', '_chi')).css("border", "1px solid #FF8000");
$('#'+_target.attr('id').replace('_eng', '_chi')).after(''+ajax_showStatusMessage(-46)+'
');
}
}
} else if( _target.attr('id').indexOf("_chi") !=-1 ){
if( $.trim($('#'+_target.attr('id').replace('_chi', '_eng')).val()) == '' ){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-46)+'
');
}
if(!$('#'+_target.attr('id').replace('_chi', '_eng')+'_err').length){
$('#'+_target.attr('id').replace('_chi', '_eng')).css("border", "1px solid #FF8000");
$('#'+_target.attr('id').replace('_chi', '_eng')).after(''+ajax_showStatusMessage(-46)+'
');
}
}
}
} else if( _target.attr('id') == 'update_org_display_fullname_eng_approved'){
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
$("#updateOrg_fullname_eng_loading_gif").stop().hide();
if(!$('#update_org_display_fullname_eng_err').length){
$('#update_org_display_fullname_eng').css("border", "1px solid #FF8000");
$('#update_org_display_fullname_eng').after('
'+ajax_showStatusMessage(-32)+'
');
}
} else if( _target.attr('id') == 'update_org_display_fullname_chi_approved'){
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
$("#updateOrg_fullname_chi_loading_gif").stop().hide();
if(!$('#update_org_display_fullname_chi_err').length){
$('#update_org_display_fullname_chi').css("border", "1px solid #FF8000");
$('#update_org_display_fullname_chi').after('
'+ajax_showStatusMessage(-36)+'
');
}
} else if( _target.attr('id') == 'update_org_display_country' ||
_target.attr('id') == 'update_org_display_email'){
_target.css("border", "1px solid #FF8000");
if(!$('#'+_target.attr('id')+'_err').length){
_target.after(''+ajax_showStatusMessage(-46)+'
');
}
} else if( _target.attr('id') == 'update_org_display_tel_areacode' ||
_target.attr('id') == 'update_org_display_tel'){
$('#update_org_display_tel_areacode').css("border", "1px solid #FF8000");
$('#update_org_display_tel').css("border", "1px solid #FF8000");
if($('#update_org_display_tel_err').length){
$('#update_org_display_tel_err').remove();
}
$('#update_org_display_tel').parent().parent().parent().parent().after(''+ajax_showStatusMessage(-46)+'
');
}
// ---- END * require field ------------
} // if(typeof(_target.attr('id')) != 'undefined'){
} else { // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
if(typeof(_target.attr('id')) != 'undefined'){
if( _target.attr('id') == 'update_org_display_fullname_eng' ||
_target.attr('id') == 'update_org_display_fullname_chi'){
if( (_target.attr('id') == 'update_org_display_fullname_eng' && $.trim($("#update_org_display_fullname_eng_approved").val()) == 0) || (_target.attr('id') == 'update_org_display_fullname_chi' && $.trim($("#update_org_display_fullname_chi_approved").val()) == 0)){
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
if(!$('#'+_target.attr('id')+'_err').length){
var msg_no;
if(_target.attr('id') == 'update_org_display_fullname_eng'){
$("#updateOrg_fullname_eng_loading_gif").stop().hide();
msg_no = -32;
} else if(_target.attr('id') == 'update_org_display_fullname_chi'){
$("#updateOrg_fullname_chi_loading_gif").stop().hide();
msg_no = -36;
}
_target.css("border", "1px solid #FF8000");
_target.after('
'+ajax_showStatusMessage(msg_no)+'
');
}
}
} else if( _target.attr('id') == 'update_org_display_website'){
var val = _target.val();
if (val && !val.match(/^http([s]?):\/\/.*/)) {
_target.val('http://' + val);
}
if(!validateURL($.trim(_target.val()))){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-45)+'
');
}
} //if(!validateURL(_target.val())){
} else if(_target.attr('id') == 'update_org_display_email' ){
if(!validateEmail($.trim(_target.val()))){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after(''+ajax_showStatusMessage(-44)+'
');
}
} //if(!validateURL(_target.val())){
} else if( _target.attr('id') == 'update_org_display_tel_areacode' ||
_target.attr('id') == 'update_org_display_tel'){
if(!$.isNumeric($('#update_org_display_tel_areacode').val()) || !$.isNumeric($('#update_org_display_tel').val()) ){
if(!$.isNumeric($('#update_org_display_tel_areacode').val())){
$('#update_org_display_tel_areacode').css("border", "1px solid #FF8000");
}
if(!$.isNumeric($('#update_org_display_tel').val())){
$('#update_org_display_tel').css("border", "1px solid #FF8000");
}
if($('#update_org_display_tel_err').length){
$('#update_org_display_tel_err').remove();
}
$('#update_org_display_tel').parent().parent().parent().parent().after(''+ajax_showStatusMessage(-56)+'
');
}
}
} //if(typeof(_target.attr('id')) != 'undefined'){
} // if($.trim(_target.val()) == '' || $.trim(Number(_target.val())) == '0'){
}
function update_org_onKeyUp(_target){
if(typeof(_target.attr('id')) != 'undefined'){
if(_target.attr('id') == 'update_org_display_fullname_eng'){
if(!$('#updateOrg_fullname_eng_loading_gif').is(':visible')){
$("#updateOrg_fullname_eng_loading_gif").stop().css('opacity', '0');
$("#updateOrg_fullname_eng_loading_gif").show().animate({"opacity": "1"}, "fast");
}
_target.css("border", "1px solid #CCCCCC");
//$("#update_org_display_fullname_eng_approved").val(0);
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
ajax_getJSON = $.ajax({
url: local_url+'lib/ajax/updateorg_fullname/?n=0&lang=1',
headers: { 'X-Etickets-Key': $('#h').val() },
data: $('#update_org_form').serialize(),
type:"POST",
dataType:'json',
beforeSend: function(msg){
//
},
complete: function(msg){
ajax_getJSON = null;
},
success: function(json_data){
//alert(json_data.status);
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
if(!json_data.status){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after('
'+ajax_showStatusMessage(-32)+'
');
}
$("#update_org_display_fullname_eng_approved").val(0);
} else {
$("#update_org_display_fullname_eng_approved").val(1);
if($('#update_org_display_fullname_chi').val() == '' || $('#update_org_display_fullname_chi').val() == '輸入資料'){
$("#update_org_display_fullname_chi_approved").val(1);
}
}
$("#updateOrg_fullname_eng_loading_gif").stop().hide();
},
error:function(xhr, ajaxOptions, thrownError){
//
}
});
} else if(_target.attr('id') == 'update_org_display_fullname_chi'){
if(!$('#updateOrg_fullname_chi_loading_gif').is(':visible')){
$("#updateOrg_fullname_chi_loading_gif").stop().css('opacity', '0');
$("#updateOrg_fullname_chi_loading_gif").show().animate({"opacity": "1"}, "fast");
}
_target.css("border", "1px solid #ccc");
//$("#update_org_display_fullname_chi_approved").val(0);
if(ajax_getJSON){
ajax_getJSON.abort();
ajax_getJSON = null;
}
ajax_getJSON = $.ajax({
url: local_url+'lib/ajax/updateorg_fullname/?n=0&lang=2',
headers: { 'X-Etickets-Key': $('#h').val() },
data: $('#update_org_form').serialize(),
type:"POST",
dataType:'json',
beforeSend: function(msg){
//
},
complete: function(msg){
ajax_getJSON = null;
},
success: function(json_data){
//alert(json_data.status);
if($('#'+_target.attr('id')+'_err').length){
$('#'+_target.attr('id')+'_err').remove();
}
//alert(json_data.status);
if(!json_data.status){
if(!$('#'+_target.attr('id')+'_err').length){
_target.css("border", "1px solid #FF8000");
_target.after('
'+ajax_showStatusMessage(-36)+'
');
}
_target.css("border", "1px solid #FF8000");
$("#update_org_display_fullname_chi_approved").val(0);
} else {
$("#update_org_display_fullname_chi_approved").val(1);
if($('#update_org_display_fullname_eng').val() == ''){
$("#update_org_display_fullname_eng_approved").val(1);
}
}
$("#updateOrg_fullname_chi_loading_gif").stop().hide();
},
error:function(xhr, ajaxOptions, thrownError){
//
}
});
}
} //if(typeof(_target.attr('id')) != 'undefined'){
}
function init_org_update_event(){
if($('#update_org_form').length){
// ------- Uploader ------
init_img_uploader($('#org_profile'), 1, true);
var strBG = '';
var strTXT = '';
switch(Number(global_js_params.lang)){
default:
case 1:
strBG = 'Theme Colors,Background Colors,Current Color,Less Colors,Back to Palette,History,No history yet.';
strTXT = 'Theme Colors,Text Colors,Current Color,Less Colors,Back to Palette,History,No history yet.';
break;
case 2:
case 3:
strBG = 'Theme Colors,Background Colors,Current Color,Less Colors,Back to Palette,History,No history yet.';
strTXT = 'Theme Colors,Text Colors,Current Color,Less Colors,Back to Palette,History,No history yet.';
break;
}
var tabsNumber = (Number(global_js_params.lang) != 1 ? 1 : 0);
$("#update_org_display_fullname_tabs").tabs({ active:tabsNumber});
$("#update_org_display_description_tabs").tabs({ active: tabsNumber });
$("#update_org_display_address_tabs").tabs({ active: tabsNumber });
$("#update_org_display_contact_person_tabs").tabs({ active: tabsNumber });
$('#update_org_form input, #update_org_form select, #update_org_form textarea').each(function(){
// --- init -----
if( $("option:selected", this).length){
if($("option:selected", this).val() != 0){
$(this).css("color", "#333333");
} else {
$(this).css("color", "#999999");
}
} //if( $("option:selected", this).length){
if(typeof($(this).attr('id')) != 'undefined'){
if(/_social_/i.test($(this).attr('id'))){
update_org_onBlur($(this));
} // if(/_social_/i.test(str)){
}
// --- END ---- init -----
if(typeof($(this).attr('type')) != 'undefined'){
if($(this).attr('type') == 'tel'){
$(this).numeric({decimal:false, negative:false});
}
}
$(this).focus(function() {
update_org_onFocus($(this));
});
$(this).blur(function() {
update_org_onBlur($(this));
});
});
}
if($('#update_org_form #update_org_display_fullname_eng').length ||
$('#update_org_form #update_org_display_fullname_chi').length
){
$('#update_org_form #update_org_display_fullname_eng, #update_org_form #update_org_display_fullname_chi').keyup(function() {
update_org_onKeyUp($(this));
});
}
$("#update_org_form input[type!='hidden']").each(function(){
$(this).bind("keypress", updateOrgHandler);
});
$("#update_org_finish_submitBtn").bind("click", updateOrgHandler);
} // function init_org_update_event(){
//--- END Update Organization -------------------------------------------------------------------