// Copyright 2003-2006 © by David D Sadler. All Rights Reserved.

var browserVersion = parseInt(navigator.appVersion);
var isNetscape     = navigator.appName.indexOf("Netscape") != -1;
var isIE           = navigator.appName.indexOf("Microsoft") != -1;
var isOpera        = navigator.userAgent.indexOf("Opera") != -1;
    if (isOpera) {isIE = false; isNetscape = false;}
var agent          = navigator.userAgent.toLowerCase();
var isWindows      = agent.indexOf("win") != -1;
var isMac          = agent.indexOf("mac") != -1;
var isUnix         = agent.indexOf("X11") != -1;
//alert("Agent = " + navigator.userAgent + "\nApp = " + navigator.appName + "\nagent = " + agent + "\nversion = " + browserVersion + "\nisIE = " + isIE + " isNetscape = " + isNetscape + " isOpera = " + isOpera + "\n\n");

var pp_1  = "https://www.paypal.com/cgi-bin/webscr" + "?cmd=_cart" + "&upload=1";
var pp_2  = "&no_note=1";
var pp_3  = "&cn=How%20Did%20You%20Hear%20About%20Us%3F";
var pp_4  = "&business=sales%40gardencards.biz";
var pp_5  = "&image_url=httpS://secured.com/~f1015/s557301.gif";
var pp_6  = "&return=http://www.gardencards.biz/html/returnwholesale.htm";
var pp_7  = "&currency_code=USD";
var pp_x1  = "&item_name_#=";
var pp_x3  = "&item_number_#=";
var pp_x5  = "&amount_#=";
var pp_x7  = "&shipping_#=";
var pp_x8  = "0.00"
var pp_x9  = "&quantity_#=";
var pp_x11 = "&on0_#=";
var pp_x13 = "&os0_#=";
var pp_x15 = "&on1_#=";
var pp_x17 = "&os1_#=";
var pp_x   = "";

var pp_winpar  = "width=700,height=400,scrollbars,resizable,status,location";
if (!bigwinparams) {var bigwinparams = "width=640,height=600,scrollbars,resizable,status,location"}

var id         = 0;  
var xc         = 0;
var totalqty   = 0;
var minvalue   = 100;
var tipe       = "wholesale";
var _pricew    = 13.00;          // $13.00 per dozen wholesale price
var _pricer    = 24.95;          // $24.95 per dozen retail price

var _price = _pricew;      
var wprice = _price/12;   // price per card
var hprice = wprice/2;    // price half dozen 

var catalogs     = new Array(); 
    catalogs[0]  = ["NoteCards", "GreetingCards", "HolidayCards"]; 
    catalogs[1]  = ["02", "03", "06"];

