// JavaScript Document
function searchArticle(siteUrl){
	//alert(siteUrl)
	var myField = document.getElementById('searchtag');
	var value1=myField.value;
	
	
	if(value1!=""){
		
		document.article.action=siteUrl+"blog/search_post";
		document.article.submit();
	}else{
		
		alert("please fill title field.");
		return false;	
		}
}
function searchmyArticle(siteUrl){
	
	var myField = document.getElementById('searchtag');
	var value1=myField.value;
	
	
	if(value1==""){
		alert("please fill title field.");
		return false;
	}else{
		document.article.action=siteUrl+"blog/search_user_post";
		document.article.submit();
			
		}
}
function searchfavArticle(siteUrl){
	
	var myField = document.getElementById('searchtag');
	var value1=myField.value;
	
	
	if(value1==""){
		alert("please fill title field.");
		return false;
	}else{
		document.article.action=siteUrl+"blog/search_fav_post";
		document.article.submit();
		}
}
function checkAll(name){
	 if($('#checkAll2').is(':checked'))
   {
      $(" INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
   }
   else
   {
      $(" INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
   }
}
function checkAllBlog(name){
	 if($('input#checkAllClass').is(':checked'))
   {
      $("#cat_list_id INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
   }
   else
   {
      $("#cat_list_id INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
   }
}

function add_blog_category(){
	if(document.getElementById('title').value==""){
		alert("Enter Category Title");
		document.getElementById('title').focus;
		return false;
	} else {
		document.catform.submit();
	}
	
}

function edit_blog_category(siteUrl){
	if(document.getElementById('title').value==""){
		alert("Enter Category Title");
		document.getElementById('title').focus;
		return false;
	} else {
		document.catform.action=siteUrl;
		document.catform.submit();
	}
	
}

function delete_my_blog(siteUrl) {
	
   if (confirm(MSG_DELETE_CONFIRMATION.replace('\%S\%', 'Blog'))) {	 
    document.location = siteUrl;
  }
}

function delete_my_blog_cate(siteUrl) {
	
   if (confirm(MSG_DELETE_CONFIRMATION.replace('\%S\%', 'Blog Category'))) {	 
    document.location = siteUrl;
  }
}

function delete_my_blog_tag(siteUrl) {
	
   if (confirm(MSG_DELETE_CONFIRMATION.replace('\%S\%', 'Blog Tag'))) {	 
    document.location = siteUrl;
  }
}

function add_blog_cat(siteUrl){
	//alert(siteUrl);
	
	var title=$('input#title').val();
	var parent_id=$('select#parent_id').val();
	if($('input#show_front').is(':checked'))
		var show_on_front=1;
	else
		show_on_front=0;
	
	var info = 'blog_title='+title+'&parent_id='+parent_id+'&show_on_front='+show_on_front;
	
	if(title==""){ 
	 $('#message_id').html("<div id='msg_div'>Please fill the category title</div>");
		 $('#msg_div').css('background-color','#9C6').animate({ opacity: "show" }, "slow");
	
	}else{
	$.ajax({
	type: "POST",
	url: siteUrl+"blog/create_blog",
	data: info,
	success: function(data) {
		//alert(data)
		location.reload();
		  $('#message_id').html("<div id='msg_div'>you have successfully added category</div>");
		$('#msg_div').css('background-color','#9C6').animate({ opacity: "show" }, "slow");
        document.cat.post_title.value="";
		$('#list_cat').html(data)  ; 
          }
	});
	}
	return false;
}

function edit_blog_cat(siteUrl,cat_id){
	var Url = $("input#url").val();
	var title=$('input#title').val();
	var parent_id=$('select#parent_id').val();
	if($('input#show_front').is(':checked'))
		var show_on_front=1;
	else
		show_on_front=0;
	var info = 'blog_title='+title+'&parent_id='+parent_id+'&cat_id='+cat_id+'&show_on_front='+show_on_front;
	//alert(info);
	if(title==""){
		 $('#message_id').html("<div id='msg_div'>Please fill the category title</div>");
		 $('#msg_div').css('background-color','#9C6').animate({ opacity: "show" }, "slow");
	}else{
		$.ajax({
		type: "POST",
		url: siteUrl+"blog/update_category",
		data: info,
		success: function(data) {
		   //alert(data)
		  window.location=siteUrl+"blog/main_category";
			 $('#message_id').html("<div id='msg_div'>you have successfully updated category</div>");
			$('#msg_div').css('background-color','#9C6').animate({ opacity: "show" }, "slow");
			$('#list_cat').html(data)  ; 
			  }
		});
	}
	return false;
}

function articleBulk(siteUrl){
	
	var action=document.getElementById('bulk_art').value;
	if(action !=0){
		var chks=document.getElementsByName('list[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++){
			if (chks[i].checked){
				hasChecked = true;
                break;
			}
 		}
 		if(hasChecked==true){
 			if (confirm("Are you sure you want to delete")) {
			document.forms.art_list.action = siteUrl+"blog/delete_bulk_post/"+action;
			document.forms.art_list.submit();
 			}
		
		} else {
 			alert("Please select atleast one Blog");
 		}
	}else{
			alert("Please select an action to be peroformed");
			return;
	}
}


function actiontagBulk(siteUrl){
	var action=document.getElementById('bulk').value;
	if(action !=0){
		var chks=document.getElementsByName('tag[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++){
			if (chks[i].checked){
				hasChecked = true;
                break;
			}
 		}
 		if(hasChecked==true){
			if (confirm("Are you sure you want to delete")) {
			document.forms.cat_list.action = siteUrl+"blog/bulk_delete_tag/"+action;
			document.forms.cat_list.submit();
			}
			} else {
 				alert("Please select atleast one tag");
 			}
		}else{
			alert("Please select an action to be peroformed");
			return;
		}
	}
function actionBulkBlogCategory(siteUrl){
	
	var action=document.getElementById('bulk').value;
	if(action !=0){
		var chks=document.getElementsByName('cat[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++){
			if (chks[i].checked){
				hasChecked = true;
                break;
			}
 		}
 		if(hasChecked==true){
			if (confirm("Are you sure you want to delete")) {
			document.forms.cat_list.action = siteUrl+"blog/bulk_action/"+action;
			document.forms.cat_list.submit();
			}
 		} else {
 			alert("Please select atleast one category");
 		}
	}else{
		alert("Please select Action");
		return;
		}	
}
function blog_comment_post(siteUrl){
	
	var post_id=$('input#post_id').val();
	var comment=$('textarea#comment').val();
	var info = 'post_id='+post_id+'&comment='+comment;
	$.ajax({
	type: "POST",
	url: siteUrl+"blog/article_comment",
	data: info,
	success: function(data) {
  	//alert(data);
	 $('#com_list').html(data)  ; 
	    $('#message_div').html("You have successfully added comment");
		/*$('#msg_div').css('background-color','#9C6').animate({ opacity: "show" }, "slow");*/
		document.post_comment.comment.value="";
		
		$('#one').hide() ;
          }
	});
	return false;
}

function confirmationBox(){
	return confirm("Are you sure you want to delete this item?");
}
function openBox(d){
	var ob=document.getElementById(d);
	ob.style.display=(ob.style.display=='none')?'block':'none';
}
	function publishClick(siteUrl){
		//alert("here in publish click");
		var to=document.getElementById('list2');
		var to2=document.getElementById('list4');
		var read_array=new Array();
		var write_array=new Array();
		for(var y=0;y<to.options.length;y++){
			var p=to.options[y];
	     	read_array[y]=p.value;
			}
			if(!Array.indexOf){
			  Array.prototype.indexOf = function(obj){
			   for(var i=0; i<this.length; i++){
				if(this[i]==obj){
				 return i;
				}
			   }
			   return -1;
			  }
			}
			if(read_array.indexOf('Y')==-1){
						if(read_array==""){
						read_array[0]="NO";
						}
						else{
							read_array[to.options.length]='N'
						}
			}
			$('#read_list').val(read_array);
			for(var y=0;y<to2.options.length;y++){
			var p=to2.options[y];
	     	write_array[y]=p.value;
			}
				if(write_array.indexOf('Y')==-1){
						if(write_array==""){
						write_array[0]="NO";
						} 
						else{
							write_array[to2.options.length]='N'
						}
			}
			
			$('#write_list').val(write_array);
		var update=document.getElementById('update');
		var myField = document.getElementById('1');
		if(update.value=="update"){
			//alert("update11");
			var pcount = document.blog.blog_count.value;
			var check=0;
			var allids = "";
			for (i = 0; i < pcount; i++) {
			if(eval('document.blog.list'+i+'.checked == true')) {
				if(allids == ""){ check++;
					allids += eval('document.blog.list'+i+'.value');}
				else{
					check++;
					allids += ","+eval('document.blog.list'+i+'.value');
					}
				}
			}//end for
			document.forms.blog.ids.value = allids;
			var myField = document.getElementById('1');
			//alert(myField.name);
			document.blog.blog_status.value=myField.name;
			document.blog.action = siteUrl+"blog/update_post/";
			document.blog.submit();
		}else{
			var pcount = document.blog.blog_count.value;
			var check=0;
			var allids = "";
			for (i = 0; i < pcount; i++) {
			if(eval('document.blog.list'+i+'.checked == true')) {
				if(allids == ""){ check++;
					allids += eval('document.blog.list'+i+'.value');}
				else{
					check++;
					allids += ","+eval('document.blog.list'+i+'.value');
					}
				}
			}//end for
			document.forms.blog.ids.value = allids;
			var myField = document.getElementById('1');
			//alert(myField.name);
			document.blog.blog_status.value=myField.name;
			document.blog.action = siteUrl+"blog/create_post/";
			document.blog.submit();
		}
	}
	
	function draftClick(siteUrl){
		//alert("here in draft click");
		var update=document.getElementById('update');
		var myField = document.getElementById('2');
		if(update.value=="update"){
			//alert("update11");
			var pcount = document.blog.blog_count.value;
			var check=0;
			var allids = "";
			for (i = 0; i < pcount; i++) {
			if(eval('document.blog.list'+i+'.checked == true')) {
				if(allids == ""){ check++;
					allids += eval('document.blog.list'+i+'.value');}
				else{
					check++;
					allids += ","+eval('document.blog.list'+i+'.value');
					}
				}
			}//end for
			document.forms.blog.ids.value = allids;
			var myField = document.getElementById('2');
			//alert(myField.name);
			document.blog.blog_status.value=myField.name;
			document.blog.action = siteUrl+"blog/update_post/";
			document.blog.submit();
		}else{
		var pcount = document.blog.blog_count.value;
		var check=0;
		var allids = "";
	
		for (i = 0; i < pcount; i++) {
		
		if(eval('document.blog.list'+i+'.checked == true')) {
			
			if(allids == ""){ check++;
				allids += eval('document.blog.list'+i+'.value');}
			else{
				check++;
				allids += ","+eval('document.blog.list'+i+'.value');
				}
			}
		}//end for
		document.forms.blog.ids.value = allids;
		var myField = document.getElementById('2');
		//alert(myField.name);
		document.blog.blog_status.value=myField.name;
		document.blog.action = siteUrl+"blog/create_post/";
		document.blog.submit();
		}
				
	}
	
	function previewClick(siteUrl){
		//alert("here in preview click");
		var update=document.getElementById('update');
		var myField = document.getElementById('3');
		
		if(update.value=="update"){
			//alert("update11");
			var pcount = document.blog.blog_count.value;
			var check=0;
			var allids = "";
		
			for (i = 0; i < pcount; i++) {
			
			if(eval('document.blog.list'+i+'.checked == true')) {
				
				if(allids == ""){ check++;
					allids += eval('document.blog.list'+i+'.value');}
				else{
					check++;
					allids += ","+eval('document.blog.list'+i+'.value');
					}
				}
			}//end for
			document.forms.blog.ids.value = allids;
			var myField = document.getElementById('3');
			//alert(myField.name);
			document.blog.blog_status.value=myField.name;
			document.blog.action = siteUrl+"blog/update_post/";
			document.blog.submit();
		
		}else{
		var pcount = document.blog.blog_count.value;
		var check=0;
		var allids = "";
		for (i = 0; i < pcount; i++) {
		if(eval('document.blog.list'+i+'.checked == true')) {
			if(allids == ""){ check++;
				allids += eval('document.blog.list'+i+'.value');}
			else{
				check++;
				allids += ","+eval('document.blog.list'+i+'.value');
				}
			}
		}//end for
		document.forms.blog.ids.value = allids;
		var myField = document.getElementById('3');
		///alert(myField.name);
		document.blog.blog_status.value=myField.name;
		document.blog.action = siteUrl+"blog/create_post/";
		document.blog.submit();
		}
	}
	

