//alert("hello")
//******************************** Main Banner ************************************
// This checks the cookie that gets dropped to see if the freight is free for vavcs or not free for 
// regular US Allegiance Orders.
function showUSABanner(noimage)
{
if (getCookieData("mainSite") == "vavcs"){
//-------------Code for vavcs site, going to be header that gets drawn here------------
// Function creates an img tag for displaying a custom banner graphic and creates an image
// map to work with the graphic. The graphics should be named according to the top-level
// category (from MAS90) being displayed--e.g., "SN_banner.jpg" for the "SN" (spay/neuter)
// category in MAS90.  That category code is passed to the page by MAS90 and is used to construct
// the jpg filename.
// IMPORTANT:  The page which includes this JavaScript file must include a small form named
// "ipledge_banner_form", containing a field (hidden, probably) called "banner_category"--
// that should probably be set to the E-Business Manager field ~~Cat$~~.

if (!noimage){
  var category = document.ipledge_banner_form.banner_category.value;
}
  var cat_image
  
  if ((category == "") || (category == null) || (category.substring(0, 1) == " ") || (category == "***SRCH***")){
  	cat_image = "general"
  }
  else {
  	cat_image = category.substr(0,2);
	cat_image = cat_image.replace(/\s+$/,'');
  }
  with (document){
if (!noimage){
write("<IMG SRC='/vavcs/images/" + cat_image + "_banner.jpg' ");
writeln("WIDTH=800 HEIGHT=90 USEMAP=\"#USA_banner_map\" BORDER=0>");
}

writeln("<MAP NAME=\"USA_banner_map\">");

writeln("<AREA SHAPE=RECT COORDS=\"115,43,155,62\" HREF=\"JavaScript:selectUSACategory('AR','0','AR','0')\" onMouseOver=\"window.status='browse the U.S. Army products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Army products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"160,44,217,62\" HREF=\"JavaScript:selectUSACategory('AF','0','AF','0')\" onMouseOver=\"window.status='browse the U.S. Air Force products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Air Force products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"220,43,262,62\" HREF=\"JavaScript:selectUSACategory('NA','0','NA','0')\" onMouseOver=\"window.status='browse the U.S. Navy products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Navy products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"266,42,345,62\" HREF=\"JavaScript:selectUSACategory('MA','0','MA','0')\" onMouseOver=\"window.status='browse the U.S. Marine Corps products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Marine Corps products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"347,43,421,62\" HREF=\"JavaScript:selectUSACategory('CG','0','CG','0')\" onMouseOver=\"window.status='browse the U.S. Coast Guard products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Coast Guard products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"425,43,462,63\" HREF=\"JavaScript:selectUSACategory('OEF','0','OEF','0')\" onMouseOver=\"window.status='browse the Operation Enduring Freedom products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the Operation Enduring Freedom products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"463,43,499,63\" HREF=\"JavaScript:selectUSACategory('OIF','0','OIF','0')\" onMouseOver=\"window.status='browse the Operation Iraqi Freedom products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the Operation Iraqi Freedom products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"500,44,557,64\" HREF=\"JavaScript:selectUSACategory('PP','0','PP','0')\" onMouseOver=\"window.status='browse the Patriotic products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the Patriotic products in our U.S. Allegiance Store\">");


writeln("<AREA SHAPE=RECT COORDS=\"556,44,602,64\" HREF=\"JavaScript:selectUSACategory('PS','0','PS','0')\" onMouseOver=\"window.status='browse the U.S. Postage Stamp products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Postage Stamp products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"601,44,686,63\" HREF=\"JavaScript:selectUSACategory('HT','0','HT','0')\" onMouseOver=\"window.status='see the Hot New Items category in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"see the Hot New Items category in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"704,8,784,80\" HREF=\"http://shop.ipledge.com\" onMouseOver=\"window.status='return to the U.S. Allegiance Homepage'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"return to the U.S. Allegiance Homepage\">");

writeln("<AREA SHAPE=RECT COORDS=\"115,63,171,79\" HREF=\"/aboutus.htm\" onMouseOver=\"window.status='read about U.S. Allegiance'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read about U.S. Allegiance\">");

writeln("<AREA SHAPE=RECT COORDS=\"172,63,210,79\" HREF=\"/faqs.htm\" onMouseOver=\"window.status='read our Frequently-Asked Questions'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read our Frequently-Asked Questions\">");

writeln("<AREA SHAPE=RECT COORDS=\"212,63,278,79\" HREF=\"/info_links.htm\" onMouseOver=\"window.status='Information and Links'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"Information and Links\">");

writeln("<AREA SHAPE=RECT COORDS=\"280,63,329,79\" HREF=\"/security.htm\" onMouseOver=\"window.status='read about our Security'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read about our Security\">");

writeln("<AREA SHAPE=RECT COORDS=\"332,63,377,79\" HREF=\"/privacy.htm\" onMouseOver=\"window.status='read our Privacy Policy'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read our Privacy Policy\">");

writeln("<AREA SHAPE=RECT COORDS=\"378,63,439,79\" HREF=\"/contact_us.htm\" onMouseOver=\"window.status='contact U.S. Allegiance'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"contact U.S. Allegiance\">");

writeln("</MAP>");
}

}
else
{
//-------------Code for us allegiance site, going to be header that gets drawn here------------
// Function creates an img tag for displaying a custom banner graphic, and creates an image
// map to work with the graphic.  The graphics should be named according to the top-level
// category (from MAS90) being displayed--e.g., "SN_banner.jpg" for the "SN" (spay/neuter)
// category in MAS90.  That category code is passed to the page by MAS90 and is used to construct
// the jpg filename.
// IMPORTANT:  The page which includes this JavaScript file must include a small form named
// "ipledge_banner_form", containing a field (hidden, probably) called "banner_category"--
// that should probably be set to the E-Business Manager field ~~Cat$~~.
if (!noimage){
  var category = document.ipledge_banner_form.banner_category.value
}
  var cat_image
  
  if ((category == "") || (category == null) || (category.substring(0, 1) == " ") || (category == "***SRCH***")){
  	cat_image = "general"
  }
  else {
  	cat_image = category.substr(0,2);
	cat_image = cat_image.replace(/\s+$/,'');
  }
  with (document){
if (!noimage){
write("<IMG SRC='/images/" + cat_image + "_banner.jpg' ");
writeln("WIDTH=800 HEIGHT=90 USEMAP=\"#USA_banner_map\" BORDER=0>");
}

writeln("<MAP NAME=\"USA_banner_map\">");

writeln("<AREA SHAPE=RECT COORDS=\"115,43,155,62\" HREF=\"JavaScript:selectUSACategory('AR','0','AR','0')\" onMouseOver=\"window.status='browse the U.S. Army products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Army products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"160,44,217,62\" HREF=\"JavaScript:selectUSACategory('AF','0','AF','0')\" onMouseOver=\"window.status='browse the U.S. Air Force products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Air Force products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"220,43,262,62\" HREF=\"JavaScript:selectUSACategory('NA','0','NA','0')\" onMouseOver=\"window.status='browse the U.S. Navy products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Navy products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"266,42,345,62\" HREF=\"JavaScript:selectUSACategory('MA','0','MA','0')\" onMouseOver=\"window.status='browse the U.S. Marine Corps products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Marine Corps products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"347,43,421,62\" HREF=\"JavaScript:selectUSACategory('CG','0','CG','0')\" onMouseOver=\"window.status='browse the U.S. Coast Guard products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Coast Guard products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"425,43,462,63\" HREF=\"JavaScript:selectUSACategory('OEF','0','OEF','0')\" onMouseOver=\"window.status='browse the Operation Enduring Freedom products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the Operation Enduring Freedom products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"463,43,499,63\" HREF=\"JavaScript:selectUSACategory('OIF','0','OIF','0')\" onMouseOver=\"window.status='browse the Operation Iraqi Freedom products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the Operation Iraqi Freedom products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"500,44,557,64\" HREF=\"JavaScript:selectUSACategory('PP','0','PP','0')\" onMouseOver=\"window.status='browse the Patriotic products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the Patriotic products in our U.S. Allegiance Store\">");


writeln("<AREA SHAPE=RECT COORDS=\"556,44,602,64\" HREF=\"JavaScript:selectUSACategory('PS','0','PS','0')\" onMouseOver=\"window.status='browse the U.S. Postage Stamp products in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"browse the U.S. Postage Stamp products in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"601,44,686,63\" HREF=\"JavaScript:selectUSACategory('HT','0','HT','0')\" onMouseOver=\"window.status='see the Hot New Items category in our U.S. Allegiance Store'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"see the Hot New Items category in our U.S. Allegiance Store\">");

writeln("<AREA SHAPE=RECT COORDS=\"704,8,784,80\" HREF=\"http://shop.ipledge.com\" onMouseOver=\"window.status='return to the U.S. Allegiance Homepage'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"return to the U.S. Allegiance Homepage\">");

writeln("<AREA SHAPE=RECT COORDS=\"115,63,171,79\" HREF=\"/aboutus.htm\" onMouseOver=\"window.status='read about U.S. Allegiance'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read about U.S. Allegiance\">");

writeln("<AREA SHAPE=RECT COORDS=\"172,63,210,79\" HREF=\"/faqs.htm\" onMouseOver=\"window.status='read our Frequently-Asked Questions'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read our Frequently-Asked Questions\">");

writeln("<AREA SHAPE=RECT COORDS=\"212,63,278,79\" HREF=\"/info_links.htm\" onMouseOver=\"window.status='Information and Links'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"Information and Links\">");

writeln("<AREA SHAPE=RECT COORDS=\"280,63,329,79\" HREF=\"/security.htm\" onMouseOver=\"window.status='read about our Security'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read about our Security\">");

writeln("<AREA SHAPE=RECT COORDS=\"332,63,377,79\" HREF=\"/privacy.htm\" onMouseOver=\"window.status='read our Privacy Policy'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"read our Privacy Policy\">");

writeln("<AREA SHAPE=RECT COORDS=\"378,63,439,79\" HREF=\"/contact_us.htm\" onMouseOver=\"window.status='contact U.S. Allegiance'; return true\" onMouseOut=\"window.status=''; return true\" TITLE=\"contact U.S. Allegiance\">");

writeln("</MAP>");
}
//Code for US site
 } 
}

