DL_ok = false;
Tpl_ok = false;
PU_objectsToHide = new Array();
PU_objectsHidden = new Array();

DOM = (document.getElementById)? true : false;
IE = (navigator.userAgent.indexOf("MSIE") != -1);
Opera = (navigator.userAgent.indexOf("Opera") != -1);

function Mm(name, mode){
	var domain='panukraine.kiev.ua';
	var strip_re=/#/;
	var web="webmaster";

	if(mode==0){
		mail=name.replace(strip_re, "@");
		document.writeln('e-mail: <a href="mailto:'+mail+'">'+mail+'</a>');
	}
	else if(mode==1){	
		document.writeln('e-mail: <a href="mailto:'+name+'@'+domain+'">'+name+'@'+domain+'</a>');
	}
	else if(mode==2){	
		document.writeln('<a href="mailto:'+name+'@'+domain+'?Subject=Site: " title="написать письмо администратору сайта">'+web+'</a>');
	};

}

function NewWin(url,w,h,title){
	imgPopup.show(url,w,h,title);
	//mapName=window.open('','','width='+w+',height='+h+',scrollbars=no,location=no,toolbar=no,directories=no,status=no,menubar=no,top='+Math.round((screen.availHeight-h)/2)+',left='+Math.round((screen.availWidth-w)/2));	
	//mapName.document.writeln('<html><head><title>'+title+'&nbsp;</title></head><body style="margin: 0px; width: '+w+'; height: '+h+'">\
	//<div style="margin: auto; text-align: center;"><a href="javascript: this.close();"><img src="'+url+'" alt="<закрыть>" border="0"><\/a><\/div>\
	//<\/body><\/html>');
 }
 
function hlRow(obj, td){
	switch (td){
		case 'over':
		obj.style.backgroundColor=rowhl; 
		break;
		case 'out':
		obj.style.backgroundColor='';
		break;
	}; 
	
}

function HideSub(submenu) {
	for(i=0; i<sub_ar.length; i++){
		if(sub_ar[i]!=submenu) eval(sub_ar[i]+'.hide();');
	};
};

function Sit(e, obj){
	mousex = e.clientX;
	mousey = e.clientY;
	pagexoff = 0;
	pageyoff = 0;
	
	if(isMSIE){
		pagexoff = document.body.scrollLeft;
		pageyoff = document.body.scrollTop;
	}
	else{
		pagexoff = window.pageXOffset;
		pageyoff = window.pageYOffset;
	};
	
	eval('objo='+obj+';');
	objs=objo.style;
 
	if(objo){
		leftoff = mousex-pagexoff;
		topoff = mousey-pageyoff;

		objs.left = (mousex+pagexoff);
		if(isOpera && topoff <= 30) objs.top = mousey + 20;
		else if( mousey <= 30) objs.top = (mousey+pageyoff) + 20;
		else if (isOpera) objs.top = mousey + 20;
		else	obj.top = (mousey+pageyoff) + 20;

		objo.setVisibility(true);
	}
	return true;
};

function Hit(obj){
	eval('objo='+obj+';');
	objo.setVisibility(false);
}

function getScroll(){
	scrollXY=document.getElementsByTagName((document.compatMode && document.compatMode == 'CSS1Compat') ? "HTML" : "BODY")[0];
	return scrollXY.scrollTop;
}
function ScrollTop( s ){
	var speed = s?s:50;
	begin=getScroll();
	for (i=begin; i > 0; i -= speed) scrollBy(0,-speed);
}
fillListFromArray = function(id, optArr, value, selAttr){
	tmpSelect = document.getElementById(id);
	if(tmpSelect){
		for(var i = 0; i < optArr.length; i++){
			tmpOpt = new Option();
			for(var key in optArr[i]){
				tmpOpt[key] = optArr[i][key];
				
			}
			
			if( optArr[i] && optArr[i].value == value ) {
				tmpOpt.selected = true;
				var value_exists = true;
			}
			if( optArr[i] ) tmpSelect.options[tmpSelect.options.length] = tmpOpt;
			
		}
		
		//alert( value );
		if( !value_exists ) tmpSelect.value = optArr[0].value;
		
		for(var key in selAttr){
			tmpSelect[key] = selAttr[key];
		}
		
	}
}
clearSelect = function(id){
	tmpSelect = document.getElementById(id);
	if(tmpSelect) tmpSelect.options.length = 0;
}

is_covered = function( obj1, obj2 ) {
	
}

getAbsolutePos = function(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;
};

