
i1= new Image(12,12);
i1.src = 'small-info.gif';

i1off= new Image(12,12);
i1off.src = 'small-info-off.gif';

i2= new Image(12,12);
i2.src = 'spc.gif';

i9= new Image(12,12);
i9.src = 'small-error.gif';

function resetphonetip() {
phnumber=document.getElementById('phonenumberbox').value;
 if (phnumber=='') {
 document.getElementById('tiparea1').src=i2.src;
 document.getElementById('tiparea2').innerHTML="";
 }
 else {
 phonenumbertest=numCheck(phnumber,'none');
  if (phonenumbertest=='no') {showtipinfo('ph1','show','error');}
  else {
  document.getElementById('tiparea1').src=i2.src;
  document.getElementById('tiparea2').innerHTML="";
  }
 }
}

function resetpwordtip() {
pwv=document.getElementById('pwordbox').value;
 if (pwv=='') {
 document.getElementById('tiparea1').src=i2.src;
 document.getElementById('tiparea2').innerHTML="";
 }
 else {
 pwl=pwv.length;

  if ((pwv!='')&&(pwl>=6)) {
  pwrdntest=numCheck(pwv,'none');
  pwrdatest=alphaCheck(pwv,'');
  pwrdantest=alphaNumCheck(pwv,'pass');
   if ((pwrdatest=='no')&&(pwrdntest=='no')&&(pwrdantest=='yes')) {
   document.getElementById('tiparea1').src=i2.src;
   document.getElementById('tiparea2').innerHTML="";
   }
   else {showtipinfo('pw','show','error');}
  }
  else {showtipinfo('pw','show','error');}

 }

}

function getsiginfo() {
siggood=document.getElementById('esigbox').disabled;
sigkey=document.getElementById('eskeybox').disabled;
}

function paymethodchange(x) {

 if (x=='pp') {
 showtipinfo();
 document.getElementById('paytypearea1').innerHTML="&#149;Paypal Address:";
 document.getElementById('paytypearea2').innerHTML="<input type=text style='width:162px;' class=srch id=payaddressbox name=payaddressbox onblur=showtipinfo() onfocus=showtipinfo()>";
 }
 else if (x=='chk') {
 fnb=document.getElementById('firstnamebox').value;
 lnb=document.getElementById('lastnamebox').value;
 fullname=fnb+' '+lnb;
 document.getElementById('paytypearea1').innerHTML="&#149;Mailing Address:";
 document.getElementById('paytypearea2').innerHTML="<textarea style='width:162px;height:56px;' class=srch id=payaddressbox name=payaddressbox onclick=showtipinfo()>"+fullname+"</textarea>";
 showtipinfo('mail','show',fullname);
 }
 else {
 showtipinfo();
 document.getElementById('paytypearea1').innerHTML="";
 document.getElementById('paytypearea2').innerHTML="";
 }
}

