var d = document;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isNs = (navigator.appName.indexOf("Netscape") != -1);

function getElementsByName(name,tag){var elements=document.getElementsByTagName(tag);var ret=new Array();for(var i=0;i<elements.length;i++){if(elements[i].name==name){ret[ret.length]=elements[i];}}if(ret.length>0){return ret;}return false;}
function getE(id,parent){if(defined(parent)){if(parent==true)return window.parent.document.getElementById(id);else return document.getElementById(id);}return document.getElementById(id);}
function defined(x){return typeof(x)!='undefined' && x!=null;}

function nl_count_params(counter, type, item, subitem) {
    var log_click = new Image();
    log_click.src = 'http://click.topturizm.ru/log_click.php?counter_id=' + counter + '&type=' + type + '&id=' + item + '&subitem=' + subitem + '&rand='+ Math.round(Math.random()*10000000);
}

function change_value(elem,oper) {
	var element = document.forms[form_name].elements[elem];
	if (oper == 'inc') {
		element.value++;			
	} 
	else  {
		if (element.value > 0) element.value--;
		if (element.value == 0) element.value="";			
	}
} 

function ccc(obj, color) {
    obj.style.backgroundColor  = color;
}

function roomChildren() {
	var room = getE("rs");
	if (rs[room.options[room.selectedIndex].value]=='2') {
		jQuery("#rs_child_block").find("table").css("display", "");
		jQuery("#ch1").attr({ "disabled":false });
		jQuery("#ch2").attr({ "disabled":false });
		
		jQuery("#cb1").html("Дети:&nbsp;").css("display", "");
		jQuery("#cb2").css("display", "");
		jQuery("#cb3").css("display", "");
		jQuery("#cb4").css("display", "");
		jQuery("#cb5").css("display", "");
	} else {
		if (rs[room.options[room.selectedIndex].value]=='1') {
			jQuery("#rs_child_block").find("table").css("display", "");
			jQuery("#ch1").attr({ "disabled":false });
			jQuery("#ch2").attr({ "disabled":false, "value":"" });
			
			jQuery("#cb1").html("Ребенок:&nbsp;").css("display", "");
			jQuery("#cb2").css("display", "");
			jQuery("#cb3").css("display", "none");
			jQuery("#cb4").css("display", "none");
			jQuery("#cb5").css("display", "");
		} else {
			jQuery("#rs_child_block").find("input").attr({"value":"", "disabled":true })
			.end()
			.find("table").css("display", "none");
		}
	}
}

