var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('firefox')!=-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));


var is_button = false;
function changemenu(num, butt){
	var active_menu = document.getElementById('js_menu_'+num);
	var status = active_menu.style.display;
	closeallmenu();
	is_button = true;
	if(status == 'none'){
		if(is_ie && !is_nav && is_win){
			active_menu.filters[0].Apply();
		}
		showAtElementYfix(butt, active_menu);
		active_menu.style.display = 'block';
		if(is_ie && !is_nav && is_win){
			active_menu.filters[0].Play();
		}
	}
}
function closeallmenu(){
	if(!is_button){
		document.getElementById('js_menu_2').style.display = 'none';
		document.getElementById('js_menu_3').style.display = 'none';
	//	document.getElementById('js_menu_4').style.display = 'none';
	}
	is_button = false;
}
function update_menus(){
}

function MoveLayer(id, x, y){
	if((clientVer >= 4) && is_ie && is_win){
		eval("js_menu_" + id).style.top = y;
		eval("js_menu_" + id).style.left = x;
   }else{
		document.getElementById('js_menu_' + id).style.top = y;
		document.getElementById('js_menu_' + id).style.left = x;
	}
}

function ChangeNews(tab){
	if(tab ==1){
		var tab_hide_1 = 2;
		var tab_hide_2 = 3;
	}else{
		if(tab ==2){
			var tab_hide_1 = 1;
			var tab_hide_2 = 3;
		}else{
			var tab_hide_1 = 1;
			var tab_hide_2 = 2;
		}
	}
	var div_tab = document.getElementById('news_div_'+tab);
	var div_tab_hide_1 = document.getElementById('news_div_'+tab_hide_1);
	var div_tab_hide_2 = document.getElementById('news_div_'+tab_hide_2);

	document.getElementById('news_'+tab).className = 'news_butt_active';
	document.getElementById('news_'+tab_hide_1).className = 'news_butt';
	document.getElementById('news_'+tab_hide_2).className = 'news_butt';

	if(is_ie && !is_nav && is_win){
		div_tab.filters[0].Apply();
	}
	div_tab.style.display = 'block';
	if(is_ie && !is_nav && is_win){
		div_tab.filters[0].Play();
	}
	div_tab_hide_1.style.display = 'none';
	div_tab_hide_2.style.display = 'none';
	return false;
}
	var month = new Array;
	month[0] = "января";
	month[1] = "февраля";
	month[2] = "марта";
	month[3] = "апреля";
	month[4] = "мая";
	month[5] = "июня";
	month[6] = "июля";
	month[7] = "августа";
	month[8] = "сентября";
	month[9] = "октября";
	month[10] = "ноября";
	month[11] = "декабря";

	function GetDateStr(){
		var now = new Date( );
		var str = '<nobr>'+now.getDate()+' '+month[now.getMonth()]+' '+now.getFullYear()+'&nbsp;г.</nobr>';
		var div_el = document.getElementById("date_str");
		div_el.innerHTML = str;
	}

	function SetCookie(sName, sValue){
	  document.cookie = sName + "=" + escape(sValue) + ";";
	}
	function DelCookie(sName){
	  sValue = '';
	  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
	}
	function GetCookie(sName){
		var cookies_string = document.cookie;
		var cookies_array = cookies_string.split(";");
		var cookies = new Array();
		for(i=0; i<cookies_array.length; i++){
			cookies = cookies_array[i].split("=");
			if(cookies[0].indexOf(sName) !=-1){
				return cookies[1];
			}
		}
		return '';
	}
var doc = null;

function ajax() {
	// Make a new XMLHttp object
	if (typeof window.ActiveXObject != 'undefined' ) doc = new ActiveXObject("Microsoft.XMLHTTP");
	else doc = new XMLHttpRequest();
}
function UpdateRating(value, id_shop, link, img_src){
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
			for(i=1; i<6; i++){
				document.getElementById('rating_'+i).disabled = true;
			}
	       doc.open("GET", link+"&rating=" + value + "&shop_id="+id_shop, false);
	       doc.send(null);
	    	// Write the response to the div	    	
		   document.getElementById('rating_user_img').src='';
		   document.getElementById('rating_user_img').src=img_src;
			for(i=1; i<6; i++){
				document.getElementById('rating_'+i).disabled = false;
			}
		   document.getElementById('rating_'+value).checked=false;
	       alert('Ваш голос принят!');
	    }else{
	    }        
}
function getAjaxData(link){
		ajax();
		// ** As far a I know firefox will only load a document on the SAME domain!!	
		if (doc){
			doc.open("GET", link, false);
			doc.send(null);
			return doc.responseText;
		}else{
		}

}
	function showAtElement(el_near, el_this) {
		var p = getAbsolutePos(el_near);
		el_this.style.left = p.x + "px";
		el_this.style.top = p.y + el_near.offsetHeight + "px";
	};
	function showAtElementYfix(el_near, el_this) {
		var p = getAbsolutePos(el_near);
		el_this.style.left = p.x + "px";
		el_this.style.top = p.y + el_near.offsetHeight + "px";
	};

	function getAbsolutePos(el) {
		var r = { x: el.offsetLeft, y: el.offsetTop };
		if (el.offsetParent) {
			var tmp = getAbsolutePos(el.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	};
	function getAbsolutePosY(el) {
	//	var r = { x: el.offsetLeft, y: el.offsetTop };
		var r = { x: Math.floor((window.screen.availWidth-20-800)/2), y: el.offsetTop };
		if (el.offsetParent) {
			var tmp = getAbsolutePos(el.offsetParent);
		//	r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	};
	function MarqStop(obj){
		obj.scrollAmount = 0;
	}
	function MarqStart(obj, val){
		obj.scrollAmount = val;
	}


function user_menu(){
	$("#top-user-menu").slideToggle();
}

function create_user_menu(){
	$("#opnMenu").bind('click', function(){
		user_menu();
	});
	var left = $("#opnMenu").offset().left;
	var top = $("#opnMenu").offset().top + $("#opnMenu").height()+5;
	var width = $("#top-user-menu").width();
	if(left - width < 0) 
		var menu_left = 5;
	else
		var menu_left = left - width + 15;

	$("#top-user-menu").css("left", menu_left+"px");
	$("#top-user-menu").css("top", top+"px");
	$("#top-user-menu").css("opacity", 0.35);
	
	$("#top-user-menu").bind('mouseenter', function(){
		$(this).animate({opacity: 0.9}, 200);
	});
	$("#top-user-menu").bind('mouseleave', function(){
		$(this).animate({opacity: 0.35}, 200);
	});

}

function tglBlock(id){
	$('#'+id+' .cnt').slideToggle();
}

