function bannerClick() {
	JsHttpRequest.query	(
		'/utils/banner_click/', 
		{}, function() {},
		true 
	);
	
	$.ajax({
	   url: 'http://www.'+mainDomain+'/utils/banner_click/?callback=?',
	   dataType: "jsonp",
	   success: function(){}
	 });
	
	
}

function viewCount(module, id) {
	JsHttpRequest.query	(
		'/utils/view_count/', 
		{'module': module, 'id': id}, function() {},
		true 
	);
}


function show_media(file, vars, width, height, bgcolor)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ width + '" height="' + height + '" id="test_draw" align="middle"><param name="allowScriptAccess" value="sameDomain" /><PARAM NAME=FlashVars VALUE="' + vars + '"><param name="movie" value="'+ file + '" /><param name="quality" value="high" /><param name="bgcolor" value="'+ bgcolor + '" /><PARAM NAME="AllowFullScreen" VALUE="true"><param name="wmode" value="Window" /><embed src="'+ file + '" FlashVars="' + vars + '" wmode="opaque" quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" name="test_draw" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}


function viewCountPeriod(module, id) {
	$.ajax({
	   type: "POST",
	   url: '/utils/view_count_period/',
	   data: "module="+module+"&id="+id,
	   dataType: "json",
	   success: function(){}
	 });
	
	
}

function viewCountPeriodJson(module, id) {
	$.ajax({
	   url: 'http://www.'+mainDomain+'/utils/view_count_period/?callback=?',
	   data: "module="+module+"&id="+id,
	   dataType: "jsonp",
	   success: function(){}
	 });
	
	
}



function clickCountPeriod(module, id) {
	$.ajax({
	   type: "POST",
	   url: '/utils/click_count_period/',
	   data: "module="+module+"&id="+id,
	   dataType: "json",
	   success: function(){}
	 });
	
	
}
function badSoft(id) {
	text=$("#badLinkText").val();
	if(text=='') {
		alert("Введите описание проблемы");
		return false;
	}
	
	var email=$("#badLinkEmail").val();
	
	wait('load');	
	$.ajax({
	   type: "POST",
	   url: '/soft/bad_link/',
	   data: "id="+id+"&text="+text+"&email="+email,
	   dataType: "json",
	   success: function(data){		   
		   ready('load');	
		   $("#badLinkForm").hide();
		   if(data.error!=undefined) alert("При отправке сообщения возникла ошибка, попробуйте позже");
		   else {
			   $("#badLink").html("Спасибо, Ваше сообщение отправлено, в ближайшее время проблема будет исправлена.");			   
			   $("#badLink").css("color", "green");			   
		   }
	   }
	 });
	
	return false;
}


function wait(id) {
	$("#"+id).html('<img src="/images/icon/wait.gif" width="16" height="16" align="absmiddle">');

}

function ready(id) {
	$("#"+id).html('');
}

// обработка поисковой формы в хедере
function searchProcess(forma) {
	if($("#q").val()=="Поиск" || $("#q").val()=='') {			
		alert("Введите поисковый запрос");
		return false;
	}

	var type=$("input[@name=type]:checked").val();	
	if(type==1 || type==2 || type==3) forma.action="http://search."+mainDomain+"/";
	forma.submit();		

}

function browserInfo() {
	this.ver = navigator.appVersion.toLowerCase();
	this.verNum = parseInt(this.ver);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = (document.getElementById ? 1 : 0);
	this.opera = (this.agent.indexOf("opera") > -1 && this.dom ? 1 : 0);
	this.ie = (this.ver.indexOf("msie") > -1 && this.dom && !this.opera ? 1 : 0);
	this.chrome = this.ver.indexOf("chrome") > -1;
	this.safari = this.chrome ? false : this.ver.indexOf("safari") > -1;
	this.moz = (this.agent.indexOf("gecko") > -1);
	this.ns6 = (this.dom && this.agent.indexOf("netscape") > -1 && this.verNum >= 5 ? 1 : 0);
	this.ff = (this.agent.indexOf("firefox") > -1);
	return this;
}

function addBookmark(url, title) {	
	if(b.ie){
		window.external.AddFavorite(url, title);		
		return false;	
	} else if(b.moz||b.ns6||b.opera) {
		return true;	
	} else return false;	
	
}

var b = new browserInfo();


function checkLabels(text){
	labelKey=-1;
	//$('labelsSet').style.display = 'none';	
	if (/,/i.test(text) && !/,[ ]*[^ ,]+$/i.test(text)) {
		return false;
	}
	else if (!/^[ ]*[^ ,]+/i.test(text)) {
		return false;
	} else {
		ref('wait').innerHTML='<img src="/images/icon/wait.gif" width="16" height="16" align="top">';
		JsHttpRequest.query	(
			'http://www.'+mainDomain+'/labels/check/', 
			{text: text}, 
			function(responseJS, responseText) {			
			
				if($("#labelsSet").attr('id')==undefined) $("#labels").after('<div id="labelsSet" style="width:423px; border-bottom: 1px solid gray; border-left: 1px solid gray; border-right: 1px solid gray; display:none;background: white" >');
				if(responseJS.error!=null) alert(responseJS.error);
				else if (responseJS.labels!=''){
					ref('labelsSet').innerHTML = responseJS.labels;						
					ref('labelsSet').style.display = '';						
				} else ref('labelsSet').style.display = 'none';
				ref('wait').innerHTML='';
			},
			true 
		);

		return false;
	}
		
	
}


