/* ----------------------------  usefull function --------------------------------------- */

// replace $ and fix bug in old IE
var $ = function (id, doc) {if((id)&&((typeof id == "string")||(id instanceof String) ) ){if (!doc) { doc = document; }var ele = doc.getElementById(id);if (ele && (ele.id != id) && doc.all) {ele = null;eles = doc.all[id];if (eles) {if (eles.length) {for (var i=0; i < eles.length; i++) {if (eles[i].id == id) {ele = eles[i];break;}}}else { ele = eles; }}}return ele;}return id;}
var $gid = function (id, doc) {if((id)&&((typeof id == "string")||(id instanceof String) ) ){if (!doc) { doc = document; }var ele = doc.getElementById(id);if (ele && (ele.id != id) && doc.all) {ele = null;eles = doc.all[id];if (eles) {if (eles.length) {for (var i=0; i < eles.length; i++) {if (eles[i].id == id) {ele = eles[i];break;}}}else { ele = eles; }}}return ele;}return id;}

function tms() {return new Date().getTime().toString();} // funtion return today date in second
function $import(src, type, media){
	if (empty(src) || empty(type)) return;  // if empty go away
	switch (type) {
		case "js" : // import some javascript
			var imprt = document.createElement('script');
			imprt.setAttribute('type','text/javascript');
			imprt.setAttribute('src',src + '?' + tms()); // Get rid of the caching
		break;
		case "css" : // import css
			var imprt = document.createElement('link');
			imprt.setAttribute("rel", "stylesheet")
			imprt.setAttribute("type", "text/css");
			imprt.setAttribute("media", empty(media) ? "all" : media);
			imprt.setAttribute("href", src + '?' + tms()); // Get rid of the caching
		break;
		case "style" :  // import some style in head
			var imprt = document.createElement('style');
			imprt.setAttribute("type", "text/css");
			if (imprt.styleSheet) imprt.styleSheet.cssText = src; //IE
			else imprt.appendChild(document.createTextNode(src)); // Others
		break;
  	default: return;
  }
  document.getElementsByTagName('head')[0].appendChild(imprt); // mount import stuff to head
  return false; // disable link href-action
}

function print_object(obj) {
	var str = "<pre>";
	for(prop in obj){
		str+=prop + " = '"+ obj[prop]+"'\n";
	}
	str+="</pre>";
	document.write(str);
}

function clone(o) {
	if(!o || "object" !== typeof o)  {
		return o;
	}
	varc = "function" === typeof o.pop ? [] : {};
	var p, v;
	for(p in o) {
		if(o.hasOwnProperty(p)) {
			v = o[p];
			if(v && "object" === typeof v) {
				c[p] = clone(v);
			}
		else c[p] = v;
		}
	}
	return c;
}

function addLoadEvent(func) {var oldonload = window.onload; if (typeof window.onload != 'function') {window.onload = func;} else {window.onload = function(){if (oldonload){oldonload();}func();}}}
function empty( mixed_var ) { if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || mixed_var === undefined) return true; if (typeof mixed_var == 'object') {var key; for (key in mixed_var) {return false;} return true;}  return false;}
function ap(obj) {var x = y = 0;	while(obj) {x += obj.offsetLeft;y += obj.offsetTop;	obj = obj.offsetParent;}return {x:x, y:y};}
function shd (idname,inline){$(idname).style.display = $(idname).style.display === "none" ? (inline ? "inline" : "block") : "none";}

function vpWidth() {return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;}
function vpHeight() {return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;}
function getBodyScrollTop() { return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);}
function getBodyScrollLeft(){  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);}
function getDocumentHeight(){return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;}
function getDocumentWidth(){return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;}

function toInt(x){return (parseInt(x) + 0)}

function cxyns (name, nv, xp, yp) {
	if (nv == null) nv = 'nv';
	if (xp == null) xp = 0;
	if (yp == null) yp = 25;
	var coords = ap($(nv));
	$(name).style.left = (coords.x + xp) + "px";
	$(name).style.top = (coords.y + yp) + "px";
	$(name).style.display = "block";
}

