var dbObjCollection = [{appNameId:'3',country:'ca',url:'https://plapro.ca/',append_url:'NO',original_url:'',redirect_url:''},]; /* console.log(temp8Check); */ var show_to_selected_country = "YES"; function RemoveLastCharFrmStringWC(dString, rchar){ if(dString != null && rchar != null){ if(dString.length > 0 && rchar.length > 0) { var lastChar = dString.substr(dString.length - 1); if(lastChar == rchar) { dString = dString.slice(0,-1); } } } return dString; } function GetLocation(href) { var l = document.createElement("a"); l.href = href; return l; } var rand="398039506"; modBarjquery (window).bind("load", function() { if(!Cookies.get("loc_select"+rand)){ if(Cookies.get("data")){ if(Cookies.get("data")!="NO"){ bar_text(); }else{ if (show_to_selected_country == "NO"){ bar_text1(); } } modBarjquery ("#mod-top-bar").css("top","0px"); modBarjquery ("#mod-top-bar").css("position","relative"); console.log("bar redirect loaded"); } if(!Cookies.get("mod_cc"+rand)){ modBarjquery .ajax({ url: '//pro.ip-api.com/json/?key=MQXSLbxUAhwAwzB', type: 'POST', dataType: 'jsonp' }).success (function (data1) { console.log ("IP API"); Cookies.set("mod_cc"+rand,data1['countryCode'],{ path: '/'}); Cookies.set("mod_cn"+rand,data1['country'],{ path: '/'}); bar_redirect(); }); }else{ modBarjquery ("#user_location").html(Cookies.get("mod_cn"+rand)); } setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery .ajax({ url: '//geoip.nekudo.com/api', type: 'POST', dataType: 'jsonp' }).success(function(data4){ var data5 = data4['country']; console.log ("Geo IP Nekudo"); Cookies.set("mod_cc"+rand,data5['code'],{ path: '/'}); Cookies.set("mod_cn"+rand,data5['name'],{ path: '/'}); bar_redirect(); }); } }, 2000); /*setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery .ajax({ url: '//freegeoip.net/json/', type: 'POST', dataType: 'jsonp' }).success(function(data2){ Cookies.set("mod_cc"+rand,data2['country_code'],{ path: '/'}); Cookies.set("mod_cn"+rand,data2['country_name'],{ path: '/'}); bar_redirect(); }); } }, 2000);*/ setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery .ajax({ url: "//modapps.com.au/geolocationredirect/index.php/redirect/geo/", dataType: "json", type: "POST", data: { data: "U2FsdGVkX1+qHEePpBAR78b6GXgO5MBpW1n1Z6/Dt4A="} }).success(function(data3){ Cookies.set("mod_cc"+rand,data3['country_code'],{ path: '/'}); Cookies.set("mod_cn"+rand,data3['country_name'],{ path: '/'}); bar_redirect(); }); } }, 2000); /*setTimeout(function(){ modBarjquery ("#mod-top-bar").css("top","0px"); modBarjquery ("#mod-top-bar").css("position","relative"); }, 3500);*/ } }); /*$(document).ready(function(){ modBarjquery ("#bar_country_list").change(function(){ if(modBarjquery ( "#bar_country_list option:selected").val()!=""){ cookie_set(); var append_url="NO"; if(append_url=="YES"){ window.top.location.href =$( "#bar_country_list option:selected").val()+ window.location.pathname; }else{ window.top.location.href =$( "#bar_country_list option:selected").val(); } } }); $("#span_mod_close").click(function(){ $("#mod-top-bar").css("top","-250px"); $("#mod-top-bar").css("position","absolute"); setTimeout(function(){ $("#mod-top-bar").remove(); cookie_set(); }, 2000); }); });*/ function bar_redirect(){ if(Cookies.get("mod_cc"+rand)){ console.log("Cookies found"); var checkUrlPath = ''; var searchAppId = "3"; var searchCountry = Cookies.get("mod_cc"+rand); if(searchCountry != null){ searchCountry = searchCountry.replace(/\"/g, ""); } var searchUrl = window.top.location.href; var resultObj = ''; resultObj = modBarjquery.grep(dbObjCollection, function(e){ return (e.appNameId == searchAppId && (e.country.toUpperCase().indexOf(searchCountry) >= 0)); }); if(resultObj != null){ if (resultObj.length == 0) { // not found console.log("Not found - bar function - searchAppId 3"); Cookies.set("data","NO",{ path: '/'}); if (show_to_selected_country == "NO"){ bar_text1(); } } else { // access the foo property using result[0].foo var rdpURL = GetLocation(resultObj[0].url); if(resultObj[0].append_url.toUpperCase() == "YES") { checkUrlPath = RemoveLastCharFrmStringWC(rdpURL.href,'/') + window.location.pathname; } else { checkUrlPath = rdpURL.href; } console.log(checkUrlPath); if(checkUrlPath.length > 0){ console.log("found county for bar function"); var barMsg = "Yes"; Cookies.set("data",barMsg,{ path: '/'}); bar_text(); } } } } } function bar_text(){ if(modBarjquery ( "#mod-top-bar" ).length==0){ modBarjquery ( "body" ).prepend( '
You are viewing our United States store. Are you in ? If not, choose your store
'); } else { modBarjquery ( "#mod-top-bar" ).html( '
You are viewing our United States store. Are you in ? If not, choose your store
'); } modBarjquery ("#user_location").html(Cookies.get("mod_cn"+rand)); modBarjquery ("#user_location_url").html(Cookies.get("data")); } function bar_text1(){ if(modBarjquery ( "#mod-top-bar" ).length==0){ modBarjquery ( "body" ).prepend( '
'); } else{ modBarjquery ( "#mod-top-bar" ).html( '
'); } modBarjquery ("#user_location").html(Cookies.get("mod_cn"+rand)); } function cookie_set(){ var date = new Date(); date.setTime(date.getTime() + (2 * 1000)); Cookies.set("loc_select"+rand, 1,{ expires: date, path: '/'}); } function call_mod_href(){ cookie_set(); window.top.location.href =modBarjquery ("#redirect_mod__link").attr("name"); return false; }