// JavaScript Document
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

var editor;

$(document).ready(function(){
	$('#searchbox').bind('click', function(){
		if ($(this).val() == "Search") {
			$(this).val('');
		}
	});
	
	$('#searchbox').bind('outerClick', function(){
		if ($(this).val() == "") {
			$(this).val('Search');
		}
	});
});

function openKCFinder_singleFile() {
    window.KCFinder = {};
    window.KCFinder.callBack = function(url) {
        window.KCFinder = null;
        // Actions with url parameter here
    };
    //window.open('/system/plugins/kcfinder/browse.php', 'kcfinder_single');
	var left = (screen.width/2)-(800/2);
	var top = (screen.height/2)-(400/2);
	window.open ('/system/plugins/kcfinder/browse.php', 'kcfinder_single','toolbar=no, location=no, directories=no, status=nomenubar=0,resizable=1,width=800,height=400,top='+top+',left='+left); 
}
 
function openKCFinder_multipleFiles() {
    window.KCFinder = {};
    window.KCFinder.callBackMultiple = function(files) {
        window.KCFinder = null;
        for (var i; i < files.length; i++) {
            // Actions with files[i] here
        }
    };
    window.open('/system/plugins/kcfinder/browse.php', 'kcfinder_multiple');
}

function removeEditor(textareaid) {
	if ( !editor )
		return;
	// Retrieve the editor contents. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	$(textareaid).val(editor.getData());
	// Destroy the editor.
	editor.destroy();
	editor = null;
}

function load_admin_page(txtpath) {
	$('#saint-admin-ajax-load').html('<div id="saint-admin-ajax-load-loader"></div>');
	$('#saint-admin-ajax-container').slideDown('slow');
	$.ajax({
	  url: txtpath,
	  success: function(data) {
		$('html, body').animate({scrollTop:0}, 'slow');
		$('#saint-admin-ajax-load').hide();
		$('#saint-admin-ajax-load').fadeIn(1000).html(data);
	  }
	});
}

function save_admin_page(txtpath,formname) {
	$.post(txtpath, 
	   $("#"+formname).serialize(),
		   function(data){
			   $('#saint-admin-ajax-container').slideUp('slow');
		   }
	   );
}

function save_admin_page_image(txtpathfile, txtpath, formname, fileid) {
	$.post(txtpath, 
	   $("#"+formname).serialize(),
		   function(data){
			   $('#saint-admin-ajax-container').slideUp('slow');
		   }
	   );
	
	$.ajaxFileUpload
	(
		{
			url:txtpathfile, 
			secureuri:false,
			fileElementId:fileid,
			dataType: 'script',
			success: function (data, status)
			{
			},
			error: function (data, status, e)
			{
			}
		}
	)
}
	
function save_page_module_file(txtpathfile,txtpath,formname,txtpathview,moduleid,fileid) {
	$.ajaxFileUpload
	(
		{
			url:txtpathfile, 
			secureuri:false,
			fileElementId:fileid,
			dataType: 'script',
			success: function (data, status)
			{
				$('#news_images_name').val(data);
				$.post(txtpath,
				   $("#"+formname).serialize(),
					   function(data){
						   //$('#saint-admin-ajax-container').slideUp('slow');
						   $('#saint-admin-ajax-load').fadeIn(1000).html(data);
						   $.ajax({
							  url: txtpathview,
							  success: function(data) {
								$('#saint-module-'+moduleid).html(data);
							  }
							});
					   }
				   );
			},
			error: function (data, status, e)
			{
				$('#saint-admin-ajax-load').html('Error!');
			}
		}
	)
}

function save_page_module(txtpath,formname,txtpathview,moduleid) {
	$.post(txtpath, 
	   $("#"+formname).serialize(),
		   function(data){
			   //$('#saint-admin-ajax-container').slideUp('slow');
			   $('#saint-admin-ajax-load').fadeIn(1000).html(data);
			   $.ajax({
				  url: txtpathview,
				  success: function(data) {
					$('#saint-module-'+moduleid).html(data);
				  }
				});
		   }
	   );
}