function selectUSACategory(cat_code,cat_lvl,cat_code0,cat_lvl3){
  document.ps2form.form_select.value = "C";
  document.ps2form.cat_lvl.value = cat_lvl;
  document.ps2form.cat.value = cat_code;
  if ((cat_code != cat_code0) && (cat_code0 != ''))
  {
    document.ps2form.cat_code0.value = cat_code0;
    document.ps2form.cat_lvl3.value = cat_lvl3;
  }
  document.ps2form.submit();
}

//****************************** Freight Functions ***********************************
// This function will check the cookie to see what site we have came from.
// Once we determine what site we have came from, we call the correct freight function
function Freight(shipvia){
  if (getCookieData("mainSite") == "vavcs"){
     calculateFreeFreight(shipvia);
     document.getElementById("shipopt").innerHTML = "<BR><FONT SIZE=1 COLOR=#880000><B>Veterans Canteen Service Members<BR>get FREE shipping at U.S. Allegiance!</B></FONT>";
  } else {
    calculateFreight(shipvia);
  }
}
//Shows only the free freight for vavcs website
function calculateFreeFreight(oSelect){
	var i = 0;
	while (i < oSelect.options.length){
	    var code = oSelect.options[i].value;					
		if ((code.replace(/\s+$/,'') != 'FREEUPS')&&(code !=='               ')){
		//  alert("i " + i + " code" + code);
		  oSelect.options[i] = null;	  
		} else {  
		//alert("i " + i + " code" + code + " - remove");
		i++;
		}
	}
	oSelect.value='FREEUPS        ';
}

