String.prototype.reverse = function () {
return this.split("").reverse().join("");
}
function reformatAmount(input) {
var inputGiven=input.split('.');
var x = inputGiven[0];
x = x.replace(/,/g, "");
x = x.reverse();
x = x.replace(/.../g, function (e) {
return e + ",";
});
x = x.reverse();
x = x.replace(/^,/, "");
if(typeof(inputGiven[1]) !== 'undefined')
{
inputGiven[1] = (inputGiven[1].length == 1) ? inputGiven[1]+'0' : inputGiven[1];
}
var rozero = (typeof(inputGiven[1]) === 'undefined' || inputGiven[1] == '00') ? '' : '.'+inputGiven[1];
return x+''+rozero
}
$(document).ready(function () {
$('body')
.on('click', '#mybutton', function() {
$('#registration').modal('hide');
}).on('click', '#backbutton', function(e) {
e.stopPropagation();
e.preventDefault();
$('#my-payment').modal('hide');
$('#registration').modal('show');
});
});
function checkLogin(){
if($("#terms").prop('checked')==true)
{
return true;
}
else
{
alert($('#lang_accept_terms').val());
return false;
}
}
function check_terms()
{
if($("#terms_").prop('checked')==true)
{
return true;
}
else
{
$('#msgspan').html($('#lang_agree_terms').val());
return false;
}
}
$(function () {
var $form = $('#mc-embedded-subscribe-form');
$('#mc-embedded-subscribe').on('click', function(event) {
if(false === $form.parsley().validate())
{
return false;
}
else
{
register($form);
}
});
});
function register($form) {
$('.listing-loading').show();
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
cache : false,
dataType : 'json',
contentType: "application/json; charset=utf-8",
error : function(err) {
$('.listing-loading').hide();
$('.errorheadcmn').html($('#lang_c_msg').val());
$('.commonMessagePopHtml').html(''+$("#lang_connect_server").val()+'.');
$('#commonMessagePop').modal('show'); },
success : function(data) {
$('.listing-loading').hide();
var sub_mail=$('#mce-EMAIL').val()
$('#mce-EMAIL').val('');
if (data.result != $('#lang_success').val()) {
var message = data.msg;
$('.errorheadcmn').html($('#lang_c_store_returns').val());
$('.commonMessagePopHtml').html(''+message+'');
$('#commonMessagePop').modal('show');
}
else {
registerafterchecknew(sub_mail);
var message = data.msg;
$('.errorheadcmn').html($('#lang_c_msg').val());
$('.commonMessagePopHtml').html(''+message+'');
$('#commonMessagePop').modal('show');
}
}
});
}
function registerafterchecknew(datalist) {
var params={
email:datalist
};
$.ajax({
type: "POST",
url: "/mailchimp_slibuy",
data: params,
dataType: 'json',
success: function (data) {
}
})
}
if ('ontouchstart' in document.documentElement) {
$('body').css('cursor', 'pointer');
}
$('.nospaces').keydown(function(e){
if (e.which === 32) {
e.preventDefault();
}
}).blur(function() {
$(this).val(function(i,oldVal){
return oldVal.replace(/\s/g,'');
});
});
function registerbpops()
{
var auiid = $('#reopenpopbpop').val();
$('#New-login-register').modal('hide');
if($('.pp_id').val()!="")
{
$('#regppid').val($('.pp_id').val());
}
setTimeout(function(){
$('#registration').modal('show');
},500);
}
function restrictemail(tis)
{
var mail = $("#regemail").val();
var x= mail.search("@slibuy");
if(-1!=x){
$('.shemailvlte').html($('#lang_sry_domain_valid').val());
$("#regemail").focus();
}
else{
$('.shemailvlte').html('');
}
}
function submit_login(thibtn,formid)
{
if(false === $('#'+formid).parsley().validate())
{
return false;
}
else
{
$('.page-load').show();
$(thibtn).html('
');
$(thibtn).prop('disabled',true);
var params = $('#'+formid).serialize();
$.ajax({
type: "POST",
url: "/login/save",
data: params,
dataType: 'json',
success: function (data) {
$('.page-load').hide();
$('.ajaxerrpopu').html('');
var textfl = (formid == 'loginform') ? $('#lang_sign_in').val() : $('#lang_c_login').val();
$(thibtn).html(' '+textfl);
if(data.msg == 'nodirect')
{
window.location.href = data.jurl;
return false;
}
else if(data.msg == 'nosep')
{
window.location = ILBASE+'/'+data.jurl;
return false;
}
else if(data.msg == 'yes')
{
window.location = ILBASE;
return false;
}
else if(data.msg == 'no')
{
$('#'+formid+' input').val('');
$(thibtn).prop('disabled',false);
$('.ajaxerrpopu').html(data.jurl);
return false;
}
}
});
}
}
function regform()
{
if(false === $("#regForm").parsley().validate())
{
return false;
}
else
{
$('.didsable').prop('disabled',true);
var params = $("#regForm").serialize();
$.ajax({
type: "POST",
url: "/checkvalidemail",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
if(data.success == 'yes')
{
$('.page-load').show();
$('#carderror-footer').html('');
$('.skippedcd').prop('disabled',true);
$('.gcdblock').prop('disabled',true);
var params = $("#regForm").serialize();
$.ajax({
type: "POST",
url: "/registration_withoutcard",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
$('.page-load').hide();
if(data.success == 'yes')
{
var rduri = $('#anregredirect').val();
var regppid = $('#regppid').val();
if(rduri != '')
{
if(regppid!="")
{
window.location = rduri+"&pro_id="+regppid;
return false;
}
else
{
window.location = rduri;
return false;
}
}
else
{
window.location = '/';
return false;
}
}
else
{
$('.skippedcd').prop('disabled',false);
$('.gcdblock').prop('disabled',false);
$('#carderror-footer').html(data.failedreason.message);
return false;
}
}
});
//$("#registration").modal('hide');
//$("#my-payment").modal('show');
//$('.didsable').prop('disabled',false);
//return false;
}
else
{
$("#regerror").html(data.failedreason);
$('.didsable').prop('disabled',false);
return false;
}
}
});
}
}
function cardregform()
{
if($('#splvi').val() == 1)
{
if($('#termslibox').is(":checked"))
{
$('.page-load').show();
$('#carderror-footer').html('');
$('.skippedcd').prop('disabled',true);
$('.gcdblock').prop('disabled',true);
var params = $("#regForm").serialize();
$.ajax({
type: "POST",
url: "/registration_withoutcard",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
$('.page-load').hide();
if(data.success == 'yes')
{
var rduri = $('#anregredirect').val();
var regppid = $('#regppid').val();
if(rduri != '')
{
if(regppid!="")
{
window.location = rduri+"&pro_id="+regppid;
return false;
}
else
{
window.location = rduri;
return false;
}
}
else
{
window.location = '/';
return false;
}
}
else
{
$('.skippedcd').prop('disabled',false);
$('.gcdblock').prop('disabled',false);
$('#carderror-footer').html(data.failedreason.message);
return false;
}
}
});
}
else
{
$('#carderror-footer').html($("lang_select_teams").val()+'!.');
return false;
}
}
else
{
if(false === $("#cardForm").parsley().validate())
{
return false;
}
else
{
if($('#termslibox').is(":checked"))
{
$('.page-load').show();
$('#carderror-footer').html('');
$('.gcdblock').prop('disabled',true);
$('.skippedcd').prop('disabled',true);
$(".gcdblock").html(''+$("#lang_sign_up").val());
var params = $("#regForm").serialize()+'&'+$("#cardForm").serialize();
$.ajax({
type: "POST",
url: "/checkvalidcard",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
$('.page-load').hide();
$(".gcdblock").html(''+$("#lang_sign_up").val());
if(data.success == 'yes')
{
var rduri = $('#anregredirect').val();
var regppid = $('#regppid').val();
if(rduri != '')
{
$('#redirecturid').val('');
if(regppid!="")
{
window.location = rduri+"&pro_id="+regppid;
return false;
}
else
{
window.location = rduri;
return false;
}
}
else
{
window.location = '/';
return false;
}
}
else
{
if(data.failedreason.code == 'E00039')
{
$('#my-payment').modal('hide');
$('#Auth-dup-pop').modal('show');
return false;
}
else
{
$('#carderror-footer').html(data.failedreason.message);
}
$('.gcdblock').prop('disabled',false);
$('.skippedcd').prop('disabled',false);
return false;
}
}
});
}
else
{
$('#carderror-footer').html($("lang_select_teams").val()+'!.');
return false;
}
}
}
}
function skipCardregform()
{
if($('.ischeckskip').is(":checked"))
{
$('.page-load').show();
$('#carderror-footer').html('');
$('.skippedcd').prop('disabled',true);
$('.gcdblock').prop('disabled',true);
var params = $("#regForm").serialize();
$.ajax({
type: "POST",
url: "/registration_withoutcard",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
$('.page-load').hide();
if(data.success == 'yes')
{
var rduri = $('#anregredirect').val();
var regppid = $('#regppid').val();
if(rduri != '')
{
if(regppid!="")
{
window.location = rduri+"&pro_id="+regppid;
return false;
}
else
{
window.location = rduri;
return false;
}
}
else
{
window.location = '/';
return false;
}
}
else
{
$('.skippedcd').prop('disabled',false);
$('.gcdblock').prop('disabled',false);
$('#carderror-footer').html(data.failedreason.message);
return false;
}
}
});
}
else
{
$('#carderror-footer').html($("#lang_select_teams").val()+'!.');
return false;
}
}
function forgot_checkemail()
{
if(false === $("#loginctrl").parsley().validate())
{
return false;
}
else
{
$('#submit_forgot_password').attr('disabled',true);
var params = $("#loginctrl").serialize();
$.ajax({
type: "POST",
url: "/forgetpasswordvalidemail",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
if(data.success == 'yes')
{
$("#loginctrl").submit();
return false;
}
else
{
$('#submit_forgot_password').attr('disabled',false);
$('#logininvaliderror').html(data.failedreason);
return false;
}
}
});
}
}
function update_auth_duplicate(obj)
{
$(obj).prop('disabled',true);
var fname = $('#firstName').val()+' '+$('input[name="lastName"]').val();
var params = { fname:fname, uname:$('input[name="userName"]').val(), email:$('#regemail').val() };
$.ajax({
type: "POST",
url: "/updateAuthDupe",
data: params,
cache: false,
dataType: 'json',
success: function (data) {
$(obj).prop('disabled',false);
$('#Auth-dup-pop').modal('hide');
return false;
}
});
}
$(document).on('hidden.bs.modal', function (event) {
if ($('.modal:visible').length) {
$('body').addClass('modal-open');
}
});