
var i = 0;
var lastCat    = '';
var lastCoupon = '';
var lastBus    = '';
var eitheror   = 'category';
var county   = 'calvert';


function couponData(cat, name, img, web){
  this.cat      = cat;
  this.name     = name;
  this.web      = web;
  this.img = img.split(",");

  return this;
}
var bus;


var calvertData = new Array(
new couponData('Restaurants', 'Mexico Restaurant', "mexicorestaurant_1.png,mexicorestaurant_2.png", ''),
new couponData('Retail Stores', 'Patuxent Wine & Spirits', "patuxentwinespirits_1.png,patuxentwinespirits_2.png", ''),
new couponData('Retail Stores', 'Pearle Vision - St. Marys County', "pearlevisionst.maryscounty_1.png,pearlevisionst.maryscounty_2.png", ''),
new couponData('Retail Stores', '231 Farm Home & Pet Center', "231farmhomepetcenter.png", 'www.231farmcenter.com'),
new couponData('Home Improvement', 'Ackerman Security', "ackermansecurity.png", 'www.ackermansecurity.com'),
new couponData('Retail Stores', 'All About Beads', "allaboutbeads.png", 'www.allaboutbeadsmd.com'),
new couponData('Education', 'Annmarie Garden - Classes', "annmariegardenclasses.png", 'www.annmariegarden.org'),
new couponData('Community', 'Annmarie Garden - Garden In Lights', "annmariegardengardeninlights.png", 'www.annmariegarden.org'),
new couponData('Automotive', 'Bayside Limousine', "baysidelimousine.png", 'www.baysidelimo.com'),
new couponData('Health & Beauty', 'Beauchamp Chiropractic', "beauchampchiropractic.png", 'www.chirosplus.com'),
new couponData('Retail Stores', 'Big Top Kids Consignment Shop', "bigtopkidsconsignmentshop.png", 'www.bigtopkidsconsignment.com'),
new couponData('Community', 'Brem Foundation', "bremfoundation.png", 'www.bremfoundation.com'),
new couponData('Restaurants', 'Burger King', "burgerking.png", 'www.bk.com '),
new couponData('Community', 'Calvert Hospice', "calverthospice.png", 'www.calverthospice.org'),
new couponData('Community', 'Calvert Marine Museum', "calvertmarinemuseum.png", 'www.calvertmarinemuseum.com'),
new couponData('Community', 'Calvert Memorial Hospital', "calvertmemorialhospital.png", 'www.calvert hospital.com'),
new couponData('Insurance', 'Carrie Polk For Nationwide', "carriepolkfornationwide.png", 'www.nationwide.com/agent/prince-frederick-maryland-insurance-agent/polk/office.html'),
new couponData('Retail Stores', 'Caton Enterprises', "catonenterprises.png", ''),
new couponData('Restaurants', 'Chesapeake Grille & Deli', "chesapeakegrilledeli.png", 'www.chesapeakegrille.com'),
new couponData('Automotive', 'Creations Auto Paint & Repair', "creationsautopaintrepair.png", ''),
new couponData('Retail Stores', 'Educate & Celebrate', "educatecelebrate.png", 'www.learning-experts.com'),
new couponData('Restaurants', 'El Cerro Grande', "elcerrogrande.png", ''),
new couponData('Health & Beauty', 'ER Massage Therapy', "ermassagetherapy.png", ''),
new couponData('Home Improvement', 'Floor Systems', "floorsystems.png", 'www.floorsystems.net'),
new couponData('Retail Stores', 'Floral Expressions', "floralexpressions.png", 'www.calvertflorist.com'),
new couponData('Health & Beauty', 'Island Pet Salon', "islandpetsalon.png", 'www.islandpetsalon.com'),
new couponData('Retail Stores', 'J.W. Jewelers', "j.wjewelers.png", ''),
new couponData('realtors', 'Kaine Homes', "kainehomes.png", 'www.kainehomes.com'),
new couponData('Attorneys', 'Law Offices Of Julie', "lawofficeofjulieschejbal.png", ''),
new couponData('Attorneys', 'Julie Schejbal', "lawofficeofjulieschejbal_1.png", ''),
new couponData('Community', 'Life Church Calvert', "lifechurchcalvert.png", ''),
new couponData('Retail Stores', 'Maertens Jewelry', "maertensjewelry.png", ''),
new couponData('Home Improvement', 'Masterpiece Refinishing', "masterpiecerefinishing.png", 'www.masterpiece-refinishing.com'),
new couponData('Health & Beauty', 'Michelle Lea & Associates', "michelleleaassociates_calvertcounty.png", 'www.leamassagetherapy.com'),
new couponData('Health & Beauty', 'Michelle Lea & Associates - St. Marys County', "michelleleaassociatesst.maryscounty.png", 'www.leamassagetherapy.com'),
new couponData('Home Improvement', 'Molly Maid', "mollymaid.png", 'www.mollymaid.com'),
new couponData('Retail Stores', 'O.W.N.', "o.w.n..png", ''),
new couponData('Restaurants', 'Outback Steakhouse', "outbacksteakhouse_st.maryscounty.png", ''),
new couponData('Restaurants', 'Outback Steakhouse - Calvert County', "outbacksteakhousecalvertcounty.png", ''),
new couponData('Restaurants', 'Papa Johns', "papajohnspizza_st.maryscounty.png", 'www.papajohnsbeachboyspizza.com'),
new couponData('Restaurants', 'Papa Johns - Calvert County', "papajohnspizzacalvertcounty.png", 'www.papajohnsbeachboyspizza.com'),
new couponData('Retail Stores', 'Pearle Vision', "pearlevision_calvertcounty.png", ''),
new couponData('Community', 'Project Echo', "projectecho.png", 'www.projectecho.net'),
new couponData('Restaurants', 'Saphron Restaurant', "saphronrestaurant.png", 'www.saphronrestaurant.com'),
new couponData('Education', 'Southern Maryland CPR', "southernmarylandcpr.png", ''),
new couponData('Home Improvement', 'Southern Maryland Windows', "southernmarylandwindows.png", 'www.smws.net'),
new couponData('Retail Stores', 'Spice Islands Wicker', "spiceislandswicker.png", 'www.yesteryearwicker.com'),
new couponData('Retail Stores', 'Spider Hall Farm', "spiderhallfarm.png", 'www.spiderhallfarm.com'),
new couponData('Home Improvement', 'Stanley Steemer', "stanleysteemer.png", ''),
new couponData('Home Improvement', 'Stevenson Pools', "stevensonpools.png", 'www.stevensonpools.com'),
new couponData('Restaurants', 'Stoneys Seafood', "stoneysseafood.png", 'www.stoneysseafoodhouse.com'),
new couponData('Gas', 'Town Center Amoco', "towncenteramoco.png", ''),
new couponData('Restaurants', 'Turn About Café', "turnaboutcafe.png", 'www.turnaboutcafe.com'),
new couponData('Community', 'United Way Of Calvert', "unitedwayofcalvert.png", ''),
new couponData('Restaurants', 'Veras Beach Club', "verasbeachclub.png", 'www.verasbeachclub.com'),
new couponData('Attorneys', 'Wilson & Parlett', "wilsonparlett.png", 'www.wilsonandparlett.com'),
new couponData('Health & Beauty', 'World Gym', "worldgym.png", 'www.somdworldgym.com')
);
var calvertCategory = new Array (
"Attorneys",
"Automotive",
"Community",
"Education",
"Gas",
"Health & Beauty",
"Home Improvement",
"Insurance",
"Restaurants",
"Retail Stores",
"realtors"
);
var charlesData = new Array(

);
var charlesCategory = new Array (

);
var stmarysData = new Array(

);
var stmarysCategory = new Array (

);