function showtipinfo(x,y,z) {
ihtml='';

getsiginfo();

 if (y=='show') {

es=i1.src;
esk=i1.src;
bpass=false;
tipareagifholder=i1.src;

  if (x=='fn') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="There is an error in the first name field.";
   }
   else {ihtml="The first name field cannot be changed.";}
  }
  else if (x=='ln') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="There is an error in the last name field.";
   }
   else {ihtml="The last name field cannot be changed.";}
  }
  else if (x=='em') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="There is an error in the email address field.";
   }
   else {ihtml="The username field cannot be changed.";}
  }
  else if (x=='mc') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="You must select your location from the list.";
   }
  }
  else if (x=='pt') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="You must select your pay method from the list.";
   }
  }
  else if (x=='reg') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="You must read the entire Terms and Conditions document, then electronically sign, before submitting this form.";
   }
   else if (z=='error2') {
   tipareagifholder=i9.src;
   ihtml="The E-Signature Key that you typed in did not match the one that we sent you.";
   }
  }
  else if (x=='pw') {
   if (z=='') {
   ihtml="Please follow these guidelines when selecting your secure account password.<br><br>Password Must:<br><br>1. Be 6-8 characters in length.<br>2. Include at least 1 letter and/or 1 number.<br>3. Only include the special characters: # _ * - !";
   }
   else if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="Your password must be 6-8 characters, with at least 1 number and 1 letter. We suggest including one of the special characters from the list below.<br><br>Special Characters:  # _ * - !";
   }
   else {bpass=true;}
  }
  else if (x=='pa') {
   if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="There is an error in the Paypal address field.";
   }
  }
  else if (x=='mail') {
  ihtml="Please format your mailing address EXACTLY as you would write it on an envelope. Please use all appropriate punctuation and capitalization.<br><br>Example:<br><br><span style='font-weight:900;'>"+z+"<br>12345 Sample St.<br>Apt. #152<br>San Diego, CA 92101</span>";
  }
  else if (x=='ph1') {
   if (z=='') {
   ihtml="Please use only numbers, just as you would dial on a telephone keypad.";
   }
   else if (z=='error') {
   tipareagifholder=i9.src;
   ihtml="You can only use numeric characters in the phone number field.";
   }
   else {bpass=true;}
  }
  else if (x=='esk') {
   if ((siggood==false)&&(sigkey==false)) {
   esk=i1off.src;
    if (z=='error') {
    tipareagifholder=i9.src;
     if (eskvalue=='') {ihtml="You must provide the E-Signature Key to proceed with this registration.";}
     else {ihtml="The E-Signature Key must by 7 numeric characters.";}
    }
    else {ihtml="You will find your E-Signature Key in the 'Registration Confirmation' email we sent you, right under the 'Confirmation Link'.";}
   }
   else {bpass=true;}
  }
  else if (x=='es') {
   if ((siggood==false)&&(sigkey==false)) {
   es=i1off.src;
    if (z=='error') {
    tipareagifholder=i9.src;
     if (esvalue=='') {ihtml="You must type (sign) your name in the field provided.";}
     else {ihtml="Please type your name with the characters you would normally sign your name with.";}
    }
    else {
    ihtml="By you typing your name in this box, in conjunction with the E-Signature Key, you reasonably satisfy the legal equivalent of signing this document in person.";
    }
   }
   else {bpass=true;}
  }
  else {}

  if (bpass==false) {
   if ((siggood==false)&&(sigkey==false)) {
   document.getElementById('esinfogif').src=es;
   document.getElementById('eskinfogif').src=esk;
   }
  document.getElementById('tiparea1').src=tipareagifholder;
  document.getElementById('tiparea2').innerHTML="<span style='cursor:pointer;'>"+ihtml+"</span>";
  }
  else {}

 }
 else {
  if ((siggood==false)&&(sigkey==false)) {
  document.getElementById('esinfogif').src=i1.src;
  document.getElementById('eskinfogif').src=i1.src;
  }
 document.getElementById('tiparea1').src=i2.src;
 document.getElementById('tiparea2').innerHTML="";
 }

}

function showSSLinfo() {
ssl="SSL Certificate Information\n---------------------------------\nSite: TopSurveyList.com\nEncryption: 128 Bit\nVerified By: Equifax SCA\nValid Until: 7/20/2011";
alert(ssl);
}

function createRequestObject() {
var ro;
browser = navigator.appName;
 if(browser == "Microsoft Internet Explorer") {
 ro = new ActiveXObject("Microsoft.XMLHTTP");
 }
 else{
 ro = new XMLHttpRequest();
 }
return ro;
}

var http = createRequestObject();
var http1 = createRequestObject();
var http2 = createRequestObject();

function validateEmail(str) {
return ((/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/).test(str))
}

function alphaCheck(x,y) {
alphaTest='no';
 if (x!='') {
  if (y=='last') {re = /[^a-z-]/ig;}
  else if (y=='sig') {re = /[^a-z \.-]/ig;}
  else {re = /[^a-z]/ig;}
  if (!re.test(x)) {alphaTest='yes';}
 }
return alphaTest;
}

function numCheck(x,n) {
numTest='no';
isVar22='no';
xl=x.length;
re = /[^0-9]/;
 if (x!='') {
  if ((xl==n)||(n=='none')) {isVar22 = 'yes';}
  if ((!re.test(x))&&(isVar22 == 'yes')) {numTest='yes';}
 }
return numTest;
}

