<?php
header('Content-Type: application/javascript');
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
require(root."/___simple_config.php");
session_start();
require(root."/".memberFolder."/_common.php");
require(root."/".memberFolder."/_lib/db.php");
require(root."/".memberFolder."/_lib/main.php");
cout('var memberFolder = "'.(memberFolder).'";');
cout('function reloadCaptcha() {alert(11);');
	cout('$(".captcha-main-image").attr("src", "/img/ajax-loader.gif");');
	cout('$(".captcha-main-image").css("height", "30px").css("width", "100px");');
	cout('setTimeout(function(){');
		cout('$(".captcha-main-image").attr("src", "/gfx/captcha/"+RandomString(10)+".gif/captcha_order/");');
	cout('}, 200);');
cout('}');
cout('function RandomString(length) {');
	cout('var chars = "0123456789".split("");');
	cout('if (!length) length = Math.floor(Math.random() * chars.length);');
	cout('var str = "";');
	cout('for (var i = 0; i < length; i++)');
	cout('str += chars[Math.floor(Math.random() * chars.length)];');
	cout('return str;');
cout('}');
cout('function memberClick2($this, parTarg) {');
	cout('var ts = Math.round((new Date()).getTime() / 1000); ');
	cout('var loadurl = $this.attr("href")+"/ajax?"+ts;');
	cout('var targ = parTarg;');
	cout('$.get(loadurl, function(data) {');
		cout('$(targ).html(data);');
		cout('if ($(targ).find("#jumlah").length) {');
			cout('$(targ).find("#jumlah").number( true, 0 );');
		cout('}');
		cout('if ($(targ).find(".captcha-main-image").length) {');
			cout('$(".captcha-main-image").bind("click", function(){reloadCaptcha();});');
		cout('}');
		cout('$(targ).find(".to-ajax").each(function(){');
			cout('$(this).bind("click", function(){');
				cout('memberClick2($(this), targ);');
				cout('return false;');
			cout('});');
		cout('});');
	cout('});');
	cout('return false;');
cout('}');
cout('function memberClick($this) {');
	cout('var ts = Math.round((new Date()).getTime() / 1000); ');
	cout('var loadurl = $this.attr("href")+"/ajax?"+ts;');
	cout('var targ = $this.attr("data-target");');
	cout('$(targ).html("<img src=\"/img/ajax-loader.gif\"/>");');
	cout('$.get(loadurl, function(data) {');
		cout('$(targ).html(data);');
		cout('if ($(targ).find("#jumlah").length) {');
			cout('$(targ).find("#jumlah").number( true, 0 );');
		cout('}');
		cout('if ($(targ).find(".captcha-main-image").length) {');
			cout('$(".captcha-main-image").bind("click", function(){reloadCaptcha();});');
		cout('}');
		cout('$(targ).find(".to-ajax").each(function(){');
			cout('$(this).bind("click", function(){');
				cout('memberClick2($(this), targ);');
				cout('return false;');
			cout('});');
		cout('});');
	cout('});');
	cout('$this.tab("show");');
	cout('$this.parent().parent().find("active").removeClass("active");');
	cout('$this.parent().addClass("active");');
	cout('return false;');
cout('}');
cout('$(\'[data-toggle="tabajax"]\').click(function(e) { memberClick($(this));return false; });');
cout('function bindDatePicker(parSelections) {');
	cout('$(parSelections).datepicker({');
		cout('inline: true,');
		cout('autosize: true,');
		cout('yearRange: "'.(date('Y', time())-70).':'.(date('Y', time())-10).'",');
		cout('changeMonth: true,');
		cout('changeYear: true,');
		cout('dateFormat: "dd-mm-yy"');
	cout('});');
cout('}');
cout('function showErrorDashboardForm(parErr) {');
	cout('var objStr = parErr.toString();');
	cout('var jsonObj = $.parseJSON(parErr);');
	cout('var results = Object.keys(jsonObj).map(function(key) {');
		cout('return [key, jsonObj[key]];');
	cout('});');
	cout('var i=0;');
	cout('var j=0;');
	cout('for (i=0;i<results.length;i++) {');
		cout('$("."+results[i][0]+"-err").html(results[i][1]);');
	cout('}');
cout('}');
?>