/***************************** Creation Log *******************************
    File Name                   -  thanks.js
    Module Name                 -  Telesign Phone verification
    Description                 -  Have the ajax and javascript velidation on the phone number verification by telsign
    Created by                  -  deepakk
    Created on                  -  2011-11-25
    ***************************** Update Log ********************************
    SNo        Updated by       Ver            Updated on          Description
    -------------------------------------------------------------------------*/
var SITE_PATH = window.location.protocol+"//www.pcgamesupply.com";

jQuery(document).ready(function() {
  setTimeout('alertMsgANDLogOut', 600000);
});


function alertMsgANDLogOut(){
    jQuery('#TeleSign').html('<div class="errMessagereset marginT8" id="formerror">Your phone verification time is over. Don\'t worry! A live customer service representative will call you in the next 30 minutes to verify your order.</div>');
}

function submitToCall(rtype){
    jQuery('#telesignpwait').hide();
    if(document.frmTele.country.value==''){
        jQuery('#formerror').html('Select your country');
        jQuery('#formerror').show();
    }else if (document.frmTele.countryCode.value==''){
        jQuery('#formerror').html('Enter ISD code in Phone Number');
        jQuery('#formerror').show();
    }else if(document.frmTele.phoneNum.value=='' || !fnc_IsValidNumber(document.frmTele.phoneNum.value)){
        jQuery('#formerror').html('Please only enter numbers. Do not include dashes or any other special characters in your phone number.');
        jQuery('#formerror').show();
    }else{
        jQuery('#formerror').hide();
        jQuery('#telesignpwait').show();
        jQuery('#telesignpwait').html("<p><span>Please wait...</span><img src='/assets/images/ajax-loader2.gif'></p>")
        var dvar = jQuery('#frmTele').serialize();
        jQuery.ajax({
            type: "POST",
            url:  "/core/make_call_by_telesign.php?sub="+rtype,
            data: dvar,
            success: function(responce){
                if(responce=='NOT_A_VALID_TYPE'){
                    jQuery('#formerror').html('It appears the phone number you are entering is not a valid phone number for your selected country. Please enter a valid phone number or update country.');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else if(responce=='NOT_A_SMS_TYPE'){
                    jQuery('#formerror').html('Landlines cannot receive a SMS. Please try to call!');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else if(responce == 'ProblemToVerify'){
                    jQuery('#formerror').html('Sorry, it looks like you are having trouble completing telephone verification. Don\'t worry! a live customer service representatives will call you in the next 30 minutes to verify your order.');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else if(responce == 'AlreadyExit'){
                    jQuery('#formerror').html('We are sorry, this phone number has already been used on another account.');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else if(responce == 'TimeOut'){
                    jQuery('#formerror').html('Your phone verification time is over. Don\'t worry! A live customer service representative will call you in the next 30 minutes to verify your order.');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else if(responce == 'NotValid'){
                    jQuery('#formerror').html('It appears the phone number you are entering is not a valid phone number for your selected country. Please enter a valid phone number or update country.');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else{
                    //jQuery('#TeleSign').html(responce);
                    jQuery('#TeleSign').html("<p><span>Please wait...</span><img src='/assets/images/ajax-loader2.gif'></p>")
                    jQuery.ajax({
                        url:  SITE_PATH+"/core/telesign_pin_code.php",
                        success: function(responce){
                            jQuery('#TeleSign').html(responce);
                        }
                    });
                }
            }
        });
    }
    return false;
}


function submitToVerify(){
    jQuery('#telesignpwait').hide();
    if(document.frmVer.verificationCode.value=='' || document.frmVer.verificationCode.value.length!=5 || !fnc_IsValidNumber(document.frmVer.verificationCode.value)){
        jQuery('#formerror').html('Enter PIN Code');
        jQuery('#formerror').show();
    }else{
        jQuery('#formerror').hide();
        jQuery('#telesignpwait').show();
        jQuery('#telesignpwait').html("<p><span>Please wait...</span><img src='/assets/images/ajax-loader2.gif'></p>")
        var dvar = jQuery('#frmVer').serialize();
        jQuery.ajax({
            type: "POST",
            url:  SITE_PATH+"/core/status_call_by_telesign.php",
            data: dvar,
            success: function(responce){
                if(responce == 'TimeOut'){
                    jQuery('#formerror').html('<div class="errMessagereset marginT8" id="formerror">Your phone verification time is over. Don\'t worry! A live customer service representative will call you in the next 30 minutes to verify your order.</div>');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else if(responce == 'NotValid'){
                    jQuery('#formerror').html('You have entered invalid PIN Code.');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                }else{
                    jQuery('#TeleSign').html(responce);
                }
            }
        });
    }
    return false;
}

function fnc_IsValidNumber(aValue)
{
    var i=0;
    var temp="";
    var test="";

    for (i=0; i < aValue.length; i++)
    {
        temp = aValue.substring(i, i+1);
        if ((temp < "0" || temp > "9"))
            test ="no";
    }

    if (test != "" )
        return false;
    else
        return true;
}

function m_load_phone_verification(ref){
    jQuery('#TeleSign').html("<p><span>Please wait...</span><img src='/assets/images/ajax-loader2.gif'></p>")
    if(ref=='1'){
        jQuery.ajax({
            url:  SITE_PATH+"/core/telesign_form.php",
            success: function(responce){
                if(responce == 'TimeOut'){
                    jQuery('#TeleSign').html('<div class="errMessagereset marginT8" id="formerror">Your phone verification time is over. Don\'t worry! A live customer service representative will call you in the next 30 minutes to verify your order.</div>');
                //jQuery('#formerror').show();
                //jQuery('#telesignpwait').hide();
                }else{
                   if(responce == 'ProblemToVerify'){
                    jQuery('#TeleSign').html('<div class="errMessagereset marginT8" id="formerror">Sorry, it looks like you are having trouble completing telephone verification. Don\'t worry! a live customer service representatives will call you in the next 30 minutes to verify your order.</div>');
                    jQuery('#formerror').show();
                    jQuery('#telesignpwait').hide();
                   }else{
                    jQuery('#TeleSign').html(responce);
                    //alert(document.frmTele.country.value);
                    var countrycode = document.frmTele.country.value;
                    m_GetCountryPhoneCode(countrycode.toUpperCase());
                  }
                }
            }
        });
    }else{
        jQuery.ajax({
            url:  SITE_PATH+"/core/telesign_pin_code.php",
            success: function(responce){
                if(responce == 'TimeOut'){
                    jQuery('#TeleSign').html('<div class="errMessagereset marginT8" id="formerror">Your phone verification time is over. Don\'t worry! A live customer service representative will call you in the next 30 minutes to verify your order.</div>');
                //jQuery('#formerror').show();
                //jQuery('#telesignpwait').hide();
                }else{
                    jQuery('#TeleSign').html(responce);
                }
            }
        });
    }
}
