//vars set in page source:
//	storeRoot, siteDirectory, server_check
//	hasPremiumAccess, hasLimitedAccess, isLoggedIn (only true when user is signed in without IP Auth)
//Add this to sites as we change them and remove the if statement for that site:
//	promoList, sourceSiteName

function trimString (str) {
   return str.split(' ').join('');
}

var theURL = escape(document.URL);
//var promo= siteDirectory; //only change the exceptions
var homeURL = "/jsp/"+siteDirectory+"/index.jsp";
var siteName = "";
var promoArray=new Array(); 
var domainRoot=storeRoot;
var warningMessage = "";

//save the user's state
var isSignedIn = false; //So we know when to let the form submit occur; must be a global variable
var displaySignIn = true;
var useremail = "";

useremail = get_cookie("useremail");

submitInactive = new Image;
submitInactive.src = "/img/universal/signin_submit_inactive.gif";
submitActive = new Image;
submitActive.src = "/img/universal/signin_submit_hover.gif";

if(server_check.search("law-prod3.element115.net") >=0){
   server_check = "www.law.com";
}



if(typeof(promoList) != "undefined" && typeof(sourceSiteName) != "undefined"){//if promolist is declared in the page source
   promoList = promoList + ";PT";//add the platinum promo code
   promoArray = promoList.split(";");
   siteName = sourceSiteName;
   
   if(siteDirectory=="mlj" || siteDirectory=="law" || siteDirectory=="iplawandbusiness" ||  siteDirectory=="scm"){
      displaySignIn = false;
   }else if(siteDirectory=="dailybusinessreview") {
      homeURL = "/index.jsp";
      domainRoot = storeRoot.replace("law", "dailybusinessreview");
   }else if(siteDirectory=="nylj_10"){      
      domainRoot=storeRoot.replace("law","newyorklawjournal");
      homeURL="/index.jsp";      
   }else if(siteDirectory == "ct"){
	  homeURL=server_check;
	  domainRoot=storeRoot.replace("law", "ctlawtribune");
   }else if(siteDirectory == "ct"){
	  homeURL=server_check;
	  domainRoot=storeRoot.replace("law", "americanlawyer");
   }  
}else{
   promoArray.push(siteDirectory);
   
   if(siteDirectory=="ca"){ 
      siteName="The Recorder"; 
   }else if(siteDirectory=="cc09" || siteDirectory=="cc"){
      siteName="Corporate Counsel";
      promoArray.pop();
      promoArray.push("cc");
   }else if(siteDirectory=="dailybusinessreview"){
      siteName="the Daily Business Review";
      homeURL = "/index.jsp";
   }else if(siteDirectory=="lawtechnologynews"){
      siteName="Law Technology News";	
      promoArray.pop();
      promoArray.push("IMLT");
      promoArray.push("LT");
   }else if(siteDirectory=="mlj"){
      siteName="Minority Law Journal";
      displaySignIn = false;
   }else if(siteDirectory=="nj"){
      siteName="New Jersey Law Journal";
   }else if(siteDirectory=="nlj"){
      siteName="National Law Journal";
      promoArray.pop();
      promoArray.push("nl");
   }else if(siteDirectory=="law_firm_inc"){
      siteName="Law Firm Inc";
      promoArray.pop();
      promoArray.push("lfi");
   }else if(siteDirectory=="nylj/nylawyer" || siteDirectory=="nylawyer"){		
      siteName="New York Lawyer";
      promoArray.pop();
      promoArray.push("nyl");
	  homeURL = "/jsp/nylj/nylawyer/index.jsp";
   }else if(siteDirectory=="pa"){
      siteName="The Legal Intelligencer";
   }else if(siteDirectory=="tal"){
      if(theURL.search(/digestTAL/)>=0 || theURL.search(/litigation_daily/)>=0){
         siteName="The Am Law Litigation Daily";
         promoArray.pop();
         promoArray.push("lit");
         homeURL = "/jsp/tal/litigation_daily.jsp";
      } else if(theURL.search(/digestAL/)>=0 ||theURL.search(/PubArticleAL/)>=0 || theURL.search(/asian_lawyer/)>=0){
		siteName="The Asian Lawyer";
		promoArray.pop();
		promoArray.push("asln");
		homeURL = "/jsp/tal/asian_lawyer/index.jsp";
	  } else {
        siteName="AmericanLawyer.com";
      }
   }else if(siteDirectory=="tal_12"){
      if(theURL.search(/digestTAL/)>=0 || theURL.search(/litigation_daily/)>=0){
         siteName="The Am Law Litigation Daily";
         promoArray.pop();
         promoArray.push("lit");
         homeURL = "/litigation_daily.jsp";
      } else if(theURL.search(/digestAL/)>=0 ||theURL.search(/PubArticleAL/)>=0 || theURL.search(/asian_lawyer/)>=0){
		siteName="The Asian Lawyer";
		promoArray.pop();
		promoArray.push("asln");
		homeURL = "/asian_lawyer/index.jsp";
	  } else {
        siteName="AmericanLawyer.com";
        homeURL = "/index.jsp";
      }
   }else if(siteDirectory=="nylitigator"){
      siteName="SmartLitigator.com";
      promoArray.pop();
      promoArray.push("li");
      storeRoot = domainRoot.replace("smartlitigator", "law");
   }else if(siteDirectory=="tx"){
      siteName="Texas Lawyer";
   }else if(siteDirectory=="law"){
      siteName="Law.com";
      promoArray.pop();
      promoArray.push("lc");
   }else if(siteDirectory=="lawjobs"){
      siteName="Lawjobs.com";
      promoArray.pop();
      promoArray.push("lj");
      promoArray.push("lc");
      homeURL = "/newsandviews/index.jsp";
      /*displaySignIn = false;*/
      domainRoot = storeRoot.replace("law", "lawjobs");
   }else if(siteDirectory=="sc"){
      siteName="the Supreme Court Insider";
      promoArray.pop();
      promoArray.push("SC");
      homeURL = "/jsp/nlj/supreme_court_insider.jsp";
   }else if(siteDirectory=="scm"){
      siteName="the U.S. Supreme Court Monitor";
      promoArray.pop();
      promoArray.push("USSupreme");
      displaySignIn = false;
   }else if(siteDirectory=="iplawandbusiness"){
      siteName="I.P. Law and Business";
      promoArray.pop();
      promoArray.push("iplb");
      displaySignIn = false;
   }else if(siteDirectory=="nylj_10"){
      siteName="New York Law Journal";
      homeURL = "/index.jsp";
   }else if(siteDirectory=="ct"){
      siteName="Connecticut Law Tribune";
      homeURL = server_check;
   }
   
   promoArray.push("PT");
}



