// ..................................................................

function upCart(){
	var httpRequest;
	if (window.XMLHttpRequest){// Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType)
		{
			httpRequest.overrideMimeType('text/xml');
		}//if mime
	}else if (window.ActiveXObject){// IE
		try{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){}
		}
	}
	if (!httpRequest){
		alert('Не могу создать экземпляр XMLHTTP');
		return false;
	}
	url='/ajax/minicart.php';
	httpRequest.onreadystatechange = function(){upContents(httpRequest);};
	httpRequest.open('GET', url, true);
	httpRequest.send('');
}//sub upcart

function upContents(httpRequest){
	
	if (httpRequest.readyState == 4){
		if (httpRequest.status == 200){
				findObj('topcart').innerHTML=httpRequest.responseText;
				if(qsoft_need_check_cart_summ==true){
					var text=httpRequest.responseText;
					var from=text.indexOf('cумма: ');
					if(from > 0){
						var to=text.indexOf('руб');
						if(to >0){
							var summ=text.substr(from+7,to-from-7);
							summ=summ.replace(' ','');
							if(parseFloat(summ) < 2000.0){
								document.getElementById('cartimage').alt='Сумма заказа недостаточна для оформления (меньше 2000руб)';
								document.getElementById('cartimage').title='Сумма заказа недостаточна для оформления (меньше 2000руб)';
							}else{
								document.getElementById('cartimage').title='Корзина';
								document.getElementById('cartimage').alt='Корзина';
							}
							//alert('from '+from+' to '+to+' res:['++']');
						}
					}
				}
		}else{
			alert('Проблема с запросом.');
		}
	}
}

function check_krt(i1,obj)
{
	if(parseInt(obj.value)<i1)
	{
		if(confirm("Внимание, укажите количество с учетом кратности! Ближайшее большее "+i1+". Округлить? "))
		{
			obj.value=i1;
			obj.focus();
		}
		else
		{
			obj.focus();
			return false;
		}
	}else
	if((parseInt(obj.value)%i1)!=0)
	{
		
		var v=i1*Math.ceil(obj.value / i1);
		if(confirm("Внимание, укажите количество с учетом кратности! Ближайшее большее "+v+". Округлить? "))
		{
			obj.value=v;
			obj.focus();
		}
		else
		{
			obj.focus();
			return false;
		}
	}
	
	return true;
}

function check_krt_color(i1, obj, row_obj)
{
	if( (parseInt(obj.value)<i1) || ((parseInt(obj.value)%i1)!=0) ) 
	{
		row_obj.style.backgroundColor="#ffc8c8";
	}
	else
		row_obj.style.backgroundColor="";
}

var krt_start=new Array();
function check_krt_start_step(i1,obj, obj_row)
{
	var v=0;
	if(parseInt(obj.value)<i1)
	{
		v=i1;
	}else
	if((parseInt(obj.value)%i1)!=0)
	{
	
		v=i1*Math.ceil(obj.value / i1);
	}
	
	if(v>0)
		krt_start[krt_start.length]=[obj,v,obj_row];
}

function check_krt_start()
{
	if(krt_start.length>0)
	{
		$('#confirm').jqm({overlay: 60, modal: true, trigger: false, toTop: true});
		  
	    check_krt_confirm("Внимание! Указанное Вами количество к заказу не соответствует кратности отпуска!<br><br>Возможно:<br>- Исправить количество вручную (сейчас эти позиции выделены в корзине красным цветом).<br><br>- Округлить количество автоматически по всем некорректным позициям до большего кратного (после округления позиции будут выделяться в корзине зеленым цветом) "); 
	}
}

function check_krt_start_submit()
{
	for(var i=0;i<krt_start.length;i++)
	{
		krt_start[i][0].value=krt_start[i][1];
		krt_start[i][2].style.backgroundColor="#ade8a5";
	}
}


var krt_runtime=new Array();
function check_krt_runtime_step(i1,obj,row)
{
	krt_runtime[krt_runtime.length]=[obj,i1,row];
}

