var dbObjCollection = [{appNameId:'2',country:'af,al,dz,ad,ao,ai,ag,as,ar,am,aw,au,at,az,bh,bd,bb,by,bs,be,bz,bj,bm,bt,ax,ba,bw,bo,br,vg,bv,bn,bg,bf,bi,tc,cm,ca,cv,ky,kh,cf,td,cl,cn,cc,co,cg,cd,ck,cx,cr,ci,hr,cu,km,cy,cz,dk,dj,ec,eg,do,gb,gq,er,sv,ee,et,eu,fk,dm,fo,fj,fi,fr,ga,gm,ge,de,gh,gi,gr,tf,gl,gd,gp,gu,pf,gt,gg,gw,gn,gy,gf,ht,hm,hn,hk,is,in,io,id,ir,hu,iq,ie,im,il,lu,mo,mk,lt,mg,mw,my,mv,ml,li,mq,mr,mu,mx,fm,md,mc,yt,mn,me,ms,ma,mh,mz,na,nr,mt,np,an,nl,ly,nc,pg,nz,lv,lb,ls,lr,ni,ne,ng,nu,nf,kp,la,mp,no,om,kg,pk,pw,ps,pe,py,pn,pl,pa,pt,pr,qa,re,ro,lc,pm,vc,ws,kn,sm,gs,sh,st,sa,sn,cs,rw,rs,sc,sl,sg,ru,sk,si,va,ve,vu,uz,vi,um,uy,ae,ua,ug,us,tm,tr,tn,tt,ke,ki,kw,sb,kz,so,za,kr,es,jo,lk,sd,sr,sj,jp,je,sz,se,eh,vn,tv,to,tk,tg,tl,tz,tj,tw,sy,ch,jm,th,wf,zw,zm,ye,it',url:'',append_url:'NO',original_url:'https://medexamcenter.com/pages/contact-us',redirect_url:'https://medexamcenter.com/pages/contact-us-2'},]; /* console.log(temp8Check); */ 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 urlString = window.top.location.href; urlParams = parseURLParams(urlString); if(urlParams){ if(urlParams['geo']=="false"){ Cookies.set('geo',"false",{ path: '/' }); } } var actual_url= window.location.href; if(actual_url != Cookies.get("same_domain")){ if(!Cookies.get('geo')){ var rand="1126442609"; /*if(Cookies.get("data"+rand)){ window.top.location.href =Cookies.get("data"+rand); } */ if(!Cookies.get("mod_cc")){ 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']); Cookies.set("mod_cn"+rand,data1['country']); auto_url_bar(); auto_bar(); }); } setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery.ajax({ url: "http://api.ipapi.com/api/check?access_key=3b026537ce9f3956700c31bee96daa53", dataType: "jsonp", type: "POST", }).success(function(data4){ var data5 = data4['country_code']; console.log ("Geo IP Nekudo") Cookies.set("mod_cc"+rand,data5['country_code']); Cookies.set("mod_cn"+rand,data5['country_name']); auto_url_bar(); auto_bar(); }); } }, 2000); /*Backed up on 3 sep 2019 due to shutdown of geoip api. setTimeout(function(){ if(!Cookies.get("mod_cc"+rand)){ modBarjquery.ajax({ url: "//geoip.nekudo.com/api", dataType: "jsonp", type: "POST", }).success(function(data4){ var data5 = data4['country']; console.log ("Geo IP Nekudo") Cookies.set("mod_cc"+rand,data5['code']); Cookies.set("mod_cn"+rand,data5['name']); auto_url_bar(); auto_bar(); }); } }, 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: "U2FsdGVkX197SWN3Py7rdUbw/9WaR1dVzAv487S1Wlc="} }).success(function(data2){ Cookies.set("mod_cc"+rand,data2['country_code']); Cookies.set("mod_cn"+rand,data2['country_name']); auto_url_bar(); auto_bar(); }); } }, 2000); } function auto_url_bar(){ if(Cookies.get("mod_cc"+rand)){ var searchAppId = "2"; var searchCountry = Cookies.get("mod_cc"+rand); console.log(searchCountry); if(searchCountry != null){ searchCountry = searchCountry.replace(/\"/g, ""); } var searchUrl = RemoveLastCharFrmStringWC(window.top.location.href,'/').replace('www.',''); console.log(searchUrl); var resultObj = ''; resultObj = modBarjquery.grep(dbObjCollection, function(e){ return (e.appNameId == searchAppId && (e.country.toUpperCase().indexOf(searchCountry) >= 0)) && RemoveLastCharFrmStringWC(e.original_url,'/').replace('www.','') == searchUrl}); console.log(resultObj); if(resultObj != null){ if (resultObj.length == 0) { // not found console.log("Not found - auto_url_bar - searchId 2"); } else { // access the foo property using result[0].foo window.top.location.href=resultObj[0].redirect_url; } } } } function auto_bar(){ if(Cookies.get("mod_cc"+rand)){ var checkUrlPath = ''; var searchAppId = "1"; 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 - auto bar function - searchAppId 1"); } 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 + window.location.search ; } else { checkUrlPath = rdpURL.href; } if(checkUrlPath.length > 0){ Cookies.set("data"+rand,checkUrlPath); Cookies.set("same_domain",resultObj[0].url); window.top.location.href = Cookies.get("data"+rand); } } } } } } function parseURLParams(url) { var queryStart = url.indexOf("?") + 1, queryEnd = url.indexOf("#") + 1 || url.length + 1, query = url.slice(queryStart, queryEnd - 1), pairs = query.replace(/\+/g, " ").split("&"), parms = {}, i, n, v, nv; if (query === url || query === "") { return; } for (i = 0; i < pairs.length; i++) { nv = pairs[i].split("="); n = decodeURIComponent(nv[0]); v = decodeURIComponent(nv[1]); if (!parms.hasOwnProperty(n)) { parms[n] = []; } parms[n].push(nv.length === 2 ? v : null); } return parms; }