/**************************/
/**** Start Global Nav ****/
/**************************/

function globalNav() {
   if(!document.getElementById) return null;
      globalNav.display(siteDirectory);
      if(displaySignIn){
         globalNav.showSignIn(siteDirectory);
      }
      
      return true;
}//function globalNav(pub)



globalNav.display=function(siteDirectory){
   if(siteDirectory == "nylj/nylawyer"){
      siteDirectory = "law";
   }	
	
   /* Write global nav links */
   document.write("<div id='law_bar3'>");
   document.write("<div id='logo'><a name='&lpos=global nav bar:logo&lid=global nav bar:logo:image' href='http://www.law.com/jsp/law/index.jsp'><img border='0' alt='Law.com' src='http://www.law.com/images/global_logo2.jpg'></a></div>");
   document.write("<div id='centered_text'><center>Welcome to the Law.com network. <a href='https://store.law.com/Registration/Default.aspx?promoCode=lc&source=http%3A//www.law.com/jsp/law/index.jsp'>Click here</a> to register and get started.</center></div>");
}//GlobalNav.display



/* Check the cookie for user state */
function get_cookie ( cookie_name){
   var results = document.cookie.match ( cookie_name+ '=(.*?)(;|$)' );
   if( results )
      return ( unescape ( results[1] ) );
   else
      return null;
}




