var show_e;
var show_img;

var flag=0;

var contentid;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

function E(id) {
 	var e = document.getElementById(id);
 	if(e) return e;
 	return null;
}

function showHideElement(element_id) {
	var e = document.getElementById(element_id);
	if(e) {
		if(e.style.display == 'none') e.style.display = '';
		else e.style.display = 'none';
	}
}

function guestflash(name) {
	if(!contentid) {
		var img = document.getElementById('dummyflashimg' + name);
		var span = document.getElementById('dummyflashspan' + name);

		if(img && span) {
			var flashname = img.getAttribute('flashname');
			var width = img.getAttribute('width');
			var height = img.getAttribute('height');

			if(!width) width = img.getAttribute('flashwidth');
			if(!height) height = img.getAttribute('flashheight');

			AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width',width,'height',height,'src',flashname,'quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie',flashname );
		}
	}
}

function setflag(cur, flagname) {
	var status = cur.checked;

	var e = null;

	for(i=1;i<=1000;i++) {
		e = document.getElementById(flagname + i);
		if(!e) break;
		e.checked = status;
	}
}

function setRadio(radio, value) {
	for(var i=0;i<radio.length;i++) {
		if(radio[i].value == value) radio[i].checked = true;
	}
	return 0;
}

function itemTestForm(form) {
	var e = null;
	var res = '';
	var require;
	var mincount;
	var minvalue;
	var fieldname;

	if(form)
	for(var i=0;i<form.childNodes.length;i++) {
		e = form.childNodes[i];

		if(e.getAttribute) {
			require = e.getAttribute('require');
			mincount = e.getAttribute('mincount');
			minvalue = e.getAttribute('minvalue');
			fieldname = e.getAttribute('fieldname');

			if(require) {
				if((e.value==0)||(e.value=='')||(e.getAttribute('type')=='checkbox' && !e.checked)) {
					res = res + 'не заполнено поле ' + require + '<br>';
				}
			}
			
			if(mincount) {
				if((e.value.length<mincount)) {
					res = res + 'неверное количество символов в поле ' + fieldname + '<br>';
				}
			}
			
			if(minvalue) {
				if((e.value<minvalue)) {
					res = res + 'слишком маленькое значение в поле ' + fieldname + '<br>';
				}
			}

			res = res + itemTestForm(e);
		}
	}

	return res;
}

function testForm(form) {
	var e = null;
	var res = '';

	res = itemTestForm(form);

	if(res) {
		res = '<b>Не верно заполнены поля:</b><br>' + res;
		showMessage(res);
		return false;
	}

	return true;
}

function confirmQuery(text, url) {
	if(confirm(text)) location.replace(url);
}

function setSelect(name, value) {
	var e = document.getElementById(name);
	if(e) {
		e.selectedIndex = 0;
		for(var i=0;i<e.length;i++) {
			if(e.options[i].value==value) e.selectedIndex = i;
		}
	}
}

