$(document).ready(function() {
	$("#confirm-form :submit").click(function(e){
		e.preventDefault();
		confirmChecking();
	});

	$("#confirm-form-2 :submit").click(function(e){
		e.preventDefault();
		confirmChecking2();
	});

	$('#ajax-form').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}
			submitHandler(form, flag);
			//console.log('form data===>'+JSON.stringify($(form).serialize()))
		}
	});

	$('#ajax-form-pwd').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			// var mobilePrefix = $('#ajax-form-pwd #mobile-prefix').val(),
			// 	mobileNo = $('#ajax-form-pwd #mobile-no').val();

			// $('#ajax-form-pwd #mobile').val(mobilePrefix+mobileNo);

			submitHandler(form, flag);
			//console.log('form data===>'+JSON.stringify($(form).serialize()))
		}
	});

	$('#ajax-form-join').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			// var mobilePrefix = $('#ajax-form-join #mobile-prefix').val(),
			// 	mobileNo = $('#ajax-form-join #mobile-no').val();

			// $('#ajax-form-join #mobile').val(mobilePrefix+mobileNo);

			submitHandler(form, flag);
			//console.log('form data===>'+JSON.stringify($(form).serialize()))
		}
	});

	$('#ajax-form-2').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			// var mobilePrefix = $('#ajax-form-join #mobile-prefix').val(),
			// 	mobileNo = $('#ajax-form-join #mobile-no').val();

			// $('#ajax-form-join #mobile').val(mobilePrefix+mobileNo);

			submitHandler(form, flag);
			//console.log('form data===>'+JSON.stringify($(form).serialize()))
		}
	});

	$('#ajax-form-3').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			// var mobilePrefix = $('#ajax-form-join #mobile-prefix').val(),
			// 	mobileNo = $('#ajax-form-join #mobile-no').val();

			// $('#ajax-form-join #mobile').val(mobilePrefix+mobileNo);

			submitHandler(form, flag);
			//console.log('form data===>'+JSON.stringify($(form).serialize()))
		}
	});

	$('#ajax-form-ireg').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			submitHandler2(form, flag);
		}
	});

	$('#afs-1').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			if($('#afs-1 .regbank-check').prop("checked") == true){
			    $('#afs-1 .regbank-accno').val($('#afs-1 .regbank-phone').val());
			    $('#afs-1 .regbank-accname').val($('#afs-1 .regbank-username').val());
		  	}
			submitHandler(form, flag);
		}
	});

	$('#afs-2').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			if($('#afs-2 .regbank-check').prop("checked") == true){
			    $('#afs-2 .regbank-accno').val($('#afs-2 .regbank-phone').val());
			    $('#afs-2 .regbank-accname').val($('#afs-2 .regbank-username').val());
		  	}
			submitHandler(form, flag);
		}
	});

	$('#afs-3').submit(function(e) {
		e.preventDefault();
	}).validate({
		submitHandler: function(form) {
			var flag = false;
			if(typeof $(form).data('flag') != "undefined"){
				flag = $(form).data('flag');
			}

			if($('#afs-3 .regbank-check').prop("checked") == true){
			    $('#afs-3 .regbank-accno').val($('#afs-3 .regbank-phone').val());
			    $('#afs-3 .regbank-accname').val($('#afs-3 .regbank-username').val());
		  	}
			submitHandler(form, flag);
		}
	});

	$(document).on('change', '.regbank-bank', function(){
		var dd = $(this).find('option:selected').attr('dd');

		$('.regbank-info').show();
		$('.regbank-check').prop("checked", false)

		if(dd == 'gopay' || dd == 'ovo' || dd == 'dana'){
			$('.regbank-tickbox').show()
		} else {
			$('.regbank-tickbox').hide()
		}

	});

	$(document).on('click', '.regbank-check', function(){
		if($(this).prop("checked") == true){
			$('.regbank-info').hide()
		} else if($(this).prop("checked") == false){
			$('.regbank-info').show()
		}
	});

	if($('.rpb').length){

		$('.rpb').val();

		$('.rpb').bind('change', function() {
			var size = this.files[0].size,
				sizeMB = (size / Math.pow(1024, 2)).toFixed(2) * 1;

			if(sizeMB > 10){
				$(this).closest('div').find('.errmsg').remove();
				$(this).closest('div').append('<div class="errmsg small text-danger">The files ('+sizeMB+' MB) you are trying to send exceeds the 10MB attachment limit.</div>')
				$(this).addClass('err');
			} else {
				$(this).closest('div').find('.errmsg').remove();
				$(this).removeClass('err');
			}

		});

	}

});