globalNav.showSignIn=function(siteDirectory){
   var userAccount = get_cookie ("userAccount");
   var accountType = get_cookie("accountType");
   var ipAccount = get_cookie("ipAccount");

   if(siteDirectory == "lawtechnologynews"){
      siteDirectory = "lt";
   }
   if(siteDirectory == "nlj"){
      siteDirectory = "nl";
   }
   if(siteDirectory == "nylj"){
      siteDirectory = "ny";
   }
   
   if(siteDirectory == "nylj_10"){
      siteDirectory = "ny";
   }
   
   if(siteDirectory == "tal_12"){
      siteDirectory = "tal";
   }
	
   /* signed in if they have a userAccount cookie */
   document.write("<div id='right_links'>");
   
   if(userAccount!=null){
      //document.write("<a class='global' href='javascript:signOut()'>Sign Out</a>");

      if(siteDirectory=="law" || siteDirectory=="law_10"){
         if(ipAccount == null && accountType == null) {
            document.write("<a name='&lpos=global nav bar:sign out' class='global' href='javascript:signOut()'>Sign Out</a><a name='&lpos=global nav bar:my account' class='global' href='https://"+storeRoot+"/Registration/MyAccount.aspx?p="+siteDirectory+"&source="+theURL+"'>My Account</a>");
         }else{
            document.write("<a name='&lpos=global nav bar:sign out' class='global' href='javascript:signOut()'>Sign Out</a>");
         }
      }else if(ipAccount == null && accountType == null) {
         document.write("<a name='&lpos=global nav bar:sign out' class='global' href='javascript:signOut()'>Sign Out</a> | <a name='&lpos=global nav bar:my account' class='global' href='https://"+storeRoot+"/Registration/MyAccount.aspx?p="+siteDirectory+"&source="+theURL+"'>My Account</a>");
      }else{
         document.write("<a name='&lpos=global nav bar:sign out' class='global' href='javascript:signOut()'>Sign Out</a>");
      }
   }else{
      document.write("<a name='&lpos=global nav bar:sign in' class='global' style=\"cursor: pointer;\" onclick=\"addForm(); scoverlay();\" class=\"overlayMore\">SIGN IN</a>")
   }

   document.write("</div>"); // End loginbar div
   document.write("</div>"); // End law_bar3 div
}//globalNav.showSignIn=function(siteDirectory)



function signOut()
{
   document.location = "http://" + domainRoot + "/Registration/Logout.aspx?source=" + theURL;
}



/********************************************/
/**** End Global Nav, Start Registration ****/
/********************************************/
  
//Sign in functions
var signInTop = '<div id="lightbox_box">';
signInTop += '<form name="Form1" method="POST" action="http://'+domainRoot+'/Registration/Login.aspx" id="login-form" ';
var xButton = 'onsubmit="return localSignIn(this, 1);"><p id="lightbox_login_close"><a id="xbox" onClick="document.getElementById(\'lightbox_login\').style.display=\'none\'; scOverlayClose();">X</a></p>';
var premiumText = "";

if(useremail == null || useremail == ""){
   premiumText = 'onsubmit="return localSignIn(this, 2);"><p id="lightbox_login_close"><a onclick="scOverlayClose();" id="xbox" href="'+homeURL+'">X</a></p>';
   premiumText += '<p class="access">The content you have requested requires a premium subscription.</p>';
}else{
   premiumText = 'onsubmit="return localSignIn(this, 2);"><p id="lightbox_login_close"><a onclick="scOverlayClose();" id="xbox" href="'+homeURL+'">X</a></p> <p class="access">The content you have requested requires a premium subscription.</p> <p class="access">'+useremail+' does not have premium access. <a href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click Here To Upgrade.</a></p>';
}



var limitedText = "";
if(typeof(theMessage) == "undefined" || theMessage == null || theMessage == "null"){
   warningMessage = 'onsubmit="return localSignIn(this, 1);"><p id="lightbox_login_close"><a onclick="scOverlayClose();" id="xbox" href="'+homeURL+'">X</a></p><p class="access">Your trial period has expired</p>';
}else{
   warningMessage ='onsubmit="return localSignIn(this, 1);"><p id="lightbox_login_close"><a onclick="scOverlayClose();" id="xbox" href="'+homeURL+'">X</a></p><p class="access">'+theMessage+'</p>';
}



if(useremail == null || useremail == ""){
   limitedText = 'onsubmit="return localSignIn(this, 1);"><p id="lightbox_login_close"><a onclick="scOverlayClose();" id="xbox" href="'+homeURL+'">X</a></p>';
	
   if(siteDirectory =="lawtechnologynews"){
      limitedText += '<p class="access">This content requires free Legal Technology Membership registration.</p>';
   }else{
      limitedText += '<p class="access">This free content is only available with registration.</p>';
   }
}else{
   limitedText = 'onsubmit="return localSignIn(this, 1);"><p id="lightbox_login_close"><a onclick="scOverlayClose();" id="xbox" href="'+homeURL+'">X</a></p> <p class="access">This free content is only available with registration.</p> <p class="access">'+useremail+' does not have an active registration to this publication. <a href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click Here to Register.</a></p>';
}



