var sbmval = 0;

mode = "normal";

if (k > 1)
 {
  if (valarray[0] == "mode")
  {
    mode = valarray[1];
  }
 }

 width = 100;
 height = 100;
 imgsrc = "white_bg.gif";
 bkgsrc = "white_bg.gif";
 itmcde = 0;

 var imgName = "imgA";
 var bkgName = "imgB";
 var imgnbr = 0;
 icnt = inm.length - 1; // to get number of images 
 bcnt = bgnm.length - 1; // to get number of backgrounds 

document.write("<table border='0' cellpadding='0' cellspacing='0' width='575'>");
document.write("<tr><td><br><font color='#FFFFFF' size='5' face='Arial'>");
document.write("<center><b>&quot;Encourage one another daily&quot;<font size='2'> (Heb. 3:13)</font><br><font size='3' color='#fcfc08'>");
document.write("<br>Custom design an animated ecard<br>and send it by email or PM to bless a friend.</b></font><br><br>");
document.write("<font color='#FFFFFF' size='2' face='Arial'>");
document.write("(see instructions below the form)<br>");
document.write("<br>");

document.write("<form action='javascript:form_action()' method='GET' name='sendemail'>");

document.write("<div align='center'><center><table border='0' cellpadding='0' cellspacing='0' bgcolor='#999999'>");
document.write("<tr><td>");
document.write("<div align='center'><center><table border='1' background='white_bg.gif' cellpadding='5' cellspacing='0' width='520' bgcolor='#FFFFFF'>");
document.write("<tr><td>");
document.write("<p align='left'><font color='#400080' size='2' face='Arial'><br>");

imgval = valarray2[2];

   if (imgval == 0)
    {
     document.write("<center><font color=red size=3><b>No image selected.</b><br><br><font size=1>(Select an image from the galleries on the left to begin building your ecard)</font></font><br><br><br></center>");
    }

// === category ===   
   document.write("<b>Season Category:<b>&nbsp;&nbsp;<select name='cat1' size='1' onChange='UpdateCatList(1)'>");
         document.write("<option selected value ='0'>Select a category ........................");
		 k = catary.length;   // to get number of catary array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option value ='" + i + "'>" + catary[i]);
		   }
   document.write("</select><br><br>");

// === title ===   
   document.write("<b>Title:<b>&nbsp;&nbsp;<select name='t' size='1'>");
         document.write("<option selected value ='0'>Select a title if desired ..........................");
		 k = ttl.length;   // to get number of ttl array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option  value ='" + i + "'>" + ttl[i]);
		   }
   document.write("</select><br><br>");

// === message ===      
   document.write("<b>Message:&nbsp;&nbsp;<b><select name='m' size='1'>");
         document.write("<option selected value ='0'>none ............................");
		 k = msgtxt.length;   // to get number of msg array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option  value ='" + i + "'>" + msgtxt[i]);
		   }
   document.write("</select>");
   document.write("&nbsp;&nbsp;<a href='javascript:previewwindow(6)' title='Preview selected message'>preview</a><br><br>");

// === message text color ===   
   document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color for message text:&nbsp;&nbsp;<select name='c' size='1'>");
         document.write("<option selected value ='0'>purple");
         document.write("<option value ='1'>blue");
         document.write("<option value ='2'>red");
         document.write("<option value ='3'>green");
         document.write("<option value ='4'>dark purple");
         document.write("<option value ='5'>gold");
         document.write("<option value ='6'>orange");
         document.write("<option value ='7'>burgundy");
         document.write("<option value ='8'>gray");
         document.write("<option value ='9'>pink");
         document.write("<option value ='10'>brown");
         document.write("<option value ='11'>black");
         document.write("</select><br><br>");
   
