var czpf_settings_current_object = '';
var czpf_dt_json_string = '';
var czpf_dt_count = 0;

var czpf_czpf_add_object_obj = '';
var czpf_czpf_add_object_pos = '';

var czpf_object_sort_array = new Array();
czpf_object_sort_array[0] = '#first_name, #last_name, #nickname, #email, #full_name, #age, #address, #city, #state, #zip, #contry, #contrytext, #sex';
czpf_object_sort_array[1] = '#facebook, #twitter, #googleplus, #linkedin';
czpf_object_sort_array[2] = '#row, #status_show, #groupsteams, #avatar, #label, #title, #description, #lang, #langtext, #custom, #space, #editdate';



czpf_init();

function czpf_init(){
	jQuery(function() {	
		jQuery('#czpf_container .contolepanel_box a').unbind("click").click(czpf_devide_row);
		jQuery('#czpf_container .contolepanel_remove').unbind("click").click(czpf_remove_object);
		jQuery( "#czpf_container ul ul" ).sortable({
			revert: true,
			handle: ".dragemove",
			placeholder: "ui-state-highlight",
			connectWith: "#czpf_container ul",
		});
	});
}

jQuery(function($) {	
	jQuery('#czpf_container #addRowobject').click(function(){
		czpf_add_row(jQuery('#czpf_container .row ul:eq(0)'),true,false);
	});
	jQuery('#czpf_add_objects #media-cpzf-nav-tab-wrapper a').click(czpf_filter_object);
	jQuery('#czpf_add_objects .media-frame-content ul li').click(czpf_add_object_show);
	
	jQuery('#welcome_to_members .close').click(function(){jQuery('#welcome_to_members').slideUp(500);});
	
	setTimeout( function(){jQuery('#czpf_container').show()}, 400 );
	
	jQuery('#czpf_add_objects .media-modal-close, #czpf_add_objects .media-toolbar-primary #media-modal-close').click(czpf_add_object_hide)	
	jQuery('#cpzf-nav-tab-wrapper a').click(czpf_change_main_menu);
	
	jQuery( "#sortable_button_list" ).sortable({placeholder: "sortable_button_list-ui-state-highlight"});
	
	
	
	function czpf_add_object_show(){ 
		if(jQuery(this).attr('id') == 'row') {
			 if(czpf_czpf_add_object_pos == 'top'){
			 	czpf_add_row(jQuery(czpf_czpf_add_object_obj).parent().find('ul:eq(0)'),true,true);
			 } else {
			 	czpf_add_row(jQuery(czpf_czpf_add_object_obj).parent().find('ul:eq(0)'),true,false);
			 }
	
		 } else if(czpf_czpf_add_object_pos == 'top'){
			jQuery(czpf_czpf_add_object_obj).parent().find('ul:eq(0)').prepend(jQuery(this).clone()).unbind("click");
			jQuery(czpf_czpf_add_object_obj).parent().find('ul:eq(0) li:eq(0)').unbind("click"); 
		 } else {
			jQuery(czpf_czpf_add_object_obj).parent().find('ul:eq(0)').append(jQuery(this).clone());
			jQuery(czpf_czpf_add_object_obj).parent().find('ul:eq(0) > li').last().unbind("click"); 
		 }
			 
			 czpf_init();
			 czpf_add_object_hide();
	}
	
});

// ----------------------------------
// Objects selector
// ----------------------------------


function czpf_change_main_menu(){
	
	jQuery(this).parent().find('.cpzf-nav-tab-active').removeClass('cpzf-nav-tab-active')
	jQuery(this).addClass('cpzf-nav-tab-active');
	
	if(jQuery(this).attr('data-id') == 'czpf_container'){
		jQuery("#RTD").show();
		jQuery("#RALL").show();
	} else {
		jQuery("#RTD").hide();
		jQuery("#RALL").hide();
	}
	

	
	jQuery(this).parent().find('a').each(function(){
		
		if(jQuery(this).hasClass('cpzf-nav-tab-active')){
			jQuery('#'+jQuery(this).attr('data-id')).delay(500).slideDown();
		} else {
			jQuery('#'+jQuery(this).attr('data-id')).slideUp();
		}
	})
	
	return false;
}