function alertMsg(msg){
	jAlert(msg, labels.alert);
}

function successMsg(msg){
	$.alerts.dialogClass = "success"; // set custom style class
	jAlert(msg, labels.success, function() {
		$.alerts.dialogClass = null; // reset to default
	});
}

function confirmMsg(msg, msgTitle, formId, flag){
	$.alerts.okButton = (buttons.yes);
	jConfirm(msg, msgTitle, function(r) {
		if(r==true){
			//$(formId).submit();
			submitHandler(formId, flag);
		}
		else{
			return false;
		}
	});
}

function confirmMsgDepo(msg, msgTitle, formId, flag){
	$.alerts.okButton = (buttons.yes);
	jConfirm(msg, msgTitle, function(r) {
		if(r==true){
			submitHandlerDepo(formId, flag);
		}
		else{
			return false;
		}
	});
}

function ajaxCaller(type, apiUrl, data, callbackFunc){
//	if(!globalObj.login && apiUrl.indexOf('/ajax')==0){
//		return false;
//	}
	jQuery.ajax({
		type: type,
		url: apiUrl+"?"+Math.random(),
		dataType: 'json',
		data: data,
		xhrFields: {
			withCredentials: true
		},
		success: function(res) {
			if(res[0] == prefixs.loginFailed){
				window.location = logout_link;
				clearInterval(intervalId);
				return false;
			}
			else if(res[0] == prefixs.errorExp){
				alertMsg(res[1]);
				return false;
			}
			else if(res[0] == prefixs.success){
				callbackFunc(res);
			}
			else if(res[0] == prefixs.logoutSuccess){
				if($('body').attr('class') == 'banner'){
					window.location = '/banner.html';
				} else {
					window.location = index_link;
				}
			}
		},
		error: function(jqXHR, textStatus, errorThrown) {
			console.log('status==='+jqXHR.status);
			console.log('response==='+jqXHR.responseText);
			//alert(jqXHR.responseText);//Unauthorized
		}
	});
}

function ajaxCaller2(type, apiUrl, data, callbackFunc){
//	if(!globalObj.login && apiUrl.indexOf('/ajax')==0){
//		return false;
//	}
	jQuery.ajax({
		type: type,
		url: apiUrl,
		dataType: 'text',
		data: data,
		xhrFields: {
			withCredentials: true
		},
		success: function(res) {
			callbackFunc(res);
		},
		error: function(jqXHR, textStatus, errorThrown) {
			console.log('status==='+jqXHR.status);
			console.log('response==='+jqXHR.responseText);
		}
	});
}

function ajaxCallerJson(type, apiUrl, data, callbackFunc){
//	if(!globalObj.login && apiUrl.indexOf('/ajax')==0){
//		return false;
//	}
	jQuery.ajax({
		type: type,
		url: apiUrl,
		dataType: 'json',
		data: data,
		xhrFields: {
			withCredentials: true
		},
		success: function(res) {
			callbackFunc(res);
		},
		error: function(jqXHR, textStatus, errorThrown) {
			console.log('status==='+jqXHR.status);
			console.log('response==='+jqXHR.responseText);
		}
	});
}