function chooseLabel(label) {
	
	if (/,/i.test(ref('labels').value)) var sep=' ';
	else var sep='';
	
	ref('labels').value = ref('labels').value.replace(/[^,]+$/g, sep+label);
	ref('labelsSet').style.display = 'none';
	return false;
}

function choosePopularLabel(label) {
	
	if (/[^ ,]+$/i.test(ref('labels').value)) var sep=', ';
	else var sep='';
	
	ref('labels').value = ref('labels').value+sep+label;
	return false;
}

function ref(name) {
	return document.getElementById(name);
}




function autocomplete(event) {
	
	if($(event.target).attr('id')=='labels') {
		var numLabels=$("#labelsSet div").get().length;
		
		if(numLabels>0 && (event.keyCode == 38 || event.keyCode == 40) ) {
			if (event.keyCode == 38) labelKey=labelKey-1;
			else if (event.keyCode == 40) labelKey=labelKey+1;
			
			if(labelKey<0) labelKey=0;
			if(labelKey>numLabels-1) labelKey=numLabels-1;	
			
			$("#labelsSet div").css('color', 'black').css('background', 'white');
			var el=$("#labelsSet div").get(labelKey);
			$(el).css('color', 'white').css('background', 'blue');
					
	
		} else if(numLabels>0 && event.keyCode == 13 ) {
			var el=$("#labelsSet div").get(labelKey);
			chooseLabel($(el).html());
			return false;
		} else {
			checkLabels($(event.target).attr("value"));
		}	

	
	}
		
}	

function actionProcess(value, id) {
	document.forma.action.value=value;
	document.forma.id.value=id;
	document.forma.submit();		
	return false;
}


function actionConfirm(value, message, id) {
	if(confirm(message))  {
		document.forma.action.value=value;
		document.forma.id.value=id;
		document.forma.submit();		
	} 
	return false;
}


	function set_cookie (name, value, nDays, path, domain, secure) {

	  var today = new Date();
	  var expires = new Date();		
	  expires.setTime(today.getTime() + 3600000*24*nDays);
	  expires=expires.toGMTString();	  
	  document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
		
	}
	
	function get_cookie(name) {
		var cookie = " " + document.cookie;
		var search = " " + name + "=";
		var setStr = null;
		var offset = 0;
		var end = 0;
		if (cookie.length > 0) {
			offset = cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				end = cookie.indexOf(";", offset)
				if (end == -1) {
					end = cookie.length;
				}
				setStr = unescape(cookie.substring(offset, end));
			}
		}
		return(setStr);
	}

function fixPNG1(element) {
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;
		
		if (element.tagName=='IMG')	{
			if (/\.png$/.test(element.src))	{
				src = element.src;
				element.src = "img/blank.gif";
			}
		} else	{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src) {
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='" + src + "',sizingMethod='scale')";
	}
}



var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
 
function fixPng(png) {
	var blank = new Image();
	blank.src = '/img/blank.gif';
	 
	// get src
	var src = png.src;
	// set width and height
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	// replace by blank image
	png.onload = function() { };
	png.src = blank.src;
	// set filter (display original image)
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

function actProcess(value, id) {
	document.forma.act.value=value;
	document.forma.id.value=id;
	document.forma.submit();		
	return false;
}


function actConfirm(value, message, id) {
	if(confirm(message))  {
		document.forma.act.value=value;
		document.forma.id.value=id;
		document.forma.submit();		
	} 
	return false;
}


// добавление/удаление полей для загрузки картинок
function processImgField(action) {
	numImage=$("div[id^=img]").get().length;
	numImageVisible=$("div:visible[id^=img]").get().length;

	if(action) numImageVisible++;
	else numImageVisible--;
	
	if(numImageVisible<1) return false;
	
	for(i=1; i<=numImage; i++) {
		if(i<=numImageVisible) {
			$("#img"+i).show();
			$("#img"+i+" input").attr("disabled", false);
		} else {
			$("#img"+i).hide();							
			$("#img"+i+" input").attr("disabled", true);								
		}
	}
	return false;

}

	var loop=0;
	function process() {
		var num=$("ul.lnk > li").get().length;		
		$("ul.lnk > li").each(function(i) {			
			if(i==loop) $(this).show();
			else $(this).hide();
		});		
		if(loop==num-1) loop=0
		else loop++;		
	}	
	
	function pr() {
		
		var num=$("ul.lnk > li").get().length;
		if(num>0) {

			$("ul.lnk > li").hide();
			$("ul.lnk > li:first-child").show();
			setInterval('process()', 5000); 
		}
	}


