/*
 |™*******************************************************************************************™*
 | jQuery mediabox by jenghy 30-09-2010
 |™*******************************************************************************************™*
*/

 /*$(document).ready(function(){
            $("#mediabox_hover").click(function(){
                  $("#popup-mediabox").slideToggle("slow")
				  $('li.mediabox').toggleClass("on");
            });
          });*/
		  
		  


/*
 |™*******************************************************************************************™*
 | TinyMCE
 |™*******************************************************************************************™*
*/
if (jQuery("#TXAwebboard_detail, #TXAwebboard_reply_detail").length > 0) { // use jQuery("textarea") for all textarea to turn tinymce
	
	tinyMCE.init({
		// General options
		mode: "textareas",
		theme: "advanced",
		editor_selector : "mceEditor",
		editor_deselector : "mceNoEditor",
		skin: "o2k7",
		plugins: "tinyBrowser,advimage, safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		// Theme options
		theme_advanced_buttons1: "newdocument,|,bold,italic,underline,strikethrough,emotions,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect",
		theme_advanced_buttons2: "",
		theme_advanced_buttons3: "",
		//theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",

		theme_advanced_toolbar_location: "top",
		theme_advanced_toolbar_align: "left",
		//theme_advanced_statusbar_location: "bottom",
		//theme_advanced_resizing: true,
		file_browser_callback : "tinyBrowser"
	});
		
}	
/*
 |----------------------------------------------------------------------------------------------
 | Form plugin
 |----------------------------------------------------------------------------------------------
*/
jQuery().ready(function() {

	
//---------->> attach handler to LINK TAG for submit event

	jQuery("#LIKsave, #LIKsend, #LIKedit, #LIKsearch").click(function() { 

		var form_action = jQuery("form").attr("action"); // get form action
		var link_type = jQuery(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&auid=" + link_split[2],
			type: "post"        
		}

		// for tinymce & form plugin ajax submit
		if (jQuery("#TXAwebboard_detail, #TXAwebboard_reply_detail").length > 0) {
			jQuery("form").bind("form-pre-serialize", function(e) {
				tinyMCE.triggerSave();
			});
		}
		
		// submit the form 
		jQuery("form").ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});

//---------->> click for rating

	$("a[name='rating']").click(function() { 
		
		var form_action = $(this).attr("href"); // get form action

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action ,
			type: "get"        
		}
		
		// submit the form 
		$(this).ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});
	
	
//---------->> attach handler to SUBMIT TAG for submit event

	jQuery("form").submit(function() { 

		var form_action = jQuery(this).attr("action"); // get form action
		var link_type = jQuery(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title
									  
		var options = {
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&auid=" + link_split[2]
		}
		
		// submit the form 
		jQuery(this).ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});
	

});

/*
 |™*******************************************************************************************™*
 | Function
 |™*******************************************************************************************™*
*/
/*
 |----------------------------------------------------------------------------------------------
 | beforeSubmit Function
 |----------------------------------------------------------------------------------------------
*/
function showRequest(formData, jqForm, options) {

	// blockUI plugin
	jQuery.blockUI({
		message: "<div id='divLoading'>Please wait ...</div>",
		css: { 
			border: "none", 
			padding: "15px", 
			backgroundColor: "#000000", "-webkit-border-radius": "10px", "-moz-border-radius": "10px", 
			opacity: "0.5", 
			color: "#ffffff" 
		}
	});
/*	    jQuery.blockUI({ 
            theme:     true, 
            title:    'This is your title', 
            message:  '<p>This is your message.</p>', 
            timeout:   2000 
        });*/
			//jQuery(document).ajaxStop(jQuery.unblockUI); 
	
}

/*
 |----------------------------------------------------------------------------------------------
 | Success Function
 |----------------------------------------------------------------------------------------------
*/
function showResponse(responseText, statusText) {

 	// for DEBUG ajax form plugin (when use upload file) change option dataType = html
	//alert("status: " + statusText + "\n\nresponseText: \n" + responseText); return false;

	jQuery.each(responseText, function(key, value) { // json format
								  
		if (key == "SUCCESS") {
			jQuery.prompt(value, { buttons: { }, top: "40%" });
		} else if (key == "UNSUCCESS") {
			jQuery.prompt(value, { buttons: { OK: true }, top: "40%" });
		} else if (key == "REDIRECT") {
			jQuery(this).delay(1000, function() {
				jQuery("form").resetForm();
				window.location.href = decodeURIComponent(value);
			});
		} else {
			value = value + "<input type='hidden' id='focusfield' name='focusfield' value='" + key + "' />";
			jQuery.prompt(value, { buttons: { OK: true }, top: "40%", callback: focusField });
		}
		
	});
	
	jQuery.unblockUI();
	
}

/*
 |----------------------------------------------------------------------------------------------
 | Focus Field
 |----------------------------------------------------------------------------------------------
*/
function focusField(v, m, f) {
	
	jQuery("#" + f.focusfield).focus().select(); // focusfield is a name of hidden field
	  
}

/*
 |----------------------------------------------------------------------------------------------
*/

/*
 |----------------------------------------------------------------------------------------------
 | [Check Change password]
 |----------------------------------------------------------------------------------------------
*/

jQuery("#CHKchange").click(function () {							  
  if(this.checked){
	jQuery("#change").css("display","inline-block");
  }else{
	jQuery("#change").css("display","none");
  }
});

/*
 |----------------------------------------------------------------------------------------------
 | 								                        jQuery Plugin Simple Toggle - 02-03-2010 
 |----------------------------------------------------------------------------------------------
*/
jQuery(".toggle_container").hide();

jQuery("h2.trigger").toggle(function(){
	jQuery(this).addClass("active"); 
	}, function () {
	jQuery(this).removeClass("active");
});

jQuery("h2.trigger").click(function(){
	jQuery(this).next(".toggle_container").slideToggle("slow,");
});


/*
 |™*******************************************************************************************™*
 | jQuery comment box by jenghy 05-10-2010
 |™*******************************************************************************************™*
*/




$(document).ready(function(){
	
	$(".reply-form").hide();

	$("span.reply-comment").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		$("#form").hide();
	});

});

$(document).ready(function(){
	$("a.cancle").click(function(){
		$(".reply-form").slideUp("normal")
	});
});
