var cur_section  = 0;  				//
var selected_list =''; 				//
var origCols; 						//
var serverAdress = "/include/ajax.php";
var tmp_class = '';


//Запрос AJAX
function AjaxRequest(div, request)
	{
	destination.push(div);
	cache.push(request);
	execAjax();
	}


function ById(id)
	{
	return document.getElementById(id);
	}

function ByTag(el,tag)
	{
	return el.getElementsByTagName(tag);
	}


function login_site()
	{
	 document.getElementById("check_login").value = "not_null";
	 login = document.getElementById("email");
	 if(login.value=='')
	 	{
		alert("Поле не заполнено");
		login.focus();
		return;
		}
	pass = document.getElementById("upass");
	 if(pass.value=='')
	 	{
		alert("Поле не заполнено");
		pass.focus();
		return;
		}
	if(confirm('Запомнить на этом компьютере?'))
		document.getElementById("remember").value = 1;

	document.getElementById("uform").submit();
	}

function ShowBlock(id)
	{
	ob = document.getElementById(id);
	if(ob)
		{
		ob.style.display  = (ob.style.display == 'none')? '' : 'none';
		}
	}

function SelectZaklad(ob,act)
	{
	if(act)
		{
		tmp_class = ob.className;
		ob.className = 'hed_zakld_s';
		}
	else
		{
		ob.className = tmp_class;
		tmp_class = '';
		}
	}

function SelectUrlico(ob,act)
	{
	 tmp_class = 'hed_zakld_s';
	 if(act)
	 	{
		document.getElementById("user_name").style.display="none";
		document.getElementById("user_sname").style.display="none";
		document.getElementById("user_adress").style.display="none";
		document.getElementById("ur_name").style.display="";
		document.getElementById("ur_inn_kpp").style.display="";
		document.getElementById("ur_adress").style.display="";
		document.getElementById("ur_index").style.display="";
		document.getElementById("urlico").value="1";
		document.getElementById('zakl_1').className = 'hed_zakld_ns';
		ob.className = 'hed_zakld_s';
		}
	else
		{
		document.getElementById("user_name").style.display="";
		document.getElementById("user_sname").style.display="";
		document.getElementById("user_adress").style.display="";
		document.getElementById("ur_name").style.display="none";
		document.getElementById("ur_inn_kpp").style.display="none";
		document.getElementById("ur_adress").style.display="none";
		document.getElementById("ur_index").style.display="none";
		document.getElementById("urlico").value="0";
		document.getElementById('zakl_2').className = 'hed_zakld_ns';
		ob.className = 'hed_zakld_s';
		}
	}


function  add_basket_sel(id)
	{
	var order = document.getElementById("order_cnt");
	var order_size = document.getElementById("order_size").value;
	var order_cnt = parseInt(order.value);

	if(!order_cnt)
		{
			alert("Не выбрано кол-во товара");
			order.focus();
			return;
		}
		if(confirm('Добавить к корзину?'))	{
			destination.push("order_us");
			ajax_req="action=add&select="+id+"&order_cnt="+order_cnt+"&size="+order_size+"&target=basket";
			cache.push(ajax_req);
			execAjax();
			order.value = '';
		}
	}

function  change_basket_sel(id,order_cnt)
	{
			destination.push("order_summ");
			ajax_req="action=change&select="+id+"&order_cnt="+order_cnt+"&target=basket";
			cache.push(ajax_req);
			execAjax();
	}