function getAllTagsInTag (tagid, tagname, aTags, j) {
	var tagaelm = $(tagid).getElementsByTagName('*');
	var aTags = aTags == null ? Object() : aTags;
	var j = j == null ? 0 : j;
	for(var i=0; i < tagaelm.length; i++) {
		if (tagaelm[i].nodeName == tagname.toUpperCase()) {
			aTags[j] = tagaelm[i];
			j++;
			//print_object(tagaelm[i]);
		}
		var inner = tagaelm[i].getElementsByTagName('*');
		if (inner.length > 0) {
			aTags = getAllTagsInTag(tagaelm[i], tagname, aTags, j);
		}
	}
	return aTags;
}

function makeBigImgSmaller (tagid, size) {
	var imgs = getAllTagsInTag(tagid, "img");
	for(prop in imgs){
		if (imgs[prop].width > size)
			imgs[prop].width = size;
	}
}

/* ----------------------------  xml --------------------------------------- */

function loadXMLDoc(dname) {
	var xmlHttpRequest;
	if (window.ActiveXObject) {
		var a_objects = [
							'MSXML2.XMLHTTP.6.0',
							'MSXML2.XMLHTTP.5.0',
							'MSXML2.XMLHTTP.4.0',
							'MSXML2.XMLHTTP.3.0',
							'MSXML2.XMLHTTP',
							'Microsoft.XMLHTTP'
						];
		for (var i = 0, length = a_objects.length; i < length; ++i) {
			try {
				xmlHttpRequest = new ActiveXObject(a_objects[i]);
				break;
			} catch(e) {}
		}
	}
	if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlHttpRequest = new XMLHttpRequest();
			if (xmlHttpRequest.overrideMimeType) {
				xmlHttpRequest.overrideMimeType('text/xml');
			}
		} catch (exception) {
			xmlHttpRequest = false;
		}
	}
	if (xmlHttpRequest) {
		xmlHttpRequest.open('GET', dname, false);
		xmlHttpRequest.send(null);
		if (xmlHttpRequest.readyState == 4) {
			if(xmlHttpRequest.status == 200 && xmlHttpRequest.responseXML != null) {
				return xmlHttpRequest.responseXML;
			}
		}
	}
	return false;
}

function loadJson(dname) {
	var xmlHttpRequest;
	if (window.ActiveXObject) {
		var a_objects = [
							'MSXML2.XMLHTTP.6.0',
							'MSXML2.XMLHTTP.5.0',
							'MSXML2.XMLHTTP.4.0',
							'MSXML2.XMLHTTP.3.0',
							'MSXML2.XMLHTTP',
							'Microsoft.XMLHTTP'
						];
		for (var i = 0, length = a_objects.length; i < length; ++i) {
			try {
				xmlHttpRequest = new ActiveXObject(a_objects[i]);
				break;
			} catch(e) {}
		}
	}
	if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlHttpRequest = new XMLHttpRequest();
			if (xmlHttpRequest.overrideMimeType) {
				xmlHttpRequest.overrideMimeType('text/xml');
			}
		} catch (exception) {
			xmlHttpRequest = false;
		}
	}
	if (xmlHttpRequest) {
		xmlHttpRequest.open('GET', dname, false);
		xmlHttpRequest.send(null);
		if (xmlHttpRequest.readyState == 4) {
			if(xmlHttpRequest.status == 200 && xmlHttpRequest.responseText != null) {
				var out = xmlHttpRequest.responseText;
				return eval('(' + out + ')');
			}
		}
	}
	return false;
}

function getElementTextNS(local, parentElem, index) {
    var result = "";
    result = parentElem.getElementsByTagName(local)[index];

    if (result) {
        if (result.childNodes.length > 1) return result.childNodes[1].nodeValue;
        else return result.firstChild.nodeValue;
    } else return "n/a";
}