function czpf_changevalue(tmp_this){
	if(jQuery(tmp_this).attr('id') == 'save_value'){
		jQuery(tmp_this).parent().parent().parent().find('#backend #save').val(jQuery(tmp_this).val());
	} else if(jQuery(tmp_this).attr('id') == 'value_value'){
		jQuery(tmp_this).parent().parent().parent().find('#backend #value').val(jQuery(tmp_this).val());
		
		if(jQuery(tmp_this).parent().parent().parent().find('#backend #value').val() != ''){
			jQuery(tmp_this).parent().parent().parent().find('.subsubtext').html(': '+jQuery(tmp_this).parent().parent().parent().find('#backend #value').val());
		} else {
			jQuery(tmp_this).parent().parent().parent().find('.subsubtext').html('');
		}
		
	} else 	if(jQuery(tmp_this).attr('id') == 'public_value'){
		jQuery(tmp_this).parent().parent().parent().find('#backend #public').val(jQuery(tmp_this).val());	
	} else 	if(jQuery(tmp_this).attr('id') == 'editable_value'){	
		jQuery(tmp_this).parent().parent().parent().find('#backend #editable').val(jQuery(tmp_this).val());	
	} else 	if(jQuery(tmp_this).attr('id') == 'round_object_value'){
		jQuery(tmp_this).parent().parent().parent().find('#backend #round_object').val(jQuery(tmp_this).val());	
	}
}


function czpf_filter_object(){
	jQuery(this).parent().find('.active').removeClass('active')
	jQuery(this).addClass('active');
	
	var tmp = jQuery(this).index() - 1;
	if(tmp >= 0){
		for(var i=0;i<czpf_object_sort_array.length;i++){
			if(i == tmp){
				jQuery('#czpf_add_objects .media-frame-content').find(czpf_object_sort_array[i]).show().stop( true, true ).removeClass('hide', 500);
			} else {
				jQuery('#czpf_add_objects .media-frame-content').find(czpf_object_sort_array[i]).hide().stop( true, true ).addClass('hide');	
			}
		}
	} else {
		jQuery('#czpf_add_objects .media-frame-content li').show().stop( true, true ).removeClass('hide', 1000);
	}
}

function czpf_add_object_hide(){
	jQuery('#czpf_add_objects').show().find('.media-modal').css('opacity','1.0').fadeTo('slow',0.0,function(){
		jQuery('#czpf_add_objects .media-modal-backdrop').show().css('opacity','0.7').fadeTo('slow',0.0,function(){
			jQuery('#czpf_add_objects').css('opacity','0.0').hide();	
		})
	})
}

function czpf_add_object_show(tmp_this,tmp_pos){
	czpf_czpf_add_object_obj = tmp_this;
	czpf_czpf_add_object_pos = tmp_pos;
	jQuery('#czpf_add_objects').css('opacity','1.0').show().find('.media-modal-backdrop').css('opacity','0.0').fadeTo('slow',0.7);	
	jQuery('#czpf_add_objects .media-modal').show().css('opacity','0.0').delay(500).fadeTo('slow',1.0);
}

 

// ----------------------------------
// Container
// ----------------------------------

function czpf_reset_object(tmp_object){
	if (confirm("Want to clear all, Are you sure?"))
	{
		jQuery(tmp_object+' .row').html('<ul></ul>');
		czpf_init();
	}
}	
	
function czpf_remove_object(tmp_this){
	if (confirm("Want to delete this, Are you sure?"))
	{
		if(jQuery(tmp_this).attr('class') == undefined){
			tmp_this = jQuery(this);
		}
		
		if(jQuery(tmp_this).parent().parent().parent().is('li')){
			jQuery(tmp_this).parent().parent().parent().remove();
		} else {
			jQuery(tmp_this).parent().parent().remove();
		}
		czpf_init();
		
	}
	return false;
}
	
