// JavaScript Document

//var mainpath = '/anneahira.com/'; // local
//var mainpath = '/v3/'; // online v3
var mainpath = '/'; // online

function addmenu(mode,jml,tid)
{
	$.post(mainpath+"system/getmenu.php", { mode: mode, jml:jml, tid: tid },function(data){
    	$('#outmenu').html(data);
    });
}

function sort_project_topic(mode,id)
{
	location.href = 'project_topic_list?sort='+mode+'&id='+id;
}

function enable_kat()
{
	$('#main_cat_id').removeAttr("disabled");
}

function set_permalink()
{
	tx=$("#mainkey").val();
	tx2 = tx.replace(/ /gi,'-');
	tx2 = tx2.toLowerCase();
	$('#permalink').html(tx2);
	$('#plink').val(tx2); 
	$("#mainkey").val(tx);
	tc = $("#meta_title").val();
	tc2 = 70-tc.length;
	$('#title_count').html(tc2);
}

function set_permalink2()
{
	tx=$("#plink").val();
	tx2 = tx.replace(/ /gi,'-');
	tx2 = tx2.toLowerCase();
	$('#permalink').html(tx2);
	$('#plink').val(tx2); 
	$("#plink").val(tx);
}

$(function(){
	$("#mainkey").keyup(function(event){ 
		tx=$(this).val();
		tx2 = tx.replace(/ /gi,'-');
		tx2 = tx2.toLowerCase();
		$('#permalink').html(tx2);
		$('#plink').val(tx2); 
		$(this).val(tx);
	});
	$("#plink").keyup(function(event){ 
		tx=$(this).val();
		tx2 = tx.replace(' ','-');
		tx2 = tx2.toLowerCase();
		$('#permalink').html(tx2);
		$(this).val(tx);
	});
	$("#meta_title").keyup(function(event){ 
		tx=$(this).val();
		tx2 = 70-tx.length;
		$('#title_count').html(tx2);
	});
	
	$('.setlinkkwd').click(function(){
		sl=$('.mceEditor').tinymce().selection.getContent({format : 'text'});
		if(sl!=''){
			$('.mceEditor').tinymce().execCommand('mceReplaceContent',false,'[kwd]{$selection}[/kwd]');
		}else alert('No KEYWORD selected!');
		return false;
	});
	
	$('.setlinkimg').click(function(){
		vi=$('.mceEditor').tinymce().selection.getContent({format : 'text'});
		kwd=$("#plink").val();
		$('.mceEditor').tinymce().execCommand('mceReplaceContent',false,'[img:left]'+kwd+'.jpg[/img]');
	});

	$('.setlinkid').click(function(){
		tk=$('.mceEditor').tinymce().selection.getContent({format : 'text'});
		if(tk!=''){
		$.fancybox({
			'hideOnOverlayClick':false,
			'href' : mainpath+'system/article_get.php',
			'width' : 800,
			'ajax' : {
				type	: 'POST',
				data	: 'k='+tk
			}
		});
		} else alert('No KEYWORD selected!');
		return false;
	});	
		
	$('.penjelasan').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
$("#newsticker_text").keyup(function(event){ 
		tx=$(this).val();
		tx2 = 120-tx.length;
		$('#title_count').html(tx2);
	});
	
	$("#newsticker_preview").click(function(){
		banner_text=$("#newsticker_text").val();
		banner_link=$("#newsticker_link").val();
		$.fancybox({
			'hideOnOverlayClick':false,
			'href' : mainpath+'system/newsticker_preview.php',
			'ajax' : {
				type	: 'POST',
				data	: 'banner_text='+banner_text+'&banner_link='+banner_link
			}
		});
	});
		
	$("#banner_b_preview").click(function(){
		
		var bid = $("input:checked[name=banner_id\[\]]").map(function() {
		return $(this).val();
		}).get().join('|');
		
		ef = $('#effect :selected').val();
		
		$.fancybox({
			'hideOnOverlayClick':false,
			'href' : mainpath+'system/banner_b_preview.php',
			'ajax' : {
				type	: 'POST',
				data	: 'effect='+ef+'&banner_id='+bid
			}
		});
	});
	
	$('input[name="chkall"]').click(function() {
		  $(":checkbox").attr('checked', $(this).attr('checked'));
	});
	});

function CheckAll() {
  for (var i = 0; i < document.FormMsgs.elements.length; i++) {
    if(document.FormMsgs.elements[i].type == 'checkbox'){
      document.FormMsgs.elements[i].checked = !(document.FormMsgs.elements[i].checked);
    }
  }
}

function get_sub_cat(v,v2,v3)
{
   $.post(mainpath+"system/getsubcat.php", { main_cat_id: v, sub_cat_id: v2, mode: v3 },
   function(data){
     $("#sub_cat_id").html(data);
   });
}

function get_sub_cat2(v,v2,v3)
{
   $.post(mainpath+"system/getsubcat.php", { main_cat_id: v, sub_cat_id: v2, mode: v3 },
   function(data){
     $("#sub_cat_id_search").html(data);
   });
}

function get_sub_cat3(a,v,v2,v3,v4)
{
   $.post(mainpath+"system/getsubcat.php", { main_cat_id: v, sub_cat_id: v2, mode: v3, div: a, x: v4 },
   function(data){
     $("#sub_cat_id"+a).html(data);
   });
}