// === animation ===   
   document.write("Animation:&nbsp;&nbsp;<select name='a' size='1'>");
         document.write("<option selected value ='0'>none");
         document.write("<option value ='1'>water drops (interactive)");
         document.write("<option value ='2'>reflection");
         document.write("<option value ='3'>light source (interactive)");
         document.write("<option value ='4'>color rotation");
         document.write("<option value ='5'>magnifying lens (interactive)");
         document.write("<option value ='6'>snow falling");
         document.write("<option value ='7'>fireworks (interactive)");
         document.write("<option value ='8'>fog");
         document.write("<option value ='9'>fog and rain");
         document.write("<option value ='10'>fog, rain, and lightning");
         document.write("</select>");

         document.write("&nbsp;&nbsp;&nbsp;&nbsp;Height <font size=1>(optional)</font>&nbsp;<input type='text' size='5' maxlength='4' name='rheight'></textarea><br><br>");

// === music/sound ===   
   document.write("Song/Sound:&nbsp;&nbsp;<select name='s' size='1'>");
         document.write("<option selected value ='1'>none");
         document.write("<option value ='2'>Amazing Grace");
         document.write("<option value ='3'>I Believe");
         document.write("<option value ='4'>American Medley");
         document.write("<option value ='5'>As the Deer");
         document.write("<option value ='6'>God Is So Good");
         document.write("<option value ='7'>Hallelujah Chorus");
         document.write("<option value ='8'>What A Friend We Have In Jesus");
         document.write("<option value ='9'>Joy to the World");
         document.write("<option value ='10'>Water");
         document.write("<option value ='11'>O Holy Night");
         document.write("<option value ='12'>O Holy Night (jazzy version)");
         document.write("<option value ='13'>Ode to Joy");
         document.write("<option value ='14'>Hiding Place");
         document.write("<option value ='15'>Happy Birthday");
         document.write("<option value ='16'>Jesus Loves Me");
         document.write("</select><br><br>");
   
  if (catnbr == 5)
  {
   document.write("<input type='hidden' name='a' value='6'>");
  }

// === background ===   
   document.write("Background Pattern:&nbsp;&nbsp;<select name='b' size='1'>");
         document.write("<option selected value ='0'>RhinoPrints (default)");
		 k = bgnm.length;   // to get number of bgnm array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option value ='" + i + "'>" + bgnm[i]);
		   }
         document.write("</select>");

   document.write("&nbsp;&nbsp;<a href='javascript:previewwindow(3)' title='Preview selected background'>preview</a><br><br>");

// === floater ===   
   document.write("Floating Image:&nbsp;&nbsp;<select name='fl' size='1'>");
         document.write("<option selected value ='0'>none...............................");
		 k = flnm.length;   // to get number of flnm array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option value ='" + i + "'>" + flnm[i]);
		   }
         document.write("</select>");
         document.write("&nbsp;&nbsp;<a href='javascript:previewwindow(1)' title='Preview selected floater'>preview</a><br><br>");

// === Frame ===   
   document.write("Frame around image:&nbsp;&nbsp;<select name='frm' size='1' onChange='UpdateMatList(1)'>");
   document.write("<option selected value ='0'>none..................................");
		 k = frmary.length;   // to get number of frmary array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option value ='" + i + "'>" + frmary[i]);
		   }
         document.write("</select>");
   document.write("&nbsp;&nbsp;<a href='javascript:previewwindow(5)' title='Preview selected frame'>preview</a><br><br>");

// === Mat ===   
   document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mat for frame:&nbsp;&nbsp;<select name='mat' size='1'>");
   document.write("<option selected value ='0'>" + matary[0]);
		 k = matary.length;   // to get number of matary array entries
		 for (i=1; i < k; i++)
           {
           document.write("<option value ='" + i + "'>" + matary[i]);
		   }
         document.write("</select>&nbsp;&nbsp;");
         document.write("&nbsp;&nbsp;<a href='javascript:previewwindow(2)' title='Preview selected mat'>preview</a><br><br>");

// === Plate  ===   
   document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Engraved Plate for frame:&nbsp;&nbsp;<select name='plt' size='1'>");
         document.write("<option selected value ='0'>none");
         document.write("<option value ='1'>brass");
         document.write("<option value ='2'>pewter");
         document.write("</select>&nbsp;&nbsp; <br><br>");