var signInMiddle1 = '<div class="formStatusMessages">';
signInMiddle1 += '<span id="emailCheckStatus"></span>';
signInMiddle1 += '</div>';
signInMiddle1 += '<h3>Sign In</h3>';
signInMiddle1 += '<table id="formLogin">';
signInMiddle1 += '<tr>';
signInMiddle1 += '<td>Email:</td>';
signInMiddle1 += '<td><input type="text" name="uid" id="uid" size="20" class="required email" onblur="this.value=trimString(this.value);" /></td>';
signInMiddle1 += '</tr>';
signInMiddle1 += '<tr>';
signInMiddle1 += '<td>Password:</td>';

var premiumPassword = '<td><input type="password" name="upass" id="upass" size="20" class="required" onKeyPress="return submitenter(this,event,2)" /></td>';
var limitedPassword = '<td><input type="password" name="upass" id="upass" size="20" class="required" onKeyPress="return submitenter(this,event,1)" /></td>';

var signInMiddle2 = '</tr>';
signInMiddle2 += '<tr>';
signInMiddle2 += '<td>&nbsp;</td>';
signInMiddle2 += '<td class="rememberMe"><input name="rememberme" value="true" checked="true" type="checkbox" /> Remember me</td>';
signInMiddle2 += '</tr>';
signInMiddle2 += '<tr>';
signInMiddle2 += '<td colspan="2">';
signInMiddle2 += '<input type="hidden" name="mode" value="logon" />';
signInMiddle2 += '<input type="hidden" name="source" id="source" value="" />';

var premiumPromo = '<input type="hidden" name="promocode" value="'+promoArray[0]+'" />';
var limitedPromo = '<input type="hidden" name="promocode" value="'+promoArray[0]+':LIMITED" />';

var signInBottom = '<input type="image" id="loginSubmit" src="/img/universal/signin_submit_inactive.gif" width="80px" height="20px" alt="Submit" name="submit" value="submit" onmouseover="img_change(\'active\')" onmouseout="img_change(\'inactive\')" />';
signInBottom += '</td>';
signInBottom += '</tr>';
signInBottom += '</table>';
signInBottom += '<p class="forgetPass"><a onclick="sendPassword();">Forgot your password?</a></p>';
signInBottom += '<p class="newUserRegister">';

var premiumSubscribe = '<a id="subscribelink" href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click here to Subscribe to '+siteName+'! >></a>';
premiumSubscribe += '</p>';
premiumSubscribe += '</form>';
premiumSubscribe += '</div>';

var lawPremiumSubscribe = '<a id="subscribelink" href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click here for your FREE registration to Law.com.  This registration will give you access to all the FREE content within the Law.com network of websites. >></a>';
lawPremiumSubscribe += '</p>';
lawPremiumSubscribe += '</form>';
lawPremiumSubscribe += '</div>';

var ltnPremiumSubscribe = '<a id="subscribelink" href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click here to sign up for free Legal Technology Membership! >></a>';
ltnPremiumSubscribe += '</p>';
ltnPremiumSubscribe += '</form>';
ltnPremiumSubscribe += '</div>';

var limitedSubscribe = '<a id="subscribelink" href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click here to Register for '+siteName+'! >></a>';
limitedSubscribe += '</p>';
limitedSubscribe += '</form>';
limitedSubscribe += '</div>';

var lawLimitedSubscribe = '<a id="subscribelink" href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click here for your FREE registration to Law.com.  This registration will give you access to all the FREE content within the Law.com network of websites. >></a>';
lawLimitedSubscribe += '</p>';
lawLimitedSubscribe += '</form>';
lawLimitedSubscribe += '</div>';

var ltnLimitedSubscribe = '<a id="subscribelink" href="https://'+storeRoot+'/Registration/Default.aspx?promoCode='+promoArray[0]+'&source=' + theURL + '">Click here to sign up for free Legal Technology Membership! >></a>';
ltnLimitedSubscribe += '</p>';
ltnLimitedSubscribe += '</form>';
ltnLimitedSubscribe += '</div>';