var inventory     = new Array();  //0->Product number, 1->title, 2->verse, 3->qty//
    inventory[0]  = ["03001","Carnations"," Happy Birthday to Someone Special"];
    inventory[1]  = ["03015","White Shrub Rose"," May all your dreams and wishes come true.<br>Happy Birthday!"];
    inventory[2]  = ["03003","Daffodil / Narcissus"," Best wishes to you on Your Birthday"];
    inventory[3]  = ["03016","Mother's Peony"," Special Thoughts of You on Your Birthday"];
    inventory[4]  = ["03027","Erin's Flowers"," An Anniversary Bouquet just for You!"];
    inventory[5]  = ["03028","June Flower - Rose"," Best wishes to both of you on your Anniversary."];
    inventory[6]  = ["03031","Fern Heart Wreath"," Wishing you Love, Laughter and Joy on your Anniversary."];
    inventory[7]  = ["03029","Summer Wreath"," Wishing you a Happy Anniversary."];
    inventory[8]  = ["03035","Iris"," A note to say Hello"];
    inventory[9]  = ["03036","Purple Violets"," Thinking of You"];
    inventory[10]  = ["03037","Parsley, Sage, Rosemary & Thyme"," You are in Our Thoughts"];
    inventory[11]  = ["03038","Japanese Anemone & Streptocarpella"," A note to say Hello"];
    inventory[12]  = ["03021","Loves me, Loves me not"," Loves You!"];
    inventory[13]  = ["03022","Purple Violets"," You are Always in My Dreams"];
    inventory[14]  = ["03023","Bleeding Hearts"," I Love You Dearly."];
    inventory[15]  = ["03024","Fern Heart Wreath"," My Heart Belongs to You"];
    inventory[16]  = ["03040","Apple Blossoms"," You're only here for a short visit."];
    inventory[17]  = ["03041","Asiatic Lily"," I'm sorry . . ."];
    inventory[18]  = ["03042","Japanese Anemone with Hosta"," Life is an Uncertain Voyage"];
    inventory[19]  = ["03043","Azalea"," Sympathy"];
    inventory[20]  = ["03050","Streptocarpella with Dusty Miller"," Thank You So Much"];
    inventory[21]  = ["03051","February Flower - Violets"," We Greatly Appreciate Your Help"];
    inventory[22]  = ["03052","Delphinium & Coreopsis"," We Greatly Appreciate Your Help"];
    inventory[23]  = ["03053","Tulip"," Warmest thanks to you"];
    inventory[24]  = ["03045","July Flower - Larkspur"," Hope You are Feeling Better Soon"];
    inventory[25]  = ["03046","Japanese Anemone with Fern"," Hope you're feeling better soon"];
    inventory[26]  = ["03047","Geranium"," Hope You are Feeling Better Soon"];
    inventory[27]  = ["03048","Morning Glories"," Hope You are Feeling Better Soon"];
    inventory[28]  = ["03055","Welcome Home - Rose"," Congratulations on your Graduation"];
    inventory[29]  = ["03056","I'm Sorry - Bleeding Hearts"," I am sorry"];
    inventory[30]  = ["03057","Divorce - Refrigerator"," The Party is Over. . . We have decided to go our separate ways."];
    inventory[31]  = ["03058","Divorce - Loves me, loves me not so much"," It's Over. . . We have decided to go our separate ways."];
    inventory[32]  = ["06030","Child's First Bouquet"," Happy Birthday to You"];
    inventory[33]  = ["06025","Easter Bunny"," Happy Easter"];
    inventory[34]  = ["06026","Tulip"," Happy Mother's Day"];
    inventory[35]  = ["06027","Daffodil / Narcissus"," Happy Easter"];
    inventory[36]  = ["06011","Loves me, Loves me not"," Happy Valentine's Day<br>I Love You"];
    inventory[37]  = ["06014","Multi-colored Violets"," Roses are Red, <br>Violets are Blue, <br>Happy Valentine's Day, <br>I Love You!"];
    inventory[38]  = ["06016","Bleeding Hearts"," Please ?"];
    inventory[39]  = ["06013","Fern Heart Wreath"," With All My Heart<br>I Love You"];
    inventory[40]  = ["06015","Purple Violets"," Roses are Red, <br>Violets are Blue, <br>On Valentine's Day, <br>I'm Thinking of You!"];
    inventory[41]  = ["06001","Winter at the Lake"," Wishing you a Happy Christmas and New Year"];
    inventory[42]  = ["06006","O' Christmas Tree"," Wishing you a Happy Christmas."];
    inventory[43]  = ["06003","Holiday Wreath"," Glad tidings of great joy."];
    inventory[44]  = ["06004","Trees for Christmas"," Merry Christmas"];
    inventory[45]  = ["06002","Ginger Bread House"," Wishing you a holiday season filled with beautiful moments."];
    inventory[46]  = ["06007","Snowy Ginger Bread House"," Wishing you a holiday season filled with beautiful moments."];
    inventory[47]  = ["02058","Erin's Flowers",""];
    inventory[48]  = ["02012","Japanese Anemone with Hosta",""];
    inventory[49]  = ["02013","Japanese Anemone with Fern",""];
    inventory[50]  = ["02014","Japanese Anemone & Streptocarpella",""];
    inventory[51]  = ["02004","Dusty Miller & African Violets",""];
    inventory[52]  = ["02003","Summer Wreath",""];
    inventory[53]  = ["02019","Streptocarpella Asters & Fern",""];
    inventory[54]  = ["02020","Streptocarpella with Dusty Miller",""];
    inventory[55]  = ["02069","Creeping Phlox & Basket of Gold",""];
    inventory[56]  = ["02007","Tulip",""];
    inventory[57]  = ["02056","Iris",""];
    inventory[58]  = ["02062","Mother's Peony",""];
    inventory[59]  = ["02057","Daisies",""];
    inventory[60]  = ["02039","January Flower - Carnations",""];
    inventory[61]  = ["02040","February Flower - Violets",""];
    inventory[62]  = ["02041","March Flower - Daffodil / Narcissus",""];
    inventory[63]  = ["02042","April Flower - Sweetpea",""];
    inventory[64]  = ["02044","June Flower - Rose",""];
    inventory[65]  = ["02045","July Flower - Larkspur",""];
    inventory[66]  = ["02047","September Flower - Asters",""];
    inventory[67]  = ["02034","Fern Heart Wreath",""];
    inventory[68]  = ["02064","Snapdragons",""];
    inventory[69]  = ["02022","Asiatic Lily",""];
    inventory[70]  = ["02037","Loves me, Loves me not",""];
    inventory[71]  = ["02067","Morning Glories",""];
    inventory[72]  = ["02063","Butterfly Weed",""];
    inventory[73]  = ["02066","Geranium",""];
    inventory[74]  = ["02065","White Shrub Rose",""];
    inventory[75]  = ["02053","Apple Blossoms",""];
    inventory[76]  = ["02059","Purple Violets",""];
    inventory[77]  = ["02009","Bleeding Hearts",""];
    inventory[78]  = ["02060","Black-eyed Susan",""];
    inventory[79]  = ["02055","Delphinium & Coreopsis",""];
    inventory[80]  = ["02061","Clematis",""];
    inventory[81]  = ["02002","Corn Tassels & Asters",""];
    inventory[82]  = ["02008","Child's First Bouquet",""];
    inventory[83]  = ["02006","Magnolia",""];
    inventory[84]  = ["02052","Parsley, Sage, Rosemary & Thyme",""];
    inventory[85]  = ["02005","Azalea",""];
    inventory[86]  = ["02054","Roses, Russian Sage & Baby's Breath",""];
    inventory[87]  = ["02111","Easter Bunny",""];
    inventory[88]  = ["02109","Winter at the Lake",""];
    inventory[89]  = ["02110","Essentials",""];
    inventory[90]  = ["02025","Fall Fern with Amur Maple",""];
    inventory[91]  = ["02026","Fern with Two Red Leaves",""];
    inventory[92]  = ["02027","Fall Fern with Red Maple Leaf",""];
    inventory[93]  = ["02036","Hydrangea Wreath",""];
    inventory[94]  = ["02120","1907 Lake Harriet",""];
    inventory[95]  = ["02129","Peace Garden",""];
    inventory[96]  = ["02122","Lake Harriet Summer Porch",""];
    inventory[97]  = ["02123","Moon Over Lake Harriet",""];
    inventory[98]  = ["02124","Yesterday at Lake Harriet",""];
    inventory[99]  = ["02121","Lake Harriet Spring Biker",""];
    inventory[100]  = ["02130","A Fountain at the Rose Gardens",""];
    inventory[101]  = ["02128","Elf House at Lake Harriet",""];
    inventory[102]  = ["02133","Lake Harriet Afternoon",""];
    inventory[103]  = ["02132","The Water Pump",""];
    inventory[104]  = ["02134","Lake Harriet Sail Boats",""];
    inventory[105]  = ["02126","April Showers at Lake Harriet",""];
    inventory[106]  = ["02125","Lake Harriet Trolley Station",""];
    inventory[107]  = ["02131","Minnehaha Creek",""];
    inventory[108]  = ["02127","Minneapolis Over Lake Calhoun",""];
    inventory[109]  = ["02073","Trees for Christmas",""];
    inventory[110]  = ["02071","Ginger Bread House",""];
    inventory[111]  = ["02075","O' Christmas Tree",""];
    inventory[112]  = ["02076","Snowy Ginger Bread House",""];