function czpf_add_row(tmp_pos,tmp_li,tmp_pre){
	var tmp_var = '';
	
	if(tmp_li){
		tmp_var += 	'<li id="row">';
	}

	tmp_var += 	'<div class="rowobject">';
	tmp_var += 		'<span class="contolepanel dragemove">';
	tmp_var += 			'<span class="contolepanel_box">';
	tmp_var += 				'<a class="colums colums_12 active" data-type="12"></a>';
	tmp_var += 				'<a class="colums colums_2_10" data-type="2_10"></a>';
	tmp_var += 				'<a class="colums colums_4_8" data-type="4_8"></a>';
	tmp_var += 				'<a class="colums colums_6_6" data-type="6_6"></a>';
	tmp_var += 				'<a class="colums colums_4_4_4" data-type="4_4_4"></a>';
	tmp_var += 				'<a class="colums colums_3_8_1" data-type="3_8_1"></a>';
	tmp_var += 				'<a class="colums colums_2_8_2" data-type="2_8_2"></a>';
	tmp_var += 				'<a class="colums colums_3_6_3" data-type="3_6_3"></a>';
	tmp_var += 				'<a class="colums colums_3_3_3_3" data-type="3_3_3_3"></a>';
	tmp_var += 				'<a class="colums colums_2_2_2_2_2_2" data-type="2_2_2_2_2_2"></a>';
	tmp_var += 				'<a class="colums colums_8_4" data-type="8_4"></a>';
	tmp_var += 				'<a class="colums colums_10_2" data-type="10_2"></a>';
	tmp_var += 				'<a class="colums colums_2_2_2_6" data-type="2_2_2_6"></a>';	
	tmp_var += 			'</span>';
	tmp_var += 			'<span class="contolepanel_remove czpficon-minus"></span>';	
	tmp_var += 		'</span>';
	tmp_var += 		'<div class="col-xs-12 singleobject">';
	tmp_var += 			'<span class="add_object top" onclick="czpf_add_object_show(this,\'top\')"></span>';
	tmp_var += 			'<ul>';
	tmp_var += 			'</ul>';
	tmp_var += 			'<span class="add_object bottom" onclick="czpf_add_object_show(this,\'bottom\')"></span>';
	tmp_var += 		'</div>';
	tmp_var += 		'<span class="clear"></span>';
	tmp_var += '</div>';
	
	if(tmp_li){
		tmp_var += 	'</li>';
	}		
	
	if(tmp_pre){
		jQuery(tmp_pos).prepend(tmp_var);
	} else {
		jQuery(tmp_pos).append(tmp_var);
	}

	czpf_init();
	
}
	
function czpf_devide_row(){
	jQuery(this).parent().find('.active').removeClass('active');
	jQuery(this).addClass('active');
	
	var tmp_data_array =  jQuery(this).attr('data-type').split("_"); 
	var tmp_numberofdiv = jQuery(this).parent().parent().parent().find('> .singleobject').length;
	var tmp_devide = tmp_data_array.length-tmp_numberofdiv;

	if(tmp_devide < 0){
		for(var i=0;i<(tmp_devide*-1);i++){
			jQuery(this).parent().parent().parent().children('.singleobject ').last().remove();
		}
	} else if(tmp_devide > 0){
		for(var i=0;i<tmp_devide;i++){
			czpf_add_single(jQuery(this).parent().parent().parent());
		}
	}
	
	jQuery(this).parent().parent().parent().children('.clear').remove();
	jQuery(this).parent().parent().parent().append('<span class="clear"></span>');
	
	for(var j=0;j<tmp_data_array.length;j++){
		jQuery(this).parent().parent().parent().children('.singleobject:eq('+(j)+')').removeClass('col-xs-1 col-xs-2 col-xs-3 col-xs-4 col-xs-5 col-xs-6 col-xs-7 col-xs-8 col-xs-9 col-xs-10 col-xs-11 col-xs-12').addClass('col-xs-'+tmp_data_array[j]);
	}
	
	czpf_init();		
	return false;
}

function czpf_add_single(tmp_this){
	var tmp_var = '<div class="col-xs-12 singleobject">';
		tmp_var += 		'<span class="add_object top" onclick="czpf_add_object_show(this,\'top\')"></span>';
		tmp_var += 		'<ul>';
		tmp_var += 		'</ul>';
		tmp_var += 		'<span class="add_object bottom" onclick="czpf_add_object_show(this,\'bottom\')"></span>';
		tmp_var += '</div>';
		
		jQuery(tmp_this).append(tmp_var);
}
// ----------------------------------------------------------------------------------
// Settings
// ----------------------------------------------------------------------------------