function check_krt_runtime()
{
	var krt_runtime_fix=new Array();
	
	for(var i=0;i<krt_runtime.length;i++)
	{
		var v=0;
		if(parseInt(krt_runtime[i][0].value)<krt_runtime[i][1])
		{	
			v=krt_runtime[i][1];
		}else
			if((parseInt(krt_runtime[i][0].value)%krt_runtime[i][1])!=0)
			{
				
				v=krt_runtime[i][1]*Math.ceil(krt_runtime[i][0].value / krt_runtime[i][1]);
			}

		if(v>0)
			krt_runtime_fix[krt_runtime_fix.length]=[krt_runtime[i][0],v];
	}
	
	if(krt_runtime_fix.length>0)
	{
		if(confirm("Внимание, укажите количество к заказу с учетом кратности! Округлить до ближайшего большего кратного? "))
		{
			for(var i=0;i<krt_runtime_fix.length;i++)
			{
				krt_runtime_fix[i][0].value=krt_runtime_fix[i][1];
			}
			return true;
		}
		else
			return false;
	}
	return true;
}


var curfoto=new Array();
function check_update()
{
	
	if(secs){
	if(secs==0)updatePage();
	else setTimeout("check_update()",1000);
	}else updatePage();
}
function hide_descr(total)
{
	setCookie('descr_c','hide');
	if(!total)total=100000;
	findObj('descr_td').style.display='none';
	findObj('descr_title').style.width='1%';
	findObj('name_title').style.width='100%';
	findObj('descr_plus').style.display='';
	
	for(i=0;i<=total;i++)
	{
		obj=findObj('descr_td3'+i);
		obj2=findObj('descr_img'+i);
		if(obj && obj2)
		{
			obj.style.display='none';
			obj2.style.display='';
		
		}else
		return;
	}
}
function show_descr(total)
{
	setCookie('descr_c','show');
	if(!total)total=100000;
	
	//findObj('descr_ch').checked=true;
	findObj('descr_td').style.display='';
	findObj('descr_title').style.width='50%';
	findObj('name_title').style.width='50%';
	findObj('descr_plus').style.display='none';
	
	for(i=0;i<=total;i++)
	{
		obj=findObj('descr_td3'+i);
		obj2=findObj('descr_img'+i);
		if(obj && obj2)
		{
			obj.style.display='';
			obj2.style.display='none';
		
			
		}else
		return;
	}
}
function hide_descr2(total)
{
	setCookie('descr_c','hide');
	if(!total)total=100000;
	if(findObj('descr_td'))
	findObj('descr_td').style.display='none';
	
	if(findObj('descr_title'))
	findObj('descr_title').style.width='1%';
	
	if(findObj('descr_plus'))
	findObj('descr_plus').style.display='';
	
	if(findObj('descr_td2'))
	findObj('descr_td2').style.display='none';
	
	if(findObj('descr_title2'))
	findObj('descr_title2').style.width='1%';
	
	if(findObj('descr_plus2'))
	findObj('descr_plus2').style.display='';
	
	for(i=0;i<=total;i++)
	{
		obj=findObj('descr_td3'+i);
		obj2=findObj('descr_img'+i);
		if(obj && obj2)
		{
			obj.style.display='none';
			obj2.style.display='';
		
		}else
		return;
	}
}
function show_descr2(total)
{
	setCookie('descr_c','show');
	if(!total)total=100000;
	
	if(findObj('descr_td'))
	findObj('descr_td').style.display='';
	
	if(findObj('descr_title'))
	findObj('descr_title').style.width='50%';
	
	if(findObj('descr_plus'))
	findObj('descr_plus').style.display='none';
	
	if(findObj('descr_td2'))
	findObj('descr_td2').style.display='';
	
	if(findObj('descr_title2'))
	findObj('descr_title2').style.width='50%';
	
	if(findObj('descr_plus2'))
	findObj('descr_plus2').style.display='none';
	
	
	
	
	
	
	
	
	for(i=0;i<=total;i++)
	{
		obj=findObj('descr_td3'+i);
		obj2=findObj('descr_img'+i);
		if(obj && obj2)
		{
			obj.style.display='';
			obj2.style.display='none';
		
			
		}else
		return;
	}
}
function submit_form2(act)
{
	url="/market/catalog/action.php?action=ADD_TO_COMPARE_LIST"
	for(i=1;i<=100000;i++)
	{
		obj=findObj('comp'+i);
		if(obj){
		if(obj.checked) url=url+'&compare_'+obj.value+'='+obj.value;
		}else {break;}
	}
	//alert(url);
	
	openWindow(url, 'temp', 'yes', 'no', 980, 650, 'center');
	
}