var oform = ""; 
var pprice = "";
var iverse = utf8('Inside verse');
function CallPayPal() {
  if (!chkmin()) {return}
  xc = 1; pp_x = ""; 
  pprice = _price/2;						   // price for half dozen cards
  oform = document.forms.orders;
  var l = oform.getElementsByTagName("Input"); 
  for (i=0;i<l.length;i++) {
    if (l[i].getAttribute("name")) {
      if (l[i].getAttribute("name").substr(0,3) == "qty") {
        onecard(l[i].getAttribute("name"));
      } 
    }
  }
  var call = pp_1 + pp_2 + pp_3 + pp_4 +  pp_5 + pp_6 + pp_7 + pp_x;
//alert("call = " + call);
  window.open (call, "paypal", pp_winpar);
  return;
}

function chkmin() {
  if (totalqty*wprice < minvalue) {alert("$100 minimum not met( " + tomoney(totalqty*wprice) + " so far). Please add more items."); return(false);}
  return(true);
}

var wcall = "";
var fflag = 0;
var totalqty = 0; 

function chkout(){
  var c = fflag = totalqty = 0; 
  wcall = "/cgi-bin/wholesale.cgi";
  for (c=0;c<catalogs[0].length;c++) {
      if (document.forms[catalogs[0][c]]) {tcat(document.forms[catalogs[0][c]])};
  }
  if (!chkmin()) {return;}
  wcall += "&onum=" + generateconnum();
//alert("wcall = " + wcall);
  window.location = wcall;
  return;
}