function writeFlash(w, h, url) {
	document.write('<object id="flash_obj" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + w + '" height="' + h + '" id="final" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="' + url + '" />');
	document.write('<param name="loop" value="true" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="quality" value="best" />');
	document.write('<param name="scale" value="noscale" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="bgcolor" value="#000000" />');
	document.write('<embed src="' + url + '" loop="true" menu="false" quality="best" scale="noscale" wmode="transparent" bgcolor="#000000" width="' + w + '" height="' + h + '" name="final" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function showFlashWin(x,y,flash,title) {
	if (flag == 1) {
		sw.close();
		flag=0;
	}

	//x = x + 20;
	//y = y + 20;


	eval("sw=window.open('',title,'top=20,left=220,width='+x+',height='+y+',scrollbars=no,resizable=no')");

	sw.document.write("<html><head><title>"+title);
	sw.document.write("</title></head><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
	sw.document.write("<center><table width='100%' height='100%' cellspacing=0 cellpadding=0 border=0><tr><td align=center>");
	sw.document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='"+x+"' height='"+y+"'><param name='movie' value='"+flash+"'><param name='quality' value='high'><embed src='"+flash+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='400' height='240'></embed></object>");
	sw.document.write("</td></tr></table>");
	sw.document.write("</center>");
	sw.document.write("</body></html>");
	sw.document.close();

	sw.focus();
	flag = 1;
}

function showwin(x,y,url) {
	showfoto(x, y, url);
}

var showing_image;
var showing_overlay;
var showing_closebtn;
var showing_image_alpha = 0;
var showing_preloader;
var showing_preloader_div;
var preloaderImagePosition = 0;
var preloaderIntervalID = 0;
var showing_isIE = (navigator.appVersion.indexOf('MSIE') > 0) ? true : false;

function showfoto(x, y, url) {
	if (window.editor && editor.element) return;
	
	var isIE = (navigator.appVersion.indexOf('MSIE') > 0) ? true : false;
	
	var pagesize = getPageSize();
	
	
	var onclick = function () {
		var i;
		if (window.showing_overlay) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_overlay)	
				document.body.removeChild(showing_overlay);
			}
			showing_overlay = null;
		}
		if (window.showing_preloader_div) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_preloader_div)	
				document.body.removeChild(showing_preloader_div);
			}
			showing_preloader_div = null;
		}
		if (window.showing_closebtn) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_closebtn)	
				document.body.removeChild(showing_closebtn);
			}
			showing_closebtn = null;
		}
		if (window.showing_image) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_image)	
				document.body.removeChild(showing_image);
			}
			
			showing_image = null;
		}
		if (preloaderIntervalID) {
			clearInterval(preloaderIntervalID);
			preloaderIntervalID = 0;
		}
	}
	
	showing_overlay = document.createElement('div');
	showing_overlay.id = 'showfoto-overlay';
	showing_overlay.className = 'fixed';
	showing_overlay.style.width = '100%';
	showing_overlay.style.height = '100%';
	showing_overlay.style.top = '0px';
	showing_overlay.style.left = '0px';
	showing_overlay.style.backgroundColor = '#000000';
	showing_overlay.style.zIndex = '1000';
	showing_overlay.onclick = onclick;
	document.body.appendChild(showing_overlay);
	
	showing_preloader = document.createElement('img');
	showing_preloader.style.display = 'block';
	showing_preloader_div = document.createElement('div');
	showing_preloader_div.className = 'fixed';
	showing_preloader_div.style.zIndex = '1001';
	showing_preloader_div.style.overflow = 'hidden';
	showing_preloader_div.onclick = onclick;
	showing_preloader_div.appendChild(showing_preloader);
	document.body.appendChild(showing_preloader_div);
	
	showing_preloader.onload = function () {
		showing_preloader.onload = null;
		showing_preloader.style.width = showing_preloader.width + 'px';
		showing_preloader.style.height = showing_preloader.height + 'px';
		showing_preloader_div.style.width = showing_preloader.width + 'px';
		showing_preloader_div.style.height = showing_preloader.width + 'px';
		showing_preloader_div.style.top = ((pagesize[3] - showing_preloader.width) / 2) + 'px';
		showing_preloader_div.style.left = ((pagesize[2] - showing_preloader.width) / 2) + 'px';
		
		if (isIE6()) {
			showing_preloader.src = '/img/spacer.gif';
			showing_preloader.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/preloader.png', sizingMethod='scale')";
		}
		
		
		preloaderIntervalID = setInterval('showPreloaderOnTimer('+showing_preloader.width+', '+showing_preloader.height+')', 60);
	}
	showing_preloader.src = 'img/preloader.png';
	
	
	
	if (isIE) {
		showing_overlay.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
	} else {
		showing_overlay.style.opacity = '0.5';
	}
	
	showing_image = document.createElement('img');
	showing_image.onload = function () {
		var imgwidth = showing_image.width;
		var imgheight = showing_image.height;
		
		if (pagesize[2] < showing_image.width + 30 || pagesize[3] < showing_image.height + 30) {
			imgwidth = pagesize[2] - 30;
			imgheight = showing_image.height * imgwidth / showing_image.width;
			if (imgheight > pagesize[3] - 30) {
				imgheight = pagesize[3] - 30;
				imgwidth = showing_image.width * imgheight / showing_image.height;
			}
			showing_image.style.width = Math.round(imgwidth) + 'px';
			showing_image.style.height = Math.round(imgheight) + 'px';
			//alert(showing_image.style.width + ' x ' + showing_image.style.height)
		}
	
		
		showing_image.className = 'fixed';
		showing_image.style.left = (pagesize[2] - imgwidth) / 2 + 'px';
		showing_image.style.top = (pagesize[3] - imgheight) / 2 + 'px';
		showing_image.style.border = '5px solid #FFF';
		showing_image.style.backgroundColor = "#FFF";
		showing_image.style.zIndex = '1001';
		showing_image_alpha = 0;
		document.body.appendChild(showing_image);
		
		
		showing_closebtn = document.createElement('img');
		showing_closebtn.style.width = '30px';
		showing_closebtn.style.height = '30px';
		if (isIE6()) {
			showing_closebtn.src = '/img/spacer.gif';
			showing_closebtn.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/close.png', sizingMethod='scale')";
		} else {
			showing_closebtn.src = '/img/close.png';
		}
		showing_closebtn.className = 'fixed';
		showing_closebtn.style.left = ((pagesize[2] + imgwidth) / 2 - 5) + 'px';
		showing_closebtn.style.top = ((pagesize[3] - imgheight) / 2 - 15) + 'px';
		showing_closebtn.style.cursor = 'pointer';
		showing_closebtn.style.zIndex = '1002';
		document.body.appendChild(showing_closebtn);
		
		
		showing_image.onclick = onclick;
		showing_closebtn.onclick = onclick;
		
		myscroll();
		
		if (isIE) {
			showing_image.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
		} else {
			showing_image.style.opacity = '0';
			showing_closebtn.style.opacity = '0';
		}
		
		showfotoontimer();
		showing_preloader_div.style.display = 'none';
		if (preloaderIntervalID) {
			clearInterval(preloaderIntervalID);
			preloaderIntervalID = 0;
		}
	}
	
	showing_image.src = url;
}