function czpf_fn_settings(tmp_this){

	if(jQuery(tmp_this).parent().parent().find('#inner_settingsbox').is(':visible')){
		jQuery(tmp_this).parent().parent().find('#inner_settingsbox').slideUp(300);
		jQuery(tmp_this).removeClass('rot');
	} else if(jQuery(tmp_this).parent().find('#inner_settingsbox').attr('id') == 'inner_settingsbox'){	
		jQuery(tmp_this).parent().parent().find('#inner_settingsbox').slideDown(300);
		jQuery(tmp_this).addClass('rot');
	} else {
		jQuery(tmp_this).parent().append(jQuery('#inner_settingsbox_CT #inner_settingsbox').clone());
		jQuery(tmp_this).addClass('rot');
		
		
		
		jQuery(tmp_this).parent().parent().find('#inner_settingsbox #value, #inner_settingsbox #save, #inner_settingsbox #round_object, #inner_settingsbox #public, #inner_settingsbox #editable ,#inner_settingsbox #object_icon').hide();
		jQuery(tmp_this).parent().parent().find('#backend input').each(function(){
			
			var tmp_id = jQuery(this).attr('id');
			
			jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id).show();
			
			
			if(tmp_id == 'object_icon'){
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' .data-icon').removeClass('active');
				if(jQuery(this).val() != '' && jQuery(this).val() != undefined && jQuery(this).val() != 'undefined'){
					jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' .data-icon.'+jQuery(this).val()).addClass('active');
				}
				jQuery(tmp_this).parent().find('#inner_settingsbox .object_icon_h .data-icon').click(czpf_change_icon);
			}
			
			if(tmp_id == 'round_object'){
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' #round_object_value option').removeAttr('selected');	
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' #round_object_value option[value=\''+jQuery(this).val()+'\']').attr('selected','selected');
			}
			
			if(tmp_id == 'public'){
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' #public_value option').removeAttr('selected');	
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' #public_value option[value=\''+jQuery(this).val()+'\']').attr('selected','selected');
			}
			
			if(tmp_id == 'editable'){
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' #editable_value option').removeAttr('selected');	
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' #editable_value option[value=\''+jQuery(this).val()+'\']').attr('selected','selected');
			}
			
			if(tmp_id == 'save' || tmp_id == 'value'){
				jQuery(tmp_this).parent().parent().find('#inner_settingsbox #'+tmp_id+' input').val(jQuery(this).val());
			}
		})
		
		jQuery(tmp_this).parent().parent().find('#inner_settingsbox').slideDown(300);
			
	}
}


function czpf_change_icon(){
	jQuery(this).parent().find('.data-icon').removeClass('active');
	jQuery(this).addClass('active');
	jQuery(this).parent().parent().parent().parent().find('#backend #object_icon').val(jQuery(this).attr('data-type'));
	jQuery(this).parent().parent().parent().parent().find('#show_object span:eq(0)').removeClass().addClass('icon_extra').addClass(jQuery(this).attr('data-type'));
}

// ----------------------------------------------------------------------------------
// Save all 
// ----------------------------------------------------------------------------------

function czpf_welcomeCreatePage(tmp_this,tmp_number){
	jQuery(tmp_this).slideUp('slow');
	
	jQuery.post( CZPF_ADMIN.ajaxurl + "/?czpf_data=true&czpf_fn=backend_welcomeCreatePage", function( data ) {
		var url = window.location.href;    
		if (url.indexOf('?') > -1){
		   url += '&url_change=1'
		}else{
		   url += '?url_change=1'
		}
		window.location.href = url;

	});

}

function czpf_welcomehide(tmp_this,tmp_number){
	jQuery(tmp_this).slideUp('slow');	
	jQuery.post( CZPF_ADMIN.ajaxurl + "/?czpf_data=true&czpf_fn=backend_welcomeRemove", { 'czpf_remove': tmp_number});
	
	return false;
}



czpf_dt_lockdown_save_all = false;