// function submitHandler(formId, flag){
// 	$.ajax({
// 		type: "POST",
// 		url: $(formId).attr('action'),
// 		dataType: 'json',
// 		data: $(formId).serialize(),
// 		async:false,
// 		success: function(res) {
// 			if(res[0] == prefixs.success){
// 				if(flag){
// 					$.alerts.dialogClass = "success"; // set custom style class
// 					if(res[1]=="labels.registerSuccess"){
// 						jAlert(labels.registerSuccess, labels.success, function() {
// 							$.alerts.dialogClass = null; // reset to default
// 							successCallBack();
// 						});
// 					}else{
// 						jAlert(res[1], labels.success, function() {
// 							$.alerts.dialogClass = null; // reset to default
// 							successCallBack();
// 						});
// 					}
// 					resetForm(formId);
// 				}
// 				else{
// 					if(res[1]=="labels.registerSuccess"){
// 						$.alerts.dialogClass = "success";
// 						jAlert(labels.registerSuccess, labels.success, function() {
// 							$.alerts.dialogClass = null;
// 							window.location = location.href;
// 						});
// 						//successMsg(labels.registerSuccess);
// 					}else{
// 						successMsg(res[1]);
// 					}
// 					resetForm(formId);
// 				}
// 			}
// 			else if(res[0] == prefixs.error){
// 				for(key in res[1]){
// 					var msg = res[1][key];
// 					if(key == prefixs.validateKey){
// 						alertMsg(msg);
// 					}
// 					else{
// 						alertMsg(key+": "+msg);
// 					}
// 				}
// 			}
// 			else if(res[0] == prefixs.errorExp){
// 				alertMsg(res[1]);
// 			}
// 			else if(res[0] == prefixs.errorExp2){
// 				confirmAgreement(res[1]);
// 			}
// 			else if(res[0] == prefixs.errorExp3){
// 				updateBankInfo(res[1]);
// 			}
// 			$(":password").val('');
// 		},
// 		error: function(jqXHR, textStatus, errorThrown) {
// 			alert(jqXHR.responseText);//Unauthorized
// 		}
// 	});
// }

function submitHandler2(formId, flag){
	$.ajax({
		type: "POST",
		url: $(formId).attr('action'),
		dataType: 'json',
		data: $(formId).serialize(),
		async:false,
		success: function(res) {
			if(res[0] == prefixs.success){
				if(flag){
					$.alerts.dialogClass = "success"; // set custom style class
					if(res[1]=="labels.registerSuccess"){
						jAlert(labels.registerSuccess, labels.success, function() {
							$.alerts.dialogClass = null; // reset to default
							successCallBack();
						});
					}else{
						jAlert(res[1], labels.success, function() {
							$.alerts.dialogClass = null; // reset to default
							successCallBack();
						});
					}
					resetForm(formId);
				}
				else{
					if(res[1]=="labels.registerSuccess"){
						$.alerts.dialogClass = "success";
						jAlert(labels.registerSuccess, labels.success, function() {
							$.alerts.dialogClass = null;
							successCallBack();
						});
						//successMsg(labels.registerSuccess);
					}else{
						successMsg(res[1]);
					}
					resetForm(formId);
				}
			}
			else if(res[0] == prefixs.error){
				for(key in res[1]){
					var msg = res[1][key];
					if(key == prefixs.validateKey){
						alertMsg(msg);
					}
					else{
						alertMsg(key+": "+msg);
					}
				}
			}
			else if(res[0] == prefixs.errorExp){
				alertMsg(res[1]);
			}
			else if(res[0] == prefixs.errorExp2){
				confirmAgreement(res[1]);
			}
			else if(res[0] == prefixs.errorExp3){
				updateBankInfo(res[1]);
			}
			$(":password").val('');
		},
		error: function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.responseText);//Unauthorized
		}
	});
}

function submitHandler(formId, flag){

	if(formId.innerHTML){
		submitHandlerDepoFinal(formId, flag);
		return false;
	}

	if($(formId +' .rpb').val()){

		if($(formId +' .rpb').hasClass('err')){
			return false;
		}

		$('body').append('<div id="lda" style="position: fixed; z-index:9999; width: 100%; height: 100%; left: 0px; top: 0px; background-color: rgba(0,0,0,0.8);"><div id="ldab" style="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; font-family: Arial; font-weight: bold; font-size: 12px; color:#ffffff"><img src="/common/images/preloader.svg"><div>Uploading...</div></div></div>');

		var form = $(formId)[0];
        var data = new FormData(form);

		$.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "/upload/id?attachType=7",
            data: data,
            processData: false,
            contentType: false,
            cache: false,
            success: function (data) {
            	$('#lda').remove();
				submitHandlerDepoFinal(formId, flag)
			},
            error: function (e) {
                // console.log("ERROR : ", e);
            }
        });
	} else {
		submitHandlerDepoFinal(formId, flag)
	}

}