var formSubmitInProgress = false;
var promoLocal, premiumReg, limitedReg, expiredReg, warningLevel="0";
var premiumAccess = false;
var limitedAccess = false;
var placAccess = false;


function rewritePage(reqAccess, userAccess, theWarning){
   if(userAccess == 2){
      hasPremiumAccess = true;
      return;
   }

   if(reqAccess == "r" && userAccess == 1){
      hasLimitedAccess = true;
      return;
   }
		
   if(reqAccess == "" || reqAccess == "u" || reqAccess == "null"){ //user has access
      return;
   }

   if(userAccess == 1){
      hasLimitedAccess = true;
   }
		
   var articleSignIn = "";
   var browser = navigator.appName;
   var theHeight = "";
	
   if(theWarning == null){
      theWarning = 0;
   }
	
   //alert("theWarning: "+theWarning+", reqAccess: "+reqAccess+", userAccess: "+userAccess);
	
   if(theWarning != 0){
      articleSignIn = '<div id="lightbox_login">'+signInTop + warningMessage + signInMiddle1 + limitedPassword + signInMiddle2 + limitedPromo + signInBottom + limitedSubscribe+'</div>';
   }else if(reqAccess == "r" && userAccess == 0){
      if(siteDirectory =="law"){
         articleSignIn = '<div id="lightbox_login">'+signInTop + limitedText + signInMiddle1 + limitedPassword + signInMiddle2 + limitedPromo + signInBottom + lawLimitedSubscribe+'</div>';
      }else if (siteDirectory =="lawtechnologynews"){
         articleSignIn = '<div id="lightbox_login">'+signInTop + limitedText + signInMiddle1 + limitedPassword + signInMiddle2 + limitedPromo + signInBottom + ltnLimitedSubscribe+'</div>';
      }else{
         articleSignIn = '<div id="lightbox_login">'+signInTop + limitedText + signInMiddle1 + limitedPassword + signInMiddle2 + limitedPromo + signInBottom + limitedSubscribe+'</div>';
      }
   }else{ //reqAccess == p && userAccess is 0 or 1
      articleSignIn = '<div id="lightbox_login">'+signInTop + premiumText + signInMiddle1 + premiumPassword + signInMiddle2 + premiumPromo + signInBottom + premiumSubscribe+'</div>';
   }

   if(browser == "Microsoft Internet Explorer"){
      document.execCommand('Stop');
   }else{
      window.stop();//non-IE
   }

   document.body.innerHTML = articleSignIn;
   document.getElementById('lightbox_login').style.display = 'block';
   document.getElementById("uid").focus();
   return;
}



//Submit the form if the enter key is pressed
function submitenter(myfield,e,mylevel){
   var keycode;

   if(window.event) keycode = window.event.keyCode;
   else if(e) keycode = e.which;
   else return true;

   if(keycode == 13){
      if(localSignIn(myfield.form, mylevel)){
         myfield.form.submit();
         return false;
      }else{
         return true;
      }
   }else{
      return true;
   }	
}



function addForm(){
   var lightbox = document.getElementById("lightbox_login");

   if(siteDirectory =="law"){
      lightbox.innerHTML = signInTop + xButton + signInMiddle1 + limitedPassword + signInMiddle2 + premiumPromo + signInBottom + lawPremiumSubscribe;
   }else if(siteDirectory =="lawtechnologynews"){
      lightbox.innerHTML = signInTop + xButton + signInMiddle1 + limitedPassword + signInMiddle2 + premiumPromo + signInBottom + ltnPremiumSubscribe;
   }else{
      lightbox.innerHTML = signInTop + xButton + signInMiddle1 + limitedPassword + signInMiddle2 + premiumPromo + signInBottom + premiumSubscribe;
   }

   lightbox.style.display='block';
   document.getElementById("uid").focus();
}



function localSignIn(theForm, theLevel){
   document.getElementById("source").value = document.URL;
   var theEmail = theForm.uid;
   var thePassword =theForm.upass;
   var rememberMe = 0;
	
   if(theForm.rememberme.checked){
      rememberMe = 1;
   }
   if(!validField(theEmail,"Email Address")){
      return false;
   }
   if(!validField(thePassword,"Password")){
      return false; 
   }
   if(!validUser(theEmail, thePassword, rememberMe, theLevel)){
      return false;
   }
   
   return true;
}



