var lastShownID = "";
var lastShownID2 = "";
var infos="";
var tstat=0;
hide_delay=500; 
function hidemenu(divID) {

timer1=setTimeout("showObj("+divID+",'')",hide_delay);

// Устанавливаем tstat=1 - признак, того, что таймер запущен.
tstat=1;

return 1;
}


function cancelhide() {
 if (tstat==1) {
 clearTimeout(timer1);
 tstat=0;
 }
return 1;
}

function showObj(o, vis)

{       if(o.style.display=="none"){vis=true;} else {vis=false;}
	o.style.visibility = (vis?"visible":"hidden");
	o.style.display  = (vis?"":"none");
 //	if (divID=='aboutDiv') hideDiv();
}

function showText(divID, text)
{
	var obj = document.getElementById(divID);
	if (obj) showObj (obj, true);
	lastShownID=divID;
}
function showText2(divID, text)
{
	var src=document.getElementById('bnt'+divID).src;
	if(src!=""){src=src.substr(src.length-8,8);
	if(src=='inus.jpg'){document.getElementById('bnt'+divID).src='images/plus.jpg';}else{document.getElementById('bnt'+divID).src='images/minus.jpg';}}
showText(divID, text);
}
function showText2(divID, text)
{
	var src=document.getElementById('bnt'+divID).src;
	if(src!=""){src=src.substr(src.length-8,8);
	if(src=='inus.jpg'){document.getElementById('bnt'+divID).src='images/plus.jpg';}else{document.getElementById('bnt'+divID).src='images/minus.jpg';}}
showText(divID, text);
}

function shText(divID, text)
{
	obj=document.getElementById(divID);
	if(obj.style.visibility!='visible'){
		obj.style.visibility = (true?"visible":"collapse");
		obj.style.display  = (true?"":"none");
	}else{
		obj.style.visibility = (false?"visible":"hidden");
		obj.style.display  = (false?"":"none");
	}
}

function showText1(divID,text,event)
{
 	 XY = getMouseXY(event);
   	 if (XY[0]+divWid>1000) {x=(1000-divWid);x+='px';}
  	 else x=XY[0]+'px';
  	 y=XY[1]+10;
  	 y += 'px';
	var obj = document.getElementById(divID);
	 with (obj.style) {position='absolute'; left=x; top=y;}
	if (lastShownID2)
	showObj (document.getElementById(lastShownID2), false);

	if (lastShownID2 != divID)
	{
		lastShownID = divID;
		if (obj) showObj (obj, true);
	}
	else
	lastShownID2 = '';
}

var add_success='отзыв был успешно добавлен';

function showTextarea(divID,url)
{	m=true;
	obj=document.getElementById(divID);
	if(document.getElementById('otziv_contentid').value==add_success){alert('Нечего добавлять');}
	else if(obj.style.visibility!='visible'){
		obj.style.visibility = (true?"visible":"collapse");
		obj.style.display  = (true?"":"none");
		obj.style.color='#e0e0e0';
		obj.value='Ваш отзыв...';
	}else{
		if(document.getElementById('otziv_contentid').value=='' || document.getElementById('otziv_contentid').value=='Ваш отзыв...')alert('Введите отзыв');
	else {
		    sendRequest(url+'?otz_cont='+document.getElementById('otziv_contentid').value,'GET',getShowDivAjax);
		}
	}
}

function clr(name)
{
	if(name=='Ваш отзыв...'){
		obj=document.getElementById("otziv_contentid");
		obj.value='';
		obj.style.color='#000000';
	}
}
function change_tops()
{
obj=document.getElementById("siteis");
m=false;
    sendUrl='includes/functions/response2.php?menu=sells'+obj.value;
    sendRequest(sendUrl,'GET',getSellsDivAjax);
}

var showProgressBar = false;
//var cnt = 0;
var req = null;
var m=true;
var divWid=320;
function hideDiv()
{
  req = null;
  showProgressBar = false;
  var elDiv = document.getElementById('aboutDiv');
  elDiv.style.visibility = 'hidden';
  document.body.removeChild(elDiv);
}
function getMouseXY(e) {
   try {
      x = event.clientX + document.body.scrollLeft;
      y = event.clientY + document.body.scrollTop;
   } catch(except) {
      x = e.clientX + window.scrollX;
      y = e.clientY +  window.scrollY;
   }
   var out = new Array(x,y);
   return out;
}

