﻿function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', loadValues);
function loadValues(){ 
    insertValue('EData_FirstName','reg_user_FirstName');
    insertValue('EData_LastName','reg_user_LastName');
    insertValue('EData_Address1','reg_user_Address1');
    insertValue('EData_Address2','reg_user_Address2');
    insertValue('EData_Email','reg_user_EmailAddress');
    insertValue('EData_City','reg_user_City');
    insertValue('EData_PostalCode','reg_user_Zip');
    
    var thisControl=window.document.getElementById('reg_user_State');
    var x;
    for(x=0;x<thisControl.options.length;x++){
        
        if(thisControl.options[x].value==ReadCookie('EData_State')){
            thisControl.selectedIndex=x;
        }
    }
    var bSpecialtySet=false;
    thisControl=window.document.getElementById('reg_user_Specialty');
    var x;
    for(x=0;x<thisControl.options.length;x++){
        if(thisControl.options[x].innerHTML==ReadCookie('EData_Specialty')){
            thisControl.selectedIndex=x;
            bSpecialtySet=true;
        }
    }
    if(!bSpecialtySet){
        for(x=0;x<thisControl.options.length;x++){
            if(thisControl.options[x].value==ReadCookie('EData_Specialty')){
                thisControl.selectedIndex=x;
            }
        }
     }
    
}
function insertValue(cookieName,controlName){
    var thisControl=window.document.getElementById(controlName);
    var thisVal=ReadCookie(cookieName);
    if(thisVal!=";")thisControl.value=thisVal;
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}