var nowArray = calvertData;
var nowCat   = calvertCategory;

var busArray   = new Array(calvertData.length);
var alpha = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");




function disCoupon(coupon, cat){
  var string ='';
  var webLink = '';

  for(i=0; i < nowArray.length; i++){
    if(coupon == nowArray[i].name ){

      get(nowArray[i].name,county);
      string += '<h3><u>Click coupon for a printable version</u> | ';
      if(cat == 'business'){
        string += '<a href="#" onclick="disBus(\'' + bus + '\');">Back</a></h3>';
      } else {
        string += '<a href="#" onclick="disCat(\'' + cat + '\');">Back</a></h3>';
      }

      for (j=0; j<nowArray[i].img.length; j++){

        string += '<a href="coupons/'+ nowArray[i].img[j] + '" border=0 target="_blank">';
        string += '<img border=0 src="couponsThumb/'+ nowArray[i].img[j] + '" width="600"><br>';
        string += '</a>';

      }
      string += '<br>';
      if(nowArray[i].web) 
          string += '<a href="http://' + nowArray[i].web + '" target="_blank">Click here to visit the website</a> | ';
    }
  }
      

      if(cat == 'business'){
        string += '<a href="#" onclick="disBus(\'' + bus + '\');">Back</a>';
      } else {
        string += '<a href="#" onclick="disCat(\'' + cat + '\');">Back</a>';
      }
      string += '<br><br>';
      document.getElementById('printCoupons').innerHTML = string;


}
function disInfo(cat){
  if(lastCat)  
    document.getElementById(lastCat).innerHTML = '<a href="#" onclick="disInfo(\'' + lastCat + '\')">' + lastCat + '</a>';
  var string = '';
  var i;
  string += '<u>' + cat +'</u><br>';
  for(i=0; i<nowArray.length; i++){
      string += '<div id="business">';
    if(cat == nowArray[i].cat ){
      string += '<a href="#" onclick="disCoupon(\'' + nowArray[i].name + '\',\''+ cat+'\')">' + nowArray[i].name + '</a><br>';
    }
      string += '</div>';
  }

    document.getElementById(cat).innerHTML = string;
    lastCat = cat;
}