function validField(formField,fieldLabel){
   var result = true;
   var theValue = formField.value;

   if(theValue == ""){
      alert('Please enter a value for the "' + fieldLabel +'" field.');
      formField.focus();
      result = false;
   }

   return result;
}


function checkPLAC(pEmail, pPassword, rememberMe, theLevel) {
    //alert("in checkPLAC");
    var theEmail = pEmail.value;
    var thePassword = pPassword.value;
    //alert("theEmail: " + theEmail);
   var theServer = document.domain;
   //alert("theServer: " + theServer);
   //var storeRootPlac = "dev.services.alm.com";
   //var storeRootPlac = "qa.services.alm.com";
   //var storeRootPlac = "stage.services.alm.com";
     var storeRootPlac = "services.alm.com";       
   //alert("storeRootPlac: " + storeRootPlac);
   
   var dataString = 'http://'+storeRootPlac+'/ALM.WebServices.dbRegistration/DataWebservice.asmx/CheckPLAC&queryString=' + 'Email%3d' + theEmail + '%26' + 'Metadata%3D' + metaStr;
   //var dataString = 'http://'+storeRoot+'/Registration/DataWebservice.asmx/CheckLoginAndGetAccessList&queryString=' + 'email%3D' + theEmail + '%26' + 'password%3D' + thePassword;
   //dataString= "http://"+theServer+"/jsp/utils/serviceProxy_test.jsp?server="+dataString; //changed from server_check to theServer
   dataString= "http://"+theServer+"/jsp/utils/serviceProxy.jsp?server="+dataString; //changed from server_check to theServer
   //alert("dataString is " + dataString);
   
   $("#emailCheckStatus").html('<p class="going">Processing...</p>');
   	
   if(formSubmitInProgress)
      return false; //Block form submissions while the prior request is still in progress
      formSubmitInProgress = true; //To block any future requests while this one is in progress
      
      
       $.ajax({
         type: "GET",
         url: dataString,
         dataType: "xml",
         timeout: 30000,
         success: function(data){
            formSubmitInProgress = false; //Remove blocking
            //alert("data: " + data);
            var result = $('string', data).text();
            //alert("result: " + result);
            //make all promo codes have a semi-colon at the beginning
            //result = ";"+result.toLowerCase(); 
       
            if (result != '0') {
                placAccess = true;
               $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
    	        isSignedIn = true; 
               $('#loginSubmit').click();
            } else if (warningLevel != "0") { //user's access has expired
               $("#emailCheckStatus").html('<p>Your ' + warningLevel+'-day access has expired. <br /><a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">Click Here To Upgrade.</a></p>');		
               document.getElementById("subscribelink").href='http://'+storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL;
               document.getElementById("xbox").href='http://'+domainRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&source=http://' + server_check + homeURL;
            }else if(limitedAccess == true && theLevel == 2) { //user has limited access, content is premium
               $("#emailCheckStatus").html('<p>The content you have requested is available only to premium access subscribers. <span class="user">'+theEmail+'</span> only has limited access. <a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">Click Here To Upgrade.</a></p>');
               document.getElementById("subscribelink").href='http://'+storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL;
               document.getElementById("xbox").href='http://'+domainRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&source=http://' + server_check + homeURL;
            }else{
               if(siteDirectory =="lawtechnologynews"){
                  $("#emailCheckStatus").html('<p><a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">This content requires free Legal Technology Membership registration.</a></p>');
               }else{
                  $("#emailCheckStatus").html('<p><span class="user">'+theEmail+'</span> does not have an active registration to this publication. <a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">Click Here to Register.</a></p>');
               }		            

               document.getElementById("subscribelink").href='http://'+storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL;
               document.getElementById("xbox").href='http://'+domainRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&source=http://' + server_check + homeURL;
            }
			
			var s = s_gi(s_account);
			s.linkTrackVars = "prop21,eVar20,events";
			s.linkTrackEvents = "event8";
			s.prop21 = theEmail;
			s.eVar20 = "subscriber login";
			s.events = "event8";
			s.tl(this,'o','login overlay signin');	

         }, //End success function


         error: function(xhr, textStatus, errorThrown) {
            formSubmitInProgress = false; //Remove blocking
            placAccess = true;
	    $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
	    isSignedIn = true; 
            $('#loginSubmit').click();
            /*
            if(textStatus == "timeout"){
               $("#emailCheckStatus").html('<p>The server did not respond in a timely fashion - please try again</p>');
            }            
            else
            {
               $("#emailCheckStatus").html('<p>The login credentials are incorrect - please try again</p>');
               document.getElementById("xbox").href=homeURL;
            }
            */
         } //End error function 
      });

   return false; //To stop the form from submitting
} //End checkPLAC function


