//js
var ajaxcounter = 0;
var interval = 0;
var interval1 = 0;
var activeuser = '';
var nitemphotoa='';
var noshowimcenter=0;
var imgcount=0;
var reviewcount=0;
var nInterval = 0;
var bAcceptBg = false;
var searchTimeOut = null;
var umTimeOut = null;
var subTimeOut = null;
var sameTimeOut = null;
var parTimeOut = null;
var zamacta = null;
var browser = new Browser();
nMenuYPos = 0;
nYDelta = 0;
nPrevScrollPos = 0;
nCurrentBlId = 7;
sDisableSearch = '';
nJabberUser = 0;
var gotolink = '';
oldstatus = 0;

nCurrentRubId = 0;
sCurrentRub = '';
nCurrentTagId = 0;
sCurrentTag = '';

vldnotb = 1;

SmthChangedInForms = new Array();

im=new Image();
im.src='/i/sp_buttono.png';

function SfindObj(n, d) 
{	//v4.01
	var p, i, x;
	if (!d) d = window.document; 
	if ((p = n.indexOf("?") ) > 0 && parent.frames.length) 
	{
		d = parent.frames [n.substring(p + 1)].document; 
		n = n.substring(0, p);
	}
	if (!(x = d [n]) && d.all) 
		x = d.all [n]; 

	for (i = 0; !x && d.forms && i < d.forms.length; i ++) 
		x = d.forms [i] [n];

	for (i = 0; !x && d.layers && i < d.layers.length; i ++)
		x = SfindObj(n, d.layers [i].document);
	if(!x && d.getElementById) 
		x = d.getElementById(n);
	return x;
}

function ShowProd (wwidth,wheight,isrc,modelid) {
	if(isrc=='/') return;
	
	obj1=SfindObj('preview');
	obj2=SfindObj('previewimg');
	obj3=SfindObj('previewtbl');
	obj4=SfindObj('loading');
	
	//if (modelid >=0 ) {
		objLoad=SfindObj("loaddata");
		objLoad.innerHTML=modelid + '&nbsp;';
		//objLoad.style.display='none';
	//}
	
	obj2.src='/i/dot.gif';
	wheight = wheight*1+20;
	obj1.style.width=wwidth+'px';
	obj1.style.height=wheight+'px';
	
	obj3.style.width=wwidth+'px';
	obj3.style.height=wheight+'px';
	
	obj4.style.width=wwidth+'px';
	obj4.style.height=wheight+'px';

	CenterLayer('preview',wwidth,wheight,window.document);
	obj1.style.visibility='visible';

	obj2.src=isrc;
}

function HideProd () {
	obj1=SfindObj('preview');
	obj2=SfindObj('previewimg');
	objLoad=SfindObj("loaddata");
	objLoad.innerHTML='';
	obj2.src='/i/dot.gif';
	obj1.style.visibility='hidden';
}