function disCat(cat){

  var string = '';
  var i;
  string += '<table border=0 cellpadding="5" cellspacing="10">';
  for(i = 0; i < nowCat.length; i++){
    string += '<tr><td id="leftCell" valign="top">';
    string += '<div id="' + nowCat[i] + '">';
    string += '<a href="#" onclick="disInfo(\'' + nowCat[i] + '\')">' + nowCat[i] + '</a>';

    string += '</div>';
    string += '</td>';

    if(nowCat[i+1]){
      string += '<td id="rightCell" valign="top">';
      string += '<div id="' + nowCat[i+1] + '">';

      string += '<a href="#" onclick="disInfo(\'' + nowCat[i+1] + '\')">' + nowCat[i+1] + '</a>';

      string += '</div>';
      string += '</td>';
    } else {
      string += '<td></td>';
    }
    string += '</tr>';
    i++;
  }
  string += '</table>';
  document.getElementById('printCoupons').innerHTML = string;
  if(cat) disInfo(cat);

}

function disBus(inbus){
  var i = '';
  var string = '';
  bus = inbus;
  if(!inbus){ bus = 'A'; }

  for (i=0;i<nowArray.length;i++){
    busArray[i] = nowArray[i].name;    
  }
  busArray.sort();

  string = '<br><br>';

  for(i = 0; i < alpha.length; i++){
    if(alpha[i] == bus){
      string += alpha[i];
    } else {
      string += '<a href="javascript:disBus(\'' + alpha[i] + '\')">' + alpha[i] + '</a>';
    }
      if(i != alpha.length-1){
        string += ', ';
      }
  }
  document.getElementById('printCoupons').innerHTML = string;
  string = '';

  string += '<div id="business"><br>';

  for(i = 0; i < busArray.length; i++){
   var busEx = /^(\w)/;
   busEx.exec(busArray[i]);
   if(RegExp.$1 == bus){
    string += '<a href="javascript:disCoupon(\'' + busArray[i] + '\',\'business\')">';
    string += busArray[i] + '</a><br><br>';
   }
  }
   string += '</div>';

   document.getElementById('printCoupons').innerHTML += string;
}

function displayCoupons(eitheror){
  var string = '';
  if(eitheror == 'category'){
    disCat('');
  } else {
    disBus('');
  }

}


function switchCounty(newArray){

    nowArray = calvertData;
    nowCat   = calvertCategory;


  lastCat = '';
  displayCoupons(eitheror);
}




