var ord = Math.random() * 10000000000000000;

 function areyousure() {
   if (document.login[1].value==""){
     window.alert("Please enter your password to cancel your membership.");
     return(false);
   }
   if (confirm('ARE YOU SURE YOU WANT TO CANCEL YOUR MEMBERSHIP?'))
     return(true);
   else
     return(false);
 }

function processerrormsg(tempstr){
  var tbullstr='&nbsp;&nbsp;<img src="/img/tbull.gif" width=12 height=13 border="0">&nbsp;',ts,
      begstr='<tr><td nowrap height=40 valign=middle><font face="verdana">'+tbullstr+'<b>',
      emailstr='please contact <font color="#0000ee">&#098;&#105;&#108;&#108;&#105;&#110;&#103;&#064;&#115;&#116;&#111;&#099;&#107;&#099;&#111;&#110;&#115;&#117;&#108;&#116;&#097;&#110;&#116;&#046;&#099;&#111;&#109;</font>';
  if (tempstr.indexOf("subexceed")>=0){
    ts=tempstr.split('&');
    document.write(begstr+'You have exceeded the daily limit for the basic membership.</b><br> &nbsp; &nbsp; &nbsp; - Please wait '+ts[1]+' hours and relogin.</font></td></tr>');
  }
  else if (tempstr.indexOf("exceednas")>=0){
    document.write(begstr+'You have exceeded the daily limit for free stock consultations.</b>');
    document.write('<br> &nbsp; &nbsp; &nbsp; - Nasdaq site visitors try the <a href="http://www.stockconsultant.com/consultnow/basicplus.cgi" target="_top">Free Consultant tool</a>.');
    document.write('</font></td></tr>');
  }
  else if (tempstr.indexOf("exceed")>=0){
    document.write(begstr+'You have exceeded the daily limit for free stock consultations.</b>');
    ts=tempstr.split('&'); 
    if (ts.length==2)
      document.write('<br> &nbsp; &nbsp; &nbsp; - Please wait '+ts[1]+' hours and retry or sign up below.');
    document.write('</font></td></tr>');
  }
  else if (tempstr.indexOf("member")>=0)
    document.write(begstr+'You have tried to access a members only page. See screenshot samples below.</b></font></td></tr>');  
  else if (tempstr.indexOf("pleasereg")>=0)
    document.write(begstr+'There was an error. Please try again.</b> If error continues '+emailstr+'</font></td></tr>');      
  else if (tempstr.indexOf("cancelerror")>=0)
    document.write(begstr+'!!! There was an error on cancel membership, please try again.</b><br><br>If error continues '+emailstr+'</font></td></tr>');
  else if (tempstr.indexOf("error")>=0)
    document.write(begstr+'!!! There was an error on sign up, please try again. Make sure you have cookies enabled.</b><br><br>If error continues '+emailstr+'</font></td></tr>');
  else if (tempstr.indexOf("existsmem")>=0)
    document.write(begstr+'Membership already exists please <a href="http://www.stockconsultant.com/login.html">Login</a>. &nbsp; Or first <a href="http://www.stockconsultant.com/signup.html#cancel">Cancel</a> if changing/upgrading a membership.</b><br><br>If in error '+emailstr+'</font></td></tr>');    
  else if (tempstr.indexOf("invalidpass")>=0)
    document.write(begstr+'Unable to cancel membership, incorrect password, please try again or <a href="http://www.stockconsultant.com/password.html">Lookup Password</a>.</b><br><br>If error continues '+emailstr+'</font></td></tr>');
  else if (tempstr.indexOf("emailnotvalid")>=0)
    document.write(begstr+'Unable to cancel membership, email address not valid or expired/cancelled, please try again.</b><br><br>If error continues '+emailstr+'</font></td></tr>');
  else if (tempstr.indexOf("oldpage")>=0){
    window.alert('You were using an old signup page. Click on ok and we will get the latest version.');
    window.location.href="http://www.stockconsultant.com/signup2.html";
   }
  else if (tempstr.indexOf("alreadycancelled")>=0)
    document.write(begstr+'Membership already cancelled.</font></td></tr>');
  else if (tempstr.indexOf("cancelexpired")>=0)
    document.write(begstr+'Membership has expired.</font></td></tr>');
  else if (tempstr.indexOf("cancelledmem")>=0)
    document.write(begstr+'Membership has been cancelled. If any refund is due you will receive an email notification.</font></td></tr>');
  else if (tempstr.indexOf("cancelinactive")>=0)
    document.write(begstr+'Unable to cancel, membership not activated, last sign up attempt was not completed.</font></td></tr>');
  else if (tempstr.indexOf("emailchanged")>=0)
    document.write(begstr+'Unable to cancel, membership email has changed.</font></td></tr>');
    
}  



  function wo(url,win,wsize){
    window.open(url,win,wsize).focus();
  }
  var rn=Math.round(Math.random(1)*100000),
  prews='resizable=1,toolbar=0,location=0,menubar=1,status=1,scrollbars=1,left=30,top=30,screenX=30,screenY=30,',
  ws='resizable=1,toolbar=1,location=1,menubar=1,status=1,scrollbars=1,';
  if (screen.width>810){
    prews+='width=550,height=750'; ws+='width=860,height=760';
  }
  else{
    prews+='width=550,height=550'; ws+='width=790,height=550';
  }

  function getuserdata(){
    var d=getCookie('loginck8753');
    if ((checkifpres(d))&&(d.length>2)&&(d.indexOf("~")>=0)){
      var ld=d.split("~"); 
      document.emailaddr[0].value=ld[1];
      document.login[0].value=ld[1];
    }
  }

  function prescreen(){ 
    wo('http://www.stockconsultant.com/consultnow/prescreened_2.cgi?'+rn,'prescreen',prews);
  }

  function setCookieHome(name, value){
    var c = new Date(); 
    c.setTime(c.getTime() + 15.552E9); /* 6 month cookie */
    document.cookie=name + "=" + escape(value) + "; expires=" + c.toGMTString() + "; path=/;";
  }

  function getCookie(name){
    var re = new RegExp(name + "=([^;]+)"), value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
  }

  function checkemailandpassword(curform) {
    var err=0,t=document.emailaddr[0].value.toLowerCase().replace(/ /g,""),
        p1=document.password[0].value.replace(/ /g,""),p2=document.password[1].value.replace(/ /g,""),
        ts="Please enter a valid email address above",
        illegalChars= /[\`\~\*\(\)\<\>\,\;\:\\\"\[\]]/, myAtSymbolAt = t.indexOf('@'), myLastDotAt = t.lastIndexOf('.'), mySpaceAt = t.indexOf(' '), myLength = t.length;
    if (t.match(illegalChars)){
      window.alert("Illegal characters used in email address, "+ts+".");
      err=1;
    }
    else if (myAtSymbolAt < 1 ){
      window.alert(ts+", at least one @ must be present and not before position 2."); 
      err=1;
    }
    else if (myLastDotAt < myAtSymbolAt){
      window.alert(ts+", at least one . (dot) afer the @ is required.");
      document.emailaddr[0].focus();  return false;
    }
    else if (myLength - myLastDotAt <= 2){
      window.alert(ts+", at least two characters [com, uk, fr, ...] must occur after the last . (dot)");
      err=1;
    }
    else if (mySpaceAt != -1){
      window.alert(ts+', no empty space " " is permitted.');
      err=1;
    }
    if (err){
      document.emailaddr[0].focus();
      return false;
    }
    
  
    eval("document.signup"+curform+".EMAILADDR.value=t;");
    
    setCookieHome('username',t);
    
    if (document.membertype.rad[1].checked)
      eval("document.signup"+curform+".CODE.value=curform+'nr';"); // non recurring code for one time
    else
      eval("document.signup"+curform+".CODE.value=curform;");
              
    err=0;
    if (p1.length<6){
      window.alert("Password not long enough. Min length 6.");
      err=1;
    }
    else if (p1.match(illegalChars)){
      window.alert("Illegal characters used in password, letters A..Z (a..z), numbers (0..9) and (@.) are allowed.");
      err=1;
    }
    else if (p1!=p2){
      window.alert("Password entries don't match, please retype.");
      err=1;
    }
    if (err){
      document.password[0].focus();
      return false;
    }
    
    eval("document.signup"+curform+".PASSWORD.value=p1;");
    
    if (sc_affil.indexOf("nasdaq")<0)
      eval("document.signup"+curform+".NASDAQ.value=0;");
    else
      eval("document.signup"+curform+".NASDAQ.value=1;");
      
    if (document.getElementById("AgreeTerms").checked==0) {
      window.alert("Please agree to the site disclaimer and privacy policy, and check the box above.");
      return false;
    }  
    
    

    return true;
}

 function checkifpres(tmpstr){
   if ((typeof(tmpstr)!='string')||(typeof(tmpstr)=='undefined')) 
     return(0); 
   else if ((tmpstr==null)||(tmpstr=='null')) 
     return(0); 
   else if (tmpstr=='undefined') return(0); 
   return(1);
 }

 function callforum(){ 
   var d=getCookie('loginck8753'),u="",ts,ld;
   if ((checkifpres(d))&&(d.length>3)&&(d.indexOf("~")>=0)) { 
     ld=d.split("~"); 
     if (ld.length==3) { ts=ld[1].split("@");
       if (ts.length==2) u="?userz="+escape(ts[0]+ld[2].substr(0,1)+ld[2].substr(ld[2].length-1,1));
     }
   }
   wo("http://www.stockconsultant.com/forums/netboard.cgi"+u,'parentWin',ws+',left=20,top=20,screenX=20,screenY=20');
 }

 function openwin(name){
   wo(name,'parentWin',ws+',left=20,top=20,screenX=20,screenY=20');
 }