function get_topic(v,v2,v3)
{
   $.post(mainpath+"system/gettopic.php", { sub_cat_id: v,topic_id: v2, mode: v3 },
   function(data){
     $("#topic_id").html(data);
   });
}

function get_topic2(v,v2)
{
   $.post(mainpath+"system/gettopic.php", { sub_cat_id: v, mode: v2 },
   function(data){
     $("#topic_id_search").html(data);
   });
}

function get_topic3(v,v2,v3)
{
   $.post(mainpath+"system/gettopic.php", { sub_cat_id: v,topic_id: v2, mode: v3 },
   function(data){
     $("#topic_id").html(data);
   });
}

function get_topic4(a,v,v2,v3,v4)
{
   $.post(mainpath+"system/gettopic.php", { sub_cat_id: v, topic_id: v2, mode: v3, div: a, x: v4 },
   function(data){
     $("#topic_id"+a).html(data);
   });
}

function get_umur(a,v,v2,v3)
{
   $.post(mainpath+"system/getumur.php", { umur_id: v, mode: v2, div: a, x: v3 },
   function(data){
     $("#umur_id"+a).html(data);
   });
}

function get_gender(a,v,v2,v3)
{
   $.post(mainpath+"system/getgender.php", { gender_id: v, mode: v2, div: a, x: v3 },
   function(data){
     $("#gender_id"+a).html(data);
   });
}

function get_writer(v,v2,v3)
{
   $.post(mainpath+"system/getwriter.php", { manager_id: v, writer_id: v2, mode: v3 },
   function(data){
     $("#writer_id").html(data);
   });
}

function reply_button(formid)
{
	$("#"+formid).show();
}

function sort_client_pages(mode)
{
	location.href = 'client_pages?sort='+mode;
}

function sort_project_keyword(mode,id)
{
	location.href = 'project_keyword_list?sort='+mode+'&id='+id;
}

function sortir_keyword(v)
{
	if (v!='')
	{
		switch(v)
		{
			case '1':
			   $.post(mainpath+"system/getgrup.php", { mode: 1 },
			   function(data){
				 $("#group_id").html(data);
				 $("#client_id").hide();
				 $("#group_id").show();
			   });
			break;
			case '2':
			   $.post(mainpath+"system/getclient.php", { mode: 1 },
			   function(data){
				 $("#client_id").html(data);
				 $("#client_id").show();
				 $("#group_id").hide();
			   });
			break;
			default:
				sort_project_keyword(v,'');
			break;
		}
	} else {
		return false;
	}
}

function delete_keyword(id,t)
{
	var answer = confirm('Apa Anda yakin akan menghapus '+t+'?');
	if (answer==1){
	   $.post(mainpath+"system/project_keyword_delete.php", { id: id },
	   function(data){
		 if (data=='ok') {
			$("#tr"+id).hide();
		 }
	   });
	}
}

function keyword_note(id,t,v)
{
	var note = prompt('Tulis pesan untuk penulis', v);
	if (note==null)
	{
		note = '';
	}
   $.post(mainpath+"system/project_keyword_note.php", { id: id, note: note },
   function(data){
	 $("#note"+id).html(data);
   });
}

// menu roll over

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// menu drop down

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;

$(document).ready(function(){
	$('.delete').click(function(){
		var answer = confirm('Apa Anda yakin akan menghapus '+jQuery(this).attr('title')+'?');
		return answer; // answer is a boolean
		});
}); 

function hackCSS()
{
    var a = document.getElementById("kat-left-line");
    var b = document.getElementById("kat-right-line");
	var c = document.getElementById("content");

	var height_a = a.offsetHeight;
	var height_b = b.offsetHeight;
	var height_c = c.offsetHeight;
		
	a.style.height = height_c + "px";
	a.style.height = height_c + "px";
}


/*function addToFavorites() {
	var metaTitle = document.title;
	var urlSite = 'http://www.anneahira.com/';
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',urlSite);
		elem.setAttribute('title',metaTitle);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(urlSite, metaTitle);
	}
}*/

function load_comment(tb,id,pg)
{
   $.post(mainpath+"system/comment_view.php", { tb:tb, id:id, pg:pg },
   function(data){
     $("#comment_list").html(data);
   });
}

function select_rss()
{
	$('#rssurl').select();
}

function sharemail(aid)
{
	$.fancybox({
		'hideOnOverlayClick':false,
		'href' : mainpath+'share.php',
		'ajax' : {
			type	: 'POST',
			data	: 'aid='+aid
		}
	});
}

function post_wp(aid)
{
	$.fancybox({
		'hideOnOverlayClick':false,
		'href' : mainpath+'post_wp.php',
		'ajax' : {
			type	: 'POST',
			data	: 'aid='+aid
		}
	});
}

function post_blogger(aid)
{
	$.fancybox({
		'hideOnOverlayClick':false,
		'href' : mainpath+'post_blogger.php',
		'ajax' : {
			type	: 'POST',
			data	: 'aid='+aid
		}
	});
}

function seo_external(sid)
{
	location.href = 'seo_external_sub?sid='+sid;
}

function get_opt(v,v2)
{
   $.post(mainpath+"system/articlev1_file.php", {path : v, file1 : v2},
	function(data){
		 $("#file1").html(data);
	   });
}