function getClientWidth()
{
  return !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function CenterLayer (layer,width,height,target,xoffset,yoffset) {
	if (!target)
		target=window.document;
	
	LeftX = LeftY = 0;
	
	topLayer=parseInt(target.body.scrollTop);

	if ((LeftX+width) > target.body.clientWidth)
		LeftX = 0;

	if ((LeftY+height) > target.body.clientHeight)
		LeftY = 0;

	if ((LeftX > 0) && (LeftY > 0)) {
		target.getElementById(layer).style.left = LeftX+'px';
		target.getElementById(layer).style.top = LeftY+topLayer+'px';
	}
	else {
		if (!xoffset)
			xoffset = 0;
			
		if (!yoffset)
			yoffset = 0;
	
		leftLayer = ((target.body.clientWidth - width)/2);
		topLayerABS = (target.body.clientHeight - height)/2;
		
		newTop = topLayer + topLayerABS;
		if (newTop < 0)
			newTop=0;
			
		nTop = topLayer + topLayerABS + yoffset;
		nLeft = leftLayer + xoffset;
		
		if (nTop < target.body.scrollTop)
			nTop = target.body.scrollTop + 5;
		
		target.getElementById(layer).style.left = nLeft + 'px';
		target.getElementById(layer).style.top= nTop + 'px';
	}
}


function Hide (sObject) {
	obj = SfindObj(sObject);
	if (obj)
		obj.style.display = 'none';
}

function HideClear (sObject) {
	obj = SfindObj(sObject);
	if (obj) {
		obj.innerHTML = '';
		obj.style.visibility = '';
		obj.style.left = '-5000px';
		obj.style.top = '-5000px';
	}
	
	if (sObject == 'ajax2')
		HideClear('ajax2_1');
}

function ButtonPress () {
	obj=SfindObj('midelaem2');
	obj.src='/i/sp_buttono.png';
	//obj.style.backgroundImage = "url(/i/sp_buttono.png)"; 
}

function ButtonUnPress () {
	obj=SfindObj('midelaem2');
	obj.src='/i/sp_button.png';
	//obj.style.backgroundImage = "url(/i/sp_button.png)";
}

function ShowLa(show)
{
	obj = SfindObj(show);
	if (obj)
		obj.style.display = 'block';
}

function HideLa(show)
{
	obj = SfindObj(show);
	if (obj)
	{
		obj.style.display = 'none';
		var obj1 = window.document.getElementById('ajaxwndimg');
		obj1.setAttribute('src','/i/dot.gif');
	}
}

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  
  this.isIE = true;
  this.version = parseFloat(ua.substr(i + s.length));
  return;
  
}

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;
var dragID = '';

function dragStart(event, id) {

  var el;
  var x, y;

	dragID = id;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.
  
  obj = SfindObj(id);
  obj.style.cursor = 'move';

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }
  
  

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  //dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

var coords = new Array();