/* ----------------------------  login --------------------------------------- */

function displayLoginForm() {
	checkSelect('hidden');
	var obj = $('login_form');
	obj.style.display = 'block';

	var obj_back = $('login_form_back');
	obj_back.style.display = 'block';

//  alert(document.body.clientHeight+' '+self.pageYOffset+' '+window.innerHeight+' '+document.documentElement.clientHeight+' '+document.body.scrollHeight+' '+document.height);
	var arr = document.getElementsByTagName('table');
//	alert(arr[0].offsetHeight);
//	document.body.style.overflow = 'hidden';
	if (navigator.appName=='Netscape') obj_back.style.height=arr[0].offsetHeight+'px';
	if (navigator.appName=='Opera') obj_back.style.height = document.body.scrollHeight;
	if (navigator.appName.indexOf('Microsoft')!=-1)	obj_back.style.height = arr[0].offsetHeight;
	if ($('js_login')) $('js_login').focus();
	if ($('js_login_')) $('js_login_').focus();

	return false;
}


function hideLoginForm() {
	checkSelect('visible');
	var obj = $('login_form');
	if (obj) {
		obj.style.display = 'none';
	}

	var obj_back = $('login_form_back');
	if (obj_back) {
		obj_back.style.display = 'none';
	}
	return false;
}

function checkSelect(visibility) {
	if (navigator.appName.indexOf('Microsoft')!=-1) {
		if (visibility=='hidden') num = 1;
		else num = 0;
		var arrSel = document.getElementsByTagName('select');
		for(i=0;i<arrSel.length-num;i++)
			arrSel[i].style.visibility=visibility;
	}
}

function displayLoginFormPhotoContest(){
	$('login_main_form').action = 'http://passport.tut.ua/login/photo_contest/';
	displayLoginForm();
	return false;
}
function displayLoginFormPhoto(){
	$('login_main_form').action = 'http://passport.tut.ua/login/photo_upload/';
	displayLoginForm();
	return false;
}

function displayLoginFormBlog() {
	$('login_main_form').action = 'http://passport.tut.ua/login/note_add/';
	displayLoginForm();
	return false;
}

function displayLoginFormTv() {
	$('login_main_form').action = 'http://passport.tut.ua/login/tv_my/';
	displayLoginForm();
	return false;
}

function displayLoginFormFun()
{
	$('login_main_form').action = 'http://passport.tut.ua/login/fun_add/';
	displayLoginForm();
	return false;
}
/* ----------------------------  ctrl --------------------------------------- */

document.onkeydown = pageJump;
var prev = '';
var next = '';
var activeWeather = '';

function pageJump(e)
{
	if (!e) e = window.event;
	var k = e.keyCode;
	if (e.ctrlKey) {
		if (k == 37 && prev!='') window.location.href = prev;
		if (k == 39 && next!='') window.location.href = next;
	}

	if (e.keyCode == 27) hideLoginForm();
	if (typeof hideBasketForm =='function') {
		if (e.keyCode == 27) {
			hideBasketForm();
			
		}
	}

	if (activeWeather == 1) {
		if (e.keyCode == 38) {
			if (activeWeatherItem>0) setActiveWeatherHelp(activeWeatherItem-1)
			else setActiveWeatherHelp(0);
		}
		if (e.keyCode == 40){
			if (activeWeatherItem<weatherLast-1) setActiveWeatherHelp(activeWeatherItem+1);
			else setActiveWeatherHelp(weatherLast-1);
		}

		if (e.keyCode == 13) setWeatherQuery();
	}
}

/* ----------------------------  base64 --------------------------------------- */

