﻿// JScript File

var lastSrc="";
var lastNum=1;
var colorNum=1;

function tabimg_onmouseover(srcId, tagId) {
    var wtImg  = document.getElementById(tagId);
    lastSrc=wtImg.src;
    wtImg.src = srcId; 
}

function tabimg_onmouseout(srcId, tagId) {
    var wtImg  = document.getElementById(tagId);
    if (lastSrc.length==0) {
        wtImg.src = srcId;
    }
    else {
        wtImg.src = lastSrc;
    }
}

function preloadImages(imageStr) { 
  //if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=imageStr; for(i=0; i<a.length; i++)
    { d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function navToPage(navPage) {
    window.open(navPage,"_self");
}

function PreloadMenuImages(bkgImage)  {
  var imgNum=0;
  var imageStr=new Array();
  imageStr[0]=bkgImage;
  for(imgNum=0; imgNum<9; imgNum++) {
    imageStr[imgNum+1]="'images/Menu" + imgNum + ".gif'";
  }
  preloadImages(imageStr);
}

function getUrlValue(varname) {
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length < 2) 
  {
    return "";
  }

  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++)
  {
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    // Check if the correct variable
    if (parts[0] == varname)
    {
      // Load value into variable
      value = parts[1];

      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;

}

function loadWineTagPage(wtValue, colorValue) {
  window.open('BuyTags2.htm?wineTag=' + wtValue + '&tagColor=' + colorValue,'_self');
}
function loadHolidayTagPage(wtValue) {
  window.open('BuyHolidayTags2.htm?holidayTag='+wtValue,'_self');
}

function setBuyTagElements(tag_next, tag_type, tag_img_id, tag_text_id, frm_color_id, frm_item_no_id, frm_item_name_id) {
  var tag_no = lastNum + tag_next;
  var max_tag_no=10;
  var tag_color="blue";
  var tag_texts=new Array();
  
  tag_texts[1]="cheers!";
  tag_texts[2]="enjoy!";
  tag_texts[3]="enjoy";
  tag_texts[4]="best wishes";
  tag_texts[5]="best wishes";
  tag_texts[6]="thanks!";
  tag_texts[7]="best wishes";
  tag_texts[8]="big thanks!";
  tag_texts[9]="celebrate!";
  tag_texts[10]="cheers!";
  
  if (tag_type=='HT') {
    max_tag_no=8;
   }
  if (tag_no>max_tag_no) {
    tag_no=1;
  }
  else if (tag_no<1) {
    tag_no=max_tag_no;
  }
  lastNum=tag_no;
  
//  var rbObj = document.getElementById(frm_color_id);
  for(i=1; i<6; i++) {
    var rbObj = document.getElementById("Radio" + i);
    if (rbObj.checked) {
      tag_color=rbObj.value;
    }
  }  
  
  var wtImg  = document.getElementById(tag_img_id);
  
  var wtUrl = "images/" + tag_type + tag_no + tag_color + ".gif";
  
  wtImg.src = wtUrl;
  
  var tagTextElem = document.getElementById(tag_text_id);
  
  tagTextElem.innerHTML = tag_type + " " + tag_no + "  {" + tag_texts[tag_no] + "}  $6.00"; // "WT 1  {cheers!}  $6.00"
  
  var oItmNameHidden = document.getElementById(frm_item_name_id);
  var oItmNumberHidden = document.getElementById(frm_item_no_id);
  
  oItmNumberHidden.value=tag_type + " " + tag_no; //WT 1
  if (tag_type=="WT") {
    oItmNameHidden.value="Wine Tag " + tag_no + "  {" + tag_texts[tag_no] + "}" ;//Wine Tag 1  {cheers!}
  }
  else {
    oItmNameHidden.value="Holiday Tag " + tag_no + "  {" + tag_texts[tag_no] + "}"
  }
   
}

function setBuyHolidayTagElements(tag_next, tag_type, tag_img_id, tag_text_id, frm_item_no_id, frm_item_name_id) {
  var tag_no = lastNum + tag_next;
  var max_tag_no=10;
  var tag_texts=new Array();
  var tag_names=new Array();
  
  tag_names[1]="peace";
  tag_names[2]="HoHoHo";
  tag_names[3]="Joy";
  tag_names[4]="Cheers";
  tag_names[5]="redsnowflake";
  tag_names[6]="greensnowflake";
  tag_names[7]="purplesnowflake";
  tag_names[8]="RedTree";
  
  tag_texts[1]="PEACE";
  tag_texts[2]="hohoho";
  tag_texts[3]="Joy";
  tag_texts[4]="cheers!";
  tag_texts[5]="red snow flake - best wishes!";
  tag_texts[6]="green snow flake - best wishes!";
  tag_texts[7]="purple snow flake - best wishes!";
  tag_texts[8]="red christmas tree - 'tis the season!";
  
  if (tag_type=='HT') {
    max_tag_no=8;
   }
  if (tag_no>max_tag_no) {
    tag_no=1;
  }
  else if (tag_no<1) {
    tag_no=max_tag_no;
  }
  lastNum=tag_no;
  
  var wtImg  = document.getElementById(tag_img_id);
  
  var wtUrl = "images/" + tag_type + tag_no + "." + tag_names[tag_no] + ".gif";
  
  wtImg.src = wtUrl;
  
  var tagTextElem = document.getElementById(tag_text_id);
  
  tagTextElem.innerHTML = tag_type + " " + tag_no + "  {" + tag_texts[tag_no] + "}  $6.00"; // "WT 1  {cheers!}  $6.00"
  
  var oItmNameHidden = document.getElementById(frm_item_name_id);
  var oItmNumberHidden = document.getElementById(frm_item_no_id);
  
  oItmNumberHidden.value=tag_type + " " + tag_no; //WT 1
  if (tag_type=="WT") {
    oItmNameHidden.value="Wine Tag " + tag_no + "  {" + tag_texts[tag_no] + "}" ;//Wine Tag 1  {cheers!}
  }
  else {
    oItmNameHidden.value="Holiday Tag " + tag_no + "  {" + tag_texts[tag_no] + "}"
  }
   
}

function loadBuyTags2(bkgImage, tag_type) {
  var imgNum=0;
  var tagCnt=1;
  var imgCnt=1;
  var imageStr=new Array();
  var imgTemp=9;
  imageStr[0]=bkgImage;
  imageStr[1]="https://id34152.securedata.net/abacusdb.com/images/order.gif";
  imageStr[2]="https://id34152.securedata.net/abacusdb.com/images/checkcart.gif";
  for(imgNum=0; imgNum<9; imgNum++) {
    imgCnt=imageStr.length;
    imageStr[imgCnt]="'images/Menu" + imgNum + ".gif'";
  }
  if (tag_type=="WT") {
    for(imgNum=imgTemp; imgNum<imgTemp+10; imgNum++) {
      imgCnt=imageStr.length;
      imageStr[imgCnt]="'images/WT" + tagCnt + "blue.gif'";
      imgCnt=imageStr.length;
      imageStr[imgCnt]="'images/WT" + tagCnt + "green.gif'";
      imgCnt=imageStr.length;
      imageStr[imgCnt]="'images/WT" + tagCnt + "orange.gif'";
      imgCnt=imageStr.length;
      imageStr[imgCnt]="'images/WT" + tagCnt + "pink.gif'";
      imgCnt=imageStr.length;
      imageStr[imgCnt]="'images/WT" + tagCnt + "red.gif'";
    }
   }
   else {
    imageStr[imgCnt]="'images/HT1.peace.gif'";
    imageStr[imgCnt+1]="'images/HT2.HoHoHo.gif'";
    imageStr[imgCnt+2]="'images/HT3.Joy.gif'";
    imageStr[imgCnt+3]="'images/HT4.Cheers.gif'";
    imageStr[imgCnt+4]="'images/HT5.redsnowflake.gif'";
    imageStr[imgCnt+5]="'images/HT6.greensnowflake.gif'";
    imageStr[imgCnt+6]="'images/HT7.purplesnowflake.gif'";
    imageStr[imgCnt+7]="'images/HT8.RedTree.gif'";
    imgCnt=imageStr.length;
   }
  
  preloadImages(imageStr);
  
  if (tag_type=="WT") {
    lastNum = parseInt(getUrlValue('wineTag'));
    if (lastNum==0) {
      lastNum=1;
    }
    colorNum = parseInt(getUrlValue('tagColor'));
    var rbObj = document.getElementById("Radio" + colorNum);
    rbObj.checked=true;
    setBuyTagElements(0, 'WT', 'wtImg', 'wt_name_text', 'os0', 'item_number', 'item_name');
  }
  else {
    lastNum = parseInt(getUrlValue('holidayTag'));
    if (lastNum==0) {
      lastNum=1;
    }
    setBuyHolidayTagElements(0, 'HT', 'htImg', 'ht_name_text', 'item_number', 'item_name');
  }
  
}