// === end of selections ===   

   document.write("<br><hr width='98%'><br>");
   document.write("<center>");
   document.write("<input type='button' onclick='submitcard(2)' value='Build eCard URL' CLASS='button'>");
   document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
   document.write("<input type='button' onclick='submitcard(1)' value='Preview/Send' CLASS='button'>");
   document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
   document.write("<input type='reset' name='reset' value='Clear Form' onclick='UpdateCatList(7)'>");
   document.write("<br><br>");
   document.write("<br></font></p>");

   document.write("<b><font color='#400080' size='2' face='Arial'>If using the RhinoPrints BBS, or Facebook, etc.,<br>copy this into your email or message after 'Build eCard URL':</font></b><br><textarea wrap='virtual' cols='50' rows='4' name='urlarea'></textarea><br><br>");

if (document.sendemail.cat1.options[document.sendemail.cat1.selectedIndex].value == 0)
{
   UpdateCatList(0);
}
else
{
   UpdateCatList(1);
}

BuildSelections();

   if (imgval == 0)
    {
     document.write("<font color=red>No image selected.<br><br><font size=1>(Select an image from the galleries on the left to begin building your ecard)</font></font></font>");
    }
   else
    {
     document.write("<font color='#400080' size='2' face='Arial'>Image selected:<br>");
     document.write("<table cellpadding='0' cellspacing='0' border='1' bordercolor=black><tr><td>");
     document.write("<a href='photo.html?" + galnbr + "=" + idxnbr + "'><img src='images/gallery/" + imgpath + ".jpg' border=0 alt='Back to photo gallery page'></a></td></tr></table>");
     document.write("<br><font size=1>( Click on the thumbnail image to return to the photo gallery page )<br><br>( You can select another image from the galleries to the left )<br><br>( Some images have a watermark - the watermarks will be removed soon )</font></font>");
    }
   document.write("<br><br><br>");

   document.write("</td></tr></table>");
   document.write("</center></div></td></tr></table>");
   
   document.write("<br><font color='#FFFFFF' size='3' face='Arial'><b>More choices to come!</b></font></center></div></form><center></td></tr></table>");

// === funtions ===

function previewwindow(itmcde)
{

nwwd = 200;
nwht = 200;

if (itmcde == 1) // floater
{
flval = document.sendemail.fl.options[document.sendemail.fl.selectedIndex].value;
nwht = flht[flval] - 1 + 175;
nwwd = flwd[flval] - 1 + 150;
}
else if (itmcde == 5) // frame
{
frmval = document.sendemail.frm.options[document.sendemail.frm.selectedIndex].value;
nwht = 350;
nwwd = 250;
}
else if (itmcde == 6) // msg
{
mval = document.sendemail.m.options[document.sendemail.m.selectedIndex].value;
nwht = 350;
nwwd = msgwdt[mval];
}

// in case prvwin already open
var prvwin=window.open('','newwin','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=100,height=100,left=20,top=20');
prvwin.close();
//
var prvwin=window.open('','newwin','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=' + nwwd + ',height=' + nwht + ',left=20,top=20');
prvwin.document.write("<HTML>");
prvwin.document.write("<TITLE>Preview Window</TITLE>");

if (itmcde == 2) // mat
{
matval = document.sendemail.mat.options[document.sendemail.mat.selectedIndex].value;
prvwin.document.write("<BODY BGCOLOR='0000A0' background='" + maturl[matval] + "'><center><br><font color='#FFFFFF' size='2'>");
}
else if (itmcde == 3) // bkgrnd
{
bval = document.sendemail.b.options[document.sendemail.b.selectedIndex].value;
prvwin.document.write("<BODY BGCOLOR='0000A0' background='" + bkgr[bval] + "'><center><br><font color='#FFFFFF' size='2'>");
}
else if (itmcde == 6)
{
prvwin.document.write("<BODY BGCOLOR='0000A0' background='paper.gif'><center><br><font color='#000000' size='2'>");
}
else
{
prvwin.document.write("<BODY BGCOLOR='0000A0'><center><br><font color='#FFFFFF' size='2'>");
}

copyright=new Date();
update=copyright.getYear();

prvwin.document.write("<b>Copyright © 2001-"+ update + " Rick Ellinger - RhinoPrints.Net - All rights Reserved.<br><br></b></font>");

//prvwin.document.write("<b>Copyright © www.RhinoPrints.Net All rights reserved.<br><br></b></font>");

if (itmcde == 1)
{
prvwin.document.write("<img src='" + flim[flval] + "' width='" + flwd[flval] + "' height='" + flht[flval] + "' border='0'><br>");
}
else if (itmcde == 5 && frmval != 0)
{
prvwin.document.write("</center><img src='" + frmimh[frmval] + "' border='0'><br>");
prvwin.document.write("<img src='" + frmimv[frmval] + "' border='0'><br><center>");
}
else if (itmcde == 6 && msgtxt[mval] != "none")
{
prvwin.document.write("<br><hr><br><b><font color='#000000' size='3'>" + msgtext[mval] + "</b><br><hr>");
}

if (itmcde == 6)
{
closclr = "#000000";
}
else
{
closclr = "#FFFFFF";
}

prvwin.document.write("<br><a href='javascript: window.close()'><font color='" + closclr + "' size='3'><b>CLOSE</b></font></a><br><br></center></BODY></HTML>");

} // end preview