function ShowWin(url,x,y,name,isscrollbars) {
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
    
    isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function ShowWinParent(url,x,y,name,isscrollbars) {
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
    
    isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}


function ShowPropWin(url,pr,name,isscrollbars) {
	var x,y;
	y=screen.availHeight
	if(!y) y=screen.height
	x=screen.availWidth
	if(!x) x=screen.width
	
	x = parseInt(pr*x/100);
	y = parseInt(pr*y/100);
	
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
	isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function ShowPropWinMod(url,prx,pry,name,isscrollbars,toolbar,status,directories,menubar,resizable,wlocation) {
	var x,y;
	y=screen.availHeight
	if(!y) y=screen.height
	x=screen.availWidth
	if(!x) x=screen.width
	
	x = parseInt(prx*x/100);
	y = parseInt(pry*y/100);
	
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
	isscrollbars=(isscrollbars=="no")?"no":"yes";
	toolbar=(toolbar=="no")?"no":"yes";
	status=(status=="no")?"no":"yes";
	directories=(directories=="no")?"no":"yes";
	menubar=(menubar=="no")?"no":"yes";
	resizable=(resizable=="no")?"no":"yes";
	wlocation=(wlocation=="no")?"no":"yes";
	window.open(url,name,"toolbar="+toolbar+",location="+wlocation+",status="+status+",directories="+directories+",menubar="+menubar+",resizable="+resizable+",width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function ShowPropWin1(url,prx,pry,name,isscrollbars) {
	var x,y;
	y=screen.availHeight
	if(!y) y=screen.height
	x=screen.availWidth
	if(!x) x=screen.width
	
	x = parseInt(prx*x/100);
	y = parseInt(pry*y/100);
	
	cx=screen.width / 2 - (x / 2);
	cy=(screen.height/2-(y/2));
	isscrollbars=(isscrollbars=="no")?"no":"yes";
	window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

function rc(obj, color) {
	if (color==1) 
	  obj.style.backgroundColor="#FAFAFA";
	else
	  obj.style.backgroundColor="#fff";
}

function ti_op(obj) {
	ShowWin(obj.href,450,400,"","yes"); 
	return false;
}

function ti_bp(obj) {
	ShowWin(obj.href,780,580,"","yes"); 
	return false;	
}

function ti_bk(obj) {
	ShowWin(obj.href,780,580,"","yes"); 
	return false;	
}

function ti_of(obj) {
	ShowWin(obj.href,780,580,"","yes"); 
	return false;	
}

function ti_ms(obj) {
	ShowWin(obj.href,450,470,"","yes"); 
	return false;	
}



function make_bookmark() {				
  var form = document.forms[form_name];
  	
  var qs = '';
  
  prepare_submit(true);
  	  
  var inputs = form.getElementsByTagName('input');;
  
  for(var i = 0; i < inputs.length; i++){
    if(qs.length) qs += '&';	  
    if (inputs[i].type=='hidden')  
    	qs += inputs[i].name+'='+inputs[i].value;
  }
	
  var names = new Array('df','dt','nf','nt','rs','ch1','ch2','ti','pf','pt','st','ld');
  
  for (key in names) {
  	var elem = form[names[key]];  	
  	if(qs.length) qs += '&';	 
  	qs += elem.name+'='+elem.value;
  }
  
  
  ShowWin("/window/bookmark/?"+qs,300,200,"","yes"); 
}



function get_cb_values(form_name,parent,name) {
	if(!parent) {
		var form = getE(form_name);
	} else {
		var form = window.parent.document.getElementById(form_name);
	}
	var values = '';

	if(defined(form)) {
		var element = form.elements;
		var checkbox = Array();
		
		if(defined(element)) {
			for (i=0; i<element.length; i++){
				if (element[i].type=='checkbox' && element[i].name==name) {
					checkbox[checkbox.length] = element[i];
				}
			}
			if (checkbox.length>0) {				
				for (i=0;i<checkbox.length;i++){	
					if (checkbox[i].checked) {
						values += checkbox[i].value+'_';
						checkbox[i].checked = false;
					}		
				}
				values = values.substr(0,values.length-1);
			}
		}
	}
	return values;
}

function addListener(element, event, func){
	if(element.attachEvent)
		element.attachEvent('on' + event, function(){ func(window.event) });
	else if(element.addEventListener)
		element.addEventListener(event, func, false);
}


function Selecter(Form, EName, S) {
    var f=Form;
    for ( i=0; i<f.length; i++ ) {
        if (f.elements[i].name==EName) {
            f.elements[i].checked=(S==1)?true:false;
        }
   }        
}


function qs2Hidden(qs) {
	farr = qs.split('?');
	var vars = new Array();
	var varval = new Array();
	if(defined(farr[1])) {
		arr = farr[1].split('&');
		for(i=0;i<arr.length;i++) {
			variable = arr[i].split('=');
			vars[i] = variable[0];
			varval[i] = variable[1];
		}
	}
	for(i=0;i<vars.length;i++) {
		if(vars[i]!=false)
			document.write('<input type="Hidden" id="id'+vars[i]+'" name="'+vars[i]+'" value="'+varval[i]+'">')
	}
}

/*
** Параметры:
** str - путь
** addarray - переменные, которые надо добавить в путь (array('name1','value1','name2','value2',...))
** removearray - перменные, которые необходимо убрать из пути (array('name1','name2',...))
*/
function my_get_qs(str,addarray,removearray) {
	farr = str.split('?');

	var vars = new Array();
	var varval = new Array();

	if(defined(farr[1])) {
		arr = farr[1].split('&');

		for(i=0;i<arr.length;i++) {
			variable = arr[i].split('=');
			vars[i] = variable[0];
			varval[i] = variable[1];
		}
		if(defined(removearray)) {
			if(removearray.length>0) {
				for(i=0;i<vars.length;i++) {
					for(j=0;j<removearray.length;j++) {
						if(vars[i]==removearray[j]) {
							vars[i] = false;
							varval[i] = false;
						}
					}
				}
			}
		}
	}

	if(defined(addarray)) {
		if(addarray.length>0) {
			for(j=0;j<addarray.length;j++) {
				find = false;
				for(i=0;i<vars.length;i++) {
					if(vars[i]==addarray[j]) {
						varval[i] = addarray[j+1];
						find = true;
					}
				}
				if(!find) {
					vars[vars.length] = addarray[j];
					varval[varval.length] = addarray[j+1];
				}
				j++;
			}
		}
	}

	qs = '';
	for(i=0;i<vars.length;i++) {
		if(vars[i]!=false)
			qs = qs+vars[i]+'='+varval[i]+'&';
	}
	
	return farr[0]+'?'+qs;
}


function freset() {
	var ch1 = document.getElementById('ch1');
	var ch2 = document.getElementById('ch2');
	ch1.disabled=true; 
	ch2.disabled=true; 
	ch1.value=ch2.value="";
}

function cb2str(name,postfix,sep) {
	var inputs = document.body.getElementsByTagName('input');
	var values = '';
	if (!defined(postfix)) { postfix = '[]'; }
	if (!defined(sep)) { sep = '_'; }
	var data = new Array();
	var l=0;
	if (inputs != null) { if (inputs.length != null) { for (i = 0; i<inputs.length; i++){ if (inputs[i].name==name+postfix) { data[l] = inputs[i]; l++; } } } }
	if (data != null){ if (data.length != null) { for (i = 0; i<data.length; i++){ if (data[i].checked) { values += data[i].value+sep; } } values = values.substr(0,values.length-1); } else { if (data.checked) { values = data.value; } } }
	return values;
}

function getAbsolutePos(el) { 
	var SL = 0, ST = 0; 
	var is_div = /^div$/i.test(el.tagName); 
	if (is_div && el.scrollLeft) SL = el.scrollLeft; 
	if (is_div && el.scrollTop) ST = el.scrollTop; 
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST }; 
	if (el.offsetParent) { 
		var tmp = this.getAbsolutePos(el.offsetParent); 
		r.x += tmp.x; 
		r.y += tmp.y; 
	} 
	return r; 
}

function showDivByEl(div,el,w,h) {
	pos = getAbsolutePos(getE(el));
	getE(div).style.top = parseInt(pos.y+h);
	getE(div).style.left = parseInt(pos.x+w);
	showHideBlock(div);
	return false;
}



function absPosition(obj) {
    this.x = 0;
    this.y = 0;
    while (obj) {
        this.x += obj.offsetLeft;
        this.y += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return {x:this.x, y:this.y};
}

/*document.onclick = function() {
	if(defined(getE("help_div"))) {
		getE("help_div").style.display = "none";
	}
}*/



function clear_help(evt) {
    evt = evt || window.event;
    evt.cancelBubble = true;
    getE("help_div").style.display = "none";
}


function contHelpStr(img, evt, str) {
    evt = evt || window.event;
    try {
        evt.cancelBubble = true;
    } catch (e) {
    }
    var rightFlag = false;
    var bodyWidth = window.innerWidth ? window.innerWidth : window.document.body.clientWidth;
    if (bodyWidth - absPosition(img).x < 300) {
        rightFlag = true;
    }
    var targetDiv = getE("help_div");
    if (img && targetDiv) {
        getE("help_div").className = "help_div";
        getE("help_div").innerHTML = "<a onclick=\"clear_help(event);return false;\" href=\"\"><img src='/i/close_help.gif' height=7 width=7 border=0 align=right></a><br><div>" + str + "</div>";
        var xRemainder = rightFlag ? -288 : 0;
        getE("help_div").style.top = absPosition(img).y;
        getE("help_div").style.left = absPosition(img).x + xRemainder;
        getE("help_div").style.display = "";
    }
    return false;
}

function prepare_submit_fac(not_reset) {
	var form = document.forms['fform'];
	var filters = new Array('ac');
	
	for (i=0;i<1;i++) {					
			// item не работает в каком-то из браузеров....
			//var ft = form.item(filter);						
			var ft = form[filters[i]];						
			// item не работает в каком-то из браузеров....
			//var inputs = form.item(filter+'_[]'); 
			var inputs = form[filters[i]+'[]']; 
			var values = '';
				
			if (inputs != null){
				if (inputs.length != null) {				
					for (i = 0; i<inputs.length; i++){	
						if (inputs[i].checked) {
							if (!not_reset) inputs[i].checked = false;					
							values += inputs[i].value+'_';
						}								
					}		
					values = values.substr(0,values.length-1);						
				} else {
					if (inputs.checked) {	
						if (!not_reset) inputs.checked = false;							
						values = inputs.value;
					}	
				}	
				ft.value = values;				
			} 										
	}
	
	return true;	
}



function getResort(co,re,cls,act) {
	var url = '/getdata?f=re&co='+co;
	var h = 13;
	var html = '';

	switch (cls) {
		case 6: h = 25; if(act) { h = h + 7; } break;
		case 5: h = 22; if(act) { h = h + 5; } break;
		case 4: h = 18; if(act) { h = h + 4; } break;
		case 3: h = 16; if(act) { h = h + 4; } break;
		case 2: h = 14; if(act) { h = h + 4; } break;
		case 1: h = 13; if(act) { h = h + 4; } break;
		default: h = 13; if(act) { h = h + 4; } break;
	}
	
	getE('re_block_data').style.display = 'none';
	showDivByEl('re_block','co'+co,0,h);
	getE('re_block_data').innerHTML = '<font class="red">подождите, идет загрузка...</font>';
	getE('re_block_data').style.display = '';

	var callback = function(data){ 
		html = '<a href="/price'+href+'co='+co+'" title="все куроты"><b>все куроты</b></a><br>';
		if (data) {
			for(i=0;i<data.length;i++){
				if (data[i].id==re) {
					style = ' class="red"';
				} else {
					style = '';
				}

				html = html + '<a href="/price'+href+'co='+co+'&re='+data[i].id+'" title="'+data[i].name+'"'+style+'>'+data[i].name+'</a><br>';
			}
		}
		getE('re_block_data').innerHTML = html;
	}
	Json.call(url, function(data){ callback(data); });
}

/**
 * Функция модификации параметров QueryString
 * @param array arrModifiedParams изменяемые параметры, формат key=>value
 * @param boolean blnRemoveEmpty флаг, удалять ли пустые параметры. по умолчанию true
 */
function changeQSParams(arrModifiedParams, blnRemoveEmpty) {
	if(typeof(blnRemoveEmpty)=="undefined") {
		blnRemoveEmpty = true;
	}
    // Создаем массив новых параметров
    arrNewParams=[];
    
    // Сначала из старой строки
    strOldQS=window.location.search.substr(1,window.location.search.length);
    arrOldParams=strOldQS.split("&");
    for(i=0;i<arrOldParams.length;i++) {
        arrCurrent=arrOldParams[i].split("=");
        strName=arrCurrent[0];
        
        if(typeof(arrModifiedParams[strName])=="undefined") {
            strValue=arrCurrent[1];
            if(typeof(strValue)=="undefined") {
                strValue="";
            }
            if(!(blnRemoveEmpty && strValue.length==0)) {
            	arrNewParams[strName]=strValue;
            }
        }
    }
    
    // Затем добавляем модифицируемые параметры
    for(strName in arrModifiedParams) {
    	if(!(blnRemoveEmpty && arrModifiedParams[strName].length==0)) {
        	arrNewParams[strName]=arrModifiedParams[strName];
        }
    }
    
    // Собираем QUERY_STRING
    strNewQS="";
    blnFirst=true;
    for(strName in arrNewParams) {
        if(strName.length>0) {
            strSeparator="&";
            if(blnFirst) {
                blnFirst=false;
                strSeparator="";
            }
            strNewQS=strNewQS+strSeparator+strName+"="+arrNewParams[strName];
        }
    }    
    
    // Выполняем переход               
    window.location.search=strNewQS;
            

}


/**
* Добавление в закладки
*/
function pageBookmark(url,title) {
 if (!url) url = location.href;
 if (!title) title = document.title;

 //Gecko
 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
 //IE4+
 else if (typeof window.external == "object") window.external.AddFavorite(url, title);
 //Opera7+
 else if (window.opera && document.createElement)
 {
   var a = document.createElement('A');
   if (!a) return false; //IF Opera 6
   a.setAttribute('rel','sidebar');
   a.setAttribute('href',url);
   a.setAttribute('title',title);
   a.click();
 }
 else return false;
 
 return true;
}



function rawurlencode(str) {
	var url = new String(str);
	url = url.replace(/([^a-z0-9_\-\.])/gi, function (str, p1, offset, s) {	var hex = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"); val = p1.charCodeAt(0); s = ""; while (val>=16) { s += hex[val%16]; val = Math.floor(val/16); } s += hex[val]; N = s.length; for (i=0,t="";i<N;i++) t += s.substring(N-i-1,N-i); return "%"+t; });
	return url;
}

function rawurldecode(str) {
	var url = new String(str);
	url = url.replace(/%([0-9ABCDEF]{2}|[0-9ABCDEF]{4})/g, function (str, p1, offset, s) { return String.fromCharCode(parseInt("0x"+p1,16)); });
	return url;
}

function unicode2cirilik(str) {
	var url = new String(str);
	url = url.replace(/&#([0-9]{4});/g, function (str, p1, offset, s) { return String.fromCharCode(p1); });
	return url;
}


// перемещение div по экрану за полосой прокрутки
function JSFX_FloatTopDiv() {

	this.timer = null;
	this.ftlObj = {};
	this.startDiv = null;

	this.DeLayer = function(id) {
		var placeX = (d.body.clientWidth - d.body.clientWidth / 2),
		placeY = (d.body.clientHeight - d.body.clientHeight / 2) + 100;
		var GetElements = d.getElementById ? d.getElementById(id) : d.all ? d.all[id] : d.layers[id];
		if (d.layers)
			GetElements.style = GetElements;
		GetElements.sP = function(x,y) {
			this.style.right = x;
			this.style.top = y;
		};
		GetElements.x = placeX;
		GetElements.y = isNs ? pageYOffset + innerHeight : d.body.scrollTop + d.body.clientHeight;
		GetElements.y -= placeY;
		return GetElements;
	}

	this.add = function(divid) {
		this.ftlObj[divid] = this.DeLayer(divid);
	}
	
	this.stop = function() {
		clearTimeout(this.timer);
		clearInterval(this.timer);
		if (defined(this.startDiv)) {
			this.startDiv.style.display = 'none';
		}
		this.startDiv = null;
	}

	this.stayTopright = function() {
		placeY = (d.body.clientHeight - d.body.clientHeight / 2) + 100;
		var pY = isNs ? pageYOffset + innerHeight : d.body.scrollTop + d.body.clientHeight;
		this.startDiv.y += (pY - placeY - this.startDiv.y) / 15;
		this.startDiv.sP(this.startDiv.x, this.startDiv.y);
		var obj = this;
		this.timer = setTimeout(function() { obj.stayTopright(); }, 10);
	}

	this.start = function(divid) {
		this.stop();
		if (defined(this.ftlObj[divid])) {
			this.startDiv = this.ftlObj[divid];
			if (defined(this.startDiv)) {
				this.startDiv.style.display = '';
			}
			this.stayTopright();
		}
	}
}

JSFX = new JSFX_FloatTopDiv();


/*
 +-------------------------------------------------------------------+
 |                   J S - T O O L T I P   (v2.1)                    |
 |             Используется в партнерском модуле турбука             |
 |                                                                   |
 | Copyright Gerd Tentler                www.gerd-tentler.de/tools   |
 | Modified by: Alex Cord                                            |
 +-------------------------------------------------------------------+
*/

var OP = (navigator.userAgent.indexOf('Opera') != -1);
var IE = (navigator.userAgent.indexOf('MSIE') != -1 && !OP);
var GK = (navigator.userAgent.indexOf('Gecko') != -1);
var SA = (navigator.userAgent.indexOf('Safari') != -1);
var DOM = document.getElementById;

var tooltip = null;

function TOOLTIP() {
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------
  this.width = 200;                     // width (pixels)
  this.bgColor = "";             // background color
  this.textFont = "";      // text font family
  this.textSize = "";                   // text font size (pixels)
  this.textColor = "";           // text color
  this.border = "";   // border (CSS spec: size style color, e.g. "1px solid #D00000")
  this.opacity = 100;                    // opacity (0 - 100); not supported by all browsers
  this.cursorDistance = 5;              // distance from mouse cursor (pixels)
  this.cursorDistanceX = -5;
  this.cursorDistanceY = 0;
  // don't change
  this.text = '';
  this.height = 0;
  this.obj = null;
  this.active = false;

//----------------------------------------------------------------------------------------------------
// Methods
//----------------------------------------------------------------------------------------------------
  this.create = function() {
  	
    if(!this.obj) this.init();

    if(DOM || IE) this.obj.innerHTML = this.text;
    if(DOM) this.height = this.obj.offsetHeight;
    else if(IE) this.height = this.obj.style.pixelHeight;
    if(this.bgColor) this.obj.style.backgroundColor = this.bgColor;
    
	if(this.obj.style.height) this.obj.style.height = this.height;	
	
	if(this.position == '1') this.cursorDistanceX = -this.width;

	
    this.setOpacity();
    this.move();
    this.show();
  }

  this.init = function() {
    if(DOM) this.obj = document.getElementById('ToolTip');
    else if(IE) this.obj = document.all.ToolTip;
  }

  this.move = function() {  
    var winX = getWinX() - (((GK && !SA) || OP) ? 17 : 0);
    var winY = getWinY() - (((GK && !SA) || OP) ? 17 : 0);
    var x = mouseX;
    var y = mouseY;

    if(x + this.width + this.cursorDistanceX > winX + getScrX())
      x -= this.width + this.cursorDistanceX;
    else x += this.cursorDistanceX;

    /*
    if(y + this.height + this.cursorDistanceY > winY + getScrY())
      y -= this.height;
    else y += this.cursorDistanceY;
    */
    y += this.cursorDistanceY

    this.obj.style.left = x + 'px';
    this.obj.style.top = y + 'px';
  }

  this.show = function() {
    this.obj.style.zIndex = 69;
    this.active = true;
    this.obj.style.visibility = 'visible';
  }

  this.hide = function() {
    this.obj.style.zIndex = -1;
    this.active = false;
    this.obj.style.visibility = 'hidden';
  }

  this.setOpacity = function() {
    this.obj.style.opacity = this.opacity / 100;
    this.obj.style.MozOpacity = this.opacity / 100;
    this.obj.style.KhtmlOpacity = this.opacity / 100;
    this.obj.style.filter = 'alpha(opacity=' + this.opacity + ')';
  }
}

//----------------------------------------------------------------------------------------------------
// Global functions
//----------------------------------------------------------------------------------------------------
function getScrX() {
  var offset = 0;
  if(window.pageXOffset)
    offset = window.pageXOffset;
  else if(document.documentElement && document.documentElement.scrollLeft)
    offset = document.documentElement.scrollLeft;
  else if(document.body && document.body.scrollLeft)
    offset = document.body.scrollLeft;
  return offset;
}

function getScrY() {
  var offset = 0;
  if(window.pageYOffset)
    offset = window.pageYOffset;
  else if(document.documentElement && document.documentElement.scrollTop)
    offset = document.documentElement.scrollTop;
  else if(document.body && document.body.scrollTop)
    offset = document.body.scrollTop;
  return offset;
}

function getWinX() {
  var size = 0;
  if(window.innerWidth)
    size = window.innerWidth;
  else if(document.documentElement && document.documentElement.clientWidth)
    size = document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    size = document.body.clientWidth;
  else size = screen.width;
  return size;
}

function getWinY() {
  var size = 0;
  if(window.innerHeight)
    size = window.innerHeight;
  else if(document.documentElement && document.documentElement.clientHeight)
    size = document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    size = document.body.clientHeight;
  else size = screen.height;
  return size;
}

function getMouseXY(e) {
  if(e && e.pageX != null) {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  else if(event && event.clientX != null) {
    mouseX = event.clientX + getScrX();
    mouseY = event.clientY + getScrY();
  }
  if(mouseX < 0) mouseX = 0;
  if(mouseY < 0) mouseY = 0;
  if(tooltip && tooltip.active){
  	tooltip.move(); 
  
  }
}

function toolTip(text, width, height, position) {
  if(text) {
 	 
    tooltip = new TOOLTIP();
    tooltip.text = text;
    if(width) tooltip.width = width;
    if(height) tooltip.height = height;    
    tooltip.position = position;
    tooltip.create();
  }
  else if(tooltip) tooltip.hide();
}

//----------------------------------------------------------------------------------------------------
// Build tooltip box
//----------------------------------------------------------------------------------------------------
document.write('<div id="ToolTip" style="position:absolute; visibility:hidden; z-index:100"></div>');

//----------------------------------------------------------------------------------------------------
// Event handlers
//----------------------------------------------------------------------------------------------------
var mouseX = mouseY = 0;
//document.onmousemove = getMouseXY;

//----------------------------------------------------------------------------------------------------


// Создание контейнера для подгрузки изображения
function loadPhoto(imgSrc){
  photo1= new Image();
  photo1.src=imgSrc;
  Control(imgSrc);
}
// Контроль предварительной загрузки изображения
function Control(imgSrc){
  if((photo1.width!=0)&&(photo1.height!=0)){
    viewFoto(imgSrc);
  }
  else{
    tmpInterval=setTimeout("Control('"+imgSrc+"');",20);
  }
}

// Вывод изображения
function viewFoto(imgSrc){
	w=photo1.width;
	h=photo1.height;
	tmpString="top="+((screen.height-h)/2)+",left="+((screen.width-w)/2)+",height="+h+",width="+w+",toolbar=no,scrollbars=no,directories=no,status=no,menubar=no,resizable=yes";
	fin = window.open("","photo",tmpString);
	fin.document.open();
	fin.document.write("<html><head><title>Фотогалерея</title></head><body style=\'margin:0;padding:0\'>"+
	"<a href=\'javascript: window.close();\'><img src=\'"+imgSrc+"\' border=0 alt=\'Кликните, чтобы закрыть\' title=\'Кликните, чтобы закрыть\'></a></body></html>");
	fin.document.close();
	fin.focus();
}

function strCode(oldstr,sep) {
	var newstr = new String(oldstr);
	if (newstr.length>0) {
		newstr = newstr.replace(/(.*)/gi, 
			function (str, p1, offset, s) {
				var hr = '';
				for ( i = 0; i < p1.length; i++) {
					hr = hr + p1.charCodeAt(i) + sep;
				}
				return hr;
            });
		return newstr.substr(0,newstr.length-1);
	} else return '';
}


function changeQSParamsByUrl(url, arrModifiedParams, blnRemoveEmpty) {
	if(typeof(blnRemoveEmpty)=="undefined") { blnRemoveEmpty = true; }
    arrNewParams=[];
	farr = url.split('?');
	strOldQS = (defined(farr[1]))?farr[1]:'';
	if (strOldQS.length) {
		arrOldParams=strOldQS.split("&");
		for(i=0;i<arrOldParams.length;i++) {
        arrCurrent=arrOldParams[i].split("=");
			strName=arrCurrent[0];
			
			if(typeof(arrModifiedParams[strName])=="undefined") {
				strValue=arrCurrent[1];
				if(typeof(strValue)=="undefined") {
					strValue="";
				}
				if(!(blnRemoveEmpty && strValue.length==0)) {
					arrNewParams[strName]=strValue;
				}
			}
		}
	}
    for(strName in arrModifiedParams) {
    	if(!(blnRemoveEmpty && arrModifiedParams[strName].length==0)) {
        	arrNewParams[strName]=arrModifiedParams[strName];
        }
    }
    strNewQS="";
    blnFirst=true;
    for(strName in arrNewParams) {
        if(strName.length>0) {
            strSeparator="&";
            if(blnFirst) {
                blnFirst=false;
                strSeparator="";
            }
            strNewQS=strNewQS+strSeparator+strName+"="+arrNewParams[strName];
        }
    }
	strNewQS = (defined(farr[0]))?farr[0]+'?'+strNewQS:'?'+strNewQS;
    return strNewQS;
}


function showOperatorInfo(className) {
	JSFX.stop();
	var opClass = new Array('A', 'B', 'C', 'D', 'E');
	for (i=0; i<opClass.length; i++) {
		if(defined(getE('class_op_block_' + opClass[i]))) {
			if (opClass[i] == className) {
				JSFX.start('class_op_block_' + opClass[i]);
			}
		}
	}
	if(defined(getE('class_all_block'))) {
		if (className == 'All') {
			JSFX.start('class_all_block');
		}
	}
}

function loginFocus() {
	log = document.getElementById('login');
	setTimeout("log.focus()", 200);//FF does not wish to understand normally method focus ()
}




function getElementPosition(elemPtr) {
    var posX = elemPtr.offsetLeft;
    var posY = elemPtr.offsetTop;

    while (elemPtr.offsetParent != null) {
        elemPtr = elemPtr.offsetParent;
        posX += elemPtr.offsetLeft;
        posY += elemPtr.offsetTop;
    }
    this.x = posX;
    this.y = posY;
    
    return this;
}

function chElVisBellow(elId, vis) {
    var calLeer = document.getElementById(elId);
    var calPosition = new getElementPosition(calLeer);
	
	MyVisibility = (vis == true) ? "visible" : "hidden";
    
    CalTop=calPosition.y;
    CalLeft=calPosition.x;
    CalBottom=CalTop+calLeer.clientHeight;
    CalRight=CalLeft+calLeer.clientWidth;
	
    // select
    for (var i=0; i<document.getElementsByTagName("select").length; i++) {
        Cu=document.getElementsByTagName("select")[i];
		
        var CuPosition=new getElementPosition(Cu);
        CuTop=CuPosition.y;
        CuLeft=CuPosition.x;
        CuBottom=CuTop+Cu.clientHeight;
        CuRight=CuLeft+Cu.clientWidth;
		
        if ((CuLeft<=CalLeft)&&(CuRight>=CalLeft)||
            (CuLeft>=CalLeft)&&(CuRight<=CalRight)||
            (CuLeft<=CalRight)&&(CuRight>=CalRight)) {
			
            if ((CuTop<=CalTop)&&(CuBottom>=CalTop)||
                (CuTop>=CalTop)&&(CuBottom<=CalBottom)||
                (CuTop<=CalBottom)&&(CuBottom>=CalBottom)) {
                Cu.style.visibility = MyVisibility;
            }
        }
    }
	
    // iframe
    for (var i=0; i<document.getElementsByTagName("iframe").length; i++) {
        Cu=document.getElementsByTagName("iframe")[i];
		
        var CuPosition=new getElementPosition(Cu);
        CuTop=CuPosition.y;
        CuLeft=CuPosition.x;
        CuBottom=CuTop+Cu.clientHeight;
        CuRight=CuLeft+Cu.clientWidth;

        if ((CuLeft<=CalLeft)&&(CuRight>=CalLeft)||
            (CuLeft>=CalLeft)&&(CuRight<=CalRight)||
            (CuLeft<=CalRight)&&(CuRight>=CalRight)) {
			
            if ((CuTop<=CalTop)&&(CuBottom>=CalTop)||
                (CuTop>=CalTop)&&(CuBottom<=CalBottom)||
                (CuTop<=CalBottom)&&(CuBottom>=CalBottom)) {
                Cu.style.visibility = MyVisibility;
            }
        }
    }

    return true;
}

function showHideBlock(elId, shide) {
	if (defined(shide)) {
		if (shide == true) {
			$("#" + elId).css("display", "block");				
			if ($.browser.msie) { chElVisBellow(elId, false); }
		} else {
			$("#" + elId).css("display", "none");
			if ($.browser.msie) { chElVisBellow(elId, true); }
		}
	} else {
		if ($("#" + elId).css("display") == "none") {
			$("#" + elId).css("display", "block");				
			if ($.browser.msie) { chElVisBellow(elId, false); }
		} else {
			$("#" + elId).css("display", "none");
			if ($.browser.msie) { chElVisBellow(elId, true); }
		}
	}
}


function parse_str(str, array) {
    var glue1 = "=";
    var glue2 = "&";
	
 	var array1 = str.split("?");
	str = defined(array1[1]) ? array1[1] : array1[0];
	
    var array2 = str.split(glue2);
    var array3 = {};
    for(var x=0; x<array2.length; x++){
        var tmp = array2[x].split(glue1);
		if (defined(tmp[0]) && defined(tmp[1])) {
			array3[unescape(tmp[0])] = unescape(tmp[1]).replace(/[+]/g, ' ');
		}
    }
    if(array){
        array = array3;
    } else{
        return array3;
    }
}




function setUrlCtAllPage(url,parent) {
	//if (defined(getE('ctAllPage',parent))) {
	//	if (defined(url)) {
	//		getE('ctAllPage',parent).setUrl(url);
	//	}
	//}
	
	$("#ctAllPage").attr("exc", "1");
}

function updateCtAllPage(url,parent) {
	if (!defined(url)) { url = "/data/allct/"; }
	params = parse_str(window.location.search);
	params.fexc = $("#ctAllPage").attr("exc");
	
	jQuery.get(url, params, function(data){
		$("#ctAllPage").html(data);
		$("a.sCtAllPage").html($("#fCtAllPage").html());
		if (excOnchange == true) {
			if (defined(getE("ct"))) { $("#ct").attr("value", $("#fCtAllPage").attr("value")); }
			getE("co").updateList();
		}
	});
}