function change_image(id,total)
{
	if(!curfoto[id])curfoto[id]=0;
	
	
	if((curfoto[id]+1)>=total)curfoto[id]=0;else
	curfoto[id]=curfoto[id]+1;
	
	for(i=0;i<=total;i++)
	{
		obj=findObj('img'+id+'_'+i);
		if(obj){
			if((curfoto[id])==i)
			{
				
				obj.style.display='';
				
				
			}else
			
			 obj.style.display='none';
			}
		}
	//alert(cc);
	//findObj('img'+id+'_'+cc).style.display="";
}
function change_image_prev(id,total)
{
	if(!curfoto[id])curfoto[id]=0;
	
	
	if(curfoto[id]==0)curfoto[id]=total-1;else
	curfoto[id]=curfoto[id]-1;
	
	for(i=0;i<=total;i++)
	{
		obj=findObj('img'+id+'_'+i);
		if(obj){
			if((curfoto[id])==i)
			{
				
				obj.style.display='';
				
				
			}else
			
			 obj.style.display='none';
			}
		}
	//alert(cc);
	//findObj('img'+id+'_'+cc).style.display="";
}
function selectText(_obj)
{
	var range = _obj.createTextRange();
	if (!range)
	{
		range = _obj.createRange();
	}
	if (range) range.select();
}

// ..................................................................

function ltrim(source)
{
	var index = 0;
	while( source.charAt(index) == " " ) index++;
	return source.substr(index);
}

function rtrim(source)
{
	var index = source.length - 1;
	while( source.charAt(index) == " " ) index--;
	return source.substring(0, index + 1);
}

function trim(source)
{
	return ltrim(rtrim(source));
}

// ..................................................................

function hideNotice()
{
	findObj("e_notice").style.display = "none";
}

// ..................................................................

function showNotice()
{
	n_div = findObj("e_notice");

	seconds = 4000;
	if (findObj("notice_message").innerHTML.length > 200) seconds = 7000;
	
	this_top = (document.body.clientHeight - 200) / 2;
	this_left = (document.body.clientWidth - 300) / 2;
	n_div.style.left = this_left + 'px';
	n_div.style.top  = this_top + 'px';
	n_div.style.display = "block";
	setTimeout("hideNotice()", seconds);
}

// ..................................................................

function setCookie(name, value)
{
	eval("document.cookie = \"" + name + "=" + value + "; path=/; expires=Wed, 1 Jan 2050 00:00:00 GMT;\"");
}
function deleteCookie(name)
{
	eval("document.cookie = \"" + name + "=1; path=/; expires=Wed, 1 Jan 2000 00:00:00 GMT;\"");
}

// ..................................................................

function findObj(n, d)
{ 
	var p, i, x;

	if(!d) d = document;
	if((p = n.indexOf("?")) > 0 && parent.frames.length)
	{
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}

	for(i = 0; !x && i < d.forms.length; i++)
	{
		x = d.forms[i][n];
	}
//alert();
	if(!x)
	{
		if(!(x = d[n]) && d.all)
		{
			x = d.all[n];
		}
		for(i = 0; !x && d.layers && i < d.layers.length; i++)
		{
			x = findObj(n, d.layers[i].document);
		}
		if(!x && document.getElementById)
		{
			x = document.getElementById(n);
		}
	}

	return x;
}

function EnableObject(obj_name, bEnable)
{
	obj = findObj(obj_name);
	if (obj)
	{
		obj.disabled = (bEnable) ? false : true;
	}
}

/*function displayObj(obj_name, bDisplay)
{
	obj = findObj(obj_name);
	if (obj)
	{
		obj.style.display = (bDisplay) ? "block" : "none";
	}
}*/
function displayObj(obj_name, bDisplay)
{
	var str = new String(obj_name);
	var objs = str.split(",");
	for (var i = 0; i < objs.length; i++)
	{
		obj = findObj(trim(objs[i]));
		if (obj)
		{
			obj.style.display = (bDisplay) ? "block" : "none";
		}
	}
}

// ..................................................................

function foldObj(obj_name)
{
	obj_link = findObj(obj_name);
	obj_content = findObj(obj_name + 'content');	
	if (obj_link && obj_content)
	{
		if (obj_content.style.display == "none")
		{
			obj_content.style.display = "";
			obj_link.className = "gray dotted click"
		}
		else
		{
			obj_content.style.display = "none";
			obj_link.className = "blue-a hover-red dotted click"
		}
	}
}

// ..................................................................