function showPreloaderOnTimer(width, height) {
	preloaderImagePosition += width;
	if (preloaderImagePosition >= height) preloaderImagePosition = 0;
	if (showing_preloader) showing_preloader.style.marginTop = '-' + preloaderImagePosition + 'px';
	
}

function showfotoontimer() {
	showing_image_alpha = showing_image_alpha + 5;
	
	if (showing_isIE) {
		showing_image.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity="+showing_image_alpha+")";
	} else {
		showing_image.style.opacity = showing_image_alpha / 100;
		showing_closebtn.style.opacity = showing_image_alpha / 100;
	}
	
	if (showing_image_alpha < 100) {
		setTimeout('showfotoontimer()', 30);
	}
}

function showflash(page,x,y)
{
	eval("sf=window.open(Name=\""+page+"\",\"FLASH\",\"top=20,left=220,width="+x+",height="+y+",scrollbars=no,resizable=no\")")
}

function domenu(id,e,img) {
	if(id == pageid) {
		e = document.getElementById(e);
		img = document.getElementById(img);
		if(e&&img) {
			//show(e,img);
			show_e = e;
			show_img = img;
		} else alert("Ошибка");
	}
	return 0;
}

function showmenu() {
	if(show_e && show_img) show(show_e, show_img);
}

function catalog_bask(zena,count) {
	if(document.getElementById('catalog_count')) catalog_count.innerText = count;
	if(document.getElementById('catalog_zena')) catalog_zena.innerText = zena;
}

var ArrayBaskId = new Array();

function parce_baskinfo() {
	var s = document.getElementById('baskinfo').innerHTML;
	listID = s.split(';');
	for (var i = 0; i < listID.length; i++) {
		if(listID[i] != "") {
			m = listID[i].split(':');
			ArrayBaskId[m[0]] = m[1];
		}
	}
}

function catalog_check(id,e) {
	if(ArrayBaskId[id]!=null) {
		e = document.getElementById(e);
		/*if(e) e.checked = "true";
		else e.checked = "false";*/
		if(e) e.value = ArrayBaskId[id];
	}
}

