// The Cookie Jar
////// Standard functions for Setting, Getting, and Deleting Cookies
////// john@xcentrixlc.com

// To set a cookie pass in the name, value, and persist type
// SetCookie("name", "value", 1) set the persist type to 1 to store your cookie
// or to 0 to last for this browser session only.  By default the storage time is for one year.
// You can add another argument to hold the length of time you want to store the cookie:
// SetCookie("name", "value",1,15768000000) would store the cookie for 6 months.
// the time is calcutaled in miliseconds so for one month of milliseconds you calculate:
// 31 * 24 * 60 * 60 * 1000=2678400000
// To get or delete a cookie simply pass in the name of the cookie you want to effect
// GetCookie("name")  DeleteCookie("name")
// if you ask for a cookie that does not exist it will return null.
var espassetsinventPath = "http://espassets.izmocars.com/inventory/bmw";
function getCookieVal(offset) {
  endstr = document.cookie.indexOf (";", offset)
  if(endstr == -1) endstr = document.cookie.length
  return unescape(document.cookie.substring(offset, endstr))
}

function GetCookie(name) {
  arg = name + "="
  alen = arg.length
  clen = document.cookie.length
  var i = 0
  while (i < clen) {
    j = i + alen
    if(document.cookie.substring(i, j) == arg) return getCookieVal(j)
    i = document.cookie.indexOf(" ", i) + 1
    if(i == 0) break
  }
  return null
}

function SetCookie (name, value, per, exp) {
  cstr = name + "=" + escape(value) + ";"
  if(per){
    addtime=(exp>0) ? exp : 31536000000
    expdate = new Date()
    expdate.setTime(expdate.getTime() + addtime)
    expdate = expdate.toGMTString()
   cstr+=" expires=" + expdate
  }
  document.cookie = cstr
}

function DeleteCookie(name) {
  exp = new Date()
  exp.setTime (exp.getTime() - 1)
  cval = GetCookie(name)
  if(cval != null)
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()
}

function expandCollapse(id,cookieInfo){
  var div = document.getElementById(id);
  var handler=document.getElementById(div.id+"_handler");
  var cookieName=id+cookieInfo;
  if (div.style.display=='none'){
    div.style.display='block';
	handler.src="http://espassets.izmocars.com/inventory/bmw/images/Close_off.png";
    SetCookie(cookieName,'block');
	
  }
  else {
    div.style.display='none';
    SetCookie(cookieName,'none');
	handler.src=espassetsinventPath+"/images/open.jpg";
  }
}

function setDisplay(div,disp){
  if (disp != null) {
  	handler=document.getElementById(div.id+"_handler");
	div.style.display = disp;
	handler.src = (disp=='none')? "http://espassets.izmocars.com/inventory/bmw/images/Open_off.png" : "http://espassets.izmocars.com/inventory/bmw/images/Close_off.png";
  }
}

function setState(cookieInfo){
	/*Provide All Collapsable Ids  */
	var ecblockids=new Array("ecblock1","ecblock2","ecblock3","ecblock4","ecblock5","ecblock6","ecblock7","ecblock8");  
	for(k=0;k<ecblockids.length;k++){
		toggleelement=document.getElementById(ecblockids[k]);
		if (toggleelement != null) {
			setDisplay(toggleelement, GetCookie(toggleelement.id + cookieInfo));
		}
	}
}