var azWin = '     Ё               ё       АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя'
var azKoi = 'ё                Ё           юабцдефгхийклмнопярстужвьызшэщчъЮАБЦДЕФГХИЙКЛМНОПЯРСТУЖВЬЫЗШЭЩЧЪ'
var AZ=azWin
var azURL = '0123456789ABCDEF'
var b64s  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
var b64a  = b64s.split('')
function enBASE64(str) {
  var a=Array(), i
  for( i=0; i<str.length; i++ ){
    var cch=str.charCodeAt(i)
    if( cch>127 ){  cch=AZ.indexOf(str.charAt(i))+163; if(cch<163) continue; }
    a.push(cch)
  };
  var s=Array(), lPos = a.length - a.length % 3
  for(i=0;i<lPos;i+=3){
    var t=(a[i]<<16)+(a[i+1]<<8)+a[i+2]
    s.push( b64a[(t>>18)&0x3f]+b64a[(t>>12)&0x3f]+b64a[(t>>6)&0x3f]+b64a[t&0x3f] )
  }
  switch ( a.length-lPos ) {
    case 1 : var t=a[lPos]<<4; s.push(b64a[(t>>6)&0x3f]+b64a[t&0x3f]+'=='); break
    case 2 : var t=(a[lPos]<<10)+(a[lPos+1]<<2); s.push(b64a[(t>>12)&0x3f]+b64a[(t>>6)&0x3f]+b64a[t&0x3f]+'='); break
  }
  return s.join('')
}
function deBASE64(str) {
  while(str.substr(-1,1)=='=')str=str.substr(0,str.length-1);
  var b=str.split(''), i
  var s=Array(), t
  var lPos = b.length - b.length % 4
  for(i=0;i<lPos;i+=4){
    t=(b64s.indexOf(b[i])<<18)+(b64s.indexOf(b[i+1])<<12)+(b64s.indexOf(b[i+2])<<6)+b64s.indexOf(b[i+3])
    s.push( ((t>>16)&0xff), ((t>>8)&0xff), (t&0xff) )
  }
  if( (b.length-lPos) == 2 ){ t=(b64s.indexOf(b[lPos])<<18)+(b64s.indexOf(b[lPos+1])<<12); s.push( ((t>>16)&0xff)); }
  if( (b.length-lPos) == 3 ){ t=(b64s.indexOf(b[lPos])<<18)+(b64s.indexOf(b[lPos+1])<<12)+(b64s.indexOf(b[lPos+2])<<6); s.push( ((t>>16)&0xff), ((t>>8)&0xff) ); }
  for( i=s.length-1; i>=0; i-- ){
    if( s[i]>=168 ) s[i]=AZ.charAt(s[i]-163)
    else s[i]=String.fromCharCode(s[i])
  };
  return s.join('')
}


/* ----------------------------  switcher --------------------------------------- */

var lastidG = new Array ('1','1','1','1');
var oName = new Array ('Категории вакансий','Категории резюме');
var kName = new Array ('Я тут','Афиша today','Мой гороскоп');
var cName = new Array ('События','Места','Новости');


function selectArrNum (serial)
{
    var aNum = 0;
	if (serial == 'k') aNum = 1;
	if (serial == 'c') aNum = 1;
	return aNum;
}


