function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=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&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_controlShockwave(objStr,x,cmdName,frameNum) { //v3.0
  var obj=MM_findObj(objStr);
  if (obj) eval('obj.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
}

var OP = (navigator.appName == "Opera" || window.opera);
var IE = (navigator.appName == "Microsoft Internet Explorer")
var NS = (navigator.appName == "Netscape") //NS и Mozilla 
var http_request = false;
var publicId;
var tabId;
var clickId = "";
var statusLoad = false;
var module = "";
var timerID;
var timerIDnum = 0;
  
var whiteBlockEdit = "table-row";
if(navigator.appName == "Microsoft Internet Explorer")
{
  whiteBlockEdit = "inline-block";
}

function inputLimit(input, maxlen, left)
{
	inputstr = input.value;
	strlen = inputstr.length;
	if (strlen > maxlen)
		input.value = inputstr.substring(0, maxlen);
	if (left)
		left = document.getElementById(left);
	if (left) {
		if (left.tagName == 'INPUT')
			left.value = maxlen - input.value.length;
		else
			left.innerHTML = maxlen - input.value.length;
	}
	return true;
}

function confirm_form(name1,name2)
{
  var obj1  = document.getElementById(name1);
  var obj2  = document.getElementById(name2);
  
  if(obj1.selectedIndex == 0 || obj2.selectedIndex == 0) 
  {
    alert("Не выбрана модель!");
    return false;
  }
  else 
  {
   return true;
  }
}

function change_section(type_id,mod)
{
	var t = new Date;
	var url  = 'xml_admin.php?type_id='+type_id+'&'+mod+'&d='+t.getTime();
	module = mod;
	alert(url);
  if(!statusLoad) GETRequest(url);
}

function GETRequest(url)
{
  http_request = false;

	if (window.XMLHttpRequest)
	{
    http_request = new XMLHttpRequest();
  	http_request.onreadystatechange = processGETReq;
  	http_request.open("GET", url, true);
  	http_request.setRequestHeader('Content-Type','text/html');
  	http_request.send(null);
	}
	else if (window.ActiveXObject) // branch for IE/Windows ActiveX version
	{
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e)
      {
        try
        {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
	  http_request.onreadystatechange = processGETReq;
  	http_request.open("GET", url, true);
  	http_request.setRequestHeader('Content-Type','text/html');
  	http_request.send();
	}

  if (!http_request)
  {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
}

function Basket(id,mod,price)
{
	var t = new Date;
	var url  = 'xml.php?id='+id+'&module='+mod+'&price='+price+'&'+mod+'&d='+t.getTime();
	module = mod;
  //alert(url);
  if(!statusLoad)  GETRequest(url);  
}

function LoadObject(id,mod,path)
{
  HideSubmenu();
	var t = new Date;
	var url  = 'xml.php?id='+id+'&module='+mod+'&path='+path+'&d='+t.getTime();
	module = mod;
  //alert(url);
  if(!statusLoad)  GETRequest(url);
}

function LoadImg(id,mod,align,path)
{
  HideSubmenu();
	var t = new Date;
	var url  = 'xml.php?id='+id+'&module='+mod+'&align='+align+'&path='+path+'&d='+t.getTime();
	module = mod;
  tabId   = "img_protector_"+align+id;
	clickId = align+id;
  //alert(url);
  //alert(tabId+" "+clickId);
  if(!statusLoad)  GETRequest(url);
}


function processGETReq()
{
  //window.status += " | " + http_request.readyState;
  //var obj = document.getElementById(tabId);
  
  if (http_request.readyState == 1)
  {
    //obj.innerHTML = '<img src="img/loading.gif" border="0">';
    statusLoad = true;
  }
  else if (http_request.readyState == 4)
  {
    if (http_request.status == 200)
    {
      if( http_request.responseText != "")
      {
        //alert(http_request.responseText);
        if(module != "")
        {
           //obj.style.display = 'none';
          //obj.innerHTML = "";
  				if(module == "public")
  				{ 
  				  //alert( http_request.responseText);
  				  var obj = document.getElementById("LayerObj");
  				  obj.innerHTML = http_request.responseText;
  				  show('LayerBgr','LayerObj');
  				}
  				else if(module == "map" || module == "descr" || module == "more" || module == "size" || module == "photos")
  				{ 
  				  //alert( http_request.responseText);
  				  var obj = document.getElementById("LayerObj");
  				  obj.innerHTML = http_request.responseText;
  				  show('LayerBgr','LayerObj');
  				}  
                                                               	else if(module == "technologies" || module == "descr" || module == "more" || module == "size" || module == "photos")
  				{ 
  				  //alert( http_request.responseText);
  				  var obj = document.getElementById("LayerObj");
  				  obj.innerHTML = http_request.responseText;
  				  show('LayerBgr','LayerObj');
  				}  				
  				else if(module == "basket" || module == "basket_clear")
  				{ 
  				  //alert( http_request.responseText);
  				  var obj = document.getElementById("SubmenuText7");
  				  //alert(obj.innerHTML);
  				  obj.innerHTML = http_request.responseText;
  				  if(module == "basket") showBasket();
  				}  			
  				else if(module == "protector")
  				{ 
  				  //alert( http_request.responseText);
  				  var obj = document.getElementById(tabId);
  				  obj.src = http_request.responseText;
  				  //alert(tabId+" "+clickId);
  				  Hide_photo(clickId,1);
  				}  				
  				
        }
        else
        {
          //obj.innerHTML = http_request.responseText;
        }

        //alert(tabId);
      }
      else
      {
        //alert("responseText=null");
        //obj.innerHTML = http_request.responseText;
      }

      if(clickId !="")
      {
        //var clicked = document.getElementById(clickId);
        //clicked.onclick = null;
        var v = "Clicked"+clickId+"=true";
        eval(v);
        //alert(v);
      }

      statusLoad = false;
    }
    else
    {
      alert("Не удалось получить данные:\n" + http_request.statusText);
    	//alert("There was a problem retrieving the XML data:\n" + http_request.statusText);
    }
  }
}

function hide(layer1,layer2)
{
  var L1 = document.getElementById(layer1);
  var L2 = document.getElementById(layer2);
  //L1.style.visibility = 'hidden';
  L1.style.height = 0;
  L2.style.height = 0;
  //L2.style.visibility = 'hidden';
  L1.style.height = 0;
  L2.style.height = 0;
  L1.style.width  = 0;
  L2.style.width  = 0;
  L1.style.display = 'none';
  L2.style.display = 'none';
  document.getElementById('LayerObj').style.display = 'none';
  document.getElementById('obj_flash').style.display = whiteBlockEdit;
}

function show(layer1,layer2)
{
  var layerBgr = document.getElementById(layer1);
  var layer = document.getElementById(layer2);
  var layer_text = document.getElementById("text_block");
  var HeaderHeight = 0; //65;
  var Window_W = 800; //858;
  var window_height;
  var window_width; //Размеры содержимого документа

  //alert(document.body.scrollWidth);
  //alert(document.body.scrollTop);

  layer.style.width = Window_W;
  
  if(IE)
  {
    window_width  = document.body.scrollWidth;
    window_height = document.body.clientHeight;
    layerBgr.style.height = document.body.scrollHeight; 
    layerBgr.style.width  = document.body.clientWidth;
    layer.style.top  = document.body.scrollTop + "px"; 
    if(document.body.scrollTop < 400) document.getElementById('obj_flash').style.display = 'none';
  }
  else  //Netscape, Mozilla, Opera 
  {
    window_width = document.width;
    window_height = window.innerHeight;
    layerBgr.style.height = document.height; 
    layerBgr.style.width  = window.innerWidth;    
    layer.style.top  = window.pageYOffset + "px"; 
    if(window.pageYOffset < 400) document.getElementById('obj_flash').style.display = 'none';
  }
  //alert(layer.style.top);  
  
  //layerBgr.style.visibility = 'visible';
  layerBgr.style.display = whiteBlockEdit;
  
  layer.style.height = 550; //(window_height +"px";;
  layer.style.left = (window_width - Window_W)/2;
  //alert(window_width+" "+Window_W+" "+layer.style.left);
  //alert(window.pageYOffset);
  
  layer_text.style.width  = 800; //600;
  layer_text.style.height = 550; //window_height;
  
  //layer.style.visibility = 'visible';
  layer.style.display = whiteBlockEdit;
  //alert("document.body.scrollTop="+document.body.scrollTop+ "layer.top="+layer.style.top );
  //window.scrollTo(0,0); 
  //alert("layertop="+layer.style.top+" clientHeight="+document.body.clientHeight + " scrollTop="+document.body.scrollTop + " scrollHeight="+document.body.scrollHeight);
}


function showBasket()
{
  HideSubmenu();
  var Lwidth = 500;
  var layerBgr = document.getElementById("LayerBgr");
  if(IE)
  {
    layerBgr.style.height = document.body.scrollHeight; 
    layerBgr.style.width  = document.body.clientWidth;
  }
  else  //Netscape, Mozilla, Opera 
  {
    layerBgr.style.height = document.height; 
    layerBgr.style.width  = window.innerWidth;    
  }
  
  //layerBgr.style.visibility = 'visible';
  layerBgr.style.display = whiteBlockEdit;
    
  var layer = document.getElementById("LayerInfo");
  layer.style.width = Lwidth;
  //alert(document.body.clientHeight+" "+document.body.scrollTop);
  
  if(IE)
  {
    layer.style.left = document.body.clientWidth/2 - Lwidth/2;
    layer.style.top  = document.body.scrollTop + (document.body.clientHeight/2 - 100) + "px"; 
    if(document.body.scrollTop < 400) document.getElementById('obj_flash').style.display = 'none';
  }
  else  //Netscape, Mozilla, Opera 
  {
    layer.style.left = window.innerWidth/2 - Lwidth/2;    
    layer.style.top  = window.pageYOffset + (window.innerHeight/2 - 100) + "px"; 
    if(window.pageYOffset < 400) document.getElementById('obj_flash').style.display = 'none';
  }  
  
  layer.style.display = whiteBlockEdit;
}

function showSubmenu(n)
{
  var layer;
  var objText;
  var px;
  //timerIDnum = 0;
  
  var frames=1; 
  if(n == 1)
  {
    frames = 1;
  }
  else if(n == 2)
  {
    frames = 47;
  }  
  else if(n == 3)
  {
    frames = 77;
  }  
  else if(n == 4)
  {
    frames = 17;
  }  
  else if(n == 5)
  {
    frames = 62;
  }  
  else if(n == 6)
  {
    frames = 62;
  }  
  else if(n == 7)
  {
    frames = 32;
  }  
  

  if(n == 7)
  {
    document.getElementById('LayerSubmenu').style.display = 'none';
    layer = document.getElementById("LayerSubmenuRight");
    objText  = document.getElementById("SubmenuTextRight");
  }
  else
  {
    document.getElementById('LayerSubmenuRight').style.display = 'none';
    layer = document.getElementById("LayerSubmenu");
    objText  = document.getElementById("SubmenuText");
  }
    
  var pixel = document.getElementById("Submenu"+n).offsetLeft;
  
  
  if(OP)
  {
    //alert("Opera");
    layer.style.top = 432;
	if (self.screen) { // для браузеров 4-тых версий
    width = screen.width 
    height = screen.height
    }
    else if (self.java) { // для NN3 (enabled Java)
    var jkit = java.awt.Toolkit.getDefaultToolkit();
    var scrsize = jkit.getScreenSize(); 
    width = scrsize.width; 
    height = scrsize.height; 
     }else{
    width = height = 'x' // для прочих браузеров
    }
	if (width == 800) {
    px = (n == 7) ? 13 : -108;
    }
    else if (width == 1024) {
	px = (n == 7) ? 124 : 3;
    }
    else if (width == 1280) {
	px = (n == 7) ? 124 : 3;
    }
	else if (width == 1600) {
	px = (n == 7) ? 124 : 3;
    }
  }
  else if(IE)
  {
    //alert("IE");
    layer.style.top = 431;  
    px = (n == 7) ? 124 : 3;
  }
  else if(NS) //NS и Mozilla 
  {
    //alert("Mozilla");
    layer.style.top = 432;
     px = (n == 7) ? 130 : 7;
  }
  else 
  {
    //alert("other");
    layer.style.top = 435;
    px = (n == 7) ? 124 : 3;
  }
  //alert(layer.style.top);
  layer.style.width = 247;
  layer.style.height = 128;
  layer.style.left = (document.body.scrollWidth - 858)/2 + pixel - px;
  
  //layer.style.visibility = 'visible';
  layer.style.display = whiteBlockEdit;
  objText.innerHTML = document.getElementById("SubmenuText"+n).innerHTML;
  //debug(document.getElementById(td));
  //alert(document.body.scrollWidth);
  clearTimeout(timerID);
  var sek;
  sek = (n == 5) ? 30000 : (n == 7) ? 10000 : 5000;
  timerID = setTimeout(HideSubmenu,sek);
  //alert("clientHeight="+document.body.clientHeight + " scrollHeight="+document.body.scrollHeight);
  try
  {
     MM_controlShockwave('f_right','','GotoFrame',frames);
     MM_controlShockwave('f_right','','Play');
  } catch (e) {}  
}

function HideInfo()
{
  //document.getElementById('LayerSubmenu').style.visibility = 'hidden';
  //document.getElementById('LayerSubmenuRight').style.visibility = 'hidden';
  document.getElementById('LayerSubmenu').style.display = 'none';
  document.getElementById('LayerSubmenuRight').style.display = 'none'; 
}

function HideSubmenu()
{
  
  //document.getElementById('LayerSubmenu').style.visibility = 'hidden';
  //document.getElementById('LayerSubmenuRight').style.visibility = 'hidden';
  //if(timerIDnum > 0)
  {
    document.getElementById('LayerSubmenu').style.display = 'none';
    document.getElementById('LayerSubmenuRight').style.display = 'none'; 
  }
  //timerIDnum = timerIDnum+1;  
}

function Hide_photo(id,act)
{
  var photo_visible;
  var photo_hide;

  if(act == 1)
  {
   photo_visible = document.getElementById('tr_protector_'+id);
   photo_hide    = document.getElementById('tr_photo_'+id);    
  }
  else
  {
   photo_visible = document.getElementById('tr_photo_'+id);
   photo_hide    = document.getElementById('tr_protector_'+id);        
  }
  photo_hide.style.display = 'none';
  photo_visible.style.display = whiteBlockEdit;
}

function Hide_photo_catalog(id,act)
{
  var photo_visible;
  var photo_hide;
  
  if(act == 1)
  {
   photo_visible = document.getElementById('tr_protector_'+id);
   photo_hide    = document.getElementById('tr_photo_'+id);    
  }
  else
  {
   photo_visible = document.getElementById('tr_photo_'+id);
   photo_hide    = document.getElementById('tr_protector_'+id);        
  }
  //alert(photo_visible);
  photo_hide.style.display = 'none';
  photo_visible.style.display = whiteBlockEdit;
}