function dragStop(event) {
	target=window.document;
	nScrollTop = target.body.scrollTop;

	dragObj.elNode.style.cursor = 'default';

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function show_wnd(width,height,img)
{
	var obj = window.document.getElementById('ajaxwnd');
	if(obj) obj.style.display = 'block';
	var obj1 = window.document.getElementById('ajaxwndimg');
	obj1.setAttribute('src',img);
	obj1.setAttribute('width',width);
	obj1.setAttribute('height',height);
	CenterLayer('ajaxwnd',width,height);	
}

//ajax

function ajax()
{
    //---------------------
    // Private Declarations
    //---------------------
    var _request = null;
    var _this = null;
    
    //--------------------
    // Public Declarations
    //--------------------
    var nAjaxWidth = 250;
    var nAjaxHeight = 200;
    var nAjaxXOffset = 0;
    var nAjaxYOffset = 0;
    
    this.GetResponseXML = function()
    {
        return (_request) ? _request.responseXML : null;
    };
    
    this.GetResponseText = function()
    {
        return (_request) ? _request.responseText : null;
    };
    
    this.GetRequestObject = function()
    {
        return _request;
    };
    
    this.InitializeRequest = function(Method, Uri)
    {
        _InitializeRequest();
        _this = this;
        
        switch (arguments.length)
        {
            case 2:
                _request.open(Method, Uri);
                break;
                
            case 3:
                _request.open(Method, Uri, arguments[2]);
                break;
        }
        
        if (arguments.length >= 4) 
            _request.open(Method, Uri, arguments[2], arguments[3]);
        this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    };
    
    this.SetRequestHeader = function(Field, Value)
    {
        if (_request) 
            _request.setRequestHeader(Field, Value);
    };
    
    this.Commit = function(Data)
    {
        if (_request) 
            _request.send(Data);
    };
    
    this.Close = function()
    {
        if (_request) 
            _request.abort();
    };
    
    //---------------------------
    // Public Event Declarations.
    //---------------------------
    this.OnUninitialize = function()
    {
    };
    this.OnLoading = function()
    {
    };
    this.OnLoaded = function()
    {
    };
    this.OnInteractive = function()
    {
    };
    this.OnSuccess = function()
    {
    };
    this.OnFailure = function()
    {
        //alert('AJAX Error. Sorry');
    };
    
    //---------------------------
    // Private Event Declarations
    //---------------------------
    function _OnUninitialize()
    {
        _this.OnUninitialize();
    };
    function _OnLoading()
    {
        _this.OnLoading();
    };
    function _OnLoaded()
    {
        _this.OnLoaded();
    };
    function _OnInteractive()
    {
        _this.OnInteractive();
    };
    function _OnSuccess()
    {
        _this.OnSuccess();
    };
    function _OnFailure()
    {
        _this.OnFailure();
    };
    
    //------------------
    // Private Functions
    //------------------
    function _InitializeRequest()
    {
        _request = _GetRequest();
        _request.onreadystatechange = _StateHandler;
    };
    
    function _StateHandler()
    {
        switch (_request.readyState)
        {
            case 0:
		try { window.setTimeout("void(0)", 100);} catch (error) {}
                _OnUninitialize();
                break;
                
            case 1:
                try { window.setTimeout("void(0)", 100);} catch (error) {}
                _OnLoading();
                break;
                
            case 2:
                try { window.setTimeout("void(0)", 100);} catch (error) {}
                _OnLoaded();
                break;
                
            case 3:
                try { window.setTimeout("void(0)", 100);} catch (error) {}
                _OnInteractive();
                break;
                
            case 4:
		try {rstatus = _request.status;} catch (error) {rstatus='';}
                if ((rstatus == 200) || !rstatus) 
                {
                    	try {
                    		ajaxcounter--;
			}
			catch(e) {;}
                    _OnSuccess();
                    
                }
                else 
                {
			try {
                    		ajaxcounter--;
			}
			catch(e) {;}
                    _OnFailure();
                }
                
                return;                break;
        }
    };
    
    function _GetRequest()
    {
        var obj;
        
        try 
        {
            obj = new XMLHttpRequest();
        } 
        catch (error) 
        {
            try 
            {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (error) 
            {
                try 
                {
                    obj = new ActiveXObject('Msxml2.XMLHTTP');
                } 
                catch (error) 
                {
                    return null;
                }
            }
        }
        
        return obj;
    };
};

function ShowAjaxIndicator()
{
}

function HideAjaxIndicator()
{
}


function apply_responce(xmldoc, nAjaxWidth, nAjaxHeight, nV, nAjaxXOffset, nAjaxYOffset)
{
    root = xmldoc.getElementsByTagName('root')[0];

    if (root) 
    {
        /*xml response*/
        //var root = xmldoc.getElementsByTagName('root')[0];
        if (root) 
        {
            for (var iNode = 0; iNode < root.childNodes.length; iNode++) 
            {
                if (root.childNodes[iNode].nodeType == 1) 
                {
					if (root.childNodes[iNode].tagName == 'scrolle') 
					{
						scrollt = 1; scrollMSG(); continue;						
					}
					else
					if (root.childNodes[iNode].tagName == 'scrolld') 
					{
						scrollt = 0; continue;						
					}
					else
                    if (root.childNodes[iNode].tagName == 'errmsg') 
					{
						
					}
					else
					if (root.childNodes[iNode].tagName == 'ajax2_1') 
                    {
                        obj = SfindObj('autosearch_title');
                        if (obj) 
                            obj.style.visibility = 'hidden';
                        obj = SfindObj('autosearch_manufacturer');
                        if (obj) 
                            obj.style.visibility = 'hidden';
                        obj = SfindObj('autosearch_model');
                        if (obj) 
                            obj.style.visibility = 'hidden';
                        obj = SfindObj('autosearch_fulltitle');
                        if (obj) 
                            obj.style.visibility = 'hidden';
                    }
                    else 
                        if (root.childNodes[iNode].tagName == 'ajax1_1') 
                        {
                            if (obj = SfindObj('autosearch_country')) 
                                obj.style.visibility = 'hidden';
                            if (obj = SfindObj('autosearch_town')) 
                                obj.style.visibility = 'hidden';
                        }

                    try 
                    {
                        innerH = root.childNodes[iNode].firstChild.nodeValue;
                        //alert(innerH);
                    } 
                    catch (error) 
                    {
                        innerH = '';
                    }

			SmthChangedInForms[root.childNodes[iNode].tagName]=0;

                    if (obj = SfindObj(root.childNodes[iNode].tagName)) 
                    {
                        if (root.childNodes[iNode].tagName == 'zcount') 
                            obj.value = innerH;
                        else {
				try {
					obj.innerHTML = innerH;
					scripts_arr = obj.getElementsByTagName("script");
					if (scripts_arr.length > 0)
						for(i in scripts_arr) eval(scripts_arr[i].text);
					if (root.childNodes[iNode].tagName == 'log')
						obj.scrollTop = '1000000';
					
				}
				catch (error) { }
			}
                    }
                    if (root.childNodes[iNode].tagName == 'shake') 
                        if(vldnotb)
                        	new Effect.Shake(innerH);
                        else 
                            msg('Проверьте введенные данные!','Ошибка');

                    if (root.childNodes[iNode].tagName.indexOf('ajax') != -1) 
                    {
                        /*obj.style.minwidth = nAjaxWidth;*/
                        /*obj.style.height = nAjaxHeight;*/
                        if (innerH) 
                        {
                            CenterLayer(root.childNodes[iNode].tagName, nAjaxWidth, nAjaxHeight, nV, nAjaxXOffset, nAjaxYOffset);
                            tag = root.childNodes[iNode].tagName;
                            wnds = ['ajax1', 'ajax2', 'ajax3', 'ajax4', 'ajaxim', 'ajaximchat'];
                            for (i = 0; i < wnds.length; i++) 
                                if (obj1 = SfindObj(wnds[i])) 
                                {//в 0 если не установлен ордер... надо бы заменить..
                                    z = parseInt(obj1.style.zIndex == undefined ? 10 : obj1.style.zIndex);
                                    if (isNaN(z)) 
                                        z = 10;
                                    else 
                                        if (z >= 1000) 
                                            z -= 1000;
                                    obj1.style.zIndex = tag == wnds[i] ? 1000 + z : z;
                                }
                        }
                    }

                    /*if (root.childNodes[iNode].tagName != 'zametkadiv' && obj && obj.style) 
                     obj.style.visibility = 'visible';*/
      if ((innerH.indexOf('<div class=ajaxi></div>') != -1) || (innerH.indexOf('<!-- begin --><!-- end -->') != -1) || (innerH.indexOf('<!-- begin --><!--') != -1)) 
      	HideClear(root.childNodes[iNode].tagName);
      
      if ((innerH.indexOf('<!-- imchat -->') != -1)) {
      	obj1 = SfindObj('prvmsg');
      	obj1.scrollTop = 10000000;
      }

		if ((root.childNodes[iNode].tagName == 'imind') && (innerH.indexOf('<!-- yes -->') != -1) && !noshowimcenter) {
								obj=SfindObj('imind');
								sText = obj.innerHTML;
                        obj=SfindObj('imcenter');
			obj.innerHTML = '<div style=padding-top:6px>' + sText + '<img src=/i/gui/closew.png class=imclose width=9 height=9 title="Закрыть" onclick=noshowimcenter=1;HideLa("imcenter")></div>';
			obj.style.display = 'block';
		}
		else if (root.childNodes[iNode].tagName == 'imind') {
			obj=SfindObj('imcenter');
			obj.style.display = 'none';
		}
                    
                    
                    if (innerH.indexOf('<!-- fulltitle -->') != -1) 
                        sDisableSearch = 'fulltitle';
                    
                    if (innerH.indexOf('<!-- title -->') != -1) 
                        sDisableSearch = 'title';
                    
                    if (innerH.indexOf('<!-- country -->') != -1) 
                        sDisableSearch = 'country';
                    
                    if (innerH.indexOf('<!-- region -->') != -1) 
                        sDisableSearch = 'region';
                    
                    if (innerH.indexOf('<!-- town -->') != -1) 
                        sDisableSearch = 'town';

		if ((root.childNodes[iNode].tagName == 'loginbar') && gotolink) 
                        document.location.href = gotolink;
		else	if ((root.childNodes[iNode].tagName == 'loginbar') && gotolinkc) {
			document.location.href = gotolinkc;
		}

                    /*if (root.childNodes[iNode].tagName == 'formresponsecontainer') 
                        AjaxSendRequest('/ajax/blognotessearch/', 'id=' + window.document.forms['formresponse'].id.value + '&gid=' + window.document.forms['formresponse'].gid.value + '', 'ajax2_1', 250, 200, 350);*/
                    if (root.childNodes[iNode].tagName.indexOf('message_') != -1) 
                    {
                        y = findPosY(root.childNodes[iNode].tagName);
                        window.scrollTo(0, y);
                    }

			if (innerH.indexOf('<!-- prvjsvgfrm -->') != -1) {
				obj=SfindObj('prvjsvgfrm');
				if (obj) {
					n = Math.round();
					obj.src = window.document.forms['vidgetjsform'].ihref.value + '&rnd=' + n;
				}
			}

			if (innerH.indexOf('<!-- formitem -->') != -1) {
				/*if (nCurrentRubId) {
					f=window.document.forms['formitem'];
					if (f.category)
						f.category.value=nCurrentRubId;
					obj=SfindObj('chooserub');
					if (obj && sCurrentRub)
						obj.innerHTML = sCurrentRub;
				}*/
				if (nCurrentTagId && sCurrentTag) {
					f=window.document.forms['formitem'];
					if (f.title)
						f.title.value=sCurrentTag;
				}
			}

                }
            }
            HideAjaxIndicator();
        }
    }
}

AjaxObject = function()
{
    this.OnSuccess = function()
    {
        xmldoc = this.GetResponseXML();
	//alert(this.GetResponseText())
        //alert(http.responseText);
        
        if (!xmldoc) 
            return;
	if (typeof apply_responce == "function")
        	apply_responce(xmldoc, this.nAjaxWidth, this.nAjaxHeight, 0, this.nAjaxXOffset, this.nAjaxYOffset);
        
    };
    
    this.GetData = function(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset)
    {
        this.InitializeRequest('POST', action, true);
        vars = vars + '&mdx0n=1';
        this.Commit(vars);
        this.nAjaxWidth = newWidth;
        this.nAjaxHeight = newHeight;
        this.nAjaxXOffset = newXOffset;
        this.nAjaxYOffset = newYOffset;
        ajaxcounter++;
    };
};

function AjaxSendRequest(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset)
{
    if (vars) 
        vars = vars + '&object=' + sObject;
    else 
        vars = 'object=' + sObject;
	 
    if (!newWidth) 
        newWidth = 347;
    if (!newHeight) 
        newHeight = 210;
    if (!newXOffset) 
        newXOffset = 0;
    if (!newYOffset) 
        newYOffset = 0;
    
    AjaxObject.prototype = new ajax();
    myObject = new AjaxObject();
    myObject.GetData(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset);
    if (action.indexOf('imreceive') <= 0) 
        ShowAjaxIndicator();
}

function AjaxSendPOST(action, form, sObject, newWidth, newHeight, newXOffset, newYOffset)
{
    vars = '';
    for (i = 0; i < window.document.forms[form].elements.length; i++) 
    {
        elem = window.document.forms[form].elements[i];
        if (((elem.type == 'checkbox') || (elem.type == 'radio')) && elem.checked != true) 
            continue;
        vars = vars + '&' + elem.name + '=' + encodeURIComponent(elem.value);
    }
    if (vars) 
        vars = vars + '&object=' + sObject;
    else 
        vars = 'object=' + sObject;
    
    if (!newWidth) 
        newWidth = 347;
    if (!newHeight) 
        newHeight = 210;
    if (!newXOffset) 
        newXOffset = 0;
    if (!newYOffset) 
        newYOffset = 0;
    ;
    
    AjaxObject.prototype = new ajax();
    myObject = new AjaxObject();
    myObject.GetData(action, vars, sObject, newWidth, newHeight, newXOffset, newYOffset);
    ShowAjaxIndicator();
}


function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  
  this.isIE = true;
  this.version = parseFloat(ua.substr(i + s.length));
  return;
  
}

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;
var dragID = '';

function dragStart(event, id) {

  var el;
  var x, y;

	dragID = id;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.
  
  obj = SfindObj(id);
  obj.style.cursor = 'move';

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }
  
  

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  //dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

var coords = new Array();

function GetXYScroll () {
	
	myPageX=parseInt(document.body.scrollLeft);
	myPageY=parseInt(document.body.scrollTop);
	
	if (!myPageY && (document.documentElement.scrollTop > 0)) {
		myPageX=parseInt(document.documentElement.scrollLeft);
		myPageY=parseInt(document.documentElement.scrollTop);
	}
	if (!myPageY && (window.pageYOffset > 0)) {
		myPageX=parseInt(window.pageXOffset);
		myPageY=parseInt(window.pageYOffset);
	}
	temp = new Array();
	temp[0] = myPageX;
	temp[1] = myPageY;
	return temp;
}

function dragStop(event) {
	/*target=window.document;
	nScrollTop = target.body.scrollTop;*/
	aXY = GetXYScroll();
	nScrollTop = aXY[1];

	/*obj = SfindObj('ajax1');obj.style.cursor = 'default';
	obj = SfindObj('ajax1_1');obj.style.cursor = 'default';
	obj = SfindObj('ajax2');obj.style.cursor = 'default';
	obj = SfindObj('ajax2_1');obj.style.cursor = 'default';
	obj = SfindObj('ajax3');obj.style.cursor = 'default';
	obj = SfindObj('ajax4');obj.style.cursor = 'default';
	obj = SfindObj('ajaxim');obj.style.cursor = 'default';
	obj = SfindObj('ajaximchat');obj.style.cursor = 'default';*/
	
	//return cursor
	dragObj.elNode.style.cursor = 'default';
	//coords[dragID+'_x'] = dragObj.elNode.style.left;
	//coords[dragID+'_y'] = dragObj.elNode.style.top;
	if(vldnotb)
	{
	}
	//alert(coords[dragID+'_x']);

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function SpyOnline () {
	AjaxSendRequest('/online/refreshlog','','log');
}

var itemsblink = new Array();

function blink()
{
  for(var i=0; i< itemsblink.length; i++) 
	itemsblink[i].style.visibility = itemsblink[i].style.visibility == 'hidden'?'visible':'hidden';
}

function init_blink(classname, id)
{
  var obj = document.getElementById(id);
  if(!obj) return;
  
  var allitems = obj.getElementsByTagName("*");
  if (allitems.length <= 0) return;
  
  for(var j=i=0;i<allitems.length;i++)  
	if (allitems[i].className.indexOf(classname) != -1) 
	  itemsblink[j++] = allitems[i];
  if(itemsblink.length>0) setInterval(blink, 1000);
}

function addHandler(node, evt, func) {
    if (node.addEventListener) {
        node.addEventListener(evt, func, false); 
    } else {
        node.attachEvent('on' + evt, func);     
    }
};
 
function isParent(child, parent) {
    if (!child || !parent) {
        return false;
    }
    while (true) {
        if (child == parent) {
            return true;
        }
        if (child.parentElement) {
            child = child.parentElement;
        } else if (child.parentNode) {
            child = child.parentNode;
        } else {
            return false;
        }
    }
}
 
addHandler(window, 'load', function() {
	init_blink('blink', 'menu');
});