function setBookmarkGlobal (id)
{
//получаем данные о букмарке и номере закладки
	var s = new String(id);
	ser = s.substring(0,1);
	num = parseInt(s.substring(1,2));
	var ArrNum = selectArrNum(ser);
	if (num != lastidG[ArrNum]){
	//возвращаем прошлую выделенную страницу к обычному виду
		if (ser=='o'){
		     $(ser+lastidG[ArrNum]).innerHTML = '<br style="line-height: 3px;"><a href="javascript:void(0)">'+oName[lastidG[ArrNum]-1]+'</a>';
		     if (lastidG[ArrNum]==2)
		       $(ser+lastidG[ArrNum]).className = 'bm_base_4_news bm_last_3';
		     else $(ser+lastidG[ArrNum]).className = 'bm_base_4_news bm_main_3';

		     if (lastidG[ArrNum]!=1) $(ser+(lastidG[ArrNum]-1)).className = 'bm_base_3 bm_main_3';

		     //выделяем указанную страницу

		     $(id).innerHTML = '<br style="line-height: 3px;"><span class="red_h2">'+oName[num-1]+'</span></div>';
		     if (num == 1){
		        $(id).className = 'bm_base_4_news bm_s_3 bm_first_3';
		        SetV();
		     }
		     else{
		     	$(id).className = 'bm_base_4_news bm_s_3';
		        $(ser+(num-1)).className = 'bm_base_4_news bm_sosed_3';
		        SetR();
		     }

		}

		if (ser=='k'){
			hideAllBlock();
			switch(num){
				case 1:$('mail_data').style.display='block'; setCookie('login', 'mail'); break;
				case 2:$('afisha_data').style.display='block'; setCookie('login', 'weather'); break;
				case 3:$('else_data').style.display='block'; setCookie('login', 'horo'); break;
			}

		     $(ser+lastidG[ArrNum]).innerHTML = '<a href="javascript:void(0)">'+kName[lastidG[ArrNum]-1]+'</a>';
		     if (lastidG[ArrNum]==3)
		       $(ser+lastidG[ArrNum]).className = 'bm_base_4_news bm_last_3';
		     else $(ser+lastidG[ArrNum]).className = 'bm_base_4_news bm_main_3';

		     if (lastidG[ArrNum]!=1) $(ser+(lastidG[ArrNum]-1)).className = 'bm_base_4_news bm_main_3';

		     //выделяем указанную страницу

		     $(id).innerHTML = '<span class="red_h2">'+kName[num-1]+'</span>';
		     if (num == 1) $(id).className = 'bm_base_4_news bm_s_3 bm_first_3';
		     else {
		     	$(id).className = 'bm_base_4_news bm_s_3';
		        $(ser+(num-1)).className = 'bm_base_4_news bm_sosed_3';
		     }
		}


		if (ser=='c'){

			hideAllCommentBlock();
			switch(num)	{
				case 1:$('c1_').style.display='block'; setCookie('login', 'c1_'); break;
				case 2:$('c2_').style.display='block'; setCookie('login', 'c2_'); break;
				case 3:$('c3_').style.display='block'; setCookie('login', 'c3_'); break;
			}

			 $(ser+lastidG[ArrNum]).innerHTML = cName[lastidG[ArrNum]-1];
		     if (lastidG[ArrNum]==3) $(ser+lastidG[ArrNum]).className = 'bm_base_4_news bm_last_3 bold_pt5';
		     else $(ser+lastidG[ArrNum]).className = 'bm_base_4_news bm_main_3 bold_pt5';

		     if (lastidG[ArrNum]!=1) $(ser+(lastidG[ArrNum]-1)).className = 'bm_base_3 bm_main_3 bold_pt5';

		     //выделяем указанную страницу

		     $(id).innerHTML = cName[num-1];
		     if (num == 1) $(id).className = 'bm_base_4_news bm_s_3 red_h2 bm_first_3';
		     else {
		     	$(id).className = 'bm_base_4_news bm_s_3 red_h2';
		        $(ser+(num-1)).className = 'bm_base_4_news bm_sosed_3 bold_pt5';
		     }
		}

	lastidG[ArrNum]=num;   //записываем текущую активную страницу как последнюю активную
	return false;
 }

function hideAllBlock(){
	$('mail_data').style.display='none';
	$('afisha_data').style.display='none';
	$('else_data').style.display='none';
}

function hideAllCommentBlock(){
	$('c1_').style.display='none';
	$('c2_').style.display='none';
	$('c3_').style.display='none';
}

}


/* ----------------------------  comments  --------------------------------------- */


function commentsFormEnable(){
	$('comments_form_controller').style.display 	= 'none';
	$('comments_form_executor').style.display 	= 'block';
}

function commentsFormDisable(){
	$('comments_form_controller').style.display 	= 'block';
	$('comments_form_executor').style.display 	= 'none';
}