function chkcusnum(which) {
  if(morder.customernumber.value != 0) {return}
  morder.customernumber.value = generatenumber();
  return;
}

function chkphone(el) {
  var num = el.value;
  if (num == "") {return}
  var re=/\d{3}[-]\d{3}[-]\d{4}/;
  if (re.test(num)) {return true}
  re=/[(]\d{3}[)]\d{3}[-]\d{4}/;
  if (re.test(num)) {return true}
  re=/\d{10}/;
  if (re.test(num)) {return true}
  if (num.substring(0,2) == "1-") {chkphone(num.slice(-10)); return}
  emess += "Telephone number format is not recognized - " + el.value + ". Formats are ########## or ###-###-#### or (###)###-####. Please correct.\n";
  pass=false;
  markerr(el);
  return false;
}

function chkzip(el) {
  var num = el.value;
  if (num == "") {return}
  var re=/\d{5}/;
  if (re.test(num)) {return true}
  re=/\d{5}[-]\d{4}/;
  if (re.test(num)) {return true}
  re=/[a-zA-Z0-9][ ][a-zA-Z0-9]/;
  if (re.test(num)) {return true}
  emess += "ZIP Code format is not recognized - " + el.value + ". Formats are ##### or #####-#### or XXX XXX. Please correct.\n";
  pass=false;
  markerr(el);
  return false;
}

function fixqty(qt){
  if(tipe == "retail") {if(document.forms.orders) {loadtotals(orders)} return;}
  var n =  qt.value;
  n = checknums(n);
  if (n < 3 && n != 0) {n = 3}
  var x = (n*1 + 3)/6; x = Math.floor(x); x = x*6;
  if (n == 0) {x = 0}
  qt.value = x;
  if (x != n) {alert("Quantity needs to be a multiple of 6. Quatity has been adjusted to " + x + ".")}
  qt.select();
  qt.focus();
  if(document.forms.orders) {loadtotals(orders)} 
  return;
}

function loadtotals(fname) {
  var l = fname.getElementsByTagName("Input"); 
  totalqty = 0;
  for (i=0;i<l.length;i++) {
    if (l[i].getAttribute("name")) {
      if (l[i].getAttribute("name").substr(0,3) == "qty") {
        var n = eval("fname." + l[i].getAttribute("name"));
        totalqty += n.value*1;
      } 
    }
  }
  fname.tcount.value = totalqty;
  fname.tamount.value = tomoney(totalqty*wprice);
  fname.tamount.select();
  chkmin();
  return;
}

function markerr(el) {
  mark  = "x-" + el.name.substring(9,30);
  if (document.images[mark]) {document.images[mark].src = errmark;}  
  return;
}

