if (window.location.host == "localhost"){ var SITE_PATH = 'http://localhost/educationforprotection/advisor/'; }else{ var SITE_PATH = 'http://educationforprotection.com/advisor/'; } function ceateFreeBookClient(){ $ = jQuery.noConflict(); //var checkedElement=document.getElementById("checked"); var email_address = $.trim($("#email_address").val()); var password = $.trim($("#password").val()); var first_name = $.trim($("#first_name").val()); var last_name = $.trim($("#last_name").val()); var street = $.trim($("#street").val()); var city = $.trim($("#city").val()); var state = $.trim($("#state").val()); var zipcode = $.trim($("#zipcode").val()); var phone = $.trim($("#phone").val()); //if(!(checkedElement.checked)) if($("input[name='ebook[]']:checked").length == 0){ toastMessage('You need to select atleast one book from Available Books.'); } else if(email_address=='' || !validateEmail(email_address)){ toastMessage('Invalid Email Address (Username)'); } else if(password.length<2){ toastMessage('Password is required.'); } else if(first_name.length<2){ toastMessage('First Name is required.'); } else if(last_name.length<2){ toastMessage('Last Name is required.'); } else if(street.length<2){ toastMessage('Street Address is required.'); } else if(city.length<2){ toastMessage('City is required.'); } else if(state.length<2){ toastMessage('State is required.'); } else if(zipcode.length<2){ toastMessage('Zip is required.'); } else if(phone.length<2){ toastMessage('Telephone is required.'); } else{ showLoading(); $.ajax({ type:"POST", data:"action=createClient&"+$("#create_client_form").serialize(), url:SITE_PATH+"api/", crossDomain:true, dataType:"json", success: function(dataresult){ hideLoading(); if(dataresult.result=="error"){ toastMessage(dataresult.message); } else if(dataresult.result=="success"){ //alert(dataresult.message); if($.trim(dataresult.thanks_page)!=''){ console.log(dataresult.thanks_page); window.location = dataresult.thanks_page; } } },error: function(xhr,error){ hideLoading(); toastMessage("Conection error please try later."); } }); } } function showLoading(){ $("#overlayer_adviosr").remove(); $("body").append('
'); } function hideLoading(){ $("#overlayer_adviosr").remove(); } function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } function toastMessage(message){ $(".display_bc_messgae").remove(); $("html").append('
'+message+'
'); setTimeout(function(){ $(".display_bc_messgae").remove(); },4000); return false ; }