// <!-- Ajax
var req;
var id;

function loadXMLDoc(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() {

    ab = window.setTimeout("req.abort();", 5000);
    
    if (req.readyState == 4) {
        clearTimeout(ab);
		
        // Если "OK"
        if (req.status == 200) {
			var div = document.getElementById(id);
			div.innerHTML = req.responseText;
			//alert(req.responseText)
        } else {
            alert("Ajax: ошибка!");
        }
    }  
}

function requestdata(params)
{
  id = 'idBigImage';
  loadXMLDoc('/modules/catalog/ajax_photo.php?'+params);
}

//  конец Ajax  -->

// <!-- Ajax
var req;
var id;

function MloadXMLDoc(url) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = MprocessReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = MprocessReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function MprocessReqChange() {

    ab = window.setTimeout("req.abort();", 500000);
    
    if (req.readyState == 4) {
        clearTimeout(ab);
		
        // Если "OK"
        if (req.status == 200) {
			var div = document.getElementById(id);
			div.innerHTML = req.responseText;
			//alert(req.responseText)
        } else {
           // alert("Ajax: ошибка!");
        }
    }  
}

function Mrequestdata(params, w, h)
{
  id = 'portphoto';
  MloadXMLDoc('/modules/catalog/ajax_mobile.php?ajax=1&'+params);
  CenterDiv(w, h);
}

function CenterDiv(w, h)
{
			var div = document.getElementById("portphoto");
			div.style.left = ((document.body.clientWidth/ 2)-(w/2)) + "px";
		    div.style.top = (document.documentElement.scrollTop+50) + "px";
			//alert(;
}

//  конец Ajax  -->

function getyScroll()
 {
  yScroll = 0;

  if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX)
   {
    yScroll = window.innerHeight + window.scrollMaxY;
    xScroll = window.innerWidth + window.scrollMaxX;

    var deff = document.documentElement;
    var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
    var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;

    xScroll -= (window.innerWidth - wff);
    yScroll -= (window.innerHeight - hff);
   } 
  else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
   { // all but Explorer Mac
    yScroll = document.body.scrollHeight;
    xScroll = document.body.scrollWidth;
   } 
  else 
   { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    yScroll = document.body.offsetHeight;
    xScroll = document.body.offsetWidth;
   }

  return yScroll;
 }


function showportform()
 {
  var portphoto = document.getElementById("portphoto");
  var screen = document.getElementById("screen");
  portphoto.style.display = 'block';
  screen.style.display = 'block';
  screen.style.height = getyScroll() + 'px'; //window.innerHeight + window.scrollMaxY;
 }

function hideportform()
 {
  var portphoto = document.getElementById("portphoto");
  var screen = document.getElementById("screen"); 
  portphoto.style.display = 'none';
  screen.style.display = 'none';
 }
 
 

function clickSmallImage(namePic){
	document.getElementById('idBigImage').innerHTML="<img src='/" + namePic + "' alt=\"\">";
}

function open_basket(lnk,width,height) //opens new window
{
   var wnd_class = "width="+width+",height="+height+",location=no,menubar=no,scrollbars=yes,resizable=yes";
   win = window.open(lnk,'win',wnd_class);
   win.focus();
}
//

function JSMenu(menu,image) {
   nameDiv=eval("document.getElementById(menu)");
   myimage=eval("document.getElementById(image)");
   if(nameDiv.style.display=='none')
   {
   nameDiv.style.display='block';
   myimage.src='/images/minus.gif';
   myimage.title='Свернуть'
   }
   else
   {
   nameDiv.style.display='none';
   myimage.src='/images/plus.gif';
   myimage.title='Развернуть'
   }
}
