//-----ticker----------------------------------------------------------------------------------------------------------------
var rssticker_ajax=new Object()
var lastid = 0
var mins = 0
var secs = 0
rssticker_ajax.Start=function (divId, divClass, delay){
document.write('<div class=blackvsmall style=display:none id="'+divId+'">Инициализация тикера...<span id="tickettimer"></span></div>')
rssticker_ajax.tickerid=divId //ID of ticker div to display information
rssticker_ajax.delay=delay //Delay between msg change, in miliseconds.
rssticker_ajax.mouseoverBol=0
rssticker_ajax.title='', rssticker_ajax.link='', rssticker_ajax.pubdate='', rssticker_ajax.amountstr=''
rssticker_ajax.TickTimer()
rssticker_ajax.rotatemsg()
}
rssticker_ajax.rotatemsg=function(){
if (rssticker_ajax.mouseoverBol==1) {//if mouse is currently over ticker, do nothing (pause it)
    setTimeout(function(){rssticker_ajax.rotatemsg()}, 100)
}
else
{
	rssticker_ajax.getAjaxcontent()
	setTimeout(function(){rssticker_ajax.rotatemsg()}, this.delay) //update container
}
}
rssticker_ajax.TickTimer=function(){
	secs+=1;if(secs>=60){secs=0;mins+=1;}	
	var secs_str = '';var timestr = '';
	if (secs<10) secs_str = '0'+secs.toString();else secs_str = secs.toString();	
	if (mins>0) timestr+=(mins+' мин. '); timestr+=(secs_str+' сек.');	
	document.getElementById('tickettimer').innerHTML=timestr;setTimeout(function(){rssticker_ajax.TickTimer()}, 1000);
}
function proceedData(xmldata, textStatus) {	
	if ("success"==textStatus && lastid != xmldata.getElementsByTagName("id")[0].firstChild.nodeValue) {
		mins = parseInt(xmldata.getElementsByTagName("minutes")[0].firstChild.nodeValue)
		secs = parseInt(xmldata.getElementsByTagName("seconds")[0].firstChild.nodeValue)
		lastid = xmldata.getElementsByTagName("id")[0].firstChild.nodeValue
		rssticker_ajax.title = xmldata.getElementsByTagName("name")[0].firstChild.nodeValue
		rssticker_ajax.link = xmldata.getElementsByTagName("link")[0].firstChild.nodeValue
		rssticker_ajax.amountstr = xmldata.getElementsByTagName("amount")[0].firstChild.nodeValue + ' $'
		rssticker_ajax.pubdate = xmldata.getElementsByTagName("date")[0].firstChild.nodeValue
		document.getElementById(rssticker_ajax.tickerid).onmouseover=function(){rssticker_ajax.mouseoverBol=1}
		document.getElementById(rssticker_ajax.tickerid).onmouseout=function(){rssticker_ajax.mouseoverBol=0}
		tickerLoc = rssticker_ajax.link	
		var timestr = '';var secs_str = '';
		if (secs<10) secs_str = '0'+secs.toString()
		else secs_str = secs.toString() 
		if (mins>0) timestr+=(mins+' мин. ')
		timestr+=(secs_str+' сек.')		
		var linktitle='«<a class=link_good href="'+rssticker_ajax.link+'">'+rssticker_ajax.title+'</a>» <span style=color:#000000;>' + rssticker_ajax.amountstr + '</span>'
		var feeddate=rssticker_ajax.pubdate
		var tickercontent='<div class=ticket>Последняя продажа <span class=ticket_timer id=tickettimer>'+timestr+'</span> назад: '+linktitle+'</div>'
		document.getElementById(rssticker_ajax.tickerid).innerHTML=tickercontent
		document.getElementById(rssticker_ajax.tickerid).style.display='none'
		setTimeout(function(){document.getElementById(rssticker_ajax.tickerid).style.display=''}, 800)
	}
}
rssticker_ajax.getAjaxcontent=function(){	
	$.get("../asp/sellticker.asp", proceedData);
}
rssticker_ajax.fromTicker=function(){
	document.location=tickerLoc
}
//--/ticker----------------------------------------------------------------------------------------------------------------
//--блокнот----------------------------------------------------------------------------------------------------------------
var noteId=0;
var noteMode=0;
function noteItem(id, mode){
	noteId=id;noteMode=mode;	
	if(document.getElementById('img'+id).title == "Добавить в блокнот") var action = "add"; else var action = "del";
	//$.get("notebook.asp?, changeNote);
	$.ajax({	
		url: "notebook.asp",
		data: "idd="+id+"&action="+action+"&rnd="+new Date().getTime(),
		cache: false,
		success: changeNote
	});
}
function changeNote(textData, textStatus){	
	var note = document.getElementById('img'+noteId);
	document.getElementById("cntgoods").innerHTML = textData;
	if(note.title == "Добавить в блокнот"){
		note.src = "images/notebook_on.gif";note.title = "Удалить из блокнота";note.className = "eraser";
		if (1==noteMode) document.getElementById('txt'+noteId).innerHTML = "Удалить из моего блокнота";
	}
	else{
		note.src = "images/notebook_off.gif";note.title = "Добавить в блокнот";note.className = "pencil";
		if (1==noteMode) document.getElementById('txt'+noteId).innerHTML = "Добавить в блокнот";
	}
}
//--/блокнот---------------------------------------------------------------------------------------------------------------
//--tooltip----------------------------------------------------------------------------------------------------------------
var tooltip_messenger  = 'Продавец в режиме онлайн-диалога готов ответить на любой ваш вопрос.<br>Нажмите на эту иконку для запуска «Веб Мессенджера».';
var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip
var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/arrow_tooltip.gif">') //write out pointer image
var ie=document.all
var nsc6=document.getElementById && !document.all
var enabletip=false
if (ie||nsc6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function fillTooltip(textData, textStatus){	
	if ("success"==textStatus){ //if request of file completed		
			tipobj.innerHTML=textData;		
	}
}
function ddrivetip(thetext, thewidth, thecolor, theurl, theparam){
if (nsc6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
if (typeof thetext!="undefined" && thetext!="") tipobj.innerHTML=thetext
else tipobj.innerHTML = "<img src=images/ajax-loader.gif>"
if (typeof theurl!="undefined" && theurl!="") $.get(theurl+"?"+theparam, fillTooltip);
enabletip=true
return false
}
}
function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(nsc6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(nsc6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}
function hideddrivetip(){
if (nsc6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}
document.onmousemove=positiontip
//--/tooltip---------------------------------------------------------------------------------------------------------------
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

function BySelected(element) {
	if( element.options[element.selectedIndex].value!='' ) {
		window.location = element.options[element.selectedIndex].value;
	}
}
//---start page (autocomplete)-----------------------------------------------------------------------------------------------
function formatItem(row) {
		return '<div style=position:relative;float:left>' + row[0] + '</div><div style="position:relative;float:right">' + row[1] + ' товаров</div>';
	}	
function seacrhSubmit() {
	var sPath = window.location.pathname;
	if (sPath.indexOf('find.asp')!=-1) document.getElementById('insideseacrhstr').value=document.getElementById('searchstr').value;
	document.forms['searchform'].submit();
}
$().ready(function() {
	$('#searchstr').autocomplete('autocomplete.asp', {
	width: 300,
	minChars:2,
	formatItem: formatItem,		
	highlight: false
	}).result(function(event, item) {
		seacrhSubmit();
	});
});
//--/start page (autocomplete)-----------------------------------------------------------------------------------------------