function processReqChange(f) 
{ if (req){
  if (req.readyState == 4 && req.status == 200 && m)
  {
  	document.getElementById('otziv_contentid').style.color='#e0e0e0';
  	document.getElementById('otziv_contentid').value=add_success;
  	document.getElementById('otziv_contentid').readOnly=true;
	document.getElementById('but_add').style.display='none';
  }
  else if (req.readyState == 4 && req.status == 200 )
  {  if (f) f(req);
  } }
}
// ---------------------------------------------
function getXMLHTTPRequest() 
{
  var xRequest=null;
  if (window.XMLHttpRequest) 
  {
    xRequest=new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    try { xRequest=new ActiveXObject("Msxml2.XMLHTTP"); } catch (err) {
    try { xRequest=new ActiveXObject("Microsoft.XMLHTTP"); } catch(err) { xRequest=false; } }
  }
  return xRequest;
}
// --------------------------------------------------
function sendRequest(url,HttpMethod,CallbackFunctionName)
{
  if (!HttpMethod) {HttpMethod="GET";}
  req=getXMLHTTPRequest();
  if (req)
  {
    req.onreadystatechange=function() { processReqChange(CallbackFunctionName); };
    req.open(HttpMethod,url,true);
    req.send('');
  }
}
// ---------------------------------------------

function showProgres(idOutput,Message)
{
  var arrayProgress = new Array('|','/','-','\\')
  if (showProgressBar)
  {
    var elOutput = document.getElementById(idOutput);
    if (elOutput)
    {
      var elP2 = document.getElementById('outputProgress');
      if (!elP2)
      {
        elOutput.innerHTML = '';
        var elP1 = document.createElement('center');
        elP1.innerHTML = Message;
        elP1.className = 'pProgressInMainWindow';
        elOutput.appendChild(elP1);
        elP2 = document.createElement('center');
        elP2.id = 'outputProgress';
        elP2.innerHTML = '.';
        elP2.className = 'pProgressInMainWindow';
        elOutput.appendChild(elP2);
      }
      else
      {
        if (elP2.innerHTML.length == 5) elP2.innerHTML = '.';
        else elP2.innerHTML += '.';
      }
    }
  setTimeout("showProgres('"+idOutput+"','"+Message+"')",200);
  }
}
function getShowDivAjax()
{
  showProgressBar = false;
  var elDiv = document.getElementById('aboutDiv');
  elDiv.innerHTML = '';
  elDiv.innerHTML = req.responseText;
}
function getSellsDivAjax()
{
  showProgressBar = false;
  //alert("test");
  var elDiv = document.getElementById('top3');
  elDiv.innerHTML = '';
  elDiv.innerHTML = req.responseText;
	divID='top3';text='';
	var src=document.getElementById('bnt'+divID).src;
	if(src!=""){src=src.substr(src.length-8,8);
	if(src!='inus.jpg'){document.getElementById('bnt'+divID).src='images/minus.jpg';
	showText(divID, text);
	}}


}
function showDiv1(url,text,className,event,progressText,charset)
{
  if (!charset) charset = 'windows-1251';
  XY = getMouseXY(event);
  if (XY[0]+divWid>1000) {x=(1000-divWid);x+='px';}
  else x=XY[0]+'px';
  y=XY[1]+10;
  y += 'px';
  m=false;
  var elDiv = document.createElement('div');
  elDiv.id = 'aboutDiv';
  elDiv.style.visibility = 'visible';
  elDiv.className = className;
  with (elDiv.style) {position='absolute'; left=x; top=y;}
  document.body.appendChild(elDiv);
  showProgressBar = true;
  showProgres(elDiv.id,progressText);
  if (url != false)
  {  if (url.lenght>2&&url.substr(0,5)!='order'&&url.substr(0,5)!='visit'){
    sendUrl='response.php?charset='+charset+'&url='+encodeURI(url);
    sendRequest(sendUrl,'GET',getShowDivAjax); }else {
    sendUrl='includes/functions/response.php?menu='+url;
    sendRequest(sendUrl,'GET',getShowDivAjax);}
  }
  else if (text != false)
  {
    getShowDivTex(elDiv,text);
  }
  else
  {
    elDiv.innerHTML = 'Не указали ни урл ни текст';
    showProgressBar = false;
  }
}
function open_win(id) {
var w=700, h=500;
infos='<pre class="prettyprint">'+id+'</pre>';
 var l = (screen.availWidth-w)/2 , t = (screen.availHeight-h)/2;
 var win = window.open("http://www.partner.sotmarket.ru/code_popup.html","_blank","width="+w+",height="+h+",left="+l+",top="+t+",statusbar=no,toolbar=no,scrollbars=never,navbar=no");
 win.focus();
}