function submitcard(sbmval)
{
 var correct = true;
 inbr = inm.length; // to get number of images 
 tnbr = ttl.length; // to get number of titles 

catnbr = document.sendemail.cat1.options[document.sendemail.cat1.selectedIndex].value;
tval = document.sendemail.t.options[document.sendemail.t.selectedIndex].value;
mval = document.sendemail.m.options[document.sendemail.m.selectedIndex].value;
sval = document.sendemail.s.options[document.sendemail.s.selectedIndex].value;
aval = document.sendemail.a.options[document.sendemail.a.selectedIndex].value;

bval = document.sendemail.b.options[document.sendemail.b.selectedIndex].value;
cval = document.sendemail.c.options[document.sendemail.c.selectedIndex].value;
flval = document.sendemail.fl.options[document.sendemail.fl.selectedIndex].value;
frmval = document.sendemail.frm.options[document.sendemail.frm.selectedIndex].value;
matval = document.sendemail.mat.options[document.sendemail.mat.selectedIndex].value;
pltval = document.sendemail.plt.options[document.sendemail.plt.selectedIndex].value;
refht = document.sendemail.rheight.value;

if (refht == "" || refht == null || refht > 9999 || refht < 10)
 {
   refht = 0;
 }

 if (imgval < "1")
   {
      correct = false;
      alert("You must select an image from the galleries to the left before building an ecard.");
   }
 else if (catnbr < "1")
   {
      correct = false;
      alert("Please select a category.");
   }
 else if (tval <= "0" && pltval >= "1")
   {
      correct = false;
      alert("You must select a title to use a plate.");
   }
 else
   {
      parmval = tval + "!";
      parmval = parmval + mval + "!";
      parmval = parmval + imgval + "!";
      parmval = parmval + sval + "!";
      parmval = parmval + aval + "!";
      parmval = parmval + bval + "!";
      parmval = parmval + cval + "!";
      parmval = parmval + flval + "!";
      parmval = parmval + frmval + "!";
      parmval = parmval + catnbr+ "!";
      parmval = parmval + matval + "!";
      parmval = parmval + pltval + "!";
      parmval = parmval + galnbr + "!";
      parmval = parmval + idxnbr + "!";
      parmval = parmval + refht;
      urlval = "ecard.html?p=" + parmval;

    if (sbmval == 2)
     {
      document.sendemail.urlarea.value = "http://www.rhinoprints.com/" + urlval;

      var urltext = document.sendemail.urlarea.value;

         alert('URL Copied to text area - now copy it and paste it into your email or PM');
     }

    if (sbmval == 1)
     {
       self.location=urlval;
     }
   }

}

