jQuery(document).ready(function($) {

	jQuery('#select-social-account-type').change(function(){
		var value = jQuery(this).val();
		if (value.indexOf('---')<0) {
			jQuery('#maxv-social-acounts-table tr:gt(0)').each(function() {
				if (value.indexOf('---')>=0 || value=='' || value=='0' || value==0 || jQuery(this).hasClass('social-account-type-'+value)) {
					jQuery(this).show();
				} else {
					jQuery(this).hide();
				}
			});
		}
	});

	jQuery('#select-social-account-log-type').change(function(){
		/*var value = jQuery(this).val();
		jQuery('#maxv-social-acounts-log-table tr:gt(0)').each(function() {
			if (value=='' || value=='0' || value==0 || jQuery(this).hasClass('social-account-type-'+value)) {
				jQuery(this).show();
			} else {
				jQuery(this).hide();
			}
		});*/
		jQuery('#social-account-log-from-date').change();
	});
	
	jQuery('#social-account-log-from-date').change(function(){
		//$(this).find(".bgHeaderH2").text();
		var value = jQuery('#select-social-account-log-type').val();
		var from = jQuery('#social-account-log-from-date').val();
		var to = jQuery('#social-account-log-to-date').val();
		var currnet_date = jQuery('#social-current-date').val();
		if (to==null || to=='' || to==undefined) to = currnet_date;
		if (to!=null && to!='' && to!=undefined) to = to + ' 23:59:59';
		if (from!=null && from!='' && from!=undefined) from = from + ' 00:00:00';
		jQuery('#maxv-social-acounts-log-table tr:gt(0)').each(function() {
			var dat = jQuery(this).find(".logdatelog").text();
			if (dat>=from && dat<=to && (value=='' || value=='0' || value==0 || jQuery(this).hasClass('social-account-type-'+value))) 
				jQuery(this).show();
			else 
				jQuery(this).hide();
		});
		var link_base = jQuery('#social-log-export-link-field').val();
		link_base = link_base+'?type='+value+'&from='+from+'&to='+to;
		jQuery('#social-log-export-link').attr('href',link_base);
		//alert(jQuery('#social-log-export-link').attr('id') + ' - ' + jQuery('#social-log-export-link').attr('href'));
	});
	jQuery('#social-account-log-to-date').change(function(){
		jQuery('#social-account-log-from-date').change();
	});
	
	// form account type change
	jQuery('#select-social-account-type-form').change(function(){
		jQuery('#maxv-social-accounts-form-networks').empty();
		var acc_type = jQuery(this).val().replace(' ','');
		acc_type = acc_type.replace('.','');
		if (acc_type!=null && acc_type!='' && acc_type!=0) {
			var formMethod = "getFormContent_"+acc_type;			
			jQuery('#maxv-social-accounts-form-networks').append(window[formMethod]());
			onOffSocialRadio('social-acc-auto-share');
			onOffSocialRadio('social-acc-attach-images');
			onOffSocialRadio('social-acc-shared-acount');
			onOffSocialRadio('social-acc-spin-content');
			onOffSocialRadio('social-acc-nsfw');
			onOffSocialRadio('slm-2nd-tier-acc');
			if(acc_type=='tumblr') {
				if (jQuery("#inputTumblrToken").val()=='' || jQuery("#inputTumblrTokenSecret").val()=='') {
					jQuery("#maxv-social-test-data-div").hide();
				}
			}
		}
		/*hideAllAccountTypesForm();
		jQuery('#maxv-social-form-div-'+value).show();
		*/
		
	});

	//re-send failed posts
	jQuery.fn.RescheduleFailedPosts = function() {
		var data = {
				who: 'slm',
				action: 'ajax_reschedule_failed_submissions'
		}
		jQuery('#submission-wait-loading-wait').show();
		jQuery.post(ajaxurl, data, function(response) {			
			if (response!=null) {
				jQuery('#submission-wait-loading-wait').hide();
				alert('Done');
			}
		});
	}

	//send posts to backlinksindexer
	jQuery.fn.SendPostsToBI = function() {
		var count = jQuery('#number-of-links-for-bi').val();
		if (count>0) {
			var data = {
					who: 'slm',
					action: 'ajax_submit_to_bi',
					count: count
			}
			jQuery('#bi-submission-wait-loading-wait').show();
			jQuery.post(ajaxurl, data, function(response) {			
				if (response!=null) {
					jQuery('#bi-submission-wait-loading-wait').hide();
					var ajaxResponse = jQuery.parseJSON(response);
					if (ajaxResponse['content']!=null && ajaxResponse['content']!='' && ajaxResponse['content']!='undefined') {
						var newContent = decodeURIComponent((ajaxResponse['content']+'').replace(/\+/g, '%20'));
						alert(newContent);
					} else {
						alert('Something went wrong');
					}
										
				}
			});
		} else {
			alert('Number of links should be greater than 0');
		}
	}
	
	// open modal for editing
	jQuery.fn.OpenAccountsEdit = function(id) {		
		jQuery('#myModalLabel').text('Add/Update Account');
		jQuery('#social-accouts-import-footer').hide();
		jQuery('#social-accouts-modal-footer').show();
		jQuery('#social-acccounts-modal-types-list').show();
		
		jQuery("#inputAccountId").val('');		
		if (id==null || id=='') id='';
		id = decodeURIComponent(id.replace(/\+/g, '%20'));
		if (id!=null && id!='') {
			var data = {
					who: 'slm',
					action: 'ajax_get_account_details',
					id: id
			}
			jQuery.post(ajaxurl, data, function(response) {
				if (response!=null) {
					var indexOf = response.indexOf('{');
					response = response.substr(indexOf);
					var ajaxResponse = jQuery.parseJSON(response);
					onOffSocialRadioInit('social-acc-post-external-content','false');
					onOffSocialRadioInit('social-acc-use-rss-feeds','false');
					onOffSocialRadioInit('social-acc-spin-content','false');
					onOffSocialRadioInit('slm-acc-videos-enabled','false');
					onOffSocialRadioInit('slm-acc-images-enabled','false');
					onOffSocialRadioInit('social-acc-use-article-builder','false');
					onOffSocialRadioInit('social-acc-use-article-builder-tips','false');
					
					onOffSocialRadio('social-acc-attach-images','false');
					if (ajaxResponse['id']!=null && ajaxResponse['id']!='') {
						var acc_type = ajaxResponse['type'].replace(' ','');
						acc_type = acc_type.replace('.','');
						jQuery('#maxv-social-accounts-form-networks').empty();
						var formMethod = "getFormContent_"+acc_type;
						if (ajaxResponse['type']=='plurk' && ajaxResponse.settings['pass']!=null && ajaxResponse.settings['pass']!='' && ajaxResponse.settings['pass']!='undefined' && ajaxResponse.settings['pass']!=undefined) {
							formMethod = formMethod + '_v1';
						}
						jQuery('#maxv-social-accounts-form-networks').append(window[formMethod]());
						onOffSocialRadio('social-acc-auto-share');
						onOffSocialRadio('social-acc-attach-images');						
						onOffSocialRadio('social-acc-shared-acount');
						onOffSocialRadio('social-acc-spin-content');						
						onOffSocialRadio('social-acc-nsfw');
						onOffSocialRadio('slm-2nd-tier-acc');
						jQuery("#inputAccountId").val(ajaxResponse['id']);
						//alert(ajaxResponse['type']+' - ' +ajaxResponse.settings['login'] + ' - ' + ajaxResponse.settings['pass']);
						switch (ajaxResponse['type']) {
							case 'twitter':
								jQuery("#inputTwitterAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputTwitterConsumerKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
								jQuery("#inputTwitterConsumerSecret").val(decodeURIComponent(ajaxResponse.settings['consumer_secret'].replace(/\+/g, '%20')));
								jQuery("#inputTwitterToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));
								jQuery("#inputTwitterTokenSecret").val(decodeURIComponent(ajaxResponse.settings['token_secret'].replace(/\+/g, '%20')));
								jQuery("#inputTwitterURL").val(decodeURIComponent(ajaxResponse.settings['url'].replace(/\+/g, '%20')));
								jQuery("#select-social-account-type-form").val(decodeURIComponent(ajaxResponse['type'].replace(/\+/g, '%20')));								
							break;						
							case 'tumblr':
								jQuery("#inputTumblrAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputTumblrConsumerKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
								jQuery("#inputTumblrConsumerSecret").val(decodeURIComponent(ajaxResponse.settings['consumer_secret'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token']!=null) jQuery("#inputTumblrToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token_secret']!=null) jQuery("#inputTumblrTokenSecret").val(decodeURIComponent(ajaxResponse.settings['token_secret'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['oauth_verifier']!=null) jQuery("#inputTumblrTokenVerification").val(decodeURIComponent(ajaxResponse.settings['oauth_verifier'].replace(/\+/g, '%20')));
								jQuery("#inputTumblrURL").val(decodeURIComponent(ajaxResponse.settings['url'].replace(/\+/g, '%20')));
								jQuery("#select-social-account-type-form").val(decodeURIComponent(ajaxResponse['type'].replace(/\+/g, '%20')));
								
								if (jQuery("#inputTumblrToken").val()=='' || jQuery("#inputTumblrTokenSecret").val()=='') {
									jQuery("#maxv-social-test-data-div").hide();
								}
							break;						
							case 'livejournal':
								jQuery("#inputLJAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputLJUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								//jQuery("#inputLJPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));
								jQuery("#inputLJPass").val(ajaxResponse.settings['pass']);
								jQuery("#select-social-account-type-form").val(decodeURIComponent(ajaxResponse['type'].replace(/\+/g, '%20')));								
							break;						
							case 'facebook':
								jQuery("#inputFacebookAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputFacebookPageID").val(decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20')));
								jQuery("#inputFacebookAppID").val(decodeURIComponent(ajaxResponse.settings['app_id'].replace(/\+/g, '%20')));
								jQuery("#inputFacebookAppSecret").val(decodeURIComponent(ajaxResponse.settings['app_secret'].replace(/\+/g, '%20')));								
								jQuery("#select-social-account-type-form").val(decodeURIComponent(ajaxResponse['type'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['user']!=null) jQuery("#inputFacebookUser").val(decodeURIComponent((''+ajaxResponse.settings['user']).replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token']!=null) jQuery("#inputFacebookToken").val(decodeURIComponent((''+ajaxResponse.settings['token']).replace(/\+/g, '%20')));
								if (ajaxResponse.settings['fb_code']!=null) jQuery("#inputFacebookCode").val(decodeURIComponent(ajaxResponse.settings['fb_code'].replace(/\+/g, '%20')));								
							break;
							case 'delicious' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['app_id']!=null) jQuery("#inputClientID").val(decodeURIComponent(ajaxResponse.settings['app_id'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['app_secret']!=null) jQuery("#inputClientSecret").val(decodeURIComponent(ajaxResponse.settings['app_secret'].replace(/\+/g, '%20')));																
								if (ajaxResponse.settings['auth_code']!=null) jQuery("#inputAuthCode").val(decodeURIComponent(ajaxResponse.settings['auth_code'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token']!=null) jQuery("#inputAccountToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['login']!=null) jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['pass']!=null) jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								//jQuery("#inputSocialAccountPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));																
							break;
							case 'pinterest' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								var boardId = decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20'));
								var boardName = decodeURIComponent(ajaxResponse.settings['page_name'].replace(/\+/g, '%20'));
								jQuery("#inputPinterestBoardID").empty();
								if (boardId!=null && boardId!='' && boardName!=null && boardName!='') {
									jQuery("#inputPinterestBoardID").append('<option value="'+boardId+'" selected>'+boardName+'</option>');
									jQuery("#inputPinterestBoardID").attr('disabled','disabled');
								}
							break;
							case 'youtube' :
							case 'rebelmouse' :
							case 'google plus' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								jQuery("#inputPageId").val(decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20')));
							break;
							case 'wordpress' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								if (ajaxResponse.settings['url']!=null) jQuery("#inputSocialAccountURL").val(decodeURIComponent(ajaxResponse.settings['url'].replace(/\+/g, '%20')));																
							break;
							case 'blog.com' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								if (ajaxResponse.settings['url']!=null) jQuery("#inputSocialAccountURL").val(decodeURIComponent(ajaxResponse.settings['url'].replace(/\+/g, '%20')));																
							break;
							case 'blogger' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								//jQuery("#inputSocialAccountURL").val(decodeURIComponent(ajaxResponse.settings['url'].replace(/\+/g, '%20')));																
								jQuery("#inputSocialAccountBlogID").val(decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20')));																
							break;
							case 'diigo' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								jQuery("#inputSocialAccountAPIKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));																
							break;
							case 'plurk' :
								if (ajaxResponse['name']!=null) jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['login']!=null) jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['pass']!=null) jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								if (ajaxResponse.settings['consumer_key']!=null) jQuery("#inputSocialAccountAPIKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
								//v2
								if (ajaxResponse.settings['consumer_key']!=null) jQuery("#inputSocialAccountAppKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['consumer_secret']!=null) jQuery("#inputSocialAccountAppSecret").val(decodeURIComponent(ajaxResponse.settings['consumer_secret'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['url']!=null) jQuery("#inputSocialAccountURL").val(decodeURIComponent(ajaxResponse.settings['url'].replace(/\+/g, '%20')));																
								if (ajaxResponse.settings['token']!=null) jQuery("#inputSocialAccountToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token_secret']!=null) jQuery("#inputSocialAccountTokenSecret").val(decodeURIComponent(ajaxResponse.settings['token_secret'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['oauth_verifier']!=null && ajaxResponse.settings['oauth_verifier']!=undefined) jQuery("#inputSocialAccountTokenVerification").val(decodeURIComponent(ajaxResponse.settings['oauth_verifier'].replace(/\+/g, '%20')));
							break;
							case 'zotero' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountAPIKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));																
							break;
							case 'stumbleupon' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								jQuery("#inputSocialAccountBoardID").val(decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20')));																
							break;
							case 'bitly' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));																
							break;
							case 'flickr':
							case 'scoop.it' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountAppKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountAppSecret").val(decodeURIComponent(ajaxResponse.settings['consumer_secret'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPageId").val(decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token']!=null) jQuery("#inputSocialAccountToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token_secret']!=null) jQuery("#inputSocialAccountTokenSecret").val(decodeURIComponent(ajaxResponse.settings['token_secret'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountTokenVerification").val(decodeURIComponent(ajaxResponse.settings['oauth_verifier'].replace(/\+/g, '%20')));
							break;
							/*case 'reddit' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));
							break;*/
							case 'kippt' :
							case 'sett' :
								/*jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));*/																
								jQuery("#inputSocialAccountPageId").val(decodeURIComponent(ajaxResponse.settings['page_id'].replace(/\+/g, '%20')));
							//break;
							case 'instapaper' :
								/*jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));																
							break;*/
							case 'deviantart' :
								/*jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));																
							break;*/
							case 'friendfeed' :
								/*jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(decodeURIComponent(ajaxResponse.settings['pass'].replace(/\+/g, '%20')));																
							break;*/
							case 'folkd' :
							case 'tribe' :
								jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
							break;
							case 'xing':
							case 'docdroid':
							case 'issuu':
							case 'scribd':
							case 'sendspace':
							case 'gett':
								//use for everything else with testing values
								if (ajaxResponse['name']!=null) jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['login']!=null) jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['login'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['user']!=null) jQuery("#inputSocialAccountUser").val(decodeURIComponent(ajaxResponse.settings['user'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['pass']!=null) jQuery("#inputSocialAccountPass").val(ajaxResponse.settings['pass']);																
								if (ajaxResponse.settings['consumer_key']!=null) jQuery("#inputSocialAccountAppKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['consumer_secret']!=null) jQuery("#inputSocialAccountAppSecret").val(decodeURIComponent(ajaxResponse.settings['consumer_secret'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token']!=null) jQuery("#inputAccountToken").val(decodeURIComponent(ajaxResponse.settings['token'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['token_secret']!=null) jQuery("#inputSocialAccountTokenSecret").val(decodeURIComponent(ajaxResponse.settings['token_secret'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['auth_code']!=null) jQuery("#inputAuthCode").val(decodeURIComponent(ajaxResponse.settings['auth_code'].replace(/\+/g, '%20')));
								if (ajaxResponse.settings['oauth_verifier']!=null) jQuery("#inputSocialAccountTokenVerification").val(decodeURIComponent(ajaxResponse.settings['oauth_verifier'].replace(/\+/g, '%20')));
							break;
						}
						if (ajaxResponse.settings['share_category']!=null) jQuery("#inputSocialAccountShareCategory").val(decodeURIComponent(ajaxResponse.settings['share_category'].replace(/\+/g, '%20')));
						jQuery("#select-social-account-type-form").val(decodeURIComponent(ajaxResponse['type'].replace(/\+/g, '%20')));
						jQuery('#select-social-account-type-form').prop('disabled', 'disabled');
						jQuery("#inputAccountMaxPosts").val(decodeURIComponent(ajaxResponse['max_posts'].replace(/\+/g, '%20')));
						jQuery("#inputAccountMaxPostsHours").val(decodeURIComponent(ajaxResponse['max_posts_hours'].replace(/\+/g, '%20')));
						if (ajaxResponse.max_posts_ext!=null) jQuery("#inputAccountMaxPostsExt").val(decodeURIComponent(ajaxResponse.max_posts_ext.replace(/\+/g, '%20')));
						if (ajaxResponse.max_posts_hours_ext!=null) jQuery("#inputAccountMaxPostsHoursExt").val(decodeURIComponent(ajaxResponse.max_posts_hours_ext.replace(/\+/g, '%20')));
						if (ajaxResponse.settings['title_format']!=null) jQuery("#inputTitleFormat").val(ajaxResponse.settings['title_format'].replace(/\+/g, '%20'));
						if (ajaxResponse.settings['content_format']!=null) jQuery("#inputContentFormat").val(ajaxResponse.settings['content_format'].replace(/\+/g, '%20'));
						
						//jQuery('#EditSocialAccount').appendTo("body").modal('show');
						$('#EditSocialAccount').modal('show');
						onOffSocialRadioInit('social-acc-auto-share',ajaxResponse.auto_share);
						if (ajaxResponse.settings['attach_image']!=null) onOffSocialRadioInit('social-acc-attach-images',ajaxResponse.settings['attach_image']);
						else onOffSocialRadioInit('social-acc-attach-images','false');
						//if (ajaxResponse.settings['use_article_builder']!=null) onOffSocialRadioInit('social-acc-use-article-builder',ajaxResponse.settings['use_article_builder']);
						
						if (ajaxResponse.settings['url_shortener']!=null) jQuery('#social-acc-url-shortener').val(ajaxResponse.settings['url_shortener']);
						else jQuery('#social-acc-url-shortener').val('');

						if (ajaxResponse.settings['use_rss_feeds']!=null) onOffSocialRadioInit('social-acc-use-rss-feeds',ajaxResponse.settings['use_rss_feeds']);
						else onOffSocialRadioInit('social-acc-use-rss-feeds','false');
						if (ajaxResponse.settings['spin_content']!=null) onOffSocialRadioInit('social-acc-spin-content',ajaxResponse.settings['spin_content']);
						else onOffSocialRadioInit('social-acc-spin-content','false');
						if (ajaxResponse.settings['videos_enabled']!=null) onOffSocialRadioInit('slm-acc-videos-enabled',ajaxResponse.settings['videos_enabled']);
						else onOffSocialRadioInit('slm-acc-videos-enabled','false');
						if (ajaxResponse.settings['images_enabled']!=null) onOffSocialRadioInit('slm-acc-images-enabled',ajaxResponse.settings['images_enabled']);						
						else onOffSocialRadioInit('slm-acc-images-enabled','false');
						if (ajaxResponse.settings['use_article_builder']!=null) onOffSocialRadioInit('social-acc-use-article-builder',ajaxResponse.settings['use_article_builder']);
						else onOffSocialRadioInit('social-acc-use-article-builder','false');
						if (ajaxResponse.settings['use_article_builder_tips']!=null) onOffSocialRadioInit('social-acc-use-article-builder-tips',ajaxResponse.settings['use_article_builder_tips']);						
						else onOffSocialRadioInit('social-acc-use-article-builder-tips','false');
						if (ajaxResponse.auto_share_ext!=null) onOffSocialRadioInit('social-acc-post-external-content',ajaxResponse.auto_share_ext);
						else onOffSocialRadioInit('social-acc-post-external-content','false');
						if (ajaxResponse.second_tire!=null) onOffSocialRadioInit('slm-2nd-tier-acc',ajaxResponse.second_tire);						
						else onOffSocialRadioInit('slm-2nd-tier-acc','false');
						
						onOffSocialRadioInit('social-acc-shared-acount',ajaxResponse.shared_account);						
						if (ajaxResponse.settings['NSFW']!=null) onOffSocialRadioInit('social-acc-nsfw',ajaxResponse.settings['NSFW']);						
						else onOffSocialRadioInit('social-acc-nsfw','false');
					}				
				}
			});
		} else {
			jQuery('#maxv-social-accounts-form-networks').empty();
			jQuery("#select-social-account-type-form").val('0');
			jQuery("#inputAccountMaxPosts").val('1');
			jQuery("#inputAccountMaxPostsHours").val('8');						
			jQuery('#select-social-account-type-form').prop('disabled', false);

			onOffSocialRadioInit('social-acc-post-external-content','false');
			onOffSocialRadioInit('social-acc-use-rss-feeds','false');
			onOffSocialRadioInit('social-acc-spin-content','false');
			onOffSocialRadioInit('slm-acc-videos-enabled','false');
			onOffSocialRadioInit('slm-acc-images-enabled','false');
			onOffSocialRadioInit('social-acc-use-article-builder','false');
			onOffSocialRadioInit('social-acc-use-article-builder-tips','false');

			//jQuery('#EditSocialAccount').appendTo("body").modal('show');
			$('#EditSocialAccount').modal('show');
		}
	}
	
	jQuery.fn.showImportDialog = function(){
		jQuery('#myModalLabel').text('Import Accounts');
		jQuery('#social-accouts-modal-footer').hide();
		jQuery('#social-acccounts-modal-types-list').hide();
		jQuery('#social-accouts-import-footer').show();
		jQuery('#maxv-social-accounts-form-networks').empty();
		jQuery('#maxv-social-accounts-form-networks').append(window["getFormContent_Import"]());
		$('#EditSocialAccount').modal('show');
	}
	
	//load pinterest boards
	jQuery.fn.loadPinterestBoards = function(){
		var user = jQuery('#inputSocialAccountUser').val();
		var pass = jQuery('#inputSocialAccountPass').val();
		if (user==null || pass==null || user=='' || pass=='') {
			alert('Please enter user name and password');
		} else {
			jQuery('#pinterest-boards-loading-wait').show();
			var data = {
					who: 'slm',
					action: 'ajax_load_pinterest_boards',
					user: encodeURIComponent(user),
					pass: encodeURIComponent(pass)
			}
			jQuery.post(ajaxurl, data, function(response) {
				if (response!=null) {
					//alert(response);
					jQuery('#pinterest-boards-loading-wait').hide();
					var ajaxResponse = jQuery.parseJSON(response);
					if (ajaxResponse['error']!=null && ajaxResponse['error']!='') {
						var newContent = decodeURIComponent((ajaxResponse['content']+'').replace(/\+/g, '%20'));
						alert(newContent);
					} else {
						if (ajaxResponse['content']!=null && ajaxResponse['content']!='' && ajaxResponse['content']!='undefined') {
							var newContent = decodeURIComponent((ajaxResponse['content']+'').replace(/\+/g, '%20'));
							jQuery("#inputPinterestBoardID").empty().append(newContent);
							jQuery("#inputPinterestBoardID").attr('disabled',false);
						}
					}
				}
			});
			
		}
	}
	
	// save social account
	jQuery('#btn-save-social-account').click(function() {		
		var social_account_type = jQuery('#select-social-account-type-form').val();
		//alert(social_account_type);
		if (social_account_type!=null && social_account_type!='') {
			var bul = true;
			jQuery( ':input[required]', '#maxv-edit-social-accounts-form' ).each( function () {
			    if ( bul && this.value.trim() === '' ) {
			        bul = false;
			    }
			});
			//alert(bul);
			if (bul) {
				var accountData = getAcccountFormData();
				if (accountData.social_account_name!=null && accountData.social_account_name!='' && accountData.social_account_name!=undefined && accountData.social_account_name!='undefined') {
					//alert(accountData.social_account_name+ ' - ' + accountData.app_id + ' - '+accountData.url);
					//alert(accountData.title_format);
					var data = {
							who: 'slm',
						action: 'ajax_save_account',
						social_account_id: accountData.social_account_id,
						social_account_name: accountData.social_account_name,
						social_account_type: accountData.social_account_type,
						auto_share: accountData.auto_share,
						shared_account: accountData.shared_account,
						max_posts: accountData.max_posts,
						max_posts_hours: accountData.max_posts_hours,
						title_format: accountData.title_format,
						content_format: accountData.content_format,					
						consumer_key: accountData.consumer_key,
						consumer_secret: accountData.consumer_secret,
						token: accountData.token,
						token_secret: accountData.token_secret,
						oauth_verifier: accountData.oauth_verifier,
						login: accountData.login,
						pass: accountData.pass,
						url: accountData.url,
						user: accountData.user,
						page_id: accountData.page_id,
						page_name: accountData.page_name,
						app_id: accountData.app_id,
						app_secret: accountData.app_secret,
						fb_code: accountData.fb_code,
						auth_code: accountData.auth_code,
						share_category: accountData.share_category,
						NSFW: accountData.NSFW,
						attach_image: accountData.attach_image,
						auto_share_ext: accountData.auto_share_ext,
						use_article_builder: accountData.use_article_builder,
						use_article_builder_tips: accountData.use_article_builder_tips,
						use_rss_feeds: accountData.use_rss_feeds,
						spin_content: accountData.spin_content,
						videos_enabled: accountData.videos_enabled,
						images_enabled: accountData.images_enabled,
						max_posts_ext: accountData.max_posts_ext,
						max_posts_hours_ext: accountData.max_posts_hours_ext,
						second_tire:accountData.second_tire,
						url_shortener:accountData.url_shortener
					}
										
					
					jQuery.post(ajaxurl, data, function(response) {
						if (response!=null) {
							var indexOf = response.indexOf('{');
							response = response.substr(indexOf);
							//alert(response);
							
							var ajaxResponse = jQuery.parseJSON(response);
							var newContent = '';
							if (ajaxResponse['content']!=null && ajaxResponse['content']!='' && ajaxResponse['content']!='undefined') {
								newContent = decodeURIComponent((ajaxResponse['content']+'').replace(/\+/g, '%20'));
								if (ajaxResponse['error']!=null && ajaxResponse['error']!='' && ajaxResponse['error']!='undefined') {
									alert(newContent);
								} else {
									jQuery("#maxv-social-accounts-container").html(newContent);
								}
							}
							//jQuery('#EditSocialAccount').modal('toggle');
							$('#EditSocialAccount').modal('toggle');
							jQuery('#select-social-account-type').change();
	
						}
					});
				} else {
					alert('Cannot save this account');
				}
			}
		}
	}); // jQuery('#btn-save-social-account').click(...)
	
	
	jQuery.fn.DeleteAccount = function(id) {
		if (id!=null && id!='') {
			if (confirm('Are you sure you wand to delete this account?')) {
				var data = {
						who: 'slm',
						action: 'ajax_delete_account',
						id: encodeURIComponent(id)
					};
				jQuery.post(ajaxurl, data, function(response) {
					if (response!=null) {
						var indexOf = response.indexOf('{');
						response = response.substr(indexOf);
						//alert(response);
						var ajaxResponse = jQuery.parseJSON(response);
						if (ajaxResponse['content']!=null && ajaxResponse['content']!='' && ajaxResponse['content']!='undefined') {
							var newContent = decodeURIComponent((ajaxResponse['content']+'').replace(/\+/g, '%20'));
							jQuery("#maxv-social-accounts-container").html(newContent);
						} else {
							jQuery("#maxv-social-accounts-container").html('');
						}
					}
				});
			}
		}
	}
	
	jQuery.fn.RescheduleAccount = function(id) {
		if (id!=null && id!='') {
			if (confirm('Are you sure you wand to reset posts for this account?')) {
				var data = {
						who: 'slm',
						action: 'ajax_reset_account',
						id: encodeURIComponent(id)
					};
				jQuery.post(ajaxurl, data, function(response) {
					if (response!=null) {
						//alert(response);
						alert('The account has been reset!');
					}
				});
			}
		}
	}	
	
	//jQuery('#btn-social-account-test-post').click(function() {
	jQuery.fn.TestTwitterPost = function() {
		var accountData = getAcccountFormData();
		accountData.title = encodeURIComponent(jQuery("#inputTestTitle").val());
		accountData.content = encodeURIComponent(jQuery("#inputTestContent").val());
		accountData.tags = encodeURIComponent(jQuery("#inputTestTags").val());
		accountData.source = encodeURIComponent(jQuery("#inputTestURL").val());		
		accountData.image = encodeURIComponent(jQuery("#inputTestURL").val());
		//alert(accountData.consumer_key);
		//alert(JSON.stringify(accountData));
		var data = {
			who: 'slm',
			action: 'ajax_test_account',
			data: encodeURIComponent(JSON.stringify(accountData))
		}
		jQuery('#maxv-social-test-wait').show();
		jQuery.post(ajaxurl, data, function(response) {
			if (response!=null) {
				//alert(response);
				jQuery('#maxv-social-test-wait').hide();
				var ajaxResponse = jQuery.parseJSON(response);
				if (ajaxResponse['content']!=null && ajaxResponse['content']!='' && ajaxResponse['content']!='undefined') {
					var newContent = decodeURIComponent((ajaxResponse['content']+'').replace(/\+/g, '%20'));
					alert(newContent);
				} else {
					alert('There was an error while posting to this account');
				}
				
			}
		}); // jQuery.post(...)
	}
	//}); //jQuery('#btn-social-account-test-post').click(...)
	
	jQuery.fn.SLMOAuthAuthorize = function(id,type,callback) {
		//alert(id+' - '+type+' - '+callback);
		var accountData = getAcccountFormData();
		var data = {
				who: 'slm',
				action: 'ajax_authorize_social_account',
				id: id,
				type: type,
				callback: callback
			}
		jQuery.post(ajaxurl, data, function(response) {
			if (response!=null) {
				//alert(response);
				var ajaxResponse = jQuery.parseJSON(response);
				var ajaxResponse = jQuery.parseJSON(response);
				if (ajaxResponse['error']!=null && ajaxResponse['error']!='' && ajaxResponse['error']!='undefined') {
					var newContent = decodeURIComponent((ajaxResponse['error']+'').replace(/\+/g, '%20'));
					alert(newContent);
				} else if (ajaxResponse['url']!=null && ajaxResponse['url']!='' && ajaxResponse['url']!='undefined') {
					var url = decodeURIComponent((ajaxResponse['url']+'').replace(/\+/g, '%20'));
					//alert('URL: '+url);
					window.location = url;
				}
				
			}
		});
	}
	
	//Tumblr authorize
	jQuery.fn.AuthorizeTumblr = function(id,callback) {
		var accountData = getAcccountFormData();
		//alert(JSON.stringify(accountData));
		/*if (	accountData.consumer_key!=null && accountData.consumer_key!='' &&
				accountData.consumer_secret!=null && accountData.consumer_secret!='' &&
				accountData.url!=null && accountData.url!='') {
			
			accountData.callback = encodeURIComponent(jQuery("#inputTumblrCallback").val())+'&tumblr=1';*/
			
			var data = {
				who: 'slm',
				action: 'ajax_authorize_tumblr_account',
				id: id,
				callback: callback
			}
	
			jQuery.post(ajaxurl, data, function(response) {
				if (response!=null) {
					//alert(response);
					var ajaxResponse = jQuery.parseJSON(response);
					if (ajaxResponse['error']!=null && ajaxResponse['error']!='' && ajaxResponse['error']!='undefined') {
						var newContent = decodeURIComponent((ajaxResponse['error']+'').replace(/\+/g, '%20'));
						alert(newContent);
					} else if (ajaxResponse['url']!=null && ajaxResponse['url']!='' && ajaxResponse['url']!='undefined') {
						var url = decodeURIComponent((ajaxResponse['url']+'').replace(/\+/g, '%20'));
						//alert('URL: '+url);
						window.location = url;
					}
					
				}
			}); // jQuery.post(...)
		//} //if for accountData
	}
	
    jQuery('#slm-posts-log-checkbox').click(function(event) {  //on click
        if(this.checked) { // check select status
            jQuery('.slm-post-log-checkbox').each(function() { //loop through each checkbox
                this.checked = true;  //select all checkboxes with class "checkbox1"              
            });
        }else{
            jQuery('.slm-post-log-checkbox').each(function() { //loop through each checkbox
                this.checked = false; //deselect all checkboxes with class "checkbox1"                      
            });        
        }
    });

    if (jQuery('.datepicker').datepicker) {
    	jQuery('.datepicker').datepicker({format:'yyyy-mm-dd',autoclose: true});
    }
		
}); //jQuery(document).ready(...)


function getAcccountFormData () {
	var data = {};
	data.social_account_type = jQuery('#select-social-account-type-form').val();
	data.social_account_id = encodeURIComponent(jQuery("#inputAccountId").val());	

	data.social_account_name = encodeURIComponent(jQuery("#inputSocialAccountName").val());
	data.login = encodeURIComponent(jQuery("#inputSocialAccountUser").val());
	data.pass = encodeURIComponent(jQuery("#inputSocialAccountPass").val());
	data.attach_image = '';
	
	if (jQuery('#inputSocialAccountShareCategory').length>0) {		
		data.share_category = jQuery('#inputSocialAccountShareCategory').val();
	} else {
		data.share_category = '';
	}
	
	var social_account_name='';
	var consumer_key='';
	var consumer_secret='';
	var token='';
	var token_secret='';
	var login='';
	var pass='';
	var url='';
	data.NSFW = 'false';
	//alert(data.social_account_type);
	switch (data.social_account_type) {
	case 'twitter':
		data.social_account_name = encodeURIComponent(jQuery("#inputTwitterAccountName").val());
		data.consumer_key = encodeURIComponent(jQuery("#inputTwitterConsumerKey").val());
		data.consumer_secret = encodeURIComponent(jQuery("#inputTwitterConsumerSecret").val());
		data.token = encodeURIComponent(jQuery("#inputTwitterToken").val());
		data.token_secret = encodeURIComponent(jQuery("#inputTwitterTokenSecret").val());
		data.url = encodeURIComponent(jQuery("#inputTwitterURL").val());
	break;
	case 'tumblr':
		data.social_account_name = encodeURIComponent(jQuery("#inputTumblrAccountName").val());
		data.consumer_key = encodeURIComponent(jQuery("#inputTumblrConsumerKey").val());
		data.consumer_secret = encodeURIComponent(jQuery("#inputTumblrConsumerSecret").val());
		data.token = encodeURIComponent(jQuery("#inputTumblrToken").val());
		data.token_secret = encodeURIComponent(jQuery("#inputTumblrTokenSecret").val());
		data.url = encodeURIComponent(jQuery("#inputTumblrURL").val());
		data.oauth_verifier  = encodeURIComponent(jQuery("#inputTumblrTokenVerification").val());
	break;
	case 'livejournal':
		data.social_account_name = encodeURIComponent(jQuery("#inputLJAccountName").val());
		data.login = encodeURIComponent(jQuery("#inputLJUser").val());
		data.pass = encodeURIComponent(jQuery("#inputLJPass").val());
	break;
	case 'facebook':
		data.social_account_name = encodeURIComponent(jQuery("#inputFacebookAccountName").val());
		data.page_id = encodeURIComponent(jQuery("#inputFacebookPageID").val());
		data.app_id = encodeURIComponent(jQuery("#inputFacebookAppID").val());
		data.app_secret = encodeURIComponent(jQuery("#inputFacebookAppSecret").val());
		data.user = encodeURIComponent(jQuery("#inputFacebookUser").val());
		data.token = encodeURIComponent(jQuery("#inputFacebookToken").val());
		data.fb_code = encodeURIComponent(jQuery("#inputFacebookCode").val());
	break;
	case 'delicious':
		data.social_account_name = encodeURIComponent(jQuery("#inputSocialAccountName").val());
		data.app_id = encodeURIComponent(jQuery("#inputClientID").val());
		data.app_secret = encodeURIComponent(jQuery("#inputClientSecret").val());
		data.auth_code = encodeURIComponent(jQuery("#inputAuthCode").val());
		data.token = encodeURIComponent(jQuery("#inputAccountToken").val());
	break;
	case 'reddit':
		data.social_account_name = encodeURIComponent(jQuery("#inputSocialAccountName").val());
		data.login = encodeURIComponent(jQuery("#inputSocialAccountUser").val());
		data.pass = encodeURIComponent(jQuery("#inputSocialAccountPass").val());
	break;
	case 'pinterest':
		data.social_account_name = encodeURIComponent(jQuery("#inputSocialAccountName").val());
		data.login = encodeURIComponent(jQuery("#inputSocialAccountUser").val());
		data.pass = encodeURIComponent(jQuery("#inputSocialAccountPass").val());
		data.page_id = encodeURIComponent(jQuery("#inputPinterestBoardID").val());
		data.page_name = encodeURIComponent(jQuery("#inputPinterestBoardID option:selected").text());
	break;
	case 'google plus':
	case 'youtube':
	case 'rebelmouse':
		data.social_account_name = encodeURIComponent(jQuery("#inputSocialAccountName").val());
		data.login = encodeURIComponent(jQuery("#inputSocialAccountUser").val());
		data.pass = encodeURIComponent(jQuery("#inputSocialAccountPass").val());
		data.page_id = encodeURIComponent(jQuery("#inputPageId").val());
	break;
	case 'wordpress':
		data.url = encodeURIComponent(jQuery("#inputSocialAccountURL").val());
	case 'blog.com':
		data.url = encodeURIComponent(jQuery("#inputSocialAccountURL").val());
	break;
	case 'blogger':
		//data.url = encodeURIComponent(jQuery("#inputSocialAccountURL").val());
		data.page_id = encodeURIComponent(jQuery("#inputSocialAccountBlogID").val());
	break;
	case 'friendfeed':
	break;
	case 'diigo': 
		data.consumer_key = encodeURIComponent(jQuery("#inputSocialAccountAPIKey").val());
	break;	
	case 'plurk': 
		if (jQuery("#inputSocialAccountAPIKey").length>0) {
			data.consumer_key = encodeURIComponent(jQuery("#inputSocialAccountAPIKey").val());
		} else {
			data.url = encodeURIComponent(jQuery("#inputSocialAccountURL").val());
			data.consumer_key = encodeURIComponent(jQuery("#inputSocialAccountAppKey").val());
			data.consumer_secret = encodeURIComponent(jQuery("#inputSocialAccountAppSecret").val());
			data.token = encodeURIComponent(jQuery("#inputSocialAccountToken").val());
			data.token_secret = encodeURIComponent(jQuery("#inputSocialAccountTokenSecret").val());
			data.oauth_verifier  = encodeURIComponent(jQuery("#inputSocialAccountTokenVerification").val());
		}
	break;	
	case 'zotero': 
		data.consumer_key = encodeURIComponent(jQuery("#inputSocialAccountAPIKey").val());
	break;	
	case 'stumbleupon':
		data.page_id = encodeURIComponent(jQuery("#inputSocialAccountBoardID").val());
		data.NSFW = encodeURIComponent(jQuery("#social-acc-nsfw-hidden").val());
	break;
	case 'instapaper':
	break;
	case 'deviantart':
	break;
	case 'bitly':
		data.token = encodeURIComponent(jQuery("#inputSocialAccountToken").val());
	break;
	case 'flickr':
	case 'scoop.it':
		data.page_id = encodeURIComponent(jQuery("#inputSocialAccountPageId").val());
		data.consumer_key = encodeURIComponent(jQuery("#inputSocialAccountAppKey").val());
		data.consumer_secret = encodeURIComponent(jQuery("#inputSocialAccountAppSecret").val());
		data.token = encodeURIComponent(jQuery("#inputSocialAccountToken").val());
		data.token_secret = encodeURIComponent(jQuery("#inputSocialAccountTokenSecret").val());
		data.oauth_verifier  = encodeURIComponent(jQuery("#inputSocialAccountTokenVerification").val());
	break;
	case 'sett':
	case 'kippt':
		data.page_id = encodeURIComponent(jQuery("#inputSocialAccountPageId").val());
	break;
	case 'folkd':
	case 'tribe':
	break;
	
	case 'xing':
	case 'docdroid':
	case 'issuu':
	case 'scribd':
	case 'sendspace':
	case 'gett':
		//use for everything else with testing values
		if (jQuery('#inputSocialAccountUser').length>0) {data.login = encodeURIComponent(jQuery("#inputSocialAccountUser").val());data.user = data.login;}
		if (jQuery('#inputSocialAccountPass').length>0) data.pass = encodeURIComponent(jQuery("#inputSocialAccountPass").val());
		if (jQuery('#inputSocialAccountAppKey').length>0) data.consumer_key = encodeURIComponent(jQuery("#inputSocialAccountAppKey").val());
		if (jQuery('#inputSocialAccountAppSecret').length>0) data.consumer_secret = encodeURIComponent(jQuery("#inputSocialAccountAppSecret").val());
		if (jQuery('#inputAuthCode').length>0) data.auth_code = encodeURIComponent(jQuery("#inputAuthCode").val());
		if (jQuery('#inputAccountToken').length>0) data.token = encodeURIComponent(jQuery("#inputAccountToken").val());
		if (jQuery('#inputSocialAccountTokenSecret').length>0) data.token_secret = encodeURIComponent(jQuery("#inputSocialAccountTokenSecret").val());
		if (jQuery('#inputSocialAccountTokenVerification').length>0) data.oauth_verifier  = encodeURIComponent(jQuery("#inputSocialAccountTokenVerification").val());
		//if (ajaxResponse['name']!=null) jQuery("#inputSocialAccountName").val(decodeURIComponent(ajaxResponse['name'].replace(/\+/g, '%20')));
		//if (ajaxResponse.settings['consumer_key']!=null) jQuery("#inputSocialAccountAppKey").val(decodeURIComponent(ajaxResponse.settings['consumer_key'].replace(/\+/g, '%20')));
		//if (ajaxResponse.settings['consumer_secret']!=null) jQuery("#inputSocialAccountAppSecret").val(decodeURIComponent(ajaxResponse.settings['consumer_secret'].replace(/\+/g, '%20')));
		
	break;
	
	}
	
	
	data.videos_enabled = '';
	data.images_enabled = '';
	data.use_rss_feeds = '';
	data.spin_content = '';
	data.second_tire = 'false'
	data.auto_share = jQuery('#social-acc-auto-share').find('button.active').attr('value');
	data.shared_account = encodeURIComponent(jQuery("#social-acc-shared-acount-hidden").val());
	data.max_posts = encodeURIComponent(jQuery("#inputAccountMaxPosts").val());
	data.max_posts_hours = encodeURIComponent(jQuery("#inputAccountMaxPostsHours").val());
	data.title_format = encodeURIComponent(jQuery("#inputTitleFormat").val());
	data.content_format = encodeURIComponent(jQuery("#inputContentFormat").val());
	
	if (jQuery('#social-acc-attach-images-hidden').length>0) data.attach_image = jQuery('#social-acc-attach-images-hidden').val();
	//external content
	if (jQuery('#social-acc-post-external-content-hidden').length>0) data.auto_share_ext = jQuery('#social-acc-post-external-content-hidden').val();
	if (jQuery('#social-acc-use-article-builder-hidden').length>0) data.use_article_builder = jQuery('#social-acc-use-article-builder-hidden').val();
	if (jQuery('#social-acc-use-article-builder-tips-hidden').length>0) data.use_article_builder_tips = jQuery('#social-acc-use-article-builder-tips-hidden').val();
	
	if (jQuery('#social-acc-use-rss-feeds-hidden').length>0) data.use_rss_feeds = jQuery('#social-acc-use-rss-feeds-hidden').val();
	if (jQuery('#social-acc-url-shortener').length>0) data.url_shortener = jQuery('#social-acc-url-shortener').val();
	
	if (jQuery('#social-acc-spin-content-hidden').length>0) data.spin_content = jQuery('#social-acc-spin-content-hidden').val();
	if (jQuery('#slm-acc-videos-enabled-hidden').length>0) data.videos_enabled = jQuery('#slm-acc-videos-enabled-hidden').val();
	if (jQuery('#slm-acc-images-enabled-hidden').length>0) data.images_enabled = jQuery('#slm-acc-images-enabled-hidden').val();
	if (jQuery('#slm-2nd-tier-acc-hidden').length>0) data.second_tire = jQuery('#slm-2nd-tier-acc-hidden').val();
	
	if (jQuery('#inputAccountMaxPostsExt').length>0) data.max_posts_ext = jQuery('#inputAccountMaxPostsExt').val();
	if (jQuery('#inputAccountMaxPostsHoursExt').length>0) data.max_posts_hours_ext = jQuery('#inputAccountMaxPostsHoursExt').val();

	return data;
}

/*function hideAllAccountTypesForm() {
	jQuery('.account_type_div').each(function() {
		jQuery(this).hide();
	});	
}*/

function onOffSocialRadio(controlId) {
	jQuery('#'+controlId+'-on').click(function(){
		//alert('onOffSocialRadio - on');
		jQuery(this).addClass('btn-success');
		jQuery(this).addClass('active');
		jQuery('#'+controlId+'-off').removeClass('btn-danger');
		jQuery('#'+controlId+'-off').removeClass('active');
		jQuery('#'+controlId+'-hidden').val('true');
	});
	jQuery('#'+controlId+'-off').click(function(){
		//alert('onOffSocialRadio - off');
		jQuery(this).addClass('btn-danger');
		jQuery(this).addClass('active');
		jQuery('#'+controlId+'-on').removeClass('btn-success');
		jQuery('#'+controlId+'-on').removeClass('active');
		jQuery('#'+controlId+'-hidden').val('false');
	});	
}

function onOffSocialSharePostRadio(controlId) {
	jQuery('#'+controlId+'-on').click(function(){
		var postId = jQuery('#'+controlId+'-id-hidden').val();
		var data = {
				who: 'slm',
				action: 'ajax_change_auto_share_post_option',
				id: postId,
				state: 'true'
		}
		jQuery.post(ajaxurl, data, function(response) {			
			if (response!=null) {
			}
		});
		jQuery(this).addClass('btn-success');
		jQuery(this).addClass('active');
		jQuery('#'+controlId+'-off').removeClass('btn-danger');
		jQuery('#'+controlId+'-off').removeClass('active');
		jQuery('#'+controlId+'-hidden').val('true');
		
	});
	jQuery('#'+controlId+'-off').click(function(){
		var postId = jQuery('#'+controlId+'-id-hidden').val();
		var data = {
				who: 'slm',
				action: 'ajax_change_auto_share_post_option',
				id: postId,
				state: 'false'
		}
		jQuery.post(ajaxurl, data, function(response) {			
			if (response!=null) {
			}
		});
		jQuery(this).addClass('btn-danger');
		jQuery(this).addClass('active');
		jQuery('#'+controlId+'-on').removeClass('btn-success');
		jQuery('#'+controlId+'-on').removeClass('active');
		jQuery('#'+controlId+'-hidden').val('false');
	});	
}

function onOffAutoShareRadio(controlId,accId,actionType) {
	jQuery('#'+controlId+'-on').click(function(){
		//var accId = controlId.replace('social-acc-auto-share-','');
		//accId = controlId.replace('slm-acc-second-tire-','');
		//alert(accId + ' - ' + actionType);
		jQuery(this).addClass('btn-success');
		jQuery(this).addClass('active');
		jQuery('#'+controlId+'-off').removeClass('btn-warning');
		jQuery('#'+controlId+'-off').removeClass('active');
		//jQuery('#'+controlId+'-hidden').val('true');
		var data = {
				who: 'slm',
				action: 'ajax_change_auto_share_option',
				actionType: actionType,
				id: accId,
				state: 'true'
		}
		jQuery.post(ajaxurl, data, function(response) {			
			if (response!=null) {
				//alert(response);
			}
		});
	});
	jQuery('#'+controlId+'-off').click(function(){
		//var accId = controlId.replace('social-acc-auto-share-','');
		//alert(accId);
		jQuery(this).addClass('btn-warning');
		jQuery(this).addClass('active');
		jQuery('#'+controlId+'-on').removeClass('btn-success');
		jQuery('#'+controlId+'-on').removeClass('active');
		//jQuery('#'+controlId+'-hidden').val('false');
		var data = {
				who: 'slm',
				action: 'ajax_change_auto_share_option',
				actionType: actionType,
				id: accId,
				state: 'false'
		}
		jQuery.post(ajaxurl, data, function(response) {			
			if (response!=null) {
			}
		});
		
	});	
}

function onOffSocialRadioInit(controlId,value) {
	if (jQuery('#'+controlId+'-on').length>0 && jQuery('#'+controlId+'-off').length) {
		if (value=='true') {
			jQuery('#'+controlId+'-on').addClass('btn-success');
			jQuery('#'+controlId+'-on').addClass('active');
			jQuery('#'+controlId+'-off').removeClass('btn-danger');
			jQuery('#'+controlId+'-off').removeClass('active');
			jQuery('#'+controlId+'-hidden').val('true');
			//jQuery('#'+controlId+'-on').click();
		} else if (value=='false') {
			jQuery('#'+controlId+'-off').addClass('btn-danger');
			jQuery('#'+controlId+'-off').addClass('active');
			jQuery('#'+controlId+'-on').removeClass('btn-success');
			jQuery('#'+controlId+'-on').removeClass('active');
			jQuery('#'+controlId+'-hidden').val('false');			
			//jQuery('#'+controlId+'-off').click();
		}
	}
}

function deleteLogItem(id) {
	if (id!=null && id!='') {
		if (confirm('Are you sure you wand to re-schedule this post?')) {
			var data = {
					who: 'slm',
					action: 'ajax_delete_log_item',
					id: encodeURIComponent(id)
				};
			jQuery('#submission-wait-loading-wait').show();
			jQuery.post(ajaxurl, data, function(response) {			
				if (response!=null) {
					jQuery('#submission-wait-loading-wait').hide();
					alert('Done');
				}
			});
		}
	}	
}


