function getCookie(name) {
  var cookies = document.cookie.split(';');
	for(var i=0,l=cookies.length; i<l; i++) {
	  var c = cookies[i].split('=');
    if (c[0].trim() == name) {
      return c[1].trim();
    }
	}
	return null;
}

function setCookie(name,value,days) {
	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 initWaitwin() {
  wait = new TModalWin('waitmsg');
  wait.opacity = 0.65;
  wait.body.innerHTML = TDOM.getElement('waittext').innerHTML;
}

function galleryNext(btn_next) {
  var gal = btn_next.parentNode;
  var body = TDOM.nextElement(btn_next);
  var btn_prev = TDOM.nextElement(btn_next);
  while (body && !TClasses.has(body,'body')) {
    body = TDOM.nextElement(body);
  }
  if (!body) { return; }
  var res = TDOM.firstChild(TDOM.firstChild(body));
  var index = parseInt(gal['GALLERY_CURRENT_INDEX']), count = 0;
  index = isNaN(index) ? 1 : index+1;
  while (res) {
    res.style.display = count == index ? 'block' : 'none';
    res = TDOM.nextElement(res);
    count++;
  }
  btn_next.style.display = index < count-1 ? 'block' : 'none';
  btn_prev.style.display = index > 0 ? 'block' : 'none';
  gal['GALLERY_CURRENT_INDEX'] = index;
}

function galleryPrev(btn_prev) {
  var gal = btn_prev.parentNode;
  var body = TDOM.nextElement(btn_prev);
  var btn_next = TDOM.previousElement(btn_prev);
  while (body && !TClasses.has(body,'body')) {
    body = TDOM.nextElement(body);
  }
  if (!body) { return; }
  var res = TDOM.firstChild(TDOM.firstChild(body));
  var index = parseInt(gal['GALLERY_CURRENT_INDEX']), count = 0;
  index = isNaN(index) ? 0 : index-1;
  while (res) {
    res.style.display = count == index ? 'block' : 'none';
    res = TDOM.nextElement(res);
    count++;
  }
  btn_next.style.display = index < count-1 ? 'block' : 'none';
  btn_prev.style.display = index > 0 ? 'block' : 'none';
  gal['GALLERY_CURRENT_INDEX'] = index;
}