function submitHandlerDepo(formId, flag){

	if($(formId +' .rpb').val()){

		if($(formId +' .rpb').hasClass('err')){
			return false;
		}

		$('body').append('<div id="lda" style="position: fixed; z-index:9999; width: 100%; height: 100%; left: 0px; top: 0px; background-color: rgba(0,0,0,0.8);"><div id="ldab" style="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; font-family: Arial; font-weight: bold; font-size: 12px; color:#ffffff"><img src="/common/images/preloader.svg"><div>Uploading...</div></div></div>');

		var form = $(formId)[0];
        var data = new FormData(form);

		$.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "/upload/id?attachType=7",
            data: data,
            processData: false,
            contentType: false,
            cache: false,
            success: function (data) {
            	$('#lda').remove();
				submitHandlerDepoFinal(formId, flag)
			},
            error: function (e) {
                // console.log("ERROR : ", e);
            }
        });
	} else {
		submitHandlerDepoFinal(formId, flag)
	}

}

function submitHandlerDepoFinal(formId, flag){
    $.ajax({
        type: "POST",
        url: $(formId).attr('action'),
        dataType: 'json',
        data: $(formId).serialize(),
        async:false,
        success: function(res) {
            if(res[0] == prefixs.success){

                if(flag){

					$.alerts.dialogClass = "success";

					if(res[1].indexOf(":") !== -1){ //auto transfer

                        var idx = res[1].lastIndexOf(":");
                        var tid = res[1].substring(0, idx);
                        var banktype = res[1].substring(idx+1);

                        if(banktype=='7'){
                        	window.open('https://api567calling.com/bankmgmt/paylink_status.html?tid='+tid, 'BCA Processing', 'width=512,height=650');
                        } else if(banktype=='105' || banktype=='106' || banktype=='107' || banktype=='108'){

                        	if($('#pgForm').length){
                        		$('#pgForm').remove();
                        	}

                        	$('body').append('\
                        		<form id="pgForm" name="pgForm" target="_blank" action="https://fundin.api567calling.com/fundin/ajax/pg/requestDeposit" method="post">\
									<input type="hidden" id="pgData" name="Data" />\
									<input type="hidden" id="pgEncryptText" name="EncryptText" />\
									<input type="hidden" id="pgRemark" name="Remark" />\
								</form>\
                        	')

							var xpres = tid.split("_");
                            var encData = xpres[1];
                            var encTxt = xpres[2];

							document.getElementById("pgData").value = encData;
							document.getElementById("pgEncryptText").value = encTxt;
							document.pgForm.submit();
							$('#pgForm').remove();

						} else if(banktype=='112' || banktype=='1000' || banktype=='1001' || banktype=='1002'){

							if($('#pgForm').length){
                        		$('#pgForm').remove();
                        	}

							var actionURL = 'https://fundin.rpy88calling.com/fundin/ajax/pg/requestDeposit.shtml';

							if (banktype=='1000') {
                        		actionURL = 'https://uatfundin.api567calling.com/fundin/ajax/qrdepo/requestDeposit'
                        	} else if (banktype=='1001' || banktype=='1002') {
                        		actionURL = 'https://uatfundin.api567calling.com/fundin/ajax/ewalletdepo/requestDeposit'
                        	}

							var xpres = tid.split("_");

                            $('body').append('\
                        		<form id="pgForm" name="pgForm" target="_blank" action="' + actionURL + '" method="post">\
									<input type="hidden" name="merchant_code" value="' + xpres[1] + '" />\
									<input type="hidden" name="username" value="' + xpres[2] + '" />\
									<input type="hidden" name="ip_address" value="' + xpres[3] + '" />\
									<input type="hidden" name="trans_amount" value="' + xpres[4] + '" />\
									<input type="hidden" name="currency_code" value="' + xpres[5] + '" />\
									<input type="hidden" name="ref_id" value="' + xpres[6] + '" />\
									<input type="hidden" name="trans_time" value="' + xpres[7] + '" />\
									<input type="hidden" name="return_url" value="' + xpres[8] + '" />\
									<input type="hidden" name="request_url" value="' + xpres[9] + '" />\
									<input type="hidden" name="bank_code" value="' + xpres[10] + '" />\
				    					<input type="hidden" name="ext_ref_id" value="' + xpres[14] + '" />\
									<input type="hidden" name="security_token" value="' + xpres[11] + '" />\
								</form>\
                        	')

							document.pgForm.submit();
							// $('#pgForm').remove();

						} else if(banktype=='113' || banktype=='115' || banktype=='116' || banktype=='117'){

							if($('#pgForm').length){
                        		$('#pgForm').remove();
                        	}

							var xpres = tid.split("_");
							var pflag = xpres[10];

							if(pflag=='1'){

								var ref_id = xpres[5];

								ajaxCaller2('post', '/ajax/credit/getDepositData', 'depId='+ref_id, function(resC){

									var objRes = jQuery.parseJSON(resC);

									if(objRes[0] == prefixs.success){

										var res = jQuery.parseJSON(objRes[1]);

										if(!$('#swalbox').length){
											$('body').append('\
												<div id="swalbox" style="display:none"><script src="/plugins/swal/sweetalert2.all.min.js"></script><link rel="stylesheet" href="/plugins/swal/sweetalert2.min.css" media="screen"></div>\
											')
										}

					                    if(res["status"] == "M00000"){

					                    	var ttt = '<table class="swt"><tr><td style="width:120px">Status:</td><td>'+ res["status"] +'</td></tr><tr><td>Description:</td><td>'+ res["description"] +'</td></tr><tr><td>TicketID:</td><td>'+ res["ticket_id"] +'</td></tr><tr><td>Ref Code:</td><td>'+ res["ref_code"] +'</td></tr><tr><td>Bank Branch:</td><td>'+ res["dest_bank_branch"] +'</td></tr><tr><td>Bank:</td><td>'+ res["dest_bank_code"] +'</td></tr><tr><td>Account No:</td><td>'+ res["dest_acc"] +'</td></tr><tr><td>Account Name:</td><td>'+ res["dest_acc_name"] +'</td></tr><tr><td>Amount:</td><td>Silahkan transfer <b style="color: #3085d6;font-size: 18px;">'+ formatNumber(res["given_amount"]) +'</b>, <br>(menggunakan nominal unik) untuk proses cepat</td></tr><tr><td>Expiry:</td><td style="font-weight: bold;color: #349100;">'+ res["expire_date"] +' (GMT+7)</td></tr><tr><td>Note:</td><td style="color:#ff0000">Harap Transfer dana dengan menggunakan nomor rekening yang sudah terdaftar</td></tr></table><style>.swt {width:100%; border-collapse: collapse; text-align:left; font-size:14px} .swt td {padding:5px; border:1px solid #999999}</style>';

											Swal.fire({
												html: ttt,
												type: 'success',
												confirmButtonText: 'OK'
											})

											return false;

					                    } else {

											var ttt = res["description"];
											var swalFt = 'Status: ' + res["status"];

											Swal.fire({
												html: ttt,
												type: 'error',
												confirmButtonText: 'OK',
												footer: swalFt
											})

											return false;

					                    }

									}

								});

							}

						}


                    } else if(res[1]=="labels.registerSuccess"){
						jAlert(labels.registerSuccess, labels.success, function() {
							$.alerts.dialogClass = null;
							successCallBack();
						});
						$('#popup_overlay').addClass('no-close'); // Prevent close popup by click outside area
					} else if (typeof successCallBackWd === 'function') {
						successCallBackWd();
					} else {
						jAlert(res[1], labels.success, function() {
							$.alerts.dialogClass = null;
							successCallBack();
						});
					}
					resetForm(formId);

				} else {
					if(res[1]=="labels.registerSuccess"){
						$.alerts.dialogClass = "success";
						jAlert(labels.registerSuccess, labels.success, function() {
							$.alerts.dialogClass = null;
							successCallBack();
						});
						$('#popup_overlay').addClass('no-close'); // Prevent close popup by click outside area
					}else{
						successMsg(res[1]);
					}
					resetForm(formId);
				}

            }
            else if(res[0] == prefixs.error){
                for(key in res[1]){
                    var msg = res[1][key];
                    if(key == prefixs.validateKey){
                        alertMsg(msg);
                    } else {
                        alertMsg(key+": "+msg);
                    }
                }
            }
			else if(res[0] == prefixs.errorExp){
				alertMsg(res[1]);
			}
			else if(res[0] == prefixs.errorExp2){
				confirmAgreement(res[1]);
			}
			else if(res[0] == prefixs.errorExp3){
				updateBankInfo(res[1]);
			}
        },
        error: function(jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);//Unauthorized
        }
    });
}

