<!-- Begin

var IEX = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion > 4) ? true : false;
var IE4 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion == 4) ? true : false;
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) ? true : false;
var NS6 = (navigator.appName == "Netscape" && navigator.appVersion == 6 || navigator.appCodeName == "Mozilla") ? true : false;
var CookieName = "tetonMWTWClips";
//var BaseURL = "http://www..com";

function clipit (id) {
  toggleImage(id); 

  var cookieValue = GetCookie(CookieName);

  if (cookieValue != null) {
    if (FindClip(cookieValue, id)) {
      RemoveClip(cookieValue, id);
    } else {
      AppendClip(cookieValue, id);
    }
  } else {
    WriteCookie(CookieName,id);
  }
}

function clipit_d (id) {
  toggleImage_d(id); 

  var cookieValue = GetCookie(CookieName);

  if (cookieValue != null) {
    if (FindClip(cookieValue, id)) {
      RemoveClip(cookieValue, id);
    } else {
      AppendClip(cookieValue, id);
    }
  } else {
    WriteCookie(CookieName,id);
  }
}

function toggleImage(id) {
  //var adId = 'cokVeh' + id;
  //var adId2 = 'cokVeh' + id + '-versions';
  //var adImage = document.images['clipImage_' + id];
  //var imageSrcOff = new Image();
  //var imageSrcOn = new Image();
  //var imageSrcOff = BaseURL + '/images/clip.gif';
  //var imageSrcOn = BaseURL + '/images/clipped.gif';

  //if (NS4) {
  //} else {
	//if ((IEX || NS6) && document.getElementById(adId)) document.getElementById(adId).className = (document.getElementById(adId).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
	//if (IE4 && document.all(adId)) document.all(adId).className = (document.all(adId).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
	//if ((IEX || NS6) && document.getElementById(adId2)) document.getElementById(adId2).className = (document.getElementById(adId2).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
	//if (IE4 && document.all(adId2)) document.all(adId2).className = (document.all(adId2).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
  //}
  //if (document.images) {
	// if (adImage) {
	//     adImage.src = (adImage.src == imageSrcOff) ? imageSrcOn : imageSrcOff;
	// }
  //}
  
  var addClipLink = '<a href="javascript:clipit(\''+id+'\');">SAVE MY AUTO</a>';
  var removeClipLink = '<a href="javascript:clipit(\''+id+'\');">REMOVE</a>';
  
  var adSel = document.getElementById('clipSel_' + id);
  //adSel.innerHTML = (adSel.innerHTML == addClipLink) ? removeClipLink : addClipLink;
  adSel.innerHTML = (adSel.innerHTML.toLowerCase() == addClipLink.toLowerCase()) ? removeClipLink : addClipLink;
  

}

/*
function toggleImage_d(id) {
  //var adId = 'cokVeh' + id;
  //var adId2 = 'cokVeh' + id + '-versions';
  //var adImage = document.images['clipImage_' + id];
  //var imageSrcOff = new Image();
  //var imageSrcOn = new Image();
  //var imageSrcOff = BaseURL + '/images/clip.gif';
  //var imageSrcOn = BaseURL + '/images/clipped.gif';

  //if (NS4) {
  //} else {
	//if ((IEX || NS6) && document.getElementById(adId)) document.getElementById(adId).className = (document.getElementById(adId).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
	//if (IE4 && document.all(adId)) document.all(adId).className = (document.all(adId).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
	//if ((IEX || NS6) && document.getElementById(adId2)) document.getElementById(adId2).className = (document.getElementById(adId2).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
	//if (IE4 && document.all(adId2)) document.all(adId2).className = (document.all(adId2).className == 'cokVeh') ? 'cokVeh_hilited' : 'cokVeh';
  //}
  //if (document.images) {
	// if (adImage) {
	//     adImage.src = (adImage.src == imageSrcOff) ? imageSrcOn : imageSrcOff;
	// }
  //}
  
  var addClipLink = '<A href="javascript:clipit_d(\''+id+'\');" class="t_save");"><!--//SAVE//--></A>';
  var removeClipLink = '<A href="javascript:clipit_d(\''+id+'\');" class="t_remove");"><!--//REMOVE//--></A>';
  
  var adSel = document.getElementById('clipSel_' + id);
  //alert(adSel.innerHTML + "\n" + addClipLink);
  if(adSel.title == "SAVE") {
	adSel.innerHTML = removeClipLink;
	adSel.title = "REMOVE";
  } else {
	adSel.innerHTML = addClipLink;  
	adSel.title = "SAVE";
  }
  

}
*/

function FindClip (cookieStr, id) {
  var clipFound = 0;
  var clips = cookieStr.split(",");
  var setSize = clips.length;
  if (setSize > 1) {
    for (var x = 0; x < setSize; x++) {
      if (clips[x] == id){
        clipFound=1;
      }
    }
  } else {
    if (cookieStr == id) {
      clipFound=1;
    }
  } 
  return clipFound;
}

function AppendClip(cookieStr, itemToAppend) {
  var cookieValue = new String();
  if (cookieStr == "") {
    cookieValue = itemToAppend;
  } else {
    cookieValue = cookieStr + ',' + itemToAppend;
  }
  WriteCookie(CookieName, cookieValue);
}

function RemoveClip (cookieStr, itemToRemove) {
  //var cookieStr = GetCookie(CookieName);
  var clips = cookieStr.split(',');
  var setSize = clips.length;
  var cookieValue = new String();
  if (setSize > 1) {
    for (var x = 0; x < setSize; x++) {
      if (clips[x] != itemToRemove)  {
        if (cookieValue == null || cookieValue == "") { 
          cookieValue = clips[x];
        } else { 
          cookieValue = cookieValue + ',' + clips[x];
        }
      }
    }
  }

  WriteCookie(CookieName, cookieValue);
  if (NS4) {
	loc = window.location.href + '&removeditem=' + itemToRemove;
	window.location = loc 
  } else if (NS6 || IE6) {
	var d = document.getElementById(itemToRemove);
	if (d) d.style.display = 'none';
  } else if (IE4) {
	var d = document.all(itemToRemove);
	if (d) d.style.display = 'none';
  }
}

function GetCookie(Name) {
  var cookieStr = document.cookie;
  var arg = Name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (cookieStr.substring(i,j) == arg) {
      return GetCookieVal(j);
    }
    i = document.cookie.indexOf(" ",i) + 1;
    if (i == 0) break;
  }
  return null;
}

function GetCookieVal (offset) {
  var endstr = document.cookie.indexOf(";",offset);
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
}

function WriteCookie (cookieName, cookieValue, path, domain, expires, secure) {
  path = "/";
  domain = "ingearct.tetonmedia.com";
  var curCookie = cookieName + "=" + escape(cookieValue) + ((expires) ? "; expires=" + expires.toGMTString() : "") + 
  ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");

  document.cookie = curCookie;
}