function catalog_buy(cost,id,e) {
	e = document.getElementById(e);
	//ordertype = document.getElementById(ordertype);

	if(e==null) alert("Ошибка скрипта");

	//check = e.checked;
	colbuy = e.value;
	if(colbuy=="") colbuy = 0;

	location.href='./buy.php?id=' + id + '&colbuy=' + colbuy;
	return;

	if(window.showModalDialog==null) {
		location.href='./?act=buy&page=' + id + '&colbuy=' + colbuy;
		return;
	}

	/*if(document.frames('doframe')) document.frames('doframe').location.href='./?act=buy&frame=1&id=' + id;
	else location.href='./?act=buy&id=' + id;*/

	if(document.getElementById('catalog_count')) count = catalog_count.innerText;
	if(document.getElementById('catalog_zena')) oldzena = catalog_zena.innerText;

	if(zena==null) zena = 0;
	if(count==null) count = 0;

	oldcol = 0;
	if((ArrayBaskId[id]!=null)&&(ArrayBaskId[id]!=0)) {
		oldcol = ArrayBaskId[id];
		if(colbuy==0) {
			count--;
		}
	} else {
		if(colbuy>0) count++;
	}
	ArrayBaskId[id] = colbuy;

	cost = parseInt(zena) * colbuy + parseInt(oldzena) - parseInt(zena) * oldcol;

	catalog_bask(cost,count);

	window.showModalDialog('./?act=buy&frame=1&page=' + id + '&colbuy=' + colbuy, '', 'menubar=no,directories=no,location=no,toolbar=no,scrollbars=no,status=no,resizable=no,height=15,width=350,dialogWidth:350px; dialogHeight:15px');
}

function catalog_col_keypres(id,onewcol,zena,ocol,ordertype) {
	if(event.keyCode==13) catalog_modify(id,onewcol,zena,ocol,ordertype);
	if((event.keyCode<48)||(event.keyCode>57)) event.keyCode = 0;
}

function catalog_newcol_keypres(zena,id,text_buy,ordertype) {
	if(event.keyCode==13) catalog_buy(zena,id,text_buy,ordertype);
	if((event.keyCode<48)||(event.keyCode>57)) event.keyCode = 0;
}

function catalog_modify(id,onewcol,zena,ocol,ordertype) {
	onewcol = document.getElementById(onewcol);
	ocol = document.getElementById(ocol);
	ordertype = document.getElementById(ordertype);

	if((onewcol==null)||(ocol==null)||(ordertype==null)) alert('Ошибка определения ID. \n Ваш браузер не поддрердивает JavaScript');

	if(ordertype.checked) ot = 1;
	else ot = 0;

	newcol = onewcol.value;
	if(newcol=="") newcol = 0;
	oldcol = ocol.value;
	ocol.value = newcol;

	/*var sum = document.all.catalog_sum.innerText;
	var nalcurs = document.all.catalog_nalcurs.innerText;
	var beznalcurs = document.all.catalog_beznalcurs.innerText;
	var nalitogo = document.all.catalog_nalitogo.innerText;
	var beznalitogo = document.all.catalog_beznalitogo.innerText;

	sum = parseInt(sum,10) + zena*(newcol-oldcol);
	nalitogo = parseInt(nalitogo,10) + zena*(newcol-oldcol)*nalcurs;
	beznalitogo = parseInt(beznalitogo,10) + zena*(newcol-oldcol)*beznalcurs;

	document.all.catalog_sum.innerText = sum;
	document.all.catalog_nalitogo.innerText = nalitogo;
	document.all.catalog_beznalitogo.innerText = beznalitogo;

	onewcol.select();

	if(document.all.doframe) document.all.doframe.src='./?act=modify&fast=1&id=' + id + '&center=buy&newcol='+newcol;
	else location.href='./?act=modify&id=' + id + '&center=buy&newcol='+newcol;*/

	location.href='./?act=modify&id=' + id + '&center=buy&newcol='+newcol+'&ordertype='+ot;
}

// Создание массива для хранения ссылок на дочерние окна.
/* Каждый член данного массива будет окном объекта, созданного
ниже с использованием метода createWindow. */
var windows = new Array();

function newWindow(url, wname) {
// Конструктор для окна
/* Данная функция может быть вызвана только функцией
   createWindow, которая приведена ниже. */
var features = "";
if (null != arguments[2])
   features = arguments[2];
return window.open(url, wname, features);
}

function createWindow(url, wname) {
// Добавление окна в семейство окон.
var features = arguments[2] == null ? "" : arguments[2];
windows[wname] = new newWindow(url, wname, features);
windows[wname].focus();
}

function closeWindows() {
// Закрытие всех окон, открытых методом addWindow.
/* Для закрытия окна вызывается его метод close. */
/* Данная функция может быть вызвана в ходе события onunload
   для автоматического закрытия всех открытых окон.  */
for (w in windows)
   if (!windows[w].closed)
	  windows[w].close();
}