function confirmAgreement(errtext){

	if(!$('#swalbox').length){
		$('body').append('\
			<div id="swalbox" style="display:none"><script src="/plugins/swal/sweetalert2.all.min.js"></script><link rel="stylesheet" href="/plugins/swal/sweetalert2.min.css" media="screen"></div>\
		')
	}

	if(!$('.isAgree').length){
		$('#confirm-form, #confirm-form-2').prepend('<input type="hidden" class="isAgree" name="isAgree" value="0">');
	}

	var ttt = errtext.replace(/\n/g ,'<br>');
		ttt = ttt + '<br><br>Syarat turnover akan ditambahkan. Apakah anda ingin melanjutkan?';

	Swal.fire({
		html: ttt,
		title: 'Apakah anda yakin?',
		type: 'warning',
		showCancelButton: true,
		confirmButtonColor: '#3085d6',
		cancelButtonColor: '#d33',
		confirmButtonText: 'Ya, setuju',
		cancelButtonText: 'Batalkan'
	}).then((result) => {
		if (result.value) {
			$('.isAgree').val('1');

			var amo1 = $("#confirm-form input[name=amount]").val(),
				amo2 = $("#confirm-form-2 input[name=amount]").val();

			if(amo1){
				submitHandler("#confirm-form", true);
			} else if(amo2){
				submitHandler("#confirm-form-2", true);
			}

			setTimeout(function(){ $('.isAgree').val('0'); }, 3000);
		}
	})

}