//// ####################
ImgPopup = function() {
	this.ID = 'img_popup';
	this.IDobj;
	this.h = 0;
	this.w = 0;
	this.status = "hidden";
	
	this.src = '\
		<div class="img_popup " id="img_popup">\
			<div ondblclick="imgPopup.close()"><img src="/images/s.gif" alt=""></div>\
			<span onclick="imgPopup.close(this)">Закрыть</span>\
		</div>\
';

	this.close = function() {
		if( !this.IDobj ) return;
		this.img.style.width = this.div.style.width = '10px';
		this.img.style.height = this.div.style.height = '10px';
		this.img.style.visibility = 'hidden';
		this.div.style.backgroundImage='url(/images/s.gif)';
		if(this.IDobj) this.IDobj.style.visibility = 'hidden';
		this.status = "hidden";
		if( PU_objectsHidden.length ) this.show_flash();
	}
	
	this.show = function(url, w, h, desc) {
		if( !this.IDobj ) return;

		this.IDobj.style.top = Math.round( getScrollY()+(getWindowHeight() - h)/2 -50 );
		this.IDobj.style.left = Math.round( (getWindowWidth() - w)/2 );
		this.IDobj.style.top = parseInt( this.IDobj.style.top ) < 0 ? 5 : this.IDobj.style.top;
		this.IDobj.style.left = parseInt( this.IDobj.style.left ) < 0 ? 5 : this.IDobj.style.left;
		this.img.style.width = this.div.style.width = w+'px';
		this.img.style.height = this.div.style.height = h+'px';

		this.close_text.style.width =w;
		
		this.div.setAttribute('title', desc);
		this.div.style.backgroundImage='url(/images/s.gif)';
		this.div.style.backgroundImage='url('+url+')';
		this.IDobj.style.visibility = 'visible';
		this.img.style.visibility = 'visible';
		this.status = "showen";
		
		this.checkHidden();
	}
	
	this.init = function() {
		document.writeln(this.src);
		this.IDobj = document.getElementById(this.ID) || false;
		var tags = this.IDobj.getElementsByTagName('img');
		this.img = tags[0];
		var tmp_div = this.IDobj.getElementsByTagName('div');
		this.div = tmp_div[0];
		var spans = this.IDobj.getElementsByTagName('span');
		this.close_text = spans[0];
	}
	
	this.checkHidden = function() {

		if( PU_objectsToHide.length == 0 ) {
			if( !PU_objectsToHide ) PU_objectsToHide = new Array();
			var embeds = document.body.getElementsByTagName('embed');
			var objects = document.body.getElementsByTagName('object');
			var selects = document.body.getElementsByTagName('select')			
			
			for( var i = 0; i < embeds.length;  i++ ) PU_objectsToHide.push( embeds[i] );
			for( var i = 0; i < objects.length; i++ ) PU_objectsToHide.push( objects[i] );
			for( var i = 0; i < selects.length; i++ ) PU_objectsToHide.push( selects[i] );			
		}
		//alert( PU_objectsToHide.length );
		for( var i = 0; i < PU_objectsToHide.length; i++ ) {
			var to_hide = PU_objectsToHide[i];
			var popup = imgPopup.IDobj;
			
			var p1 = getAbsolutePos( popup );
			var EX1 = p1.x;
			var EX2 = popup.offsetWidth + EX1;
			var EY1 = p1.y;
			var EY2 = popup.offsetHeight + EY1;
			
			//alert( p1.x );
			
			var p2 = getAbsolutePos( to_hide );
			var cc = to_hide;
			var CX1 = p2.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = p2.y;
			var CY2 = cc.offsetHeight + CY1;

			//alert( '(obj.x > pop.w) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)' );
			//alert( '('+CX1+' > '+EX2+') || ('+CX2+' < '+EX1+') || ('+CY1+' > '+EY2+') || ('+CY2+' < '+EY1+')' );
			
			if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				PU_objectsHidden[i] = null;
				to_hide.style.visibility = 'inherit';
			}
			else {
				PU_objectsHidden[i] = PU_objectsToHide[i];
				to_hide.style.visibility = 'hidden';
			}
			
		
		}
	}

	this.show_flash = function() {
		for( i = 0; i < PU_objectsHidden.length; i++ ) {
			if ( PU_objectsHidden[i] ) {
				PU_objectsHidden[i].style.visibility = 'inherit';
				PU_objectsHidden.splice( i, 1 );
			}
		}
	}
	
	this.init();
}
ImgPopup_ok = true;

