var user_info_continue=0;var base_url=ajax_base_path;$("#phone").intlTelInput({allowExtensions:false,defaultCountry:"auto",nationalMode:true,numberType:"MOBILE",preferredCountries:['sa','ae','kw','qa','bh','eg','dz','sy'],utilsScript:utils_path});$('#mobile_number_continue').click(function(){$('.info').html('');var submit=true;var number=$("#phone").intlTelInput("getNumber");if(number===""||!check_mobile_number(number)){submit=false;mark($('#phone'),general_error_mobile_number);return submit;}else if(is_mobile_number_exist(number)){mark($('#phone'),error_mobile_number_exist);submit=false;return submit;}
if(submit){wiating_bar("#mobile_number_continue","start");$.ajax({type:"GET",url:base_url+'reg_mobile_number_ajax',data:{number:number},cache:false,async:false,success:function(data){switch(data.status){case '0':mark($('#phone'),data.message);break;case '1':$('#mobile_username').val(data.suggested_names);unmark($('#mobile_username'));getNextStage(2);break;case '3':go_to_register();break;}},fail:function(data){}});wiating_bar("#mobile_number_continue","end");}});$('#mobile_user_info_continue').click(function(){$('.info').html('');var submit=true;var username=$('#mobile_username').val();var password=$('#mobile_password').val();if(user_info_continue==1||username==""||password==""||!check_mobile_password()){submit=false;return false;}
if(submit){try{unmark($('#mobile_username'));unmark($('#mobile_password'));wiating_bar("#mobile_user_info_continue","start");$.ajax({type:"GET",url:base_url+'reg_mobile_user_info_ajax',data:{username:username,password:password,landing_id:bg,c_name:aid,b_id:bid,ref_id:ref},cache:false,async:false,success:function(data){switch(data.status){case '0':mark($('#'+data.field),data.message);break;case '1':getNextStage(3);break;case '3':go_to_register();break;}},fail:function(data){}});wiating_bar("#mobile_user_info_continue","end");}catch(e){alert(e)}}});$('#mobile_active_code_continue').click(function(){var submit=true;var activation_code=$('#activation_code').val();if(activation_code==""){mark($('#activation_code'),error_active_code);submit=false;return submit;}
if(submit){wiating_bar("#mobile_active_code_continue","start");$.ajax({type:"GET",url:base_url+'reg_mobile_activation_code_ajax',data:{activation_code:activation_code,},cache:false,async:false,success:function(data){switch(data.status){case '0':mark($('#activation_code'),data.message);break;case '1':unmark($('#activation_code'));alert(activation_successfully);go_to_base();break;case '3':go_to_register();break;}},fail:function(data){}});wiating_bar("#mobile_active_code_continue","end");}});function is_username_exist(val){var flag=false;$.ajax({type:"GET",url:base_url+'username_ajax_check/'+val,data:{value:val},cache:false,async:false,success:function(data){if(data.indexOf('false')===-1){flag=false;unmark($("#mobile_username"));}else{flag=true;}},fail:function(data){}});return flag;}
function is_mobile_number_exist(number){var flag=false;$.ajax({type:"GET",url:base_url+'is_mobile_number_exist_ajax',data:{number:number},format:'json',cache:false,async:false,success:function(data){if(data.status=='0'){flag=true;}else{flag=false;}},fail:function(data){}});return flag;}
function check_mobile_number(){var telInput=$("#phone");if($.trim(telInput.val())){if(telInput.intlTelInput("isValidNumber")){return true;}else{return false;}}
return true;}
function check_mobile_password(){var val=$("#mobile_password").val();if(val==""){mark($("#mobile_password"),general_error_password);return false;}else{if((val.length<8)||(!val.match((/^(?=.*\d)(?=.*[A-Za-z])[a-zA-Z0-9 !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{8,}$/)))){mark($("#mobile_password"),general_error_password);return false;}}
return true;}
$("#mobile_login").click(function(){getNextStage(1);});function getNextStage(f){switch(f){case 1:$('.info').html('');$('#mobileLoginForm').show('slow');$('#mobile_login').hide('slow');$('#whatsappButton').hide('slow');$('#normal_login').hide('slow');$('#choose').hide('slow');$('#fberrorline').css('display','none');$('#fb-auth').hide('slow');$('#google_login').hide('slow');break;case 2:$('.info').html('');$('#mobileLoginForm').hide('slow');$('#mobileLoginForm').removeClass("go_back");$('#mobile_login').hide("slow");$('#mobileLoginFormSecond').show('slow');break;case 3:$('.info').html('');$('#mobile_activation_code').show('slow');$('#mobileLoginFormSecond').hide('slow');break;}}
function mobileRegisteration(){$('#mobileLoginForm').show('slow');$('#mobile_login').hide('slow');$('#whatsappButton').hide('slow');$('#normal_login').hide('slow');$('#choose').hide('slow');$('#fberrorline').css('display','none');$('#fb-auth').hide('slow');$('#google_login').hide('slow');$('#mobileLoginFormSecond').hide('slow');$('#mobile_activation_code').hide('slow');}
$("#back_main_menu").click(function(){getPreviousStage(0);});$("#back_mobileLoginForm").click(function(){getPreviousStage(1);});$("#back_mobileLoginFormSecond").click(function(){getPreviousStage(2);});function getPreviousStage(f){switch(f){case 0:$('.info').html('');$('#mobileLoginForm').hide('slow');$('#mobile_login').html("الجوال");$('#mobile_login').removeClass("go_back");$('#normal_login').show('slow');$('#mobile_login').show('slow');$('#fb-auth').show('slow');$('#whatsappButton').show('slow');$('#choose').show('slow');$('#fb-auth').show('slow');$('#google_login').show('slow');break;case 1:$('.info').html('');$('#mobileLoginFormSecond').hide('slow');$('#mobileLoginForm').show('slow');break;case 2:$('.info').html('');$('#mobileLoginFormSecond').show('slow');$('#mobile_activation_code').hide('slow');break;}}
$("#mobile_password").blur(function(e){var val=$("#mobile_password").val();if(val===""||val.length<8||(!val.match((/^(?=.*\d)(?=.*[A-Za-z])[a-zA-Z0-9 !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{8,}$/))))
{mark($("#mobile_password"),general_error_password);user_info_continue=1;}else{unmark($('#mobile_password'));user_info_continue=0;}});$("#mobile_username").blur(function(e){var val=$(this).val();unmark($(this));$(this).removeClass('valid');if(val==""||val.length<8||isArabic(val)||(is_username_exist(val))){mark($("#mobile_username"),general_error_username);user_info_continue=1;}else{unmark($("#mobile_username"));user_info_continue=0;}});$("#phone").keydown(function(e){if($.inArray(e.keyCode,[46,8,9,27,13,110,190])!==-1||(e.keyCode==65&&e.ctrlKey===true)||(e.keyCode>=35&&e.keyCode<=40)){return;}
if((e.shiftKey||(e.keyCode<48||e.keyCode>57))&&(e.keyCode<96||e.keyCode>105)){e.preventDefault();}});function isNumeric(n){return!isNaN(parseFloat(n))&&isFinite(n);}
$("#mobileLoginFormSecond").submit(function(event){event.preventDefault();});function getURLParameter(name){return decodeURIComponent((new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g,'%20'))||null}
function go_to_register(){window.location.href="http://af.gamepower7.com/Register";}
function go_to_base(){window.location.href="http://af.gamepower7.com/Download";}
function wiating_bar(div_name,mode){switch(mode){case "start":$(div_name+'_load').html("<img src='"+loading_img+"'  />");$(div_name).css('visibility','hidden');break;case "end":$(div_name+'_load').html("");$(div_name).css('visibility','visible');break;}}
$(document).ready(function(){$('#phone').focus(function(){$('.info').html(info_mobile_number);});$('#activation_code').focus(function(){$('.info').html(activation_message);});});