function validUser(pEmail, pPassword, rememberMe, theLevel) {
   //alert("in validUser");
   if(isSignedIn){
      return true; //Validation already done, quit now
   }
        	
   var theEmail = pEmail.value;
   var thePassword = pPassword.value;
   var theServer = document.domain;
     
   var dataString = 'http://'+storeRoot+'/Registration/DataWebservice.asmx/CheckLoginAndGetAccessList&queryString=' + 'email%3D' + theEmail + '%26' + 'password%3D' + thePassword;
   dataString= "http://"+theServer+"/jsp/utils/serviceProxy.jsp?server="+dataString; //changed from server_check to theServer
   $("#emailCheckStatus").html('<p class="going">Processing...</p>');
	
   if(formSubmitInProgress)
      return false; //Block form submissions while the prior request is still in progress
      formSubmitInProgress = true; //To block any future requests while this one is in progress

      $.ajax({
         type: "GET",
         url: dataString,
         dataType: "xml",
         timeout: 30000,
         success: function(data){
            formSubmitInProgress = false; //Remove blocking

            var result = $('string', data).text();
            //make all promo codes have a semi-colon at the beginning
            result = ";"+result.toLowerCase(); 

            //comment out 9/26/2011
            //var promoLocal, premiumReg, limitedReg, expiredReg, warningLevel="0";
            //var premiumAccess = false;
            //var limitedAccess = false;
            
            //var regMessage = regMessage;
            //alert("promo array is "+promoArray);
	        
            for(var i = 0; i<promoArray.length;i++){
               //make everything lowercase so that it doesn't matter what we get, it still works
               promoLocal = promoArray[i].toLowerCase();

               if(!premiumAccess){
                  premiumReg=new RegExp(";"+promoLocal+";");
                  premiumAccess = premiumReg.test(result);
               }
			
               if(!limitedAccess){
                  //for checking limited access, change platinum to law.com
                  if(promoLocal == "pt"){
                     limitedReg=new RegExp(";lc;");
                  }else{
                     limitedReg=new RegExp(";"+promoLocal+":limited;");
                  }
                  
                  limitedAccess = limitedReg.test(result);
               }
			
               if(!premiumAccess){
                  //for checking expired access, don't do platinum
                  if(promoLocal != "pt"){
                     expiredReg=new RegExp(";"+promoLocal+":expltd:[0-9]*;");
                     //the promo code is ny, user's codes are ;ny:expltd:1
                     if(expiredReg.test(result)){
                        var temp = expiredReg.exec(result);
                        var getLevel =new RegExp("[0-9]+");
                        warningLevel= getLevel.exec(temp);
                     }
                  }
               }
            }	
            
            
            //Only include cases that grant access here 		
	    if(isLoggedIn == false && (hasPremiumAccess == true || hasLimitedAccess == true)){ //already signed in with IP Auth
	       $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
	       isSignedIn = true; 
	       $('#loginSubmit').click();
	    } else if (limitedAccess == true && theLevel == 1) { //user has limited access
	       $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
	       isSignedIn = true;
	       $('#loginSubmit').click();
	    } else if (premiumAccess == true) { //user has premium access
	       $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
	       isSignedIn = true;
	       $('#loginSubmit').click();
	    }
	    else {//checkPlac
	       checkPLAC(pEmail, pPassword, rememberMe, theLevel); //check plac
	      return false;
           }
            
            
	    /*    		
            if(isLoggedIn == false && (hasPremiumAccess == true || hasLimitedAccess == true)){ //already signed in with IP Auth
               $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
               isSignedIn = true; 
               $('#loginSubmit').click();
            }else if (warningLevel != "0"){ //user's access has expired
               $("#emailCheckStatus").html('<p>Your ' + warningLevel+'-day access has expired. <br /><a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">Click Here To Upgrade.</a></p>');		
               document.getElementById("subscribelink").href='http://'+storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL;
               document.getElementById("xbox").href='http://'+domainRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&source=http://' + server_check + homeURL;
            }else if(limitedAccess == true && theLevel == 1) { //user has limited access
               $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
               isSignedIn = true;
               $('#loginSubmit').click();
            }else if(premiumAccess == true) { //user has premium access
               $("#emailCheckStatus").html('<p class="going">Login successful, please wait...</p>');
               isSignedIn = true; 
               $('#loginSubmit').click();
            }else if(limitedAccess == true && theLevel == 2) { //user has limited access, content is premium
               $("#emailCheckStatus").html('<p>The content you have requested is available only to premium access subscribers. <span class="user">'+theEmail+'</span> only has limited access. <a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">Click Here To Upgrade.</a></p>');
               document.getElementById("subscribelink").href='http://'+storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL;
               document.getElementById("xbox").href='http://'+domainRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&source=http://' + server_check + homeURL;
            }else{
               if(siteDirectory =="lawtechnologynews"){
                  $("#emailCheckStatus").html('<p><a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">This content requires free Legal Technology Membership registration.</a></p>');
               }else{
                  $("#emailCheckStatus").html('<p><span class="user">'+theEmail+'</span> does not have an active registration to this publication.   <a href="http://' + storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL + '">Click Here to Register.</a></p>');
               }		            

               document.getElementById("subscribelink").href='http://'+storeRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&returnUrl=' + theURL;
               document.getElementById("xbox").href='http://'+domainRoot + '/Registration/Login.aspx?mode=logon&uid=' + theEmail + '&upass=' + thePassword + '&rememberme=' + rememberMe + '&promoCode=' + promoArray[0] + '&source=http://' + server_check + homeURL;
            }
	 	*/  	
	 	
	    	
			var s = s_gi(s_account);
			s.linkTrackVars = "prop21,eVar20,events";
			s.linkTrackEvents = "event8";
			s.prop21 = theEmail;
			s.eVar20 = "subscriber login";
			s.events = "event8";
			s.tl(this,'o','login overlay signin');	

         }, //End success function



         error: function(xhr, textStatus, errorThrown) {
            formSubmitInProgress = false; //Remove blocking

            if(textStatus == "timeout"){
               $("#emailCheckStatus").html('<p>The server did not respond in a timely fashion - please try again</p>');
            }else{
               $("#emailCheckStatus").html('<p>The login credentials are incorrect - please try again</p>');
               document.getElementById("xbox").href=homeURL;
            }
         } //End error function 
      });

   return false; //To stop the form from submitting
}//End validUser function
//End Sign in fucntions