function processWsData(obj2){
	if(location.host.includes('demolx2.com')) {
		if(obj2.type == ws_logout) {
			sessionLogout();
		} else if(obj2.type == ws_notification) {
			$.alerts.okButton = 'OK';
			jAlert(obj2.message, obj2.username);
			$('#popup_overlay, #popup_container').addClass('no-close'); // Prevent close popup by click outside area
		}
		return;
	}
	var obj = obj2[1];
	if (typeof obj == 'undefined') {
		return;
	}
	if(obj[0] == ws_logout){
		sessionLogout();
	}
	else if(obj[0] == ws_notification){
		var msgData = obj[2];
		// $.jGrowl(msgData[1], {header: msgData[0], sticky: true, position: "bottom-left", glue: "before", close: function(e, m, o){
		// 	send("r::"+obj[1]);
		// }});
		$.alerts.okButton = 'OK';
		jAlert(msgData[1], msgData[0], function() {
			send("r::"+obj[1]);
		});
		$('#popup_overlay, #popup_container').addClass('no-close'); // Prevent close popup by click outside area
	}
	else if(obj[0] == ws_credit){
		var msgData = obj[2];
		$("#currCredit").text(msgData[1]);
	}
}

function parseCurrency(num){
	if(num.length==0){
		return "0";
	}
	var numFixed = num.replace(/\./g,"");
	numFixed = numFixed.replace(",",".");
	numFixed = parseFloat(numFixed);
	return numFixed;
}

function formatDate(val){
	return dateFormat(val, "dd-mmm-yyyy HH:MM");
}

function formatTime(val){
	return dateFormat(val, "HH:MM:ss");
}

function formatNumber(val){
    var rev     = parseInt(val, 10).toString().split("").reverse().join("");
    var rev2    = "";
    for(var i = 0; i < rev.length; i++){
        rev2  += rev[i];
        if((i + 1) % 3 === 0 && i !== (rev.length - 1)){
            rev2 += ",";
        }
    }
    return rev2.split("").reverse().join("");
//    return "Rp. " + rev2.split("").reverse().join("") + ",00";
}

function formatNumberDot(val){
    var rev     = parseInt(val, 10).toString().split("").reverse().join("");
    var rev2    = "";
    for(var i = 0; i < rev.length; i++){
        rev2  += rev[i];
        if((i + 1) % 3 === 0 && i !== (rev.length - 1)){
            rev2 += ".";
        }
    }
    return rev2.split("").reverse().join("");
}

function getUrlParam(){
	var urlParams = {};
	(function () {
		var match,
		pl     = /\+/g,  // Regex for replacing addition symbol with a space
		search = /([^&=]+)=?([^&]*)/g,
		decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
		query  = window.location.search.substring(1);

		while (match = search.exec(query))
			urlParams[decode(match[1])] = decode(match[2]);
	})();

	setPageInfo(urlParams);
}

function delete_cookie ( cookie_name )
{
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();