function commentsPostAnswer(parent_id){
	commentsFormEnable();
	$('comments_parent').value = parent_id;
	$('comments_title_textarea').innerHTML = 'Ответ на комментарий';
}

function commentsAddSmile(smile){
	c_target = $('comments_form_content');
	c_target.value = c_target.value + ' '+smile+' ';
}

function commentsShowAllSmiles(domain)
{
	var smiles = Array();
	var smiles = [
	'smile','mouth','heart','pity','bomb','mail','kiss','sos','smoke','wall',
	'rest','rofl','comp','devil','fight','build','flower','beer','boyan','wink',
	'air','baboon','bannana','drink','glass','hey','hockey','headball','numberone','hug',
	'hunter','idiot','isterichka','joker','magic','music','party','pink','pirate','tongue',
	'toy','plusone','minusone','bra','bruise','bue','ftopku','ua','eu','ru',
	'ussr','pixel','pumka','kote','kotesol','up4kman'];

	var codes = Array();
	var codes = [
	':)',':D',':heart:',':(',':bomb:',':mail:',':kiss:',':sos:',':smoke:',':wall:',
	':rest:',':rofl:',':comp:',':devil:',':fight:',':build:',':flower:',':beer:',':boyan:',':wink:',
	':air:',':baboon:',':bannana:',':drink:',':glass:',':hey:',':hockey:',':headball:',':numberone:',':hug:',
	':hunter:',':idiot:',':isterichka:',':joker:',':magic:',':music:',':party:',':pink:',':pirate:',':tongue:',
	':toy:',':plusone:',':minusone:',':bra:',':bruise:',':bue:',':ftopku:',':ua:',':eu:',':ru:',
	':ussr:',':pixel:',':pumka:',':kote:',':kotesol:',':up4kman:'];

	var html = '';

	for (var i=0; i<codes.length;i++) {
		html = html + '<a href="javascript:commentsAddSmile(\''+codes[i]+'\');"><img src="http://lib.'+domain+'/img/smiles/'+smiles[i]+'.gif" border="0"></a>\n';
	}

	c_target = $('comments_smiles');
	c_target.innerHTML = html;
}

/* ----------------------------  cookie --------------------------------------- */

function setCookie(name, value){
		var domain = '.tut.ua';
		var path = '/';
		var exdate = new Date(); exdate.setDate(exdate.getDate()+14);
		var expires = exdate.toGMTString();
        var curCookie = name + "=" + escape(value)
                + ((expires) ? "; expires=" + expires : "")
                + ((path) ? "; path=" + path : "")
				+ ((domain) ? "; domain =" + domain : "")

        if ((name + "=" + escape(value)).length <= 4000) document.cookie = curCookie
        else if (confirm("Cookie превышает 4KB и будет вырезан !")) document.cookie = curCookie
}

