var adminFolder = "cantik~jelita";
function callDate() {
	$('.date-pick').datePicker({startDate:'1996-01-01'});
}
function binding() {
	setTimeout(function(){
		$("#miniPopUp").bind("mouseenter", function(){
			$("#miniPopUpStatus #inside").html("1");
		});
		$("#miniPopUp").bind("mouseleave", function(){
			$("#miniPopUpStatus #inside").html("0");
		});
		$("#miniPopUp a.close").bind("click", function(){
			unbind();
			closeBrowse();
		});
		$("html").bind("click", function(){
			if ($("#miniPopUpStatus #inside").html()=="0" && $("#miniPopUpStatus #open").html()=="1") {
				closeBrowse();
			}
		});
	}, 100);
}
function unbind() {
	$("#miniPopUp").unbind("mouseenter");
	$("#miniPopUp").unbind("mouseleave");
	$("html").unbind("click");
}
function closeBrowse() {
	$("#miniPopUpStatus #open").html("0");
	$("#miniPopUp").css({ "display":"none" });
	//alert($("#miniPopUpStatus #open").html());
	unbind();
}
function browseSelect(parID, pari, parv) {
	$("#i"+ parID).val(pari);
	$("#v"+ parID).val(parv);
	closeBrowse();
}
function browseSelectForSell(parID, pari, parv, parp) {
	$("#i"+ parID).val(pari);
	$("#v"+ parID).val(parv);
	$("#harga").val(parp);
	closeBrowse();
}
function clearContents(parID) {
	$("#i"+ parID).val("");
	$("#v"+ parID).val("");
}
function browseContents(parID, parPage) {
	if ($("#miniPopUpStatus #open").html()=="0") {
		$("#miniPopUpStatus #open").html("1");
		
		binding();
		
		var $this = $("#browse"+ parID);
		var pos = $this.position();
		var top = pos.top - 5;
		var left = pos.left + 25;
		var ajaxURL = "";
		if (parPage=="products") { ajaxURL = "/"+adminFolder+"/_ajax/products.php"; }
		if (parPage=="mini-products") { ajaxURL = "/"+adminFolder+"/_ajax/products.php"; }
		//if (parPage=="products") { ajaxURL = "/"+adminFolder+"/_ajax/products.php"; }
		if (ajaxURL!="") {
			$.ajax({
				type: "GET",
				url: ajaxURL,
				data: "a=browse&b="+ parID,
				success: function(resp) {
					$("#miniPopUp").html(resp);
					$("#miniPopUp").css({ "display":"inline-block", "top":top+"px", "left":left+"px" });
				}
			});
		}
	}
	
}