function findcard(cid) {
  var q = cid.substr(3);
  var j = 0; id = -1;
  for (j=0;j<inventory.length+1;j++) {
    if(inventory[j][0] == q) {id=j; break;}
  }
  if (id == -1) {alert("card not found in inventory - " + cid); return(false);}
  var x = eval("document.forms.orders." + cid); y = x.value;
  if (y == 0) {return false}
  return true;
}
  
  function onecard(cid) {
  if (!findcard(cid)) {return}
  var v = ''; if (inventory[id][2] != '') {v = pp_x11 + iverse + pp_x13 + utf8(inventory[id][2])}

  var x = eval("document.forms.orders." + cid); var y = (x.value)/6;
  var c = pp_x1 + utf8(inventory[id][1]) + pp_x3 + inventory[id][0] + pp_x5 + pprice + pp_x9 + y + v;
  c = c.replace(/#/g, xc); 
  pp_x += c; 
//alert("c = " + c);
  ++xc;
  return;
}

function rst(fname) {
  var l = fname.getElementsByTagName("Input"); 
  for (i=0;i<l.length;i++) {
    if (l[i].getAttribute("name")) {
      if (l[i].getAttribute("name").substr(0,3) == "qty") {
        var n = eval("fname." + l[i].getAttribute("name"));
        n.value = 0;
      } 
    }
  }
  return;
}

function startcart(){
  totalqty = 0;
  minvalue   = 100;
  tipe = "wholesale";
  return;
}

function showbig(cardno){
  var f = "/cgi-bin/big.cgi?cardid=" + cardno; var n =  "Big_View";
  openWin(f, n, bigwinparams);
  return;
}

function showdet(cardno){
  var f = "/cgi-bin/details.cgi?cardid=" + cardno + "&return=close"; var n = "Card_Details";
  openWin(f, n, bigwinparams);
  return;
}

var hdr = asp("#",3,"R") + asp("Qty", 5,"R") + asp("Card",7,"R") + "  " + asp("Title (Verse)",45,"L") + asp("Price",7,"R") + "\n";
var  li = '';  //Line image

function submitorder(which){
  if (!checkform(which)) {return false}
  var cs = '';
  var it = 1;
  var totalqty = 0;
  var l = orders.getElementsByTagName("Input");
  li = hdr;
  for (var i=0;i<l.length;i++) {
    if (l[i].getAttribute("name")) {
      var y = l[i].getAttribute("name");
      if (y.substr(0,3) == "qty") {
         if (!findcard(y)) {return false}
		 var x = eval("document.forms.orders." + y); var z = x.value;
//alert("line 347 - x = " + x);
         var t = (z/12)*_price; 
         li += asp(it,3,"R") + asp(z, 5,"R") + asp(y.substr(3),7,"R") + "  " + asp(inventory[id][1],45,"L") + asp(tonumber(t),7,"R") + "\n";
         if (inventory[id][2] != "") {
		   var str = inventory[id][2].replace(/<br>/g," ");
           li += sfr(18) + asp(str,45,"L") + "\n";
           }
         if (cs != "") {cs += "+"}
         cs +=  y.substr(3) + "-" + z;
         totalqty = totalqty*1 + z*1;
         ++it; 
      }
    } 
  }
  y = (totalqty/12)*_price; 
  li += asp("Subtotal ",62,"R") + asp(tonumber(y),7,"R") + "\n";
  li += asp("Shipping & Handling ",62,"R") + asp("N/C",7,"R") + "\n";
  li += asp("Total ",62,"R") + asp(tomoney(y),7,"R") +  "\n";
  worder.items.value = li;
  morder.cards.value = cs;
  worder.odate.value = morder.odate.value = bdate("F");
  return;
}

function asp(string,w,j) {
  if (j == "L" || j == 'l') {
    var s = string + sfr(w);
    return (s.substring(0,w))
  } else {
    var s = sfr(w) + string;
    return (s.slice(-w))
  }
  return(l);
}

function sfr(ct) {
  var l = '';
  for (var i=0;i<ct;i++) {l += " "}
  return(l);
}

function tomoney(val) {
  var str,pos,rnd=0;
  if (val == 0) { return ""}
  if (val < .995) rnd = 1;  // for old Netscape browsers
    str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
    pos = str.indexOf (".");
  if (pos > 0) str = "$" + str.substring (rnd, pos + 3);
  return str;
}

function tonumber(val) {
  var str = tomoney(val);
  str = str.replace(/\$/g,"");
  return str;
}

function tcat(cname){
 var l = cname.getElementsByTagName("Input");
  for (var i=0;i<l.length;i++) {
    if (l[i].getAttribute("name")) {
      var y = l[i].getAttribute("name");
      if (y.substr(0,3) == "qty") {
        var n = eval("cname." + y); var x = n.value;
        if (x != 0) {
          totalqty +=  x*1;
          if(fflag == 0) {wcall += "?cards="; fflag++;} else {wcall += "+" }
          wcall+= y.substr(3) + "-" + x;
        }
      } 
    }
  }
  return;
}

function checknums(num) {
  var anum=/(^\d+$)/;
  if (num != "" && anum.test(num)==false) {
    alert ("A number is required. "+ num +" is not a number.\n\nQuantity set to 6.");
	num = 6;
  }
  return(num);
}

var charsalph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var charsnum  = "0123456789";
var charsall  = charsalph + charsnum;

function bdate(f) {
  var s = ""; 
  if (f == "F" || f == "f") {s = "/"}
  var time = new Date();
  var lmonth = time.getMonth() + 1; 
  var date   = time.getDate(); 
  var year   = time.getYear();  if (year < 1900) {year = year*1 + 1900}; year = year.toString();
  if (date < 10) {date = "0" + date}
  if (lmonth < 10) {lmonth = '0' + lmonth}
  var d = lmonth + s + date +  s + year.substr(2,2);
  return(d);
}

function generatenumber() {
  var cwidth = 12;
  var m = 4;
  var n = bdate('S');
  for (i=0; i<cwidth-6; i++) {
    n += charsnum.charAt(Math.floor(Math.random()*charsnum.length));
  }
  var connum = Math.floor(n/m); connum = connum*m;
  if (connum.length < cwidth) {connum += "000000000000"; connum = connum.slice(-cwidth)}
//alert("connum = " + connum + "  n = " + n);
return(connum);
}

function generateconnum() {
  var cwidth = 15;
  var connum = bdate('S');
  connum += charsalph.charAt(Math.floor(Math.random()*charsalph.length));
  for (i=0; i<4; i++) {
    connum += charsall.charAt(Math.floor(Math.random()*charsall.length));
  }
  for (i=0; i<cwidth-11; i++) {
  connum += charsnum.charAt(Math.floor(Math.random()*charsnum.length));
  }
//alert("connum = " + connum);
return(connum);
}

function openWin(ThisFile,ThisName,TheseProps) {
 var ThisWin=window.open(ThisFile,ThisName,TheseProps);
 ThisWin.focus();
 return;
}

function round(val) {
  var str,pos,rnd=0;
  if (val == 0) { return ""}
  if (val < .995) rnd = 1;  // for old Netscape browsers
    str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
    pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function utf8(strng) {
  var s = strng;
  s = s.replace(/\%/g, "%25");
  s = s.replace(/\ /g, "%20");
  s = s.replace(/\&/g, "%26");
  s = s.replace(/\,/g, "%2C");
  s = s.replace(/\=/g, "%3A");
  s = s.replace(/\:/g, "%3D");
  s = s.replace(/\@/g, "%40");
  s = s.replace(/\~/g, "%7E");
  s = s.replace(/\?/g, "%3F");
  s = s.replace(/\#/g, "%23");
  s = s.replace(/\'/g, "%27");  
  s = s.replace(/\(/g, "%28");
  s = s.replace(/\)/g, "%29");
  s = s.replace(/\!/g, "%21");
  return(s);
}

var pleft = 382; var ptop = 135;             // Position for IE MAC

function setpos() {
  if (isOpera)    {pleft = 515;  ptop = 225}           //Opera
  if (isNetscape) {pleft = 515;  ptop = 225}           //Netscape
  if (isIE)       {pleft = 515;  ptop = 235}           //IE
  document.getElementById("header").style.left = pleft + "px";
  document.getElementById("header").style.top  = ptop  + "px";
//alert("Browser = " + navigator.appName + "  Agent = " + navigator.userAgent + "\n" + "  isIE = " + isIE  + "  isOpera = " + isOpera + "\n" + "Position left = " + pleft + "  Position top = " + ptop);
  return;
}

function today() {
	var months=new Array(13);
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
    var year   = time.getYear();  if (year < 1900) {year = year*1 + 1900};
	document.write(lmonth + " " + date + ", " + year);
	}

var emesspre  = "The form was not submitted due to the following errors:\n\n"; 
var emess     = "";
var pass      = true;
var mark      = "";
var errmark   = "/images/Misc/redx.gif";
var blankmark = "/images/Misc/spacer.gif";

function checkform(which) {
  pass  = true;
  emess = emesspre;
  if (document.images) 
  clrredxs(which);
  for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i];
//alert("tempobj.name = " + tempobj.name);
    if (tempobj.name.indexOf('zip') != -1) {chkzip(tempobj)}
    if (tempobj.name.indexOf('phone') != -1) {chkphone(tempobj)}
    if (tempobj.name.indexOf('email') != -1) {emailCheck(tempobj)}
//    if (tempobj.name.indexOf('customernumber') != -1) {chkcusnum(which)}
    if (tempobj.name.substring(0,9)=="required-") {checkfield(tempobj,9,30)}
  }
  if (!pass) {
    emess = emess + "\n";
    alert(emess);
    return false;
  } 
    return true; 
}

function checkgform(which) {
  pass = true;
  checks(which);
  if (!pass) {return false};
  checkr("YourFriend", "Friend's Name");
  checke("TheirEmail", "Friend's Email Address");
  checkr("YourName", "Your Name");
  checke("YourEmail", "Your Email Address");
  if (!pass) {return false};
  return true; 
}

function checkrform(which) {
  pass = true;
  if (!checks(which)) return false;
  checkr("required-Name", "Your Name");
  checke("required-Email", "Email Address");
  if (!pass) {return false}
  return true; 
}

function checke(id,s) {
  checkr(id,s);
  if (!pass) {return false};
  var e = document.getElementById(id);
  emailCheck(e);
  if (pass) {return true}
  emess = emess + "\n";
  alert(emess);
  return false; 
}

function checkfield(field,b,e) {
  if (((field.type=="text"||field.type=="textarea")&&
    field.value=='')||(field.type.toString().charAt(0)=="s"&&
    field.selectedIndex==0)) {
      pass=false;
      emess = emess + "Please make sure the " + field.name.substring(b,e).toUpperCase() + " field is properly completed.\n";
      markerr(field);
//      if (document.images[mark]) {document.images[mark].src = errmark;}
  }
return;
}

function checkr(id,s) {
  var e = document.getElementById(id);
  if (e.value == "") {alert(emesspre + '"' + s +'" is blank. "' + s + '" must be specified. Please correct.'); pass=false; return false};
  return true; 
}

function checks(which) {
  pass  = true;
  emess = emesspre;
  for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i].value;
    var x=which.elements[i];
//alert("x.name = " + x.name + "\nx.value = " + x.value);
    if (tempobj.indexOf( "http://") != -1) {pass=false};
  }
  if (!pass) {alert("SPAM detected. Form ignored."); return false;}
  return true; 
}