//Shows only the non-free freight for us allegiance website
function calculateFreight(oSelect){
	var i = 0;
	while (i < oSelect.options.length){
	   var code = oSelect.options[i].value;
		if (code.replace(/\s+$/,'') == 'FREEUPS'){ 
		  //Remove option value from select box and do not increment the length of the select box since we lose a value (i.e. option3 becomes option2)
		  oSelect.options[i] = null;		  
		} else {  
		//Since the length of the select box has not changed, we increment to read next value
		i++;
		}
	}
}

//*************************** End Freight Functions **********************************

//*************************** Handles cookie functions *******************************

function setCookieData(name,value){
 var refarray = new Array();

// write list of domains and its associated redirect page
 refarray['vacanteen.com'] = "/vavcs/";
 refarray['armygamegear.com'] = "/armygamegear.htm";

// automatically redirect if visitor clicks through from an above-listed domain
 for (var i in refarray){
  if (document.referrer.indexOf(i) != -1){
   var refgo = refarray[i];
   if (i.indexOf("vacanteen.com") != -1){
    value = "vavcs";
   }
  }
 }
 if (refgo){
  setCookieData2(name,value);
  window.location.replace(refgo);
 }
}

function setCookieData2(name,value){
 var days="1";
 if (days){
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
 }
 else {var expires = "";}
 document.cookie = name+"="+value+expires+"; path=/";
}

function getCookieData(labelName){
// returns cookie data from corresponding label, or null if label does not exist.
 var cookieData = document.cookie; // grab the data once
 var cookieEnd;
 for (i=0; i < cookieData.length; i++){
  var j = i + labelName.length;
  if (cookieData.substring(i,j) == labelName){
   cookieEnd = cookieData.indexOf(";",j)
   if (cookieEnd == -1) { cookieEnd = cookieData.length; }
   return unescape(cookieData.substring(j+1, cookieEnd));
  }
 }
 return null;
}

function delCookieData(labelName){
// deletes specific cookie by label name
 document.cookie = labelName + "=" + ";expires=Thursday, 01 Jan 1970 00:00:01 GMT;";
 return null;
}
//*************************** End of cookie functions *******************************
