

var e;
var fs;

var e;
function p(name, w, h)
{
	e = window.open(name, 'popup', 'scrollbars=yes,width=' + w + ',height=' + h);
	if (window.focus) { e.focus(); }
	return false;
}


function pi(img, w, h)
{
	e = window.open('', 'pic', 'scrollbars=no,width=' + w + ',height=' + h);
	if (window.focus) { e.focus(); }

	e.document.open();
	e.document.write('<html><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
	e.document.write('<img id="img" src=' + img + ' width=' + w + ' height=' + h + '><br>');
	e.document.close('</body></html>');

        e.window.resizeTo(100,100);
        e.window.resizeTo(100-(e.document.body.clientWidth-e.document.getElementById("img").width), 100-(e.document.body.clientHeight-e.document.getElementById("img").height));
	return false;

}


function on_select(obj)
{
	if (obj.selectedIndex > 0) 
	{
		window.location.href = obj.options[obj.selectedIndex].value; 
	}
}


function vote (id)
{
  var w = 400;
  var h = 400;
  var posX = (screen.width - w) / 2;
  var posY = (screen.height - h) / 2;
  var vcookie = document.cookie.split('; ');

  if (id) {
    var pid = id.split('|');
    for (var i = 0; i < pid.length; i++) {
      var found = 0;
      for (var j = 0; j < vcookie.length; j++) {
        var value = vcookie[j].split('=');
        if (value[0] == 'APOLL' + pid[i]) {
          found = 1;
        }
      }
      if (!found) {
        var v = window.open('/poll/' + pid[i] + '/', 'poll' + i, 'scrollbars=yes,width=' + w + ',height=' + h + ',top=' + posY + ',left=' + posX);
        if (window.focus) { v.focus(); }
      }
    }
  } else {
    var found = 0;
    for (var i = 0; i < vcookie.length; i++) {
      var value = vcookie[i].split('=');
      if (value[0] == 'POLL') {
        found = 1;
      }
    }
    if (!found) {
      var v = window.open('/poll/', 'poll', 'scrollbars=yes,width=' + w + ',height=' + h + ',top=' + posY + ',left=' + posX);
      if (window.focus) { v.focus(); }
    }
  }

}

function FontSizer (minsize, maxsize, defsize) {
	this.minsize = minsize || 12;
	this.maxsize = maxsize || 32;
	this.defsize = defsize || 16;

	this.init = function () {
		if (document.getElementById && document.getElementsByTagName) {
			var sizer = document.getElementById('sizer');
			if (sizer) {
				sizer.style.display="block";
				this.cursize = getCookie("fontSize");
				this.cursize = !isNaN(parseFloat(this.cursize)) ? parseFloat(this.cursize) : this.defsize;
				if (this.cursize > this.maxsize)
					this.cursize = this.maxsize;
				if (this.cursize < this.minsize)
					this.cursize = this.minsize;
				var el = document.getElementsByTagName("div");
				for(i=0;el[i];i++) {
					if (el[i].className == "inner") {
						el[i].style.fontSize= this.cursize + "px";
						this.el = el[i];
					}
				}
			}
		}
	}

	this.adjust = function (n) {
		if (this.cursize && this.el) {
			this.cursize += n;
			if (this.cursize > this.maxsize)
				this.cursize = this.maxsize;
			if (this.cursize < this.minsize)
				this.cursize = this.minsize;
			this.el.style.fontSize= this.cursize + "px";
			setCookie("fontSize",this.cursize,180,"/");
		}
	}

}

/*********************************************************************************
  dw_cookies.js - cookie functions for www.dyn-web.com
  Recycled from various sources 
**********************************************************************************/

// Modified from Bill Dortch's Cookie Functions (hidaho.com) 
// (found in JavaScript Bible)
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

// Modified from Jesse Chisholm or Scott Andrew Lepera ?
// (found at both www.dansteinman.com/dynapi/ and www.scottandrew.com/junkyard/js/)
function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

// from Bill Dortch's Cookie Functions (hidaho.com) 
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


var lat=new Array("jo","zh","i'","ch","sh","xh","je","ju","ja","a","b","v","g","d","e","z","i","k","l","m","n","o","p","r","s","t","u","f","x","c","'","y","`","j","h");
var cyr=new Array("ё","ж","й","ч","ш","щ","э","ю","я","а","б","в","г","д","е","з","и","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ы","ъ","ж","х");

var latcap=new Array("JO","Jo","ZH","Zh","I'","Ch","CH","Sh","SH","Xh","XH","Je","JE","Ju","JU","Ja","JA","A","B","V","G","D","E","Z","I","K","L","M","N","O","P","R","S","T","U","F","X","C","Y","J","H");
var cyrcap=new Array("Ё","Ё","Ж","Ж","Й","Ч","Ч","Ш","Ш","Щ","Щ","Э","Э","Ю","Ю","Я","Я","А","Б","В","Г","Д","Е","З","И","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ы","Ж","Х");


function translate(text)
{
  var i;
  for (i=0;i<latcap.length;i++)
  {
    text = replace(text, latcap[i], cyrcap[i], 1, 0);
  }

  for (i=0;i<lat.length;i++)
  {
    text = replace(text, lat[i], cyr[i], 1, 0);
  }

  return text;
}

function replace(target,oldTerm,newTerm,caseSens,wordOnly) {

  var work = target;
  var ind = 0;
  var next = 0;

  if (!caseSens) {
    oldTerm = oldTerm.toLowerCase();
    work = target.toLowerCase();
  }

  while ((ind = work.indexOf(oldTerm,next)) >= 0) {
    if (wordOnly) {
      var before = ind - 1;
      var after = ind + oldTerm.length; 
      if (!(space(work.charAt(before)) && space(work.charAt(after)))) {
        next = ind + oldTerm.length; 
        continue;
      }
    }
    target = target.substring(0,ind) + newTerm + 
    target.substring(ind+oldTerm.length,target.length); 
    work = work.substring(0,ind) + newTerm + 
    work.substring(ind+oldTerm.length,work.length); 
    next = ind + newTerm.length;
    if (next >= work.length) { break; } 
  }

  return target;

}


function gphoto(src, name, text)
{
	document.getElementById("gphoto").src = src;
	document.getElementById("gname").innerHTML = name;
	document.getElementById("gdetail").innerHTML = text;

	return false;
}


function ismax (text) {
	if (text.value.length > 2000) {
//		alert("Ваше сообщение превысило максимально допустимый размер в 2000 символов!");
		text.value = text.value.substring(0, 2000);
	} 
	
}

function blinkIt() {
 
 
   for(i=0;i<document.getElementsByTagName('BLINK').length;i++){
      	s=document.getElementsByTagName('BLINK')[i];
	s.parentNode.style.color = '#a10000';
      	s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
	   }

}