function czpf_fn_save_all(){
	if(!czpf_dt_lockdown_save_all){
	
		czpf_dt_lockdown_save_all = true;
		
		
		jQuery('#buttoncontrole #btsavelable').show().css('opacity',0.0).fadeTo('slow',1.0);
		var tmp_container = czpf_fn_level_save(jQuery('#czpf_container .row'));
			tmp_container = encodeURIComponent(tmp_container);

		tmp_advancesettings = jQuery('#advancesettings_form').serializeArray();
		
		var tmp_members_roles = '';
		var tmp_groups_create_roles = '';
		
		jQuery('#members_roles option:selected').each(function(){
			if(tmp_members_roles != ''){
				tmp_members_roles += '|';
			}
			
			tmp_members_roles += jQuery(this).val();
		})
		
		jQuery('#groups_create_roles option:selected').each(function(){
			if(tmp_groups_create_roles != ''){
				tmp_groups_create_roles += '|';
			}
			
			tmp_groups_create_roles += jQuery(this).val();
		})
		
		for(var i=0;i < tmp_advancesettings.length; i++){
			if(tmp_advancesettings[i].name == "members_roles"){
				tmp_advancesettings[i].value = tmp_members_roles;
			}
			
			if(tmp_advancesettings[i].name == "groups_create_roles"){
				tmp_advancesettings[i].value = tmp_groups_create_roles;
			}
		}
		
		
		
		tmp_advancesettings = encodeURIComponent(JSON.stringify(tmp_advancesettings));
		
		var sortable_button_list = '';
		
		jQuery('#sortable_button_list li').each(function(){
			if(sortable_button_list != ''){
				sortable_button_list += '|';
			}
			
			sortable_button_list += jQuery(this).attr('id');
		});
		
		jQuery.post( CZPF_ADMIN.ajaxurl + "/?czpf_data=true&czpf_fn=backend_save", { 'czpf_container': tmp_container,'czpf_advancesettings':tmp_advancesettings,'czpf_sortable_button_list':sortable_button_list}, function( data ) {
			if(data.R != 'OK'){
				alert(data.MSG);
			} else {
				jQuery('#profil_url').html(data.RETURN_URL);
				jQuery('#members_url').html(data.MEMBERS_URL);
				jQuery('#groupsteams_url').html(data.GROUPS_URL);
			}
			
			
			jQuery('#buttoncontrole #btsavelable').show().css('opacity',1.0).fadeTo('slow',0.0, function(){
				jQuery('#buttoncontrole #btsavelable').removeClass('spinner').removeClass('data-icon').removeClass('fui-check').addClass('data-icon fui-check');
				jQuery('#buttoncontrole #btsavelable').show().css('opacity',0.0).fadeTo('slow',1.0, function(){
					jQuery('#buttoncontrole #btsavelable').delay(1000).fadeTo('slow',0.0,function(){
						jQuery('#buttoncontrole #btsavelable').removeClass('spinner').removeClass('data-icon').removeClass('fui-check').addClass('spinner');
					});
				});
			})
			czpf_dt_lockdown_save_all = false;
		}, "json");	
	}	
}