window.onunload=closeWindows;

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {     
	    xScroll = window.innerWidth + window.scrollMaxX;
	    yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	    xScroll = document.body.scrollWidth;
	    yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	    xScroll = document.body.offsetWidth;
	    yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {     // all except Explorer
	    if(document.documentElement.clientWidth){
	         windowWidth = document.documentElement.clientWidth; 
	    } else {
	         windowWidth = self.innerWidth;
	    }
	    windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	    windowWidth = document.documentElement.clientWidth;
	    windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
	    windowWidth = document.body.clientWidth;
	    windowHeight = document.body.clientHeight;
	}     
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
	    pageHeight = windowHeight;
	} else { 
	    pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){     
	    pageWidth = xScroll;          
	} else {
	    pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function hideSubElements(element) {
	var childrens = element.childNodes;
	for(var i=0;i<childrens.length;i++) {
		if(childrens[i].getAttribute && childrens[i].style.display != 'none') {
	 		childrens[i].setAttribute('washided', true);
	 		childrens[i].style.display = 'none';
		}
	}
}

function showSubElements(element) {
	var childrens = element.childNodes;
	for(var i=0;i<childrens.length;i++) {
		if(childrens[i].getAttribute && childrens[i].style.display == 'none' && childrens[i].getAttribute('washided')) {
			childrens[i].setAttribute('washided', false);
	 		childrens[i].style.display = '';
		}
	}
}

function wrapSubElements(element, tagname) {
 	if(element.childNodes.length == 1) {
 	 	return element.childNodes[0];
	} else {
	 	var node = document.createElement(tagname);
	 	element.appendChild(node);
	 	
	 	var childrens = element.childNodes;
	 	for(var i=0;i<childrens.length;i++) {
	 	 	node.appendChild(childrens[i]);
		}
		
		return node;
	}
}

var g_dialogcount = 0;
var g_m_dialogconteiner = [];

// возвращает номер текущего диалога в глобальном массиве диалогов начиная с единицы
function currentDialogNum() {
	var root = getRootWindow();
	if(!root.g_m_dialogconteiner[0]) return -1;
 	for(var i=0;i<root.g_m_dialogconteiner.length;i++) {
 	 	if(root.g_m_dialogconteiner[i] && root.g_m_dialogconteiner[i].childNodes[0] && root.g_m_dialogconteiner[i].childNodes[0].contentWindow == window) return i;
	}
}

function getRootWindow() {
 	var win = window;
 	while(win.parent && win.parent != win) {
 	 	win = win.parent;
	}
	return win;
}

function getParentDialog() {
	var root = getRootWindow();
 	//var parentdiv = root.g_m_dialogconteiner[root.g_m_dialogconteiner.length-2];
 	var parentdiv = root.g_m_dialogconteiner[currentDialogNum()-1];
 	if(parentdiv && parentdiv.childNodes && parentdiv.childNodes[0]) {
 		var iframe = parentdiv.childNodes[0];
		return iframe.contentWindow;
	}
}

// закрытие диалога
function closeDialog() {
	var root = getRootWindow();
	
	// если первый диалог, то показываем все элементы, если нет, то показываем предыдущий диалог
	if(root.g_dialogcount == 1) {
		root.showSubElements(root.document.body);
		
		var node = root.g_m_dialogconteiner.pop();
		root.g_dialogcount--;
		if (node.closeWindow) node.closeWindow();
 		else node.parentNode.removeChild(node);
	} else {
		var obj = root.g_m_dialogconteiner[root.g_m_dialogconteiner.length-2];
		var node = root.g_m_dialogconteiner.pop();
		root.g_dialogcount--;
		
		if (obj.css) {
			node.closeWindow();
		} else {
			obj.style.display = '';
			node.parentNode.removeChild(node);
		}
	}
}

function createDialog(pid) {
	mod = arguments[1];
	
 	// старый вариант
 	/*if(pid == 'mod') createWindow('dialog/?pid=' + pid + '&center=' + mod + '', 'dialog', 'width=800,height=500,status=no,toolbar=no,menubar=no,scrollbars=yes');
 	else createWindow('dialog/?pid=' + pid + '&mod=' + mod + '', 'dialog', 'width=800,height=500,status=no,toolbar=no,menubar=no,scrollbars=yes');*/
 	
 	var dialogurl = '';
 	if(!mod) {
 		dialogurl = '?pid=' + pid;
	} else {
 		if(pid == 'mod') dialogurl = '?pid=' + pid + '&center=' + mod + '';
 		else dialogurl = '?pid=' + pid + '&mod=' + mod + '';
	}
 	
 	view = arguments[2];
 	viewplace = arguments[3];
 	viewparam = arguments[4];
 	
 	if(view) {
 	 	dialogurl += '&view_name_'+viewplace+'='+view;
	}
	if(viewparam) {
 	 	dialogurl += '&view_param_'+viewplace+'='+viewparam;
	}
	
	createURLDialog(dialogurl);
}

// создания диалога
function createURLDialog(dialogurl) {
	if (createWindowDialog(dialogurl)) return;
	
 	// новый вариант
 	var root = getRootWindow();
 	
 	dialogurl = '/dialog/' + dialogurl;
 	
 	root.g_dialogcount++;
 	var zindex = root.g_dialogcount + 1000;
	
	// если первый диалог, то скрываем все элементы, если нет, то скрываем все предыдущие диалоги
	if(root.g_dialogcount == 1) hideSubElements(document.body);
	else {
	 	for(var i=0;i<root.g_m_dialogconteiner.length;i++) {
	 	 	root.g_m_dialogconteiner[i].style.display = 'none';
		}
	}
 	
 	var width = '100%';
 	var height = '100%';
 	var framewidth = '100%';
 	var frameheight = '100%';
 	
 	/*if(testIE6()) {
 		var m = getPageSize();
 		var framewidth = m[0];
 		var frameheight = '100%';
	}*/
 	
 	var node = root.document.createElement('div');
 	node.style.width = width;
 	node.style.height = height;
 	node.style.position = 'absolute';
 	node.style.left = '0px';
 	node.style.top = '0px';
 	node.style.zindex = zindex;
 	node.style.backgroundColor = '#FFFFFF';
 	root.document.body.appendChild(node);
 	
 	root.g_m_dialogconteiner.push(node);
 	
 	node.innerHTML = '<iframe id="dialogframe" width="' + framewidth + '" height="' + frameheight + '" src="' + dialogurl + '" border="0" frameborder="0" style="overflow-x:hidden"></iframe>';
}

var dialogWindowReLoaded = new Array();
var currentDialog;

function createWindowDialog(dialogurl) {
	
	var dialogframe;
	var root = getRootWindow();
	if (root != window) return root.createWindowDialog(dialogurl);
	
	try {
		if (!$(window).dialogWin) return false;
		
		var dialogurl = '/dialog/' + dialogurl;
		g_dialogcount++;
		
		var iframeId = 'dialogframe' + g_dialogcount;
		dialogWindowReLoaded[iframeId] = false;
		var iframe = '<iframe id="'+ iframeId + '" src="' + dialogurl + '" border="0" frameborder="0" style="width:100%;height:100%;"></iframe>';
		$(document.body).append(iframe);
		dialogframe = $(document.getElementById(iframeId));

		
		dialogframe.dialogWin({
			closeBtn : true,
			refreshBtn : true,
			maxBtn : true,
			preloader : true,
			preloaderSrc : '/img/preloader2.gif',
			sizeable : true
		}).hideWindow();
		//dialogframe.css('opacity', '0');
		//
		dialogframe.load(getOnLoad(dialogframe));
		root.g_m_dialogconteiner.push(dialogframe);
		
		try {
			myscroll()	
		} catch(er) { }
		
	} catch (e) {
		return false;
	}
	
	return true;
	
	function getOnLoad(dialogframe) {
		return function (e) {
			var frame = e.target;
			dialogframe.showWindow();
			
			var caption = $(frame.contentWindow.document).find('title').html();
			if (caption.length > 40) caption = caption.substr(0,37) + '...';;
			
			var obj = $(frame.contentWindow.document.getElementById('center'));
			var width = obj.width();
			var height = obj.height();
			
			var disableSizeable = false;
			
			var contDOM = frame.contentWindow.document.getElementById('maincont');
			if (contDOM) {
				var cont = $(contDOM);

				var contWidth = parseInt(cont.css('width'));
				var contHeight = parseInt(cont.css('height'));
				if (contWidth) width = contWidth;
				if (contHeight) height = contHeight;
				
				cont.css('width', '100%');
				cont.css('height', '100%');
				
				
				if (cont.css('min-width') == cont.css('max-width') && cont.css('min-height') == cont.css('max-height')) {
					disableSizeable = true;	
				}
				
			}
			
			
			
			
			dialogframe
				.setWindowSize(width, height, true)
				.css('width',  '100%')
				.css('height', '100%')
				.css('opacity', 1)
				.hidePreloader()
				.setCaption(caption);
			if (disableSizeable) {
				dialogframe.setSizeable(false);
			}
			dialogWindowReLoaded[frame.id] = true;
		}
	}
}

var g_testie6 = null;
function testIE6() {
	if(g_testie6) {
	 	if(g_testie6 == 1) return true;
	 	else if(g_testie6 == 2) return false;
	}
	
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	
	var re = new RegExp('; MSIE 6\.*;', "gim");

	if(b_version.search(re) != -1) {
		g_testie6 = 1;
		return true;
	} else {
		g_testie6 = 2;
		return false;
	}
} 
function onScrollAjaxHider() {
	if(testIE6()) {
		if(E('ajaxhider')) E('ajaxhider').style.top = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		if(E('popuphider')) E('popuphider').style.top = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		if(E('messagecont')) E('messagecont').style.top = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	}
}
//window.onscroll = onScrollAjaxHider;

function fakeSelect(sel) {
	var fake = E(sel.id + 'val');
	if(fake) {
		fake.innerHTML = sel.options[sel.selectedIndex].innerHTML;
	}
}

function showMessage(mess) {
	
	if(E('messagecont')) document.body.removeChild(E('messagecont'));
	
	var div = document.createElement('div');
	div.className = 'messagecont fixed';
	div.id = 'messagecont';
	div.innerHTML = '<table class="h"><tr><td><a href="#" onclick="E(\'messagecont\').style.display=\'none\';return false;">Close</a><div class="messagetext" id="messagetext">' + mess + '</div></td></tr></table>';
	document.body.appendChild(div);
}

function hideMessage() {
	if(E('messagecont')) document.body.removeChild(E('messagecont'));
}

function shadow() {
	//$(".textshadow").textShadow({x: 1, y: 1, radius: 3, color: "#000000"});
}

var g_isie6 = 0;

function isIE6() {
	if(g_isie6) {
	 	if(g_isie6 == 1) return true;
	 	else if(g_isie6 == 2) return false;
	}
	
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	
	var re = new RegExp('; MSIE 6\.*;', "gim");

	if(b_version.search(re) != -1) {
		g_isie6 = 1;
		return true;
	} else {
		g_isie6 = 2;
		return false;
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
			node = document;
	if ( tag == null )
			tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
					classElements[j] = els[i];
					j++;
			}
	}
	return classElements;
}