function save_admin_message(txtpath,formname) {
	$.post(txtpath, 
	   $("#"+formname).serialize(),
		   function(data){
			   $('#saint-admin-ajax-load').fadeIn(1000).html(data);
		   }
	   );
}

function showmodulemenu (moduleid) {
	 //Following events are applied to the subnav itself (moving subnav up and down)  
	 $("ul#saint_module_menu"+moduleid).fadeIn('slow').show(); //Drop down the subnav on click  

	 $("#saint-module-downmenu"+moduleid).parent().hover(function() {  
	 }, function(){  
		 $("ul#saint_module_menu"+moduleid).hide(); //When the mouse hovers out of the subnav, move it back up  
	 });  
}

function delete_confirm(txtpath) {
	var answerdelete = confirm("Are you sure you want to delete this?");
	if (answerdelete) {
		window.location = txtpath;
	} else {
		alert("Delete cancel");
	}
	return false;
}

function admin_delete_confirm(txtpath) {
	var answerdelete = confirm("Are you sure you want to delete this?");
	if (answerdelete) {
		$.ajax({
		  url: txtpath,
		  success: function(data) {
			$('#saint-admin-ajax-load').hide();
			$('#saint-admin-ajax-load').fadeIn(1000).html(data);
		  }
		});
	} else {
		alert("Delete cancel");
	}
	return false;
}

ImageList= new Array();
ImageListHover = new Array();

function load_image_template(ImageName, ImageNormal) {
	ImageList[ImageName] = new Image();
	ImageList[ImageName].src = ImageNormal;
}

function change_image_template() {
	skitemplate_id = $('#skintemplate_id').val();
	document.images['skin-template-pic'].src = ImageList[skitemplate_id].src;
}

function password_hashmd5(tbid) {
	(function($) { 
		txtpass = $(tbid).val();
		var s_txtpass = new String(txtpass);
		txtpass = s_txtpass.trim();
	})(jQuery);
	hashmd5 = hex_md5(txtpass);
	(function($) { 
		$(tbid).val(hashmd5);
	})(jQuery);
}

/* saint Menu */

function loadsaintMenu() {
	$(".saint-main-menu li").bind('mouseover', function(){ 
		$(this).find(".saint-sub-menu-container").fadeIn();
	 });
	 
	$(".saint-sub-menu-container").parent().hover(function() {  
	 }, function(){  
		 $(".saint-sub-menu-container").hide(); 
	 });
}

/* saint Menu */

/* saint Comments */

function post_saint_comments(id, module_id, txtpath, formname) {
	$('#saint-comments-loadingspinner'+module_id).show();
	$.post(txtpath, 
	   $("#"+formname).serialize(),
		   function(data){
			   $('#saint-comments-loadingspinner'+module_id).hide();
			   $('#saint-comments-message'+module_id).html(data);
		   }
	   );
}

function delete_saint_comments(comments_id, txtpath) {
	$('#saint-comments-loadingspinner'+comments_id).show();
	var answerdelete = confirm("Are you sure you want to delete this?");
	if (answerdelete) {
		$.ajax({
		  url: txtpath+"/"+comments_id,
		  success: function(data) {
			$('#saint-comments-loadingspinner'+comments_id).hide();
			$('#saint-comments-'+comments_id).remove();
		  }
		});
	} else {
		$('#saint-comments-loadingspinner'+comments_id).hide();
	}
}

function approve_saint_comments(comments_id, txtpath) {
	$('#saint-comments-loadingspinner'+comments_id).show();
	$.ajax({
	  url: txtpath+"/"+comments_id,
	  success: function(data) {
		$('#saint-comments-loadingspinner'+comments_id).hide();
		$('#saint-disable'+comments_id).show();
		$('#saint-approve'+comments_id).hide();
	  }
	});
}

function disable_saint_comments(comments_id, txtpath) {
	$('#saint-comments-loadingspinner'+comments_id).show();
	$.ajax({
	  url: txtpath+"/"+comments_id,
	  success: function(data) {
		$('#saint-comments-loadingspinner'+comments_id).hide();
		$('#saint-disable'+comments_id).hide();
		$('#saint-approve'+comments_id).show();
	  }
	});
}

/* */