function CheckLatin(el)
	{
		str = el.value;
		reg = new RegExp("^[0-9a-zA-Z_\-]{1,150}$","i");
        result = reg.test(str);
		if(result==false)
			{
			alert("Поле должно содержать только латинские символы и знаки '_' '-'");
			el.focus();
			return 0;
			}
	return 1;
	}

	function show_submenu(ob,id,class_name)
		{
		ob.className = class_name;
		obj = 	document.getElementById(id);
		//obj.className = class;
		if(obj)
			{
			obj.style.display = (obj.style.display=="none")? "" : "none";
			event.cancelBubble=true;
			}
		}

	function SendQuest(flag)
		{
		if(document.getElementById('name').value=='')
			{
			document.getElementById('name').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('date').value=='')
			{
			document.getElementById('date').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('regplace').value=='')
			{
			document.getElementById('regplace').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('adress').value=='')
			{
			document.getElementById('adress').focus();
			alert('Поле должно быть заполнено');
			return;
			}
		if(document.getElementById('phone').value=='')
			{
			document.getElementById('phone').focus();
			alert('Поле должно быть заполнено');
			return;
			}

		if(flag)
			{
			if(document.getElementById('auto').value=='')
			{
			document.getElementById('auto').focus();
			alert('Поле должно быть заполнено');
			return;
			}
			if(document.getElementById('number').value=='')
			{
			document.getElementById('number').focus();
			alert('Поле должно быть заполнено');
			return;
			}
			}
		document.getElementById("quest_form").submit();
		}

	 function CheckUserForm()
		{
			uForm = document.getElementById("reg_form")
			for (var i=0; i < uForm.length; i++)
				{
				if(uForm[i].name!='subscribe'  && uForm[i].name!='description' && uForm[i].name!='blog' && uForm[i].name!='photo' && uForm[i].value=='')
					{
					alert("Поле должно быть заполнено"+uForm[i].name);
					uForm[i].focus();
					return;
					}
				}
			var ob = document.getElementById("login");
			if(CheckLatin(ob)==0)
				{
				ob.focus();
				return 0;
				}

			pass1 =  document.getElementById("pass");
			pass2 =  document.getElementById("pass2");
			if(pass2.value==pass1.value)
				{
				 uForm.submit();
				}
			else
				alert("Пароли не совпадают");
				return;
		}

		function SendForm(id)
			{
			var form =  document.getElementById(id);
			if(id=='form_contact')
				{
				var ob = document.getElementById('email');
				if(!chekEmail(ob))
					{
					alert('Поле E-mail не верно заполнено');
					ob.focus();
					return 0;
					}

				ob = document.getElementById('message');
				if(!CheckEmptyField(ob))
					{
					alert('Поле Сообщение не заполнено');
					ob.focus();
					return 0;
					}
				 document.getElementById('send').value='send';
				}
			form.submit();
			}



		function chekEmail(el1)
			{
			 var el = el1;
				str = el.value;
				reg = new RegExp("^[0-9\\-a-z_]+@[0-9\\-a-z_^\\.]+\\.[a-z]{2,3}$","i");

				result = reg.test(str);
				if(result==false)
					 {
						el.className="in_error";
						el.onchange=function(){
						this.className ='in_ok';
						};
						return false;
					 }
			return true;
			}


		function CheckEmptyField(ob)
			{
				if(ob.value=='')
					  {
					  return 0;
					  }
			return 1;
			}

		function ChoicePayment()
			{
			var ob =  document.getElementById("pay_system");
			location.href = document.getElementById("url").value + ob.value + "/";

			}

		function GetVideoSubSection(ob)
			{
			sub_ob = document.getElementById("sub_section_id");
			sub_ob.disabled  = true;
			destination.push("sub_section_id");
	  	    ajax_req="sid="+ob.value+"&action=get_subsection&target=video";
			cache.push(ajax_req);
			execAjax();
			return 0;
			}

		function UploadCheck(form_id)
			{
				if(document.getElementById('title').value=='')
				{
				document.getElementById('title').focus();
				alert('Поле должно быть заполнено');
				return;
				}
				if(document.getElementById('sub_sec_id').value==0)
				{
				alert('Не выбран раздел');
				return;
				}

			//document.getElementById(form_id).submit();
			//setTimeout('GetProgressbar()',1000);
			}

			function GetProgressbar()
				{
				destination.push("progressbar");
	  	    	ajax_req="action=get_progressbar&target=video";
				cache.push(ajax_req);
				execAjax();
				setTimeout('GetProgressbar()',1000);
				}

			function ShowMapCityList(id, el)
				{
				var ob = document.getElementById(id);
				if(ob)
				{
					if(ob.style.display=='none')
						{
						ob.style.display = '';
						el.innerHTML = '[-]';
						}
					else
						{
						ob.style.display = 'none';
						el.innerHTML = '[+]';
						}
					}
				}


			//Опеределяет позицию курсора мышки
			function defMousePosition(event) {
				var x = y = 0;
				if (document.attachEvent != null) { // Internet Explorer & Opera
					x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
					y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
				}
				if (!document.attachEvent && document.addEventListener) { // Gecko
					x = event.clientX + window.scrollX;
					y = event.clientY + window.scrollY;
				}
				return {x:x, y:y};
			}




		 function ShowFlash()
				{
				document.getElementById('flashtop').style.display = 'block';
				document.getElementById('flashbottom').style.display = 'block';
				}

		  function ClearEvent(e)
				{
				if(e.stopPropagation) e.stopPropagation();
			    else e.cancelBubble = true;
			    if(e.preventDefault) e.preventDefault();
			    else e.returnValue = false;
	 			}


		function SetCenterPage(el)
			{
			     var offset =  (document.documentElement) ?  document.documentElement : document.body;
			     var div_h = el.clientHeight;
		         var clientH = offset.clientHeight;
		         var scrollTop = (offset.scrollTop >  document.body.scrollTop) ? offset.scrollTop : document.body.scrollTop;
		         el.style.top = (clientH < div_h) ?  scrollTop+"px" : parseInt((clientH - div_h)/2)+scrollTop+"px";
		         el.style.left = parseInt((offset.clientWidth - el.clientWidth)/2) + 'px';
			}


		function RestorePageBg()
			{
		    var div_bg =  document.getElementById('img_bg_bl');
		    if(div_bg) div_bg.parentNode.removeChild(div_bg);
			}

		function SetPageBg(color,opacity)
			{
		    RestorePageBg();
		    var  div_bg = document.createElement("div");
		    div_bg.id  = 'img_bg_bl';
		    div_bg.className = "img_bg_bl_new";
		    div_bg.style.backgroundColor = color;
		    var off_w = (document.documentElement &&
		    			 document.documentElement.clientWidth &&
		    			 document.documentElement.clientWidth > document.body.clientWidth)  ?  document.documentElement.clientWidth :
		    			 document.body.clientWidth;
		    var off_y = (document.documentElement &&
		    			 document.documentElement.scrollHeight &&
		    			 document.documentElement.scrollHeight > document.body.scrollHeight) ? document.documentElement.scrollHeight :
		    			 document.body.scrollHeight;
		    var left_off  = (document.documentElement && document.documentElement.scrollWidth) || document.body.scrollWidth;

		    var width_bg = (left_off > off_w) ? left_off : off_w;
		    div_bg.style.width = left_off+'px';
		    div_bg.style.height = off_y + 'px';
		    div_bg.style.opacity = opacity;
		    div_bg.style.filter = "alpha(opacity='"+opacity*100+"')";
		    div_bg.style.top = 0;
		    div_bg.style.left = 0;
			document.body.appendChild(div_bg);
			}

		function ShowBgImg(img_url)
			{
		     if(ById('show_img_bg')) CloseShowBgImg();
		   	 var i = document.createElement("img");
		     i.id  = 'show_img_src';
		     i.alt  = '';
		     i.style.display = 'none';
		     var div_box = document.createElement("div");
		     var div_cl = document.createElement("div");
		     div_cl.className = 'show_bg_img_close';
		     div_cl.onclick = CloseShowBgImg;

		     div_cl.appendChild(document.createTextNode('Закрыть'));
		     div_box.className = "show_img_bg";
		     div_box.id = "show_img_bg";
		     div_box.appendChild(div_cl);
		     div_box.appendChild(i);
		     div_box.style.textAlign = 'right';
		     div_box.style.width = 300 + 'px';
		     div_box.style.height = 300 + 'px';
		     div_box.style.padding = '10px';
		     div_box.style.backgroundColor = '#fff';

		     div_box.style.filter = "alpha(opacity='100')";
		     SetPageBg('#000',0.7);
		     document.body.appendChild(div_box);
		     tmp_big_img.onload  = function()
		     				{
		                     i.src =  this.src;
		                     i.style.display = 'inline';
		                     SetSizeShowBgimg(i);
		                     this.src = null;
			  				}
			 tmp_big_img.src = img_url;
		     SetCenterPage(div_box);
		     //SelectHide(1);
		     if(i && i.width > 0){SetSizeShowBgimg(i)};
		   	}


			function CloseUserDialog(id)
			 	{
			 	var dialog = ById(id)
				if(dialog){dialog.parentNode.removeChild(dialog); }
				if(arguments[1]) RestorePageBg();
			 	}

		     function CloseUserDialogDelay(id,time)
					 	{
		                var dialog = ById(id);
		                if(!dialog) return;
		                time = parseInt(time*1000);
		                if(arguments[2]){
		                	var dialog = ById(id)
		                	dialog.innerHTML = '<div>'+arguments[2]+'</div>';
		                	}
		                setTimeout(function(){CloseUserDialog(id)},time);
					 	}

			function ShowDialogForm(dialog)
					 	{
						CloseUserDialog('show_dialog');
						var div = document.createElement("div");
						div.id = 'show_dialog';
						div.className = 'user_dialog';
						div.innerHTML = '<div></div>';
						SetPageBg('#000',0.70);
						ById('img_bg_bl').onclick = function(){CloseUserDialog('show_dialog',true)}
						document.body.appendChild(div);
					    SetCenterPage(div);
						ajax_req="action=show_dialog&name="+dialog+"&target=users&div="+div.id;
						AjaxRequest('for_eval', ajax_req)
					 	}

			function CenterDialog(el)
					{
		             if(el){
			             el.style.border = 'none';
			             el.style.background = 'none';
			             el.style.width = 'auto';
			             el.style.height = 'auto';
		    	         SetCenterPage(el);
		    	       }
					}

			function ShowGallery(){                   ShowDialogForm('gallery');
			}

			function GalleryInit(){
				$("a[rel='gallery']").colorbox({opacity:0.7,
												current: ''});			}

			function hideGallery(){				$('#show_dialog').hide();
				$('#img_bg_bl').hide();			}