function form_action()  // to avoid form action conflict with button action 
{
 junk = "";
}

  
function viewbg()
{

bval = document.sendemail.b.options[document.sendemail.b.selectedIndex].value;
  
  if (bval < "0")
   {
      correct = false;
      alert("Please select a valid background to view.");
   }
  else
   {
    bkgnbr = bval;
    bkgSwap = bkgr[bkgnbr];
    document [bkgName].src = bkgSwap;
   }
  
}

function UpdateCatList(optionIn)
{
  // Remove all existing items from lists
 document.sendemail.t.options.length = 0;
 document.sendemail.m.options.length = 0;
 document.sendemail.b.options.length = 0;
 document.sendemail.fl.options.length = 0;

 if (optionIn == 7) // clear
 {
  document.sendemail.cat1.options[0].selected = true;
  optionIn = 0;
 }

 var defaultSelected = false;
 var selected = false;

 catnbr = document.sendemail.cat1.options[document.sendemail.cat1.selectedIndex].value;

 // images, titles, msgs, bkgrnds, fltrs

 ttlselect(catnbr);
 bgselect(catnbr);

    if (optionIn == 0 || catnbr == 0)
     {

      catnbr = 0;
      document.sendemail.cat1.options[document.sendemail.cat1.selectedIndex].value = 0;

      var optionName = new Option("Select a category above.........................................", 1, defaultSelected, selected);
      var length = document.sendemail.t.options.length;
      document.sendemail.t.options[length] = optionName;

      var optionName = new Option("Select a category above.......................................................", 1, defaultSelected, selected);
      var length = document.sendemail.m.options.length;
      document.sendemail.m.options[length] = optionName;

      var optionName = new Option("Select a category above.............................", 1, defaultSelected, selected);
      var length = document.sendemail.b.options.length;
      document.sendemail.b.options[length] = optionName;

      var optionName = new Option("Select a category above.............................", 1, defaultSelected, selected);
      var length = document.sendemail.fl.options.length;
      document.sendemail.fl.options[length] = optionName;

      document.sendemail.cat1.options[0].selected = true;

     }
    else
     {

      var optionName = new Option("Select a title  - optional ...............", 0, defaultSelected, selected);
      var length = document.sendemail.t.options.length;
      document.sendemail.t.options[length] = optionName;

      k = ttl.length;
      for (i=1; i < k; i++)
      {
      var optionName = new Option(ttl[i], i, defaultSelected, selected);
      var length = document.sendemail.t.options.length;
      document.sendemail.t.options[length] = optionName;
      }

      var optionName = new Option("Select a message - optional ......", 0, defaultSelected, selected);
      var length = document.sendemail.m.options.length;
      document.sendemail.m.options[length] = optionName;

      k = msgtxt.length;
      for (i=1; i < k; i++)
      {
      var optionName = new Option(msgtxt[i], i, defaultSelected, selected);
      var length = document.sendemail.m.options.length;
      document.sendemail.m.options[length] = optionName;
      }

      var optionName = new Option("RhinoPrints (default)", 0, defaultSelected, selected);
      var length = document.sendemail.b.options.length;
      document.sendemail.b.options[length] = optionName;

      k = bgnm.length;
      for (i=1; i < k; i++)
      {
      var optionName = new Option(bgnm[i], i, defaultSelected, selected);
      var length = document.sendemail.b.options.length;
      document.sendemail.b.options[length] = optionName;
      }

      var optionName = new Option("none", 0, defaultSelected, selected);
      var length = document.sendemail.fl.options.length;
      document.sendemail.fl.options[length] = optionName;

      k = flnm.length;
      for (i=1; i < k; i++)
      {
      var optionName = new Option(flnm[i], i, defaultSelected, selected);
      var length = document.sendemail.fl.options.length;
      document.sendemail.fl.options[length] = optionName;
      }
     }

   // Do the next lines to make sure the top items are selected on each
   document.sendemail.m.options[0].selected = true;
   document.sendemail.b.options[0].selected = true;
   document.sendemail.fl.options[0].selected = true;

   UpdateMatList(optionIn);

}