DL_fileInfoObject = function(){

	this.showTimeout = 200;
	this.hideTimeout = 5000;
	this.divID =  'DL_FILE_INFO';
	this.ok_divID =  'DL_ok';
	this.err_divID =  'DL_error';
	this.progress_divID =  'DL_progress';
	
	this.zipText = 'в архиве Zip (.zip)';
	this.rarText = 'в архиве Rar (.rar)';
	this.docText = 'в формате MS Word (.doc)';
	this.xlsText = 'в формате MS Excel (.xls)';
	this.pdfText = 'в формате Adobe Acrobat (.pdf)';
	
	this.sizeText = '~<SIZE>';
	this.download_timeText = '~<TIME> мин:сек';
	this.errorText = 'Файл \'<FILE>\' <br>не найден.<br>Пожалуйста, сообщите об этом администору сайта<br> (e-mail - см. внизу страницы) <br>или менеджеру по продажам.';
		
	this.cache = Array();
	
	//TEMPLATE
	document.writeln('<div id="DL_FILE_INFO">\
		<div id="DL_ok">\
			<table class="tblhl" cellpadding="0" cellspacing="2">\
				<tr class="cell nw">\
					<td class="r tbl_head">файл:</td>\
					<td><span id="DL_name"></span></td>\
				</tr>\
				<tr class="cell nw">\
					<td class="r tbl_head">тип:</td>\
					<td class="rowhl"><span id="DL_type"></span></td>\
				</tr>\
				<tr class="cell nw">\
					<td class="r tbl_head">размер:</td>\
					<td><span id="DL_size"></span></td>\
				</tr>\
				<tr class="cell nw">\
					<td class="r tbl_head">дата:</td>\
					<td><span id="DL_date1"></span></td>\
				</tr>\
				<tr class="cell nw">\
					<td class="r tbl_head">загрузка:</td>\
					<td class="rowhl"><span id="DL_time"></span></td>\
				</tr>\
			</table>\
		</div>\
		<div id="DL_error" class="tblhl nw cell c"></div>\
		<div id="DL_progress" class="tblhl nw cell c">Загрузка данных...</div>\
		</div>');	
	
	//private
	this.DIV = document.getElementById( this.divID );
	this.kDIV = layer( this.divID );
	this.okDIV = document.getElementById( this.ok_divID );
	this.errDIV = document.getElementById( this.err_divID );
	this.err_kDIV = layer( this.err_divID );
	this.progressDIV = document.getElementById( this.progress_divID );
	
	
	this.timeout	= null;
	this.timeout_flag = false;
	this.name = document.getElementById( 'DL_name' );
	this.type = document.getElementById( 'DL_type' );
	this.size = document.getElementById( 'DL_size' );
	this.date1 = document.getElementById( 'DL_date1' );
	this.download_time = document.getElementById( 'DL_time' );
	
	this.ajax = new sack();
	this.ajax.parent = this;
	
	this.tmpID = 1;


	this.show = function( node, data ) {
		this.data = data;
		this.node = node;
		
		this.tmpID++;
		tmpNode = node.childNodes.item(0);
		tmpNode.setAttribute( 'id', 'tmp'+this.tmpID);
		var kNode =  layer( 'tmp'+this.tmpID );
		this.kDIV.moveTo( layer( 'tmp'+this.tmpID ).getAbsoluteLeft() + layer( 'tmp'+this.tmpID ).getWidth(), layer( 'tmp'+this.tmpID ).getAbsoluteTop() + layer( 'tmp'+this.tmpID ).getHeight() );	
		
		this.name.innerHTML = data.name;
		this.date1.innerHTML = data.date1;
		
		eval( "this.type.innerHTML = this." + data.type + "Text;" );
		
		if( data.mode && data.mode == 'ajax' && !this.search( data.name ) ) {
			this.okDIV.style.display = 'none';
			this.errDIV.style.display = 'none';
			this.progressDIV.style.display = 'block';
			this.kDIV.show();
			
			this.ajax.reset();
			this.ajax.method = 'POST';
			this.ajax.setVar( "f", data.name );
			this.ajax.requestFile = "/inc/site_lib/file_info.php";
			this.ajax.onCompletion = this.onCompletion;
			this.ajax.runAJAX();
			return ;
		}
		else {
			if ( this.search( data.name ) ) this.data = this.search( data.name, 1 );
		};
		
		this.size.innerHTML = this.sizeText.replace( /<SIZE>/,  this.data.size );
		this.download_time.innerHTML = this.download_timeText.replace( /<TIME>/,  this.data.download_time );
		this.date1.innerHTML = this.data.date1;
		
		this.kDIV.hide();
		if( !this.data.size ){
			tmpNode.src = '/images/ico_none.gif';
			node.href = '#';
			this.err_kDIV.write( this.errorText.replace( /<FILE>/,  this.data.name ) );
			this.okDIV.style.display = 'none';
			this.errDIV.style.display = 'block';
		}
		else this.okDIV.style.display = 'block';
			
		this.timeout = setTimeout( 'DL.fshow()', this.showTimeout );
	
	}

	this.fshow = function() {
		this.kDIV.show();
		this.timeout = setTimeout( 'DL.fhide()', this.hideTimeout );
		this.timeout_flag = true;
	}

	this.hide = function () {
		this.ajax.reset();
		if ( !this.timeout_flag ) setTimeout( 'DL.fhide()', this.hideTimeout );
	}

	this.fhide = function () {
		clearTimeout( this.timeout );
		this.err_kDIV.write('');
		this.errDIV.style.display = 'none';
		this.okDIV.style.display = 'none';
		this.progressDIV.style.display = 'none';
		this.kDIV.hide();
		this.ajax.reset();
		//this.timeout	= false;
	}
	
	this.onCompletion = function(){
		this.parent.progressDIV.style.display = 'none';
		if ( this.responseStatus && this.response != '' ) {
			try {
				var resp = this.response.replace(/.*<results>(.*)<\/results>.*/, '$1');
				eval( 'this.data = '+resp+';' );
			}
			catch(e){};
			this.parent.cache.push( this.data );
			this.parent.show( this.parent.node, this.data );
		}
		else {
			this.parent.data.size = false;
			if( !this.search( data.name ) ) this.parent.cache.push( this.parent.data );
			this.parent.show( this.parent.node, this.parent.data );
		}
		
	}
	
	this.search = function ( name, m ){
		for ( i = 0; i < this.cache.length; i++ ){
			//alert(this.cache[i].name);
			if ( this.cache[i].name == name ) {
				if( m ) return this.cache[i];
				else return true;
			}
		}
		return false;	
	}
	
}

	function file( name, ext ) {
		this.name = name;
		this.ext = ext;
		this.dir = '/downloads/';
		n = 0;
		
	this.init = function() {
		if( ext.match( /x/ ) ) {
			type = 'xls';
			document.writeln( "<a href='"+this.dir+"?f="+name+"."+type+"'  onmouseover=\"DL.show( this,  { name: '"+name+"."+type+"', mode: 'ajax' } );\" onmouseout=\"DL.fhide();\"><img src='/images/ico_"+type+".gif' alt='' width='15' height='15' class='fico'></a>" );
			n++;
		}
		if( ext.match( /d/ ) ) {
			type = 'doc';
			document.writeln( "<a href='"+this.dir+"?f="+name+"."+type+"'  onmouseover=\"DL.show( this,  { name: '"+name+"."+type+"', mode: 'ajax' } );\" onmouseout=\"DL.fhide();\"><img src='/images/ico_"+type+".gif' alt='' width='15' height='15' class='fico'></a>" );
			n++;
		}

		if( ext.match( /z/ ) ) {
			type = 'zip';
			if( n ) document.writeln( " ");
			document.writeln( "<a href='"+this.dir+"?f="+name+"."+type+"'  onmouseover=\"DL.show( this,  { name: '"+name+"."+type+"', mode: 'ajax' } );\" onmouseout=\"DL.fhide();\"><img src='/images/ico_"+type+".gif' alt='' width='15' height='15' class='fico'></a>" );
		}
		if( ext.match( /r/ ) ) {
			type = 'rar';
			if( n ) document.writeln( " ");
			document.writeln( "<a href='"+this.dir+"?f="+name+"."+type+"'  onmouseover=\"DL.show( this,  { name: '"+name+"."+type+"', mode: 'ajax' } );\" onmouseout=\"DL.fhide();\"><img src='/images/ico_"+type+".gif' alt='' width='15' height='15' class='fico'></a>" );
		}
		if( ext.match( /p/ ) ) {
			type = 'pdf';
			if( n ) document.writeln( " ");
			document.writeln( "<a href='"+this.dir+"?f="+name+"."+type+"'  onmouseover=\"DL.show( this,  { name: '"+name+"."+type+"', mode: 'ajax' } );\" onmouseout=\"DL.fhide();\"><img src='/images/ico_"+type+".gif' alt='' width='15' height='15' class='fico'></a>" );
		}

	}
	
	this.init();
}

DL_ok = true;