function openWindow(href, title, scroll, resizable, width, height, position, return_window)
{
	if(scroll != "yes")
	{
		scroll = "no";
	}

	if(resizable != "yes")
	{
		resizable = "no";
	}

	var xx = null;
	if(position != 'center')
	{
		xx = window.open(href, title, 'toolbar=no, scrollbars=' + scroll + ', menubar=no, directories=no, status=no, resizable=' + resizable + ', width=' + width + ', height=' + height);
	}
	else
	{
		this_top = (screen.height - height) / 2;
		this_left = (screen.width - width) / 2;
		xx = window.open(href, title, 'toolbar=no, scrollbars=' + scroll + ', menubar=no, directories=no, status=no, resizable=' + resizable + ', width=' + width + ', height=' + height + ', top=' + this_top + ', left=' + this_left);
	}

	if (xx)	xx.focus();

	return (return_window) ? xx : false;
}

// ..................................................................

function imagePopup(imageUrl, imageW, imageH, title)
{
	x3 = imageW;
	y3 = imageH;
	x4 = (screen.width < 2000) ? (screen.width / 2 - (x3 / 2)) : (screen.width / 4 - (x3 / 2));
	y4 = screen.height / 2 - (y3 / 2);
	mywin = window.open('', 'big', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=' + x3 + ',height=' + y3 + ',top=' + y4 + ',left=' + x4 + '');
	mywin.document.open();
	mywin.document.write("<html><head><title>"+title+"</title><style>body { overflow:-moz-scrollbars-none; }</style></head><body bgcolor=#ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><a href='javascript:window.close()'><img src='" + imageUrl + "' border=0></a></body></html>");
	mywin.document.close();
	mywin.focus();
	return false;
}

// ..................................................................

function changeLocation(theURL)
{
	document.location.href = theURL;

	return false;
}

// ..................................................................

function confirm_submit(obj, str)
{
	form = findObj(obj);

	if(confirm(str))
	{
		form.submit();
	}
}

// ..................................................................

function validEmail(email)
{
	var not_valid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4})(\]?)$/;

	if(not_valid.test(email) || !valid.test(email)) return false;
	else return true;
}

function validEmails(_emails)
{
	var emails = new String(_emails); 
	var emails_array = emails.split(",");

	if (emails_array.length > 0)
	{
		for (var i = 0; i < emails_array.length; i++)
		{
			if (!validEmail(trim(emails_array[i])))
			{
				return false;
			}
		}
		return true;
	}
	else
	{
		return false;
	}
}

// ..................................................................

function formSetRequirements(obj, req, check, friendly_name)
{
	obj = findObj(obj);

	if(obj)
	{
		obj.validateReq		= req;
		obj.validateCheck	= check;

		if (friendly_name)
		{
			obj.friendly_name = friendly_name;
		}
	}
}

// ..................................................................

function formSetUnique(obj, unique)
{
	obj = findObj(obj);
	
	if(obj)
	{
		obj.validateCheckUnique	= true;
		obj.validateUnique	= unique;
	}
}

// ..................................................................

function formSetNotequal(obj1, obj2)
{
	obj1 = findObj(obj1);
	obj2 = findObj(obj2);
	
	if(obj1 && obj2)
	{
		obj1.validateNotequal = obj2;
	}
}

// ..................................................................

function formSetEqual(obj1, obj2)
{
	obj1 = findObj(obj1);
	obj2 = findObj(obj2);
	
	if(obj1 && obj2)
	{
		obj1.validateEqual = obj2;
	}
}

// ..................................................................