function BuildSelections()
{

if (k < 2)
 {
  UpdateCatList(0);
 }

if (k < 9)
 {
 UpdateCatList(0);
 }
else
 {
msgnbr = valarray2[0];
verse = valarray2[1];
songval = valarray2[3] - 1;   // song index 0 = choice 1
applval = valarray2[4];
bkgrval = valarray2[5];
txtclr = valarray2[6];
fltrval = valarray2[7];
frmnbr = valarray2[8];
galnbr = valarray2[12];
idxnbr = valarray2[13];
imgval = valarray2[2];
refht = valarray2[14];

if (refht == "" || refht == null || refht > 9999 || refht < 10)
 {
   refht = 0;
 }

if (galnbr == '6')
 {
  imgpath = "paw2/pii" + valarray2[2];
 }
else if (galnbr == '7')
 {
  imgpath = "poems/" + valarray2[2];
 }
else if (galnbr == '8')
 {
  imgpath = "misc/" + valarray2[2];
 }
else
 {
  imgpath = valarray2[2];
 }
 
 if (valarray2[9] != null)
  {
  catnbr = valarray2[9];
  }
 else
  {
  catnbr = 0;
  }

 if (valarray2[10] != null)
  {
  matval = valarray2[10];
  }
 else
  {
  matval = 0;
  }

 if (valarray2[11] != null)
  {
  pltnbr = valarray2[11];
  }
 else
  {
  pltnbr = 0;
  }

 document.sendemail.cat1.options[document.sendemail.cat1.selectedIndex].value = catnbr;
 UpdateCatList(1);
 document.sendemail.t.options[msgnbr].selected = true;
 document.sendemail.m.options[verse].selected = true;
 document.sendemail.s.options[songval].selected = true;
 document.sendemail.a.options[applval].selected = true;
 document.sendemail.b.options[bkgrval].selected = true;
 document.sendemail.fl.options[fltrval].selected = true;
 document.sendemail.frm.options[frmnbr].selected = true;
 document.sendemail.c.options[txtclr].selected = true;
 UpdateMatList(1);
 document.sendemail.mat.options[matval].selected = true;
 document.sendemail.plt.options[pltnbr].selected = true;
 document.sendemail.cat1.options[catnbr].selected = true;
 document.sendemail.rheight.value = refht;

 }

}

function UpdateMatList(optionIn)
{
  // Remove all existing items from lists
 document.sendemail.mat.options.length = 0;
 document.sendemail.plt.options.length = 0;
 
  var defaultSelected = false;
  var selected = false;
 
  frmval = document.sendemail.frm.options[document.sendemail.frm.selectedIndex].value;

// mats and plates
    if (optionIn == 0 || frmval == 0)
     {
      var optionName = new Option("Select a frame above.......", 0, defaultSelected, selected);
      var length = document.sendemail.mat.options.length;
      document.sendemail.mat.options[length] = optionName;

      var optionName = new Option("Select a frame above.......", 0, defaultSelected, selected);
      var length = document.sendemail.plt.options.length;
      document.sendemail.plt.options[length] = optionName;
     }
    else
     {
      var optionName = new Option("solid black", 0, defaultSelected, selected);
      var length = document.sendemail.mat.options.length;
      document.sendemail.mat.options[length] = optionName;

      k = matary.length;
      for (i=1; i < k; i++)
      {
      var optionName = new Option(matary[i], i, defaultSelected, selected);
      var length = document.sendemail.mat.options.length;
      document.sendemail.mat.options[length] = optionName;
      }

      var optionName = new Option("Select a plate.............", 0, defaultSelected, selected);
      var length = document.sendemail.plt.options.length;
      document.sendemail.plt.options[length] = optionName;

      var optionName = new Option("brass", 1, defaultSelected, selected);
      var length = document.sendemail.plt.options.length;
      document.sendemail.plt.options[length] = optionName;

      var optionName = new Option("pewter", 2, defaultSelected, selected);
      var length = document.sendemail.plt.options.length;
      document.sendemail.plt.options[length] = optionName;
     }

   document.sendemail.plt.options[0].selected = true;
   document.sendemail.mat.options[0].selected = true;

}


