var allcookies = document.cookie; var posaafpid = allcookies.indexOf("aafpid"); var posrmid = allcookies.indexOf("RM"); var aafpid = ''; var rmid = ''; var loggedin = false; var loginreferer = new String(window.location); //alert("loginreferer: " + loginreferer); var showlogindebugging = false; if(loginreferer.match("debugloginscript"+"$")){ showlogindebugging = true; } if (posaafpid != -1) { var start = posaafpid + 7; var end = start + 7; aafpid = allcookies.substring(start,end); } if (posrmid != -1) { var start = posrmid + 3; var end = start + 7; rmid = allcookies.substring(start,end); } var remembercheck = ''; if (rmid) { remembercheck = 'CHECKED'; } if (aafpid == '' || aafpid == '0000000') { if(rmid == ''){ rmid = 'ID Number'; } ShowLogin(); } else { NoLogin(); } function hideLoginElement(name) { if (document.getElementById){ document.getElementById(name).style.display = 'none'; } else if (document.all) { document.all[name].style.display = 'none'; } } function showLoginElement(name) { if (document.getElementById) document.getElementById(name).style.display = 'inline'; else if (document.all) document.all[name].style.display = 'inline'; } function getFieldvalue(name) { if (document.getElementById) return document.getElementById(name).value; else if (document.all) return document.all[name].value; } function getImageUrl(argImagePath){ var imagePath = new String(argImagePath); var referPage = new String(window.location); var referUrl = new String("http://www.aafp.org"); if(referPage.indexOf("https://") > -1){ referUrl = new String("https://secure.aafp.org"); } if(imagePath.indexOf("/") == 0){ imagePath = referUrl + imagePath; } else if(imagePath.indexOf("http://") > -1 && referPage.indexOf("https://") == 0){ imagePath = imagePath.replace(/http:/gi, "https:"); } return imagePath; } function NoLogin () { var loginHeaderImageStr = getImageUrl('/online/etc/medialib/aafp_org/images/global_images/mem-sub-login.Par.0001.Image.gif'); document.write('

member / paid subscriber log-in
'); document.write('Log Out

'); loggedin = true; } function ShowLogin () { showLoginAlert("1"); var loginButtonImageStr = getImageUrl('/online/etc/medialib/aafp_org/images/global_images/arrows/redarrow.Par.0001.Image.gif'); showLoginAlert(loginButtonImageStr); showLoginAlert("2"); var loginHeaderImageStr = getImageUrl('/online/etc/medialib/aafp_org/images/global_images/mem-sub-login.Par.0001.Image.gif'); showLoginAlert(loginHeaderImageStr); showLoginAlert("3"); document.write('
'); document.write(''); document.write(''); document.write(''); document.write('

member / paid subscriber log-in
'); document.write('  '); document.write('  '); document.write('
'); showLoginAlert("4"); document.write(''); document.write('Remember Me    '); document.write('Log-in Help

'); document.write('
'); showLoginAlert("5"); if(rmid == 'ID Number'){ hideLoginElement('passwordlogin'); } else{ hideLoginElement('passwordloginshow'); } showLoginAlert("6"); } function showLoginAlert(str){ if(showlogindebugging){ alert(str); } } function LaunchPopup(url,width,height,toolbar,posX,posY) { if (!posX) { posX = 5; } if (!posY) { posY = 5; } var winName = "genPopup"; var window_specifics = 'toolbar='+toolbar+',location='+toolbar+',directories='+toolbar+',status='+toolbar+','+ 'menubar='+toolbar+',scrollbars=1,resizable=1,copyhistory=0,'+ 'width='+width+',height='+height; var helpwin = open('', winName, window_specifics); helpwin.moveTo(posX,posY); helpwin.document.write('Loading... Please Wait' + '

Loading... Please Wait