function myscroll() {
	if(isIE6()) {
		var top = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		var left = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
		var m_fixed_elements = getElementsByClass('fixed');
		for(i=0;i<m_fixed_elements.length;i++) {
			var fixedtop = m_fixed_elements[i].getAttribute('fixedtop');
			if(!fixedtop) {
				fixedtop = parseInt(m_fixed_elements[i].style.top);
				if (!fixedtop) fixedtop = 0;
				if (fixedtop == 0) fixedtop = 'zero';
				m_fixed_elements[i].setAttribute('fixedtop', fixedtop);
			}
			if (!fixedtop) fixedtop = 0;
			if (fixedtop == 'zero') fixedtop = 0;
			m_fixed_elements[i].style.top = (fixedtop + top) + 'px';
			
			
			var fixedleft = m_fixed_elements[i].getAttribute('fixedleft');
			if(!fixedleft) {
				fixedleft = parseInt(m_fixed_elements[i].style.left);
				if (!fixedleft) fixedleft = 0;
				if (fixedleft == 0) fixedleft = 'zero';
				m_fixed_elements[i].setAttribute('fixedleft', fixedleft);
			}
			if (!fixedleft) fixedleft = 0;
			if (fixedleft == 'zero') fixedleft = 0;
			m_fixed_elements[i].style.left = (fixedleft + left) + 'px';
		}

	}
}

window.onscroll = myscroll;


