// Requires styles in edhelperbaby.css
//
// Log:
//   06/24/08: created - we don't have many so just have random links for now
//
// z=Math.floor(Math.random()*(L2));
// if ((z>=0)&&(z<L2)) {

function babyrand(n1,n2) {
   // return a number from n1 to n2
   var n,r;
   n=n2-n1+1;
   r=Math.floor(Math.random()*(n))+n1;
   return r;
}

var GLOBDN;
function babylinks_str() {
   var R,S,N,A,N1,N2,x,y,S2;
   // GLOBDN[URL]=1 once we are done with it!
   GLOBDN=new Array();
   R="";
   S="";

   // questions
   // try to add N1 questions for pregnancy
   N1=2;
   A=new Array();
   N=babyquestionsnumP();
   S2=new Array();
   N2=0;
   for (x=1;x<=N1+5;x++) {
      y=babyrand(1,N);
      S="T"+y;
      if (N2>=N1) {
      }
      else if (A[S]==1) {
      } else {
         A[S]=1;
         S2[S2.length]=babyquestions_P(y);
         N2++;
         // R=R+"Saving ["+S2[S2.length-1]+"] y="+y+"<BR>";
      }
   }
   // R=R+"S2Length="+S2.length+"<BR>";
   R=R+babylinks_html("PREGNANCY QUESTIONS",S2,R);

   // pregnancy ACTIVITIES
   // try to add N1 activities for pregnancy
   N1=2;
   A=new Array();
   N=babyactivitiesnumP();
   S2=new Array();
   N2=0;
   for (x=1;x<=N1+5;x++) {
      y=babyrand(1,N);
      S="T"+y;
      if (N2>=N1) {
      }
      else if (A[S]==1) {
      } else {
         A[S]=1;
         S2[S2.length]=babyactivities_P(y);
         N2++;
         // R=R+"Saving ["+S2[S2.length-1]+"] y="+y+"<BR>";
      }
   }
   // R=R+"S2Length="+S2.length+"<BR>";
   R=R+babylinks_html("PREGNANCY ACTIVITIES",S2,R);

   // try to add N1 questions for "baby"
   N1=1;
   A=new Array();
   N=babyquestionsnumB();
   S2=new Array();
   N2=0;
   for (x=1;x<=N1+5;x++) {
      y=babyrand(1,N);
      S="T"+y;
      if (N2>=N1) {
      }
      else if (A[S]==1) {
      } else {
         A[S]=1;
         S2[S2.length]=babyquestions_B(y);
         N2++;
      }
   }
   R=R+babylinks_html("QUESTIONS",S2,R);

   if (R.length>0) {
      R="<TABLE cellspacing=0 cellpadding=0 width=100%><TR><TD>&nbsp;&nbsp;</TD><TD>"+R+"</TD><TD>&nbsp;&nbsp;</TD></TR></TABLE><BR>";
   }
   return R;
}

function babylinks_html(T,A,CRTR) {
   // T: Title
   // A: Array of results from the .js calls
   // CRT: the current HTML text; use this so we know if <BR><BR> needed?
   var x,L,R,T2,TITLE,N;
   L=A.length;
   R="";
   N=0;
   for (x=0;x<L;x++) {
      T2=A[x].split(",");
      if (T2.length>=2) {
         URL="http://www.edhelperbaby.com/"+unescape(T2[0]);
         TITLE=unescape(T2[1]);
         if (GLOBDN[URL]==1) {
         } else {
            GLOBDN[URL]=1;
            N++;
            if (N==1) {
               if (CRTR.length>0) {
                   // R=R+"<BR>";
                   R=R+"<TABLE style=\"margin-bottom: 10px;\"></TABLE>";
               }
               R=R+"<span class=\"linkshead\">"+T+"</span><BR>";
            }
            R=R+"<TABLE style=\"margin-bottom: 5px;\"><TR><TD><a href=\""+URL+"\" class=\"articleslinksa\">"+TITLE+"</a></TD></TR></TABLE>";
         }
      }
   }
   return R;
}