function alphaNumCheck(x,idVar) {
alphaNumTest='no';
re = /[^a-z0-9 \.]/ig;
if (idVar=='pass') {re=/[^a-z0-9-_!*#]/ig;}
 if (x!='') {
  if(!re.test(x)){alphaNumTest='yes';}
 }
return alphaNumTest;
}

function checkForm1() {

document.getElementById('newsignupsubmitbutton').disabled=true;
document.getElementById('homepageloginbutton').disabled=true;

unx=document.getElementById('un1').value;
pwx=document.getElementById('pw1').value;
pwxl=pwx.length;
vix=document.getElementById('vc1').value;

t=validateEmail(unx);

 if ((unx!='')&&(pwx!='')&&(vix!='')&&(t==true)&&(pwxl>5)) {
 getverification2(vix);
 }
 else {
 alert('Please complete all fields correctly.');
 document.getElementById('newsignupsubmitbutton').disabled=false;
 document.getElementById('homepageloginbutton').disabled=false;
 }

}

function checkForm2() {

document.getElementById('newsignupsubmitbutton').disabled=true;
document.getElementById('homepageloginbutton').disabled=true;

fn=document.getElementById('fn1').value;
ln=document.getElementById('ln1').value;
em=document.getElementById('em1').value;
vi=document.getElementById('vi2').value;

err=0;
errmsg='';

 if (fn=='') {err++;errmsg='- First name field cannot be blank.';}
 else {
 fn=fn.replace(/^\s+|\s+$/g, '');
 fn=fn.toLowerCase();
 st=fn.length;
  for (i = 0; i < st; i++) {
   if (i == 0) {
   tmpChar = fn.substring(0,1).toUpperCase();
   postString = fn.substring(1,st);
   fn = tmpChar + postString;
   }
  }

 achk=alphaCheck(fn,'');
 if (achk=='no') {err++;errmsg='- First name can only contain characters Aa-Zz.';}
 else {document.getElementById('fn1').value=fn;}

 }

 if (ln=='') {
 err++;
  if (errmsg=='') {errmsg='- Last name field cannot be blank.';}
  else {errmsg+='\n- Last name field cannot be blank.';}
 }
 else {
 ln=ln.replace(/^\s+|\s+$/g, '');
 ln=ln.toLowerCase();
 st=ln.length;
  for (i = 0; i < st; i++) {
   if (i == 0) {
   tmpChar = ln.substring(0,1).toUpperCase();
   postString = ln.substring(1,st);
   ln = tmpChar + postString;
   }
  }

 achk2=alphaCheck(ln,'last');
 if (achk2=='no') {
 err++;
  if (errmsg=='') {errmsg='- Last name can only contain the characters Aa-Zz.';}
  else {errmsg+='\n- Last name can only contain the characters Aa-Zz.';}
 }
 else {document.getElementById('ln1').value=ln;}

 }

 if (em=='') {
 err++;
  if (errmsg=='') {errmsg='- Email address field cannot be blank.';}
  else {errmsg+='\n- Email address field cannot be blank.';}
 }
 else {
 em=em.replace(/^\s+|\s+$/g, '');
 em=em.toLowerCase();
 emchk=validateEmail(em);
 if (emchk==false) { 
 err++;
  if (errmsg=='') {errmsg='- Email address must be formatted correctly.';}
  else {errmsg+='\n- Email address must be formatted correctly.';}
 }
 else {document.getElementById('em1').value=em;}

 }

 if (vi=='') {
 err++;
  if (errmsg=='') {errmsg='- Verification field cannot be blank.';}
  else {errmsg+='\n- Verification address field cannot be blank.';}
 }
 else {
 vi=vi.replace(/^\s+|\s+$/g, '');
 nchk=numCheck(vi,5);
  if (nchk=='no') {
  err++;
   if (errmsg=='') {errmsg='- Verification must be 5 numeric characters.';}
   else {errmsg+='\n- Verification must be 5 numeric characters.';}
  }

 }

 if (err==0) {getverification(vi);}
 else {
 alert('Error! Please Correct:\n\n'+errmsg);
 document.getElementById('newsignupsubmitbutton').disabled=false;
 document.getElementById('homepageloginbutton').disabled=false;
 }

}

function enableFullSubmit(x) {
 if (x=='e') {
 document.getElementById('deletemebutton').disabled=false;
 document.getElementById('fullsignupresetbutton').disabled=false;
 document.getElementById('fullsignupsubmitbutton').disabled=false;
 }
 else {
 document.getElementById('deletemebutton').disabled=true;
 document.getElementById('fullsignupresetbutton').disabled=true;
 document.getElementById('fullsignupsubmitbutton').disabled=true;
 }
}

function checkForm3() {

getsiginfo();
fullform=false;

 if ((siggood==false)&&(sigkey==false)) {

 enableFullSubmit('d');

 elementlist="firstnamebox,lastnamebox,emailaddressbox,pwordbox,memberlocation,phonenumberbox,paytype,payaddressbox,esigbox,eskeybox";

 elist=elementlist.split(',');

 s=0;
  while (s<elist.length) {

  thispc=elist[s];

   if (thispc=='firstnamebox') {
   fnvalue=document.getElementById(thispc).value;
   testfnvalue=alphaCheck(fnvalue,'');
    if (testfnvalue!='yes') {showtipinfo('fn','show','error');enableFullSubmit('e');break;}
   }
   else if (thispc=='lastnamebox') {
   lnvalue=document.getElementById(thispc).value;
   testlnvalue=alphaCheck(lnvalue,'last');
    if (testlnvalue!='yes') {showtipinfo('ln','show','error');enableFullSubmit('e');break;}
   }
   else if (thispc=='emailaddressbox') {
   emvalue=document.getElementById(thispc).value;
   testemvalue=validateEmail(emvalue);
    if (testemvalue!=true) {showtipinfo('em','show','error');enableFullSubmit('e');break;}
   }


   else if (thispc=='pwordbox') {
   pwvalue=document.getElementById(thispc).value;
   pwvalue=pwvalue.replace(/^\s+|\s+$/g, '');
   document.getElementById(thispc).value=pwvalue;
   pwlength=pwvalue.length;
    if ((pwvalue!='')&&(pwlength>=6)) {
    pwrdnumtest=numCheck(pwvalue,'none');
    pwrdalphatest=alphaCheck(pwvalue,'');
    pwrdalphanumtest=alphaNumCheck(pwv,'pass');
     if ((pwrdalphatest=='no')&&(pwrdnumtest=='no')&&(pwrdalphanumtest=='yes')) {
     document.getElementById('tiparea1').src=i2.src;
     document.getElementById('tiparea2').innerHTML="";
     }
     else {showtipinfo('pw','show','error');enableFullSubmit('e');break;}
    }
    else {showtipinfo('pw','show','error');enableFullSubmit('e');break;}
   }


   else if (thispc=='memberlocation') {
   mcvalue=document.getElementById(thispc).value;
    if (mcvalue==0) {showtipinfo('mc','show','error');enableFullSubmit('e');break;}
   }
   else if (thispc=='phonenumberbox') {
   phvalue=document.getElementById(thispc).value;
   phvalue=phvalue.replace(/^\s+|\s+$/g, '');
   phonenumbertest2=numCheck(phvalue,'none');
    if (phonenumbertest2=='no') {showtipinfo('ph1','show','error');enableFullSubmit('e');break;}
    else {document.getElementById(thispc).value=phvalue;}
   }
   else if (thispc=='paytype') {
   ptvalue=document.getElementById(thispc).value;
    if (ptvalue==0) {showtipinfo('pt','show','error');enableFullSubmit('e');break;}
   }
   else if (thispc=='payaddressbox') {
    if (ptvalue=='pp') {
    pavalue=document.getElementById(thispc).value;
    pavalue=pavalue.replace(/^\s+|\s+$/g, '');
    pavalue=pavalue.toLowerCase();
    testpavalue=validateEmail(pavalue);
     if (testpavalue!=true) {showtipinfo('pa','show','error');enableFullSubmit('e');break;}
     else {document.getElementById(thispc).value=pavalue;}
    }
   }
   else if (thispc=='esigbox') {
   esvalue=document.getElementById(thispc).value;
   esvalue=esvalue.replace(/^\s+|\s+$/g, '');
   testesvalue=alphaCheck(esvalue,'sig');
    if (testesvalue!='yes') {showtipinfo('es','show','error');enableFullSubmit('e');break;}
    else {document.getElementById(thispc).value=esvalue;}
   }
   else {
    if (thispc=='eskeybox') {
    eskvalue=document.getElementById(thispc).value;
    eskeytest=numCheck(eskvalue,'7');
     if (eskeytest=='no') {showtipinfo('esk','show','error');enableFullSubmit('e');break;}
     else {
     n=Math.floor(Math.random()*9999999);
     http1.open('get', '/gsk.cgi?a='+eskvalue+'&z='+n);
     http1.onreadystatechange = GetSignatureKeyResponse;
     http1.send(null);
     }
    }
   }
  s++;
  }

 }
 else {showtipinfo('reg','show','error');}
}

function GetSignatureKeyResponse() {
 if(http1.readyState == 4){
 response = http1.responseText;
  if (response=='good') {
  alert("Registration Success!\n\nYou have completed your registration and\nwill be redirected to our login page.\n\nThank you again...and \"Welcome\"!");
  document.getElementById('fullsignupform').submit();
  } 
  else {
  showtipinfo('reg','show','error2');
  enableFullSubmit('e');
  }
 }
}

function getverification(x) {
n=Math.floor(Math.random()*9999999);
http.open('get', 'members/vi-3.cgi?a='+x+'&b=signup&z='+n);
http.onreadystatechange = GetVerificationResponse;
http.send(null);
}

function GetVerificationResponse() {
 if(http.readyState == 4){
 response = http.responseText;
  if (response=='true') {document.getElementById('newsignupform').submit();} 
  else {alert(response);
  alert('Error! Please Correct:\n\n- Verification numbers do not match.');
  document.getElementById('vi2').value='';
  document.getElementById('vi2').focus();
  document.getElementById('newsignupsubmitbutton').disabled=false;
  document.getElementById('homepageloginbutton').disabled=false;
  }
 }
}

function getverification2(x) {
n=Math.floor(Math.random()*9999999);
phvalue=document.getElementById('pv').value;
http.open('get', 'members/vi.cgi?a='+x+'&b='+phvalue+'&z='+n);
http.onreadystatechange = GetVerificationResponse2;
http.send(null);
}

function GetVerificationResponse2() {
 if(http.readyState == 4){
 response = http.responseText;
  if (response=='true') {document.getElementById('homepageloginform').submit();} 
  else {
  alert('Error! Please Correct:\n\n- Verification numbers do not match.');
  document.getElementById('vc1').value='';
  document.getElementById('vc1').focus();
  document.getElementById('newsignupsubmitbutton').disabled=false;
  document.getElementById('homepageloginbutton').disabled=false;
  }
 }
}

function confirmdeletemember() {

enableFullSubmit('d');

answer=confirm("This action will delete your\ninformation. Is that OK?");

 if (answer) {
 n=Math.floor(Math.random()*9999999);
 http.open('get', '/dm.cgi?z='+n);
 http.onreadystatechange = DeleteMemberResponse;
 http.send(null);
 }
 else {enableFullSubmit('e');}

}

function DeleteMemberResponse() {
 if(http.readyState == 4){
 response = http.responseText;

  if (response=='good') {
  alert('Registration Cancelled!\n\nYour account has been marked for deletion.');
  location.href='https://members.topsurveylist.com/';
  }
  else {
  alert('Delete Unsuccessful!\n\nPlease contact support to remove your account.');
  enableFullSubmit('e');
  }

 }

}

function checkScrollPosition(elem) {
getsiginfo();
 if(elem.scrollHeight<(elem.scrollTop+elem.offsetHeight)) {
 document.getElementById('esigbox').disabled=false;
 document.getElementById('eskeybox').disabled=false;
 document.getElementById('esinfogif').src=i1.src;
 document.getElementById('eskinfogif').src=i1.src;
 document.getElementById('esigbox').focus();
 }
}