// name - имя считываемого cookie

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) end = cookie.length;
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function setCookieByDeer(c_name,value){
	var expiredays = 14;
	var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookieByDeer(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

/* ------------------------------------- redirect count----------------------------------*/
function goTo(link, type) {
    var script = document.createElement('script');
    script.src = 'http://www.tut.ua/go/?t='+type+'&r=0&l='+link;
    document.body.appendChild(script);
    return true;
}
/* ------------------------------------- redirect count----------------------------------*/
// <-- AJAX ---------------------------------------- <--
function ajaxLib()
{
	this.req = null;
	this.READY_STATE_COMPLETE = 4;

	function initRequest()
	{
		var xRequest = null;

		if (window.XMLHttpRequest) {
			xRequest = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			var a_objects = [
							'MSXML2.XMLHTTP.6.0',
							'MSXML2.XMLHTTP.5.0',
							'MSXML2.XMLHTTP.4.0',
							'MSXML2.XMLHTTP.3.0',
							'MSXML2.XMLHTTP',
							'Microsoft.XMLHTTP'
							];
			for (var i = 0, length = a_objects.length; i < length; ++i) {
				try
				{ 
					xRequest = new ActiveXObject(a_objects[i]); break;
				}
				catch(e) {}
			}
		}
		return xRequest;
	}

	this.sendRequest = function(url, onReadyState, params, httpMethod)
	{
		var method = "GET";
		if (httpMethod == "POST") {
			method = "POST";
		} else if(httpMethod == "GET") {
			method = "GET";
		}
		this.req = initRequest();
		if (this.req) {
			this.req.onreadystatechange = eval(onReadyState);
			this.req.open(method,url,true);
			if (method == "POST") {
				this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				this.req.setRequestHeader("Content-length", params.length);
			} else {
				this.req.setRequestHeader("Content-Type","text/xml");
			}
			this.req.send(params);
		}
	}
}
var request = new ajaxLib();
// --> AJAX ---------------------------------------- -->


function CDTimer(container, targetdate, targetstring, targetmessage) {
	if (!document.getElementById || !document.getElementById(container)) return;
	this.container=document.getElementById(container);
	this.currentTime=new Date();
	this.targetdate=new Date(targetdate);
	this.targetstring=targetstring;
	this.targetmessage=targetmessage;
	this.timesup=false;
	this.updateTime();
}

CDTimer.prototype.updateTime=function(){
	var thisobj=this;
	this.currentTime.setSeconds(this.currentTime.getSeconds()+1);
	setTimeout(function(){thisobj.updateTime()}, 1000);
}

CDTimer.prototype.displaytimer=function(baseunit){
	this.baseunit=baseunit;
	this.showresults();
}

CDTimer.prototype.showresults=function(){
	var thisobj=this;
	var timediff=(this.targetdate-this.currentTime)/1000;
	if (timediff<=0){
		this.timesup=true;
		this.container.innerHTML=this.formattimer();
		return;
	}

	var oneMinute=60;
	var oneHour=60*60;
	var oneDay=60*60*24;
	var dayfield=Math.floor(timediff/oneDay);
	var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour);
	var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
	var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute));
	if (this.baseunit=="hours"){
		hourfield=dayfield*24+hourfield;
		dayfield=0;
	}else if (this.baseunit=="minutes"){
		minutefield=dayfield*24*60+hourfield*60+minutefield;
		dayfield=hourfield=0;
	}else if (this.baseunit=="seconds"){
		var secondfield=timediff;
		dayfield=hourfield=minutefield=0;
	}
	this.container.innerHTML=this.formattimer(dayfield, hourfield, minutefield, secondfield);
	setTimeout(function(){thisobj.showresults()}, 1000);
}

CDTimer.prototype.formattimer=function(){
	if (this.timesup==false) {
		var day = this.declofnum(arguments[0], new Array('день','дня','дней'));
		var hour = this.declofnum(arguments[1], new Array('час','часа','часов'));
		var minute = this.declofnum(arguments[2], new Array('минуту','минуты','минут'));
		var second = this.declofnum(arguments[3], new Array('секунда','секунды','секунд'));

		var displaystring = this.targetstring+" <span class='cdtimer'>";
		if (arguments[0] != 0) {
			displaystring += " "+arguments[0]+" <sup>"+day+"</sup>";
		}
		if (arguments[1] != 0) {
			displaystring += " "+arguments[1]+" <sup>"+hour+"</sup>";
		}
		if (arguments[2] != 0) {
			displaystring += " "+arguments[2]+" <sup>"+minute+"</sup>";
		}
		displaystring += " "+arguments[3]+" <sup>"+second+"</sup></span>";
	} else {
		var displaystring = "<span class='cdtimer'>"+this.targetmessage+"</span>";
	}
	return displaystring;
}

CDTimer.prototype.declofnum=function(number, titles) {
	number	= parseInt(number);
	var cases = new Array(2, 0, 1, 1, 1, 2);
	return titles[(number%100>4 && number%100<20)? 2 : cases[Math.min(number%10, 5)]];
}