function browseContentsPN(parID, parPage, pagingNo) {
	var $this = $("#browse"+ parID);
	var pos = $this.position();
	var top = pos.top - 5;
	var left = pos.left + 25;
	var ajaxURL = "";
	if (parPage=="products") { ajaxURL = "/"+adminFolder+"/_ajax/products.php"; }
	if (parPage=="mini-products") { ajaxURL = "/"+adminFolder+"/_ajax/products.php"; }
	//if (parPage=="products") { ajaxURL = "/"+adminFolder+"/_ajax/products.php"; }
	if (ajaxURL!="") {
		$.ajax({
			type: "GET",
			url: ajaxURL,
			data: "a=browse&currpage="+ pagingNo +"&b="+ parID,
			success: function(resp) {
				$("#miniPopUp").html(resp);
				$("#miniPopUp").css({ "display":"inline-block", "top":top+"px", "left":left+"px" });
			}
		});
	}
	
}
function testInit(parMode, parElem) {
	var theMode = "textareas";
	var theElem = "";
	switch(parMode) {
		case "":
			theMode = "textareas";
			break;
		case "exact":
			theMode = "exact";
			theElem = parElem;
			break;
	}
	tinyMCE.init({
		// General options
		file_browser_callback: "openKCFinder",
		mode : theMode,
		elements: theElem,
		theme : "advanced",
		plugins : "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,wordcount,advlist,autosave",

		// Theme options
		/*
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		*/
		
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,image,cleanup,code,|,preview",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "/"+adminFolder+"/tinymce/example/css/content.css",
		
		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "/"+adminFolder+"/tinymce/example/lists/template_list.js",
		external_link_list_url : "/"+adminFolder+"/tinymce/example/lists/link_list.js",
		external_image_list_url : "/"+adminFolder+"/tinymce/example/lists/image_list.js",
		media_external_list_url : "/"+adminFolder+"/tinymce/example/lists/media_list.js",

		// Style formats
		style_formats : [
			{title : "Bold text", inline : "b"},
			{title : "Red text", inline : "span", styles : {color : "#ff0000"}},
			{title : "Red header", block : "h1", styles : {color : "#ff0000"}},
			{title : "Example 1", inline : "span", classes : "example1"},
			{title : "Example 2", inline : "span", classes : "example2"},
			{title : "Table styles" },
			{title : "Table row 1", selector : "tr", classes : "tablerow1"}
		],
		width: "500",
		height: "400",
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}

function openKCFinder(field_name, url, type, win) {
	tinyMCE.activeEditor.windowManager.open({
		file: "/"+adminFolder+"/kcfinder/browse.php?opener=tinymce&type=" + type,
		title: "KCFinder",
		width: 700,
		height: 500,
		resizable: "yes",
		inline: true,
		close_previous: "yes",
		popup_css: true
	}, {
		window: win,
		input: field_name
	});
	return false;
}
function checkAlerts() {
	var aurl = "/"+adminFolder+"/_ajax/alerts.php";
	var adata = "a=check&b=all";
	//alert(aurl+"?"+adata);
	$.ajax({
		type: "GET",
		url: aurl,
		data: adata,
		success: function(resp){
			var sresp = resp.split("$$");
			var noteDepo = 0;
			var noteWD = 0;
			var noteMem = 0;
			var notif = '';
			var zz = 0;
			for (var zz=0;zz<sresp.length;zz++) {
				notif = sresp[zz].split("$");
				if (notif[0]=="deposit") {
					noteDepo += parseInt(notif[1]);
					if (parseInt(notif[1]) > 0) {
						$(".toplink-deposit").css({ "background":"#0f0" });
						$(".toplink-deposit .notif").html(""+ notif[1] +"");
						$(".toplink-deposit").attr("title", ""+ notif[1] +" Pending Deposits");
					} else {
						$(".toplink-deposit").css({ "background":"#fff" });
						$(".toplink-deposit .notif").html("");
						$(".toplink-deposit").attr("title", ""+ notif[1] +" Pending Deposits");
					}
				} else
				if (notif[0]=="withdraw") {
					noteWD += parseInt(notif[1]);
					if (parseInt(notif[1]) > 0) {
						$(".toplink-withdraw").css({ "background":"#0f0" });
						$(".toplink-withdraw .notif").html(""+ notif[1] +"");
						$(".toplink-withdraw").attr("title", ""+ notif[1] +" Pending Withdraws");
					} else {
						$(".toplink-withdraw").css({ "background":"#fff" });
						$(".toplink-withdraw .notif").html("");
						$(".toplink-withdraw").attr("title", ""+ notif[1] +" Pending Withdraws");
					}
				} else
				if (notif[0]=="member") {
					noteMem += parseInt(notif[1]);
					if (parseInt(notif[1]) > 0) {
						$(".toplink-member").css({ "background":"#0f0" });
						$(".toplink-member .notif").html(""+ notif[1] +"");
						$(".toplink-member").attr("title", ""+ notif[1] +" Pending Members");
					} else {
						$(".toplink-member").css({ "background":"#fff" });
						$(".toplink-member .notif").html("");
						$(".toplink-member").attr("title", ""+ notif[1] +" Pending Members");
					}
				}
				
			}
			if (noteMem>0) {
				$.sound.play("/sounds/Temple-Bell-SoundBible.com-756181215.wav", {timeout: 10000});
			}
			if (noteWD>0) {
				$.sound.play("/sounds/notification.wav", {timeout: 10000});
			}
			if (noteDepo>0) {
				//$.playSound("/sounds/notification.wav");
				$.sound.play("/sounds/Bike-Horn-SoundBible.com-602544869.wav", {timeout: 10000});
				setTimeout(function(){
					$.sound.play("/sounds/Bike-Horn-SoundBible.com-602544869.wav", {timeout: 10000});
				}, 1050);
			}
		}
	});
}

function checkTourneyAlerts() {
	var aurl = "/"+adminFolder+"/_ajax/turney-alerts.php";
	var adata = "a=check&b=all";
	//alert(aurl+"?"+adata);
	$.ajax({
		type: "GET",
		url: aurl,
		data: adata,
		success: function(resp){
			var sresp = resp.split("$$");
			var noteDepo = 0;
			var noteMem = 0;
			var notif = '';
			var zz = 0;
			for (var zz=0;zz<sresp.length;zz++) {
				notif = sresp[zz].split("$");
				if (notif[0]=="deposit") {
					noteDepo += parseInt(notif[1]);
					if (parseInt(notif[1]) > 0) {
						$(".toplink-turney-deposit").css({ "background":"#0f0" });
						$(".toplink-turney-deposit .notif").html(""+ notif[1] +"");
						$(".toplink-turney-deposit").attr("title", ""+ notif[1] +" Pending Tournament Deposits");
					} else {
						$(".toplink-turney-deposit").css({ "background":"#fff" });
						$(".toplink-turney-deposit .notif").html("");
						$(".toplink-turney-deposit").attr("title", ""+ notif[1] +" Pending Tournament Deposits");
					}
				} else
				if (notif[0]=="member") {
					noteMem += parseInt(notif[1]);
					if (parseInt(notif[1]) > 0) {
						$(".toplink-turney-members").css({ "background":"#0f0" });
						$(".toplink-turney-members .notif").html(""+ notif[1] +"");
						$(".toplink-turney-members").attr("title", ""+ notif[1] +" Pending Tournament Members");
					} else {
						$(".toplink-turney-members").css({ "background":"#fff" });
						$(".toplink-turney-members .notif").html("");
						$(".toplink-turney-members").attr("title", ""+ notif[1] +" Pending Tournament Members");
					}
				}
				
			}
			if (noteMem>0 || noteDepo>0) {
				$.sound.play("/sounds/Quack-Quack-SoundBible.com-620056916.wav", {timeout: 10000});
			}
		}
	});
}
function callTableLiveSearch(parSelector) {
	var stripeTable = function(table) { //stripe the table (jQuery selector)
		table.find('tr').removeClass('striped').filter(':visible:even').addClass('striped');
	};
	$('table'+ parSelector +'').filterTable({
		callback: function(term, table) { stripeTable(table); } //call the striping after every change to the filter term
	});
	stripeTable($('table'+ parSelector +'')); //stripe the table for the first time
}