function clrredxs(form) {
  for (i=0;i<form.length;i++) {
    var tempobj=form.elements[i];
	mark  = "x-" + tempobj.name.substring(9,30);
    if (document.images[mark]) {document.images[mark].src = blankmark;}  
  }
  return;
}

function emailerr (el,em) {
  
  emess += em + '\nPlease correct email address - "' + el.value + '".\n';
  pass=false;
  markerr(el);  
  return false;
}

// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 
// V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) 
// Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) 
function emailCheck (el) {
    var emailStr = el.value;
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (emailStr == '') {return true};
	if (matchArray==null) {
		emailerr(el, "Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("The Email username contains invalid characters.");
			emailerr(el);
			return false;
   		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		  emailerr(el, "The Email domain name contains invalid characters.");
          return false;
	   }
	}

	if (user.match(userPat)==null) {
		emailerr(el, "The Email username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				emailerr(el, "The Email destination IP address is invalid!");
				return false;
		   }
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			emailerr(el, "The Email domain name does not seem to be valid.");
			return false;
	   }
	}
//alert("checkTLD = " + checkTLD + "  domArr[domArr.length-1].length = " + domArr[domArr.length-1].length + "  domArr[domArr.length-1].search(knownDomsPat) = " + domArr[domArr.length-1].search(knownDomsPat));
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		emailerr(el, "The Email address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	return true;
}
//alert("Here - 703");
// Copyright 2003-2006 © by David D Sadler. All Rights Reserved.