function isType(val, type)
{
	if (val == '') {
		return true;
	} else if (window.RegExp) {
		var query = '';
		switch (type) {
			case "date"	:		query = "^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$"; break;
			case "email":		query = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-\.])+\.)+([a-zA-Z0-9]{2,4})+$"; break;
			case "short_time":	query = "^[0-9]{1,2}:[0-9]{2}$"; break;
			case "time":		query = "^[0-9]{1,2}:[0-9]{2}:[0-9]{2}$"; break;
			case "rate":		query = "^[0-9]{1,2}/\./[0-9]|[0-9]{1,2}$"; break;
			case "translit":	query = "^[a-zA-Z0-9-_]+$"; break;
			default:			query = ".*";
		}
		var r = new RegExp(query);
		if (r.test(val)) {
			return true;
		} else {
			return false;
		}
	}
	return true;
}

function getFrameWindow(frameId)
{
	var frame	= document.getElementById(frameId);
	var result	= null;
	if (frame.contentDocument) {
		result = frame.contentDocument.window || frame.contentDocument.defaultView; 
	} else if (frame.contentWindow) {
		result = frame.contentWindow;
	} else if (frame.document) {
		result = frame.document.window;
	}
	return result;
}

function showBelka(x, y, hide)
{
	x = parseInt(x);
	y = parseInt(y);
	hide = parseInt(hide);
//	var objFs = document.getElementById('premiumFrame');
//	var objF = getFrameWindow('premiumFrame').document;
	var objE = document.getElementById('KBe') ? document.getElementById('KBe') : document.getElementById('KBo');
	var objC = document.getElementById('KBc');
	if (objE && objC) {
		if ((parseInt(objC.style.height) != y || parseInt(objC.style.width) != x) && hide != 1) {
			objC.style.position = 'absolute';
			objC.style.right = '20px';
			objC.style.zindex = '3000';
		}
		if (parseInt(objC.style.width) != x) {
			objC.style.width = x+'px';
//			objFs.style.width = x+'px';
			objE.style.width = x+'px';
		}
		if (parseInt(objC.style.height) != y) {
			objC.style.height = y+'px';
//			objFs.style.height = y+'px';
			objE.style.height = y+'px';
		}
		if (hide == 1) {
			objC.style.position = 'relative';
			objC.style.right	= '0px';
		}
	}
}

function showPremium(x, y, hide)
{
	x = parseInt(x);
	y = parseInt(y);
	hide = parseInt(hide);
	var objE	= document.getElementById('KBe') ? document.getElementById('KBe') : document.getElementById('KBo');
	var objC	= document.getElementById('KBc');
	var pC		= document.getElementById('premium_center');
	
	if (objE && objC) {
		if ((parseInt(objC.style.height) != y || parseInt(objC.style.width) != x) && hide != 1) {
			pC.style.display = 'block';
			pC.style.width = '380px';
			pC.style.height = '200px';

			objC.style.position = 'absolute';
			objC.style.right = '2px';
			objC.style.top = '-132px';
			objC.style.zindex = '3000';
		}
		if (hide == 1) {
			objE.setAttribute('flashvars', objE.getAttribute('flashvars')+'&kostil=1');
		} else {
			var k = objE.getAttribute('flashvars');
			if (k) {
				var kk = '';
				var k = k.split('&');
				for(var i = 0; i < k.length; i++) {
					if (k[i].indexOf('kostil') == -1) {
						kk = kk + k[i] + '&';
					}
				}
			}
			objE.setAttribute('flashvars', kk);
		}
		if (parseInt(objC.style.width) != x) {
			objC.style.width = x+'px';
			objE.style.width = x+'px';
		}
		if (parseInt(objC.style.height) != y) {
			objC.style.height = y+'px';
			objE.style.height = y+'px';
		}
		if (hide == 1) {
			objC.style.position = 'relative';
			objC.style.right	= '0px';
			objC.style.top		= '0px';
		}
	}
}