function formUpdate(obj, skip_obj)
{
	if (obj.disabled)
	{
		return false;
	}
	err = false;

	if(obj.method == 'post' || obj.method == 'get')
	{
		for(var i = 0; i < obj.elements.length; i++)
		{
			formUpdate(obj.elements[i]);
		}
		return;
	}
	if(obj.type == 'select-one')
	{
		val = obj.options[obj.selectedIndex].value;
	}
	else if(obj.type == 'radio')
	{
		for (i = 0; i < obj.options.length; i++)
		{
			if (obj.options[i].checked)
			{
				val = obj.options[i].value;
			}
		}
//		val = obj.value;
	}
	else
	{
		val = obj.value;
	}

	if(val == '' && obj.validateReq == true)
	{
		err = true;
	}

	if(err == false && val != '')
	{
		if(obj.validateCheck == 'url' && val.indexOf('http://') != 0 && val.indexOf('https://') != 0)
		{
			err = true;
			obj.ibs_error_message = "Неверный формат URL-адреса!";
		}
		else if(val == 'http://' || val == 'https://')
		{
			err = true;
			obj.ibs_error_message = "Неверный формат URL-адреса!";
		}

		if(obj.validateCheck == 'email')
		{
			if(val == "") err = true;
			else if (!validEmail(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Неверный формат E-mail адреса!";
			}
		}

		if(obj.validateCheck == 'emails')
		{
			if(val == "") err = true;
			else if (!validEmails(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Неверный формат E-mail адреса!";
			}
		}

		if(obj.validateCheck == 'date')
		{
			var valid = /(\d{2}.\d{2}.\d{4})/;

			if(val == "") err = true;
			else if(val.length != 10 || !valid.test(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Неверный формат даты! Необходимо использовать следующий формат: дд.мм.гггг";
			}
		}

		if(obj.validateCheck == 'datetime')
		{
			var valid = /(\d{2}.\d{2}.\d{4} \d{2}:\d{2})/;

			if(val == "") err = true;
			else if(val.length != 16 || !valid.test(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Неверный формат даты! Необходимо использовать следующий формат: дд.мм.гггг чч:мм";
			}
		}

		if(obj.validateCheck == 'time')
		{
			var valid = /(\d{2}:\d{2}:\d{2})/;

			if(val == "") err = true;
			else if(!valid.test(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Неверный формат даты! Необходимо использовать следующий формат: дд.мм.гггг чч:мм";
			}
		}

		if(obj.validateCheck == 'oneword')
		{
			var not_valid = /( )/;
			var valid = /^([a-zA-Z0-9\-\.]+)$/;

			if(val == "") err = true;
			else if(not_valid.test(val) || !valid.test(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Значение поля должно состоять только из символов латиницы, цифр, знаков подчеркивания и дефиса";
			}
		}

		if(obj.validateCheck == 'urlword')
		{
			var not_valid = /( )/;
			var valid = /^([a-zA-Z0-9\-\._]+)$/;

			if(not_valid.test(val) || !valid.test(val)) err = true;

			if (err)
			{
				obj.ibs_error_message = "Значение поля должно состоять только из символов латиницы, цифр, знаков подчеркивания и дефиса!";
			}
		}

		if(obj.validateCheck == 'natural' && (isNaN(val) || val <= 0))
		{
			err = true;
		}

		if(obj.validateCheck == 'number*' && (isNaN(val) && val != '*' || val < 0))
		{
			err = true;
		}

		if(obj.validateCheck == 'number+' && (isNaN(val) && val != '-'  || val < 0))
		{
			err = true;
		}

		if(obj.validateCheckUnique == true)
		{
			needle = obj.value.toLowerCase();
			haystack = obj.validateUnique.toLowerCase();

			if(haystack.indexOf('|' + needle + '|') > -1)
			{
				err = true;
			}
		}

		if(obj.validateNotequal)
		{
			obj2 = obj.validateNotequal;
			if(obj2.type == 'select-one')
			{
				val2 = obj2.options[obj2.selectedIndex].value;
			}
			else
			{
				val2 = obj2.value;
			}

			if(val == val2)
			{
				err = true;
			}
		}
		else if (obj.validateEqual)
		{
			obj2 = obj.validateEqual;
			if(obj2.type == 'select-one')
			{
				val2 = obj2.options[obj2.selectedIndex].value;
			}
			else
			{
				val2 = obj2.value;
			}

			if(val != val2)
			{
				err = true;
				obj.ibs_error_message = "Значения полей должны совпадать!";
			}
		}
	}

	if (!skip_obj)
	{
		var frm = obj.form;
		if (frm && frm.submit_button)
		{
			var btn = findObj(frm.submit_button);
			if (btn)
			{
				btn.disabled = !formCheck(frm, true);
			}
		}
	}

	return(err);
}

// ..................................................................

function formCheck(f, no_alerts)
{
	var noerrors = true;
	var first	 = false;
	var fields   = new Array();

	for(var i = 0; i < f.elements.length; i++)
	{
		if(f.elements[i].validateCheck || f.elements[i].validateReq || f.elements[i].validateEqual)
		{
			err = formUpdate(obj = f.elements[i], f.elements[i]);

			if(err)
			{
				if (first == false)
				{
					first = i;
				}

				noerrors = false;
			}
		}
	}

	if(noerrors == false)
	{
		if (!no_alerts)
		{
			alert((f.elements[first].ibs_error_message) ? f.elements[first].ibs_error_message : ( (f.elements[first].friendly_name) ? ("Некорректно заполнено поле \"" + f.elements[first].friendly_name + "\"!") : "Некорректно заполнено поле!"));
		}
		else if (f.error_message_area)
		{
				f.error_message_area.innerHTML = (f.elements[first].ibs_error_message) ? f.elements[first].ibs_error_message : ( (f.elements[first].friendly_name) ? ("Некорректно заполнено поле &laquo;" + f.elements[first].friendly_name + "&raquo;!") : "Некорректно заполнено поле!");
		}

		if(f.elements[first].type != 'select-one' && !no_alerts)
		{
			f.elements[first].select();
		}

		if(!no_alerts)
		{
			f.elements[first].focus();
		}
	}
	else if (f.error_message_area)
	{
		f.error_message_area.innerHTML = "";
	}

	return noerrors;
}

// ..................................................................

function CopyClipboard(obj)
{
	obj = findObj(obj);

	if(obj)
	{
		window.clipboardData.setData('Text', obj.value);
	}
}

// ..................................................................

function setColor(obj, clr)
{
	obj.style.backgroundColor = clr;
}

// ..................................................................

function setPreviewFile(filepath, field_name, width)
{
	_filepath = new String(filepath);
	fileparts = _filepath.split("\\");
	if (fileparts.length > 0)
	{
		filename = new String(fileparts[fileparts.length-1]);
		_fileext = filename.split('.');
		if (_fileext.length > 0)
		{
			ext = _fileext[_fileext.length-1];
			obj = findObj(field_name);
			if (obj && ext == "gif" || ext == "jpg" || ext == "jpeg" || ext == "png")
			{
				obj.src=filepath;
				obj.style.width = (width > 0) ? width : 100;
			}
			else if (obj)
			{
				obj.src='';
				obj.style.width = 0;
			}
		}
	}
}

// ..................................................................

function openFromPopup(url)
{
	if (window.opener) 
	{ 
		window.opener.location.href = url; 
		window.opener.window.focus();
	} 
	else 
	{ 
		window.open(url); 
	}
	return false; 
}

// ..................................................................

function Browser() 
{                                         
          this.dom = document.getElementById?1:0;
          this.ie4 = (document.all && !this.dom)?1:0;
          this.ns4 = (document.layers && !this.dom)?1:0;
          this.ns6 = (this.dom && !document.all)?1:0;
          this.ie5 = (this.dom && document.all)?1:0;
          this.ok = this.dom || this.ie4 || this.ns4;
          this.platform = navigator.platform;

          this.ie = (this.ie5) ? 1 : 0;
          this.ns = (this.ns6 || this.name=="Netscape") ? 1 : 0;
          this.opera = (window.opera)?1:0;

          this.name = navigator.appName;
          this.version = parseFloat(navigator.appVersion);
          if (!this.opera && this.name == "Microsoft Internet Explorer" && navigator.userAgent.indexOf("MSIE 6.0") != -1)
          {
                  this.version = 6;
          }
          else if (!this.opera && this.name == "Microsoft Internet Explorer" && navigator.userAgent.indexOf("MSIE 5.5") != -1)
          {
                  this.version = 5.5;
          }
				  else if (this.opera && navigator.userAgent.indexOf("Opera 7") != -1)
          {
                  this.version = 7;
          }
          else if (this.opera && navigator.userAgent.indexOf("Opera/6") != -1)
          {
                  this.version = 6;
          }

          this.ie6 = (this.ie && this.version > 5) ? true : false;
          this.png = (this.ie6 || this.opera) ? true : false;
}

// ..................................................................

function loadPNG(png, img, width, height, extra_param)
{
    var browser = new Browser();
    if (browser.png)
        document.write("<img border=0 src='" + png + "' width='" + width + "' height='" + height + "' " + extra_param + " />");
    else
        document.write("<img border=0 src='" + img + "' width='" + width + "' height='" + height + "' " + extra_param + " />");
}

// ..................................................................

function Dump(d,l)
{
    if (l == null) l = 1;
    var s = '';
    if (typeof(d) == "object") {
        s += typeof(d) + " {\n";
        for (var k in d) {
            for (var i=0; i<l; i++) s += "	";
            s += k+": " + Dump(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) s += "	";
        s += "}\n"
    } else {
        s += "" + d + "\n";
    }
    return s;
}

function _debug(object)
{
	qqq = window.open();
	qqq.document.write(Dump(object, 1));
}

// ..................................................................

function matchClass( objNode, strCurrClass ) {
	return ( objNode && objNode.className.length && objNode.className.match( new RegExp('(^|\\s+)(' + strCurrClass + ')($|\\s+)') ) );
}

function addEvent(objElement, strEventType, ptrEventFunc) {
	if (objElement.addEventListener) objElement.addEventListener(strEventType, ptrEventFunc, false);
		else if (objElement.attachEvent) objElement.attachEvent('on' + strEventType, ptrEventFunc);
}

function removeEvent(objElement, strEventType, ptrEventFunc) {
	if (objElement.removeEventListener) objElement.removeEventListener(strEventType, ptrEventFunc, false);
		else if (objElement.detachEvent) objElement.detachEvent('on' + strEventType, ptrEventFunc);
}

// ..................................................................

function getValueOf(element, nodeName)
{
	var opt = element.getElementsByTagName(nodeName);

	if (opt == null || opt.length == 0)
	{
		return false;
	}
	if (!(element.text === undefined))
	{
		return element.getElementsByTagName(nodeName)[0].text;
	}
	else if (!(element.innerHTML === undefined))
	{
		return element.getElementsByTagName(nodeName)[0].innerHTML;
	}
	else
	{
		return element.getElementsByTagName(nodeName)[0].textContent;
	}
}

// ..................................................................

function sendXMLRequest(url, params, method, callback)
{
	var xmlhttp =  new XMLHttpRequest();

	method = (method == "POST") ? "POST" : "GET";
	xmlhttp.open(method, url, true);
  xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200 && callback)
			{
				eval(callback + "(xmlhttp.responseXML);");
			}
			else if (xmlhttp.status != 200)
			{
				alert("Ошибка: не удалось выполнить запрос.");
			}
		}
	}

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; windows-1251');
	xmlhttp.send(params);
}

// ..................................................................

function clearOptions(cb)
{
	while (cb.childNodes.length)
	{
		// Данный if только для Opera-ы, которая не удаляет
		// optgroup, если в нем есть элементы.
		if (cb.firstChild.tagName == 'OPTGROUP')
		{
			while (cb.firstChild.childNodes.length)
			{
				cb.firstChild.removeChild(cb.firstChild.firstChild);
			}
		}
		cb.removeChild(cb.firstChild);
	}
	return true;
}

// ..................................................................

function fullSearch (type, _id)
{               
	var form = findObj('search_' + type + '_form_div' + _id);
	var text = findObj(type + '_text');
	var button = findObj(type + '_button');
	if (form.style.display == 'block') 
	{
		form.style.display = 'none';
		text.className = 'blue-a dotted hover-red';
		if (button)
		{
			button.src = '/img/icons/icon-plus.gif';
			button.alt = "Открыть форму";
			button.title = "Открыть форму";
		}
		text.title = "Открыть форму";
	}
	else 
	{
		form.style.display = 'block'; 
		text.className = 'gray';
		if (button)
		{
			button.src = '/img/icons/icon-minus.gif';
			button.alt = "Скрыть форму";
			button.title = "Скрыть форму";
		}
		text.title = "Скрыть форму";
	}
}

// ..................................................................

function selectAllOptions(cb_id)
{
	var cb_obj = findObj(cb_id);
	for (var i = 0; i < cb_obj.options.length; i++)
	{
		cb_obj.options[i].selected = true;
	}
	return false;
}

// ..................................................................

function getCheckedItemsCount(array_name)
{
	var items = findObj(array_name + "[]");

	var items_count = 0;
	for (var i = 0; i < items.length; i++)
	{
		if (items[i].checked) items_count++;
	}
	return items_count;
}

// ..................................................................

function checkItemsCount(array_name, current_item, max_count)
{
	var items_count = getCheckedItemsCount(array_name);

	var is_error = false;
	if (items_count > max_count)
	{
		current_item.checked = false;
		is_error = true;
	}

	return !is_error;
}

// ..................................................................

function addToFavorites(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 set_asid(frm)
{
	frm["b_submit"].disabled = true;
	frm["__asid"].value = __asid;
}

// ..................................................................

function doSize(sizingObjs, mainObj)
{
	var mainObj = findObj(mainObj);
	var str = new String(sizingObjs);
	var objs = str.split(",");
	for (var i = 0; i < objs.length; i++)
	{
		obj = findObj(trim(objs[i]));
		if (obj)
		{
			obj.style.width = mainObj.offsetWidth;
			obj.style.height = mainObj.offsetHeight;
		}
	}
	return false;
}

// ..................................................................

function doResize()
{
  doSize('curtain', 'document_wrapper');
  return false;
}

addEvent(window, "resize", doResize);

// ..................................................................

function displayCurtain(bDisplay)
{

	var wrapper = findObj('document_wrapper');
	var curtain = findObj('curtain');
	if (curtain && wrapper && bDisplay)
	{
		alert(curtain);
		curtain.style.width = wrapper.offsetWidth;
		curtain.style.height = wrapper.offsetHeight;
		curtain.style.display = 'block';
	}
	else if (curtain)
	{
		curtain.style.display = 'none';
	}
	return false;
}

// ..................................................................

function closeSiteSelector(bRemember)
{
	displayCurtain(false);
	if (findObj('site_selector'))
	{
		findObj('site_selector').style.display='none';
	}
	if (bRemember)
	{
		rememberSite();
	}
	return false;
}

function rememberSite()
{
	sendXMLRequest("?action=remember_site", "", "GET", null);
	return false;
}


// ..................................................................

function matchClass( objNode, strCurrClass )
{
	return ( objNode && objNode.className.length && objNode.className.match( new RegExp('(^|\\s+)(' + strCurrClass + ')($|\\s+)') ) );
}

// ..................................................................

function getElementsByTagName(tag, parent)
{
	if (parent == undefined) parent = document.body;
	return parent.getElementsByTagName(tag);
}

// ..................................................................

function getElementsByClassName(cls, parent)
{
	var clses = [];
	var i = 0;
	if (parent == undefined) parent = document.body;
	var childs = parent.childNodes;

	for (var i = 0; i < childs.length; i++)
	{
		if (childs[i].className != undefined)
		{
		 	if (matchClass(childs[i], cls))
		 	{
		 		clses[clses.length] = childs[i];
		 	}

			if (childs[i].childNodes.length > 0)
			{
			  var childclses = [];
				childclses = getElementsByClassName(cls, childs[i]);
				clses = clses.concat(childclses);
			}
		}
	}

	return clses;
}

// ..................................................................

////////////////////////////////////////////////////////////////
// Добавить в избранное / удалить из избранного
////////////////////////////////////////////////////////////////

function setFavorites(_id, _type)
{
	var url		= "/ajax/favorites.php";
	var params	= "id=" + _id + "&type=" + _type;

	sendXMLRequest(url, params, "POST", "updateFavIcon");
/*
	if ($('fav_'+_id).title != 'Добавить в избранное')
		$('fav_'+_id).title = 'Добавить в избранное';
	else
		$('fav_'+_id).title = 'Удалить из избранного';
*/
}

function updateFavIcon(responseXML)
{
	var opt		= responseXML.getElementsByTagName('result');

	if (opt == null)
	{
		alert("Ошибка: Не удалось обработать ответ сервера (1).");
		return false;
	}

	var status	= getValueOf(opt[0], "status");
	var id		= getValueOf(opt[0], "id");

	if (!status || status == "error" || !id)
	{
		alert("Ошибка: Не удалось обработать ответ сервера (2).");
		return false;
	}

	var icon = $("fav_" + id);
	var icon_small = $("fav_small_" + id);
	var favtext = $("favtext_" + id);

	if (icon && icon.src)
	{
		icon.src = (status == "active") ? "/img/icons/icon-fav-a.gif" : "/img/icons/icon-fav-n.gif";
	}
	else if (icon && icon.value)
	{
		icon.checked = (status == "active") ? true : false;
	}

	if (icon) icon.title = (status == "active") ? "Удалить из избранного" : "Добавить в избранное";

	if (icon_small)
	{
		icon_small.src = (status == "active") ? "/img/icons/icon-small-fav-a.png" : "/img/icons/icon-small-fav.png";
		icon_small.title = (status == "active") ? "Удалить из избранного" : "Добавить в избранное";
	}

	if (favtext)
	{
		favtext.title = (status == "active") ? "Удалить из избранного" : "Добавить в избранное";
		favtext.innerHTML = (status == "active") ? "Удалить из избранного" : "Добавить в избранное";
	}

	var fav_line1 = $("fav_line1_" + id);
	var fav_line2 = $("fav_line2_" + id);

	if (fav_line1 && fav_line2)
	{
		fav_line1.style.display = "none";
		fav_line2.style.display = "none";
	}
}

function setSession(name,val) {
	
//var xmlHttp = false;
//  if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
//	  xmlHttp = new XMLHttpRequest();
//  }  
  
  
   var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }

  
  
  
  //alert(xmlhttp);
  xmlhttp.open("GET", '/ajax/setsession.php?name='+name+'&val='+val, true);
//alert('/ajax/setsession.php?name='+name+'&val='+val);
  // Установить функцию для сервера, которая выполнится после его ответа
  //xmlHttp.onreadystatechange = check_update;

  // SПередать запрос
  xmlhttp.send(null);
}