// JavaScript Document
function searchArticle(siteUrl){
	//alert(siteUrl)
	var myField = document.getElementById('searchtag');
	var value1=myField.value;
	
	
	if(value1!=""){
		
		document.article.action=siteUrl+"classified/search_post";
		document.article.submit();
	}else{
		
		alert(MSG_TITLE.replace('\%S\%', 'Title'));
		return false;	
		}
}
function delete_my_job(siteUrl) {
	//alert(MSG_DELETE_CONFIRMATION);
   if (confirm(MSG_DELETE_CONFIRMATION.replace('\%S\%', 'Job'))) {	 
    document.location = siteUrl;
  }
}
function searchmyArticle(siteUrl){
	
	var myField = document.getElementById('searchtag');
	var value1=myField.value;
	
	
	if(value1==""){
		alert(MSG_TITLE.replace('\%S\%', 'Title'));
		return false;
	}else{
		document.article.action=siteUrl+"classified/search_user_post";
		document.article.submit();
			
		}
}
function searchfavArticle(siteUrl){
	
	var myField = document.getElementById('searchtag');
	var value1=myField.value;
	
	
	if(value1==""){
		alert(MSG_TITLE.replace('\%S\%', 'Title'));
		return false;
	}else{
		document.article.action=siteUrl+"classified/search_fav_post";
		document.article.submit();
			
		}
}
function checkAllClassified(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_job_category(){
	if(document.getElementById('title').value==""){
		alert(MSG_TITLE.replace('\%S\%', 'Category title'));
		document.getElementById('title').focus;
		return false;
	} else {
		document.catform.submit();
	}
	
}
function edit_job_category(siteUrl){
	if(document.getElementById('title').value==""){
		alert(MSG_TITLE.replace('\%S\%', 'Category title'));
		document.getElementById('title').focus;
		return false;
	} else {
		document.catform.action=siteUrl;
		document.catform.submit();
	}
	
}

function add_job_category_old(siteUrl){
	
	
	var title=$('input#title').val();
	var parent_id=$('select#parent_id').val();
	 if($('input#show_on_front').is(':checked'))
	 	show_on_front=$('input#show_on_front').val();
	else
		show_on_front='No';
	
	var info = 'blog_title='+title+'&parent_id='+parent_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+"classified/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.catform.post_title.value="";
		$('#list_cat').html(data)  ; 
          }
	});
	}
	return false;
}
function edit_blog_category_old(siteUrl,cat_id){
	var Url = $("input#url").val();
	var title=$('input#title').val();
	var parent_id=$('select#parent_id').val();
	var info = 'blog_title='+title+'&parent_id='+parent_id+'&cat_id='+cat_id;
	//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+"classified/update_category",
		data: info,
		success: function(data) {
		   //alert(data)
		  window.location=siteUrl+"classified/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(MSG_CONFIRM)) {
			document.forms.art_list.action = siteUrl+"classified/delete_bulk_post/"+action;
			document.forms.art_list.submit();
			}
 		} else {
 			alert(MSG_SELECT.replace('\%S\%', 'Job'));
 		}
	}else{
		alert(MSG_SELECT_ACTION);
		return;
		}	
	
}
function actionBulkCategory(siteUrl){
	
	var action=document.getElementById('bulk').value;
	if(action !=0){
		var chks=document.getElementsByName('category[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++){
			if (chks[i].checked){
				hasChecked = true;
                break;
			}
 		}
 		if(hasChecked==true){
			if (confirm(MSG_CONFIRM)) {
			document.forms.cat_list.action = siteUrl+"classified/bulk_action/"+action;
			document.forms.cat_list.submit();
			}
 		} else {
 			alert(MSG_SELECT.replace('\%S\%', 'Category'));
 		}
	}else{
		alert(MSG_SELECT_ACTION);
		return;
		}	
}
function actiontagBulk(siteUrl){
	var action=document.getElementById('bulk').value;
	//alert(action);
	
	if(action !=0){
		if (confirm(MSG_CONFIRM)) {
		document.forms.cat_list.action = siteUrl+"classified/bulk_delete_tag/"+action;
		document.forms.cat_list.submit();
		}
	}else{
		alert(MSG_SELECT_ACTION);
		return;
		}
}
function 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+"classified/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(MSG_CONFIRM);
}
function openBox(d){
	var ob=document.getElementById(d);
	ob.style.display=(ob.style.display=='none')?'block':'none';
}
		function publishClick(siteUrl){
		
		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+"classified/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+"classified/create_post/";			
			document.blog.submit();
		}
		
	}