function czpf_reset_to_delful(){
	if (confirm("Want to reset to default, this will reload the page after, Are you sure?"))
	{
		if(!czpf_dt_lockdown_save_all){
		
			czpf_dt_lockdown_save_all = true;
			
			jQuery('#buttoncontrole #btsavelable').show().css('opacity',0.0).fadeTo('slow',1.0);
			var tmp_container = '%7B%22rowobject_5_1%22%3A%7B%22single_3_2%22%3A%7B%22object_3%22%3A%7B%22round_object%22%3A%221%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22avatar%22%7D%7D%2C%22single_8_4%22%3A%7B%22rowobject_0_5%22%3A%7B%22single_12_6%22%3A%7B%22object_7%22%3A%7B%22object_icon%22%3A%22no-icon%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22full_name%22%7D%7D%7D%2C%22rowobject_3_8%22%3A%7B%22single_6_9%22%3A%7B%22object_10%22%3A%7B%22object_icon%22%3A%22czpficon-uniE5B2%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22address%22%7D%2C%22object_11%22%3A%7B%22object_icon%22%3A%22czpficon-uniE3B4%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22city%22%7D%2C%22rowobject_3_12%22%3A%7B%22single_6_13%22%3A%7B%22object_14%22%3A%7B%22object_icon%22%3A%22czpficon-uniE398%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22zip%22%7D%7D%2C%22single_6_15%22%3A%7B%22object_16%22%3A%7B%22object_icon%22%3A%22czpficon-uniE39D%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22state%22%7D%7D%7D%2C%22object_17%22%3A%7B%22object_icon%22%3A%22czpficon-uniE4E1%22%2C%22public%22%3A%221%22%2C%22id%22%3A%22groupsteams%22%7D%7D%2C%22single_6_18%22%3A%7B%22object_19%22%3A%7B%22object_icon%22%3A%22czpficon-uniE117%22%2C%22public%22%3A%22-%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22email%22%7D%2C%22object_20%22%3A%7B%22object_icon%22%3A%22czpficon-uniE3BC%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22contry%22%7D%2C%22object_21%22%3A%7B%22object_icon%22%3A%22czpficon-uniE0E0%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22lang%22%7D%2C%22object_22%22%3A%7B%22object_icon%22%3A%22czpficon-uniE02B%22%2C%22id%22%3A%22status_show%22%7D%7D%7D%7D%2C%22single_1_23%22%3A%7B%22object_24%22%3A%7B%22public%22%3A%221%22%2C%22id%22%3A%22facebook%22%7D%2C%22object_25%22%3A%7B%22public%22%3A%221%22%2C%22id%22%3A%22twitter%22%7D%2C%22object_26%22%3A%7B%22public%22%3A%221%22%2C%22id%22%3A%22googleplus%22%7D%2C%22object_27%22%3A%7B%22public%22%3A%221%22%2C%22id%22%3A%22linkedin%22%7D%7D%7D%2C%22rowobject_0_28%22%3A%7B%22single_12_29%22%3A%7B%22object_30%22%3A%7B%22value%22%3A%22Please%20write%20a%20title%22%2C%22object_icon%22%3A%22no-icon%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22title%22%7D%2C%22object_31%22%3A%7B%22value%22%3A%22Please%20write%20a%20description%22%2C%22object_icon%22%3A%22no-icon%22%2C%22public%22%3A%221%22%2C%22editable%22%3A%221%22%2C%22id%22%3A%22description%22%7D%7D%7D%7D';
			
			jQuery.post( CZPF_ADMIN.ajaxurl + "/?czpf_data=true&czpf_fn=backend_save", { 'czpf_container': tmp_container,'czpf_resettodefault':true}, function( data ) {
				if(data.R != 'OK'){
					alert(data.MSG);
				}
				
				window.location.reload();
				czpf_dt_lockdown_save_all = false;
			}, "json");	
		}
	}
}

function czpf_fn_level_save(this_objce){
	czpf_dt_json_string = '';
	czpf_dt_count = 0;
	czpf_fn_level_save_loop(this_objce);
	czpf_dt_json_string = '{'+czpf_dt_json_string+'}';
	return czpf_dt_json_string;
}



function czpf_row_level_save_loop(this_objce,tmp_type){
	jQuery(this_objce).each(function(index){
		czpf_dt_count++;
		if(index != 0){
			czpf_dt_json_string += ',';
		}
		czpf_dt_json_string += '"single_'+czpf_check_obejct(jQuery(this))+'_'+czpf_dt_count+'":{';
		czpf_fn_level_save_loop(jQuery(this),true);
	});
}

function czpf_fn_level_save_loop(this_objce,tmp_type){
	jQuery(this_objce).children('ul').children('li').each(function(index, item) {
		czpf_dt_count++;
		if(index > 0){
			czpf_dt_json_string += ',';
		}
		
		if(jQuery(this).attr('id') == 'row'){
			//czpf_dt_json_string += '"rowobject_'+czpf_check_obejct(jQuery(this))+'_'+czpf_dt_count+'":{';
			tmp = '';
			tmp = jQuery(this).children().children('span:eq(0)').children('.contolepanel_box').find('a.active').index();
			
			czpf_dt_json_string += '"rowobject_'+tmp+'_'+czpf_dt_count+'":{';
			tmp = '';
			czpf_row_level_save_loop(jQuery(this).children().children('div'),true)
			
			czpf_dt_json_string += '}';
		} else {
			tmp = '"object_'+czpf_dt_count+'":{';
			jQuery(this).find('#backend input').each(function(item2) {
				tmp += '"'+jQuery(this).attr('id')+'":"'+jQuery(this).val()+'",';
			});
			tmp += '"id":"' + jQuery(this).find('div:eq(0)').attr('data-obj') + '"';
			tmp += '}';

			czpf_dt_json_string += tmp;
			tmp = '';
		}	
    });
    if(tmp_type){
	    czpf_dt_json_string += '}';
    }
}

function czpf_check_obejct(tmp_this){
	for(i=12;i>0;i--){
		if(jQuery(tmp_this).hasClass( "col-xs-"+i )){
			return i;
		}	
	}
	return 0;
}
