function detectBrowser(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	alert(b_version);
	if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=6)){
		return(0);
	}else{
		return(1);
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
		  
var mouseOverTest = "";
		  
function changeSwatch(which, cName, attrib, desc){
    var sizeSelect = document.getElementById("sizeSelect");
    if(sizeSelect.selectedIndex == 0) {
        document.getElementById("color_name").innerHTML = "You Must First Choose Your Size";
        return;
    }
	  var imgs
	  var i;
	  var temp;
	  imgs = document.getElementsByTagName('img');
	  for(i in imgs) {
		    temp = imgs[i].id;
		    if(temp){
			      if(temp.substr(0,6)=="swatch"){
			          document.getElementById(temp).style.border = "2px solid #000000"
			      }
		    }
    }
  
	  document.getElementById(which).style.border = "2px solid #ff0000"
	  document.getElementById("color_name").innerHTML = cName;
	  document.getElementById("color_desc").innerHTML = desc;
	  if(attrib){
		    document.getElementById("color_attrib").innerHTML = "&nbsp;&nbsp;" + attrib;
	  }
}
function setstyle(){
	
	  if(document.getElementById("same_as_billing").checked == true)    {

		document.getElementById("first_name_shipping").disabled = true;
		 document.getElementById("last_name_shipping").disabled = true;
		 document.getElementById("address_1_shipping").disabled = true;
		 document.getElementById("address_2_shipping").disabled = true;
		 document.getElementById("city_shipping").disabled = true;
		 document.getElementById("military_shipping").disabled = true;
		 document.getElementById("state_shipping").disabled = true;
		 document.getElementById("zip_shipping").disabled = true;
		 document.getElementById("telephone_shipping").disabled = true;
		 document.getElementById("first_name_shipping").style.background = '#8f8f8e';
		 document.getElementById("last_name_shipping").style.background = '#8f8f8e';
		 document.getElementById("address_1_shipping").style.background = '#8f8f8e';
		 document.getElementById("address_2_shipping").style.background = '#8f8f8e';
		 document.getElementById("city_shipping").style.background = '#8f8f8e';
		 document.getElementById("military_shipping").style.background = '#8f8f8e';
		 document.getElementById("state_shipping").style.background = '#8f8f8e';
		 document.getElementById("zip_shipping").style.background = '#8f8f8e';
		 document.getElementById("telephone_shipping").style.background = '#8f8f8e';
		 changeClass("form_gray");
      }else   {
	      changeClass("form_black");
		 document.getElementById("first_name_shipping").disabled = false;
		 document.getElementById("last_name_shipping").disabled = false;
		 document.getElementById("address_1_shipping").disabled = false;
		 document.getElementById("address_2_shipping").disabled = false;
		 document.getElementById("city_shipping").disabled = false;
		 document.getElementById("military_shipping").disabled = false;
		 document.getElementById("state_shipping").disabled = false;
		 document.getElementById("zip_shipping").disabled = false;
		 document.getElementById("telephone_shipping").disabled = false; 
		 document.getElementById("first_name_shipping").style.background = '#ffffff';
		 document.getElementById("last_name_shipping").style.background = '#ffffff';
		 document.getElementById("address_1_shipping").style.background = '#ffffff';
		 document.getElementById("address_2_shipping").style.background = '#ffffff';
		 document.getElementById("city_shipping").style.background = '#ffffff';
		 document.getElementById("military_shipping").style.background = '#ffffff';
		 document.getElementById("state_shipping").style.background = '#ffffff';
		 document.getElementById("zip_shipping").style.background = '#ffffff';
		 document.getElementById("telephone_shipping").style.background = '#ffffff';
     }
}

function changeClass(which){
	var i;
	for(i=1;i<10;i++){
		 document.getElementById("f" + i).className = which;
	}
}

function gettheyear(){
	var y = new Date();
	var year = y.getFullYear();
	document.write(year);
}

function showPopUp(el) {
  alreadyClosed = false;
  var cvr = document.getElementById("cover");
  var dlg = document.getElementById(el);
  cvr.style.display = "block";
  dlg.style.display = "block";

  if (document.body.style.overflow == "hidden") {
    cvr.style.width =  getOverlayWidth(); // was "100%"; 
    cvr.style.height = "2048px"; // 2048 is the max that IE7 on Vista will allow!
  }
  flipSelectsAndZoom();
  document.body.style.overflowY = "auto";
}

function flipSelectsAndZoom() {
	  if(BrowserDetect.version<7 && BrowserDetect.browser =='Explorer'){
	      var selectList = document.getElementsByTagName('select');         
	      for ( var curSelect=0; curSelect<selectList.length; curSelect++){
	          hideShow(selectList[curSelect].id);
	      }
	  }
	  hideShow('zoom_tool1');
}

function openFitGuide(which){
	window.open (which,"mywindow","menubar=1,resizable=1,scrollbars=yes,width=630,height=600"); 
}

function turnOff(Id){
    var es;

    if(BrowserDetect.version<7 && BrowserDetect.browser =='Explorer'){
        es = document.getElementById(Id);
        es.style.visibility = 'hidden';
    }
}

function turnOn(Id){
    var es;
    
    if(BrowserDetect.version<7 && BrowserDetect.browser =='Explorer'){
        es = document.getElementById(Id);
        es.style.visibility = 'visible';
    }
}

function hideShow(id){
	var es;
	
	if ( document.getElementById && (es = document.getElementById(id)) && (es = es.style)){
		es.display = ('none' == es.display)? '' : 'none';
	}
}

function show(id){
	var es;
	
	if ( document.getElementById && (es = document.getElementById(id)) && (es = es.style)){
		es.display = '';
	}
}

function getOverlayWidth() {
	winW = document.body.offsetWidth;
	return winW + "px" ;
}

function showPopUp2(el) {
	var dlg = document.getElementById(el);
	dlg.style.display = "block";
	
}
function showTab(ft,st){
	
	var cvr = document.getElementById(ft)
	var dlg = document.getElementById(st)
	cvr.style.display = "none"
	dlg.style.display = "block"
}

function closePopUp2(el) {
	var dlg = document.getElementById(el);
	dlg.style.display = "none";
	document.body.style.overflowY = "auto";
}

var alreadyClosed = false;

function closePopUp(el) {
  if(alreadyClosed) {
      return;
  }
  var cvr = document.getElementById("cover");
  var dlg = document.getElementById(el);
  cvr.style.display = "none";
  dlg.style.display = "none";
  document.body.style.overflowY = "auto";
  flipSelectsAndZoom();
  alreadyClosed = true;
}

//----home subnav code
var ribbonDiv="";
var mytime="";
function changeRibbonImage(which,dir,whichImage){
	ribbonDiv = dir;
	document.getElementById(which).src="images/home_rollovers/"+ dir + "/" + whichImage;
}

function changeRibbonImageOut(which,dir,whichImage){
	ribbonDiv="";
	mouseOverTest="";
	document.getElementById(which).src="images/home_rollovers/"+ dir + "/" + whichImage;
	 mytime = setTimeout("closeRibbon('" + dir + "')",2000)
}

function closeRibbon(which){
	if(ribbonDiv!=which && mouseOverTest!=which){
		document.getElementById(which+'_subNav_home').style.display= "none";
	}
}

function changeImage(which,whichImage){
	document.getElementById(which).src=whichImage;
}

function changeImageHome(which,whichImage){
	hideSubNav();
	mouseOverTest = which;
	document.getElementById(which+'_subNav_home').style.display = 'block';
	document.getElementById(which).src="images/nav/"+whichImage;
}

function changeImageHomeCA(which,whichImage){
	hideSubNavCA();
	mouseOverTest = which;
	document.getElementById(which+'_subNav_home').style.display = 'block';
	document.getElementById(which).src="images/nav/"+whichImage;
}

function changeImageHomeOut(which,whichImage){
	mouseOverTest = "";
	document.getElementById(which).src="images/nav/"+whichImage;
	 mytime = setTimeout("closeNav('" + which + "')",1000)
}

function changeImageHomeOutCA(which,whichImage){
	mouseOverTest = "";
	document.getElementById(which).src="images/nav/"+whichImage;
	 mytime = setTimeout("closeNav('" + which + "')",1000)
}

function setSubNav(which){
	mouseOverTest = which;
}

function closeNav(which){
	if(mouseOverTest!=which){
		document.getElementById(which+'_subNav_home').style.display= "none";
	}
}

function hideSubNav(){
	document.getElementById('men_subNav_home').style.display = "none";
	document.getElementById('women_subNav_home').style.display = "none";
	document.getElementById('girls_subNav_home').style.display = "none";
	document.getElementById('boys_subNav_home').style.display = "none";
	document.getElementById('hot_subNav_home').style.display = "none";
	document.getElementById('clearance_subNav_home').style.display = "none";
}

function hideSubNavCA(){
	document.getElementById('work_subNav_home').style.display = "none";
	document.getElementById('wear_subNav_home').style.display = "none";
	document.getElementById('accessories_subNav_home').style.display = "none";
	document.getElementById('hot_subNav_home').style.display = "none";
	document.getElementById('clearance_subNav_home').style.display = "none";
 
}

function changePoster(which){
	document.getElementById('poster1').style.backgroundColor = "#333333";
	document.getElementById('poster2').style.backgroundColor  = "#333333";
	document.getElementById('poster3').style.backgroundColor  = "#333333";
	document.getElementById('poster4').style.backgroundColor  = "#333333";
	if(which){
		document.getElementById(which).style.backgroundColor  = "#a61311";
	}
}

function changeLeftImage(which,whichImage){
	document.getElementById(which).src="images/leftnav/"+whichImage;
}

function changeLeftImageSearch(which,whichImage){
	document.getElementById(which).src="images/nav/side_nav/"+whichImage;
}

function changeMensImage(which,whichImage){
	document.getElementById(which).src="images/mens/"+whichImage;
}

function changeNav(which){
		document.getElementById(which).className="page_on";  //sets the nav item on
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function checkSearch(msg){
	var temp;
    temp=document.getElementById('searchfield').value;
    if(temp==msg){
      document.getElementById('searchfield').value="";
    }
}

 function checkSearchField(noValue, badValue, defaultValue) {
	var value = document.getElementById('searchfield').value;
	if (value == "" || value == defaultValue) {
         alert(noValue);
	return false;
    }
     else if(value.match(/[^ A-Za-z0-9\-\"'\*\?\+]/)) {
     	alert(badValue);
      	return false;
    }
   	else {
    	return true;
    }
  }

function flash(movie, theWidth, theHeight) {
  output = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
      "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" " +
      "width=\"" + theWidth + "\" height=\"" + theHeight + "\" id=\"video2\" align=\"middle\">  ";
  output += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />  ";
  output += "<param name=\"movie\" value=\"" + movie + "\" />  ";
  output += "<param name=\"quality\" value=\"high\" />  ";
  output += "<param name=\"wmode\" value=\"transparent\">  ";
  output += "<embed src=\"" + movie + "\" quality=\"high\" wmode=\"transparent\" width=\"" +
      theWidth + "\" height=\"" + theHeight +
      "\" name=\"TFSLogo\" align=\"middle\" allowScriptAccess=\"sameDomain\" " +
      "type=\"application/x-shockwave-flash\" " +
      "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />  ";
  output += "</object>  ";
  document.write(output);
}

function flash2(banner, theWidth, theHeight,vars) {
	output = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ";
	output += "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab";
	output += "#version=8,0,0,0\" width=\"" + theWidth + "\" height=\"" + theHeight;
	output += "\" id=\"video2\" align=\"middle\">  ";
	output += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />  ";
	output += "<param name=\"movie\" value=\"" + banner + "?" + vars +"\" />  ";
	output += "<param name=\"quality\" value=\"high\" />  ";
	output += "<param name=\"wmode\" value=\"transparent\">  ";
	output += "<embed src=\"" + banner + "?" + vars;
	output += "\" quality=\"high\" wmode=\"transparent\" width=\"" + theWidth;
	output += "\" height=\"" + theHeight + "\" name=\"TFSLogo\" align=\"middle\" ";
	output += "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" ";
	output += "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />  ";
	output += "</object>  ";
	document.write(output);
}