' + ''); helpwin.location=url; helpwin.opener = self; helpwin.opener.name = "genParent"; } function LaunchWin(url,width,height,toolbar) { window_specifics = 'toolbar='+toolbar+',location='+toolbar+',directories='+toolbar+',status='+toolbar+','+ 'menubar='+toolbar+',scrollbars=1,resizable=1,copyhistory=0,'+ 'width='+width+',height='+height; this.childWin = window.open(url,'childWin', + "" +window_specifics); this.childWin.opener = self; } showLoginAlert("7"); // This is Javascript that will determine if the page is loaded or not // ******************************************************************** if(/Safari/i.test(navigator.userAgent)){ //Test for Safari showLoginAlert("7.1"); var _timer=setInterval(function(){ if(/loaded|complete/.test(document.readyState)){ clearInterval(_timer) doLoginInit() // call target function }}, 10) showLoginAlert("7.2"); } else if (document.addEventListener){ showLoginAlert("7.3"); document.addEventListener("DOMContentLoaded", function(){doLoginInit();}, false); showLoginAlert("7.4"); } else if (document.all && !window.opera){ showLoginAlert("7.5"); logintrythisimg = getImageUrl('/online/images/spacer.gif'); showLoginAlert("logintrythisimg: " + logintrythisimg); document.write(""); showLoginAlert("7.6"); var contentloadtag=document.getElementById("contentloadtag"); showLoginAlert("7.7"); contentloadtag.onreadystatechange=function(){ showLoginAlert("7.7.1"); if (this.readyState=="complete"){ showLoginAlert("7.7.2"); doLoginInit(); } } showLoginAlert("7.8"); } // ******************************************************************** showLoginAlert("8"); function doLoginInit() { showLoginAlert("aafpid: '" + aafpid + "'"); if (aafpid == '' || aafpid == '0000000') { try{ showLoginAlert("9"); if(document.loginForm1.username.value != 'ID Number'){ showLoginAlert("10"); document.loginForm1.username.className='inputtext'; } showLoginAlert("11"); if (window.location && window.location!=""){ document.loginForm1.referer.value = window.location; } /* function body goes here */ showLoginAlert("12"); var pass = getFieldvalue('passwordlogin'); showLoginAlert("13 - pass: '" + pass + "'"); if(rmid == 'ID Number'){ showLoginAlert("14"); showLoginElement('passwordloginshow'); hideLoginElement('passwordlogin'); } else if(pass != '' && pass != 'Last Name/Password'){ showLoginAlert("15"); hideLoginElement('passwordloginshow'); showLoginElement('passwordlogin'); } else{ showLoginAlert("16"); showLoginElement('passwordloginshow'); hideLoginElement('passwordlogin'); } } catch(e){ } } else{ showLoginAlert("No AAFPID"); } } function loginAjax(url, vars, callbackFunction) { request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0"); request.open("GET", url, true); request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { if (request.responseText) { callbackFunction(request.responseText); } }}; request.send(vars); } function loginShowInstitution(json) { var customer; try{ customer = eval('(' + json + ')'); } catch(eeee){ } try{ name = ""; if(customer){ if(customer.name && customer.name != ""){ name = customer.name; } } if(name != ""){ var txt = 'Institution: ' + name + ''; if(!loggedin){ txt = 'Institution: ' + name + ''; } document.getElementById('loginarea').innerHTML = txt; } } catch(eeee){ } } function createUrl(argUrl){ showLoginAlert("IN createUrl: " + argUrl); url = '/online/en/home/publications/journals/afp.proxy.html?p=HomepageLogin&a=InstitutionURL'; hostname = window.location.hostname; if(hostname == 'www.aafp.org' || hostname == 'secure.aafp.org'){ url = argUrl; } showLoginAlert("createUrl: " + url); return url } if(!loggedin){ showLoginAlert("InstitutionURL: http://www.aafp.org/rest/v1/public.pl/model/customer/name?format=json"); loginAjax(createUrl("/rest/v1/public.pl/model/customer/name?format=json"), null, loginShowInstitution); }