// Password Reminder
function sendPassword(){
   var emailField = document.getElementById("uid");
   var theEmail = emailField.value;
   if(theEmail == ""){
      $("#emailCheckStatus").html('<p>Please enter your email address.</p>');
      emailField.focus();
      return false;
   }
   
   var dataString = 'http://'+ storeRoot+'/Registration/DataWebservice.asmx/SendPasswordReminder&queryString=' + escape('Email=' + theEmail + '&PromotionCode=' + promoArray[0]);
   dataString= "http://"+server_check+"/jsp/utils/serviceProxy.jsp?server="+dataString;
   $("#emailCheckStatus").html('<p class="going">Processing...</p>');
   $.ajax({
      type: "GET",
      url: dataString,
      dataType: "xml",
      timeout: 60000,
      success: function(data){
         $("#emailCheckStatus").html('<p>Email sent, please check your inbox.</p>');
      }, //End success function

      error: function(xhr, textStatus, errorThrown){
         if(textStatus == 'timeout'){
            $("#emailCheckStatus").html('<p>The server did not respond in a timely fashion - please try again</p>');
         }else{
            $("#emailCheckStatus").html('<p>There was an error processing your request. Please check your email address.</p>');
         }
         
         emailField.focus();
      } //End error function
   }); //End ajax call
   
   return false;
}



function img_change(imgName){
   if(imgName == "active"){
      document.getElementById("loginSubmit").src = submitActive.src;
   }else{
      document.getElementById("loginSubmit").src = submitInactive.src;
   }
}

/**************************/
/**** End Registration ****/
/**************************/

