﻿// JScript 文件
var currentPage='1';
var show='0';
var sort='d';
           
function mouseCoords(ev)
{
   if(ev.pageX || ev.pageY)
   {
     return {x:ev.pageX,y:ev.pageY};
   }
     return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
             y:ev.clientY + document.documentElement.scrollTop - document.body.clientTop};
}

function mouseClick(e)
{
  var e = e || window.event;  
  var mousePos = mouseCoords(e);
  var objClick = document.getElementById('imgClick'); 
  objClick.style.left = (mousePos.x-60)+"px";
  objClick.style.top = (mousePos.y-60)+"px";
  objClick.style.display = 'block';
  setTimeout("hideClick()",100);
}

function hideClick()
{
   document.getElementById('imgClick').style.display="none";
   //objClick.style.display = 'none';
}

function getClientSize()
{
   var clientWidth;
   var clientHeight;
   if(navigator.appName.indexOf("Netscape") != -1)
   {
       clientWidth=Math.min(window.innerWidth,
                document.documentElement.clientWidth);
       clientHeight=Math.min(window.innerHeight,
                document.documentElement.clientHeight);
//clientWidth = document.documentElement.clientWidth;
//       clientHeight = document.documentElement.clientHeight;
   }
   if(navigator.appName.indexOf("Microsoft") != -1)
   {
       clientWidth = document.documentElement.clientWidth;
       clientHeight = document.documentElement.clientHeight;
   }
   if(navigator.appName.indexOf("Opera") != -1)
   {
       clientWidth=Math.min(window.innerWidth,
                document.documentElement.clientWidth);
       clientHeight=Math.min(window.innerHeight,
                document.documentElement.clientHeight);
   }
   return {width:clientWidth,height:clientHeight};
}

function showQuickView(id)
{
    var clientBounds = getClientSize();
    var clientWidth = clientBounds.width;
    var clientHeight = clientBounds.height;
    var quickViewDialog = document.getElementById("quickView");
    var scrollLeft = clientWidth/2-quickViewDialog.style.width.replace('px','')/2 ;
    var scrollTop = getPos(document.getElementById('n_celldetail_'+id)).tagTop; 
    
    quickViewDialog.style.left = scrollLeft+"px";
    quickViewDialog.style.top = scrollTop+"px";
    quickViewDialog.style.display = 'block';
    
    xmlHttpQV = createXMLHttpRequest();
    if(xmlHttpQV)
    {
       var url = "/ajax/GetProductDetail.aspx?id="+id+"&ts="+new Date().getTime(); 
       xmlHttpQV.open("Get",url);
       xmlHttpQV.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpQV.onreadystatechange=outPutDetail;
       xmlHttpQV.send(null);                                   
       quickViewDialog.innerHTML = "<img src=\"/Controls/ctrlImg/loading2.gif\" />";
    }
                       
}

function gotoPage(page)
{
    var ajaxLayer = document.getElementById("ajaxLayer");
     currentPage = page;
    
    xmlHttpSearch = createXMLHttpRequest();
    if(xmlHttpSearch)
    {
       var url = "/ajax/search.aspx?categorys="+document.getElementById('hyCategory').value
                +"&key="+document.getElementById('hyKey').value
                +"&show="+show
                +"&sort="+sort
                +"&page="+page+"&ts="+new Date().getTime(); 
       xmlHttpSearch.open("Get",url);
       xmlHttpSearch.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
       xmlHttpSearch.onreadystatechange=outPutSearch;
       xmlHttpSearch.send(null); 
                                        
       ajaxLayer.innerHTML = "<img src=\"/Controls/ctrlImg/loading2.gif\" />";
       
    }
}

function changeShow(showtype)
{
   show=showtype;
   document.getElementById("divshow").className = showtype=='0'?'productList':'productGrid';
   if(showtype=='0')
   {
       //document.getElementById('hyShow').value==
       document.getElementById("img_grid").src = "/Controls/ctrlImg/display_mode_grid.gif";
       document.getElementById("img_list").src = "/Controls/ctrlImg/display_mode_list_act.gif";
       
   }
   else
   {
       document.getElementById("img_grid").src = "/Controls/ctrlImg/display_mode_grid_act.gif";
       document.getElementById("img_list").src = "/Controls/ctrlImg/display_mode_list.gif";
   }
   
   gotoPage(currentPage);
}

function changeSort(sorttype)
{
    sort=sorttype;
    
   if(sorttype=='p')
   {
       //document.getElementById('hyShow').value==
       document.getElementById("img_price").src = "/Controls/ctrlImg/sortby_price_up_act.gif";
       document.getElementById("img_pricedown").src = "/Controls/ctrlImg/sortby_price_down.gif";
       
   }
   else if(sorttype == "pd")
   {
       document.getElementById("img_price").src = "/Controls/ctrlImg/sortby_price_up.gif";
       document.getElementById("img_pricedown").src = "/Controls/ctrlImg/sortby_price_down_act.gif";
   }
   else
   {
       document.getElementById("img_price").src = "/Controls/ctrlImg/sortby_price_up.gif";
       document.getElementById("img_pricedown").src = "/Controls/ctrlImg/sortby_price_down.gif";
   }
   
   gotoPage(currentPage);
}

function getPos(obj)
{
	x=obj.offsetLeft;
	y=obj.offsetTop;	
	while(obj=obj.offsetParent)
	{
		x+=obj.offsetLeft;
		y+=obj.offsetTop;
	}	
	return {tagLeft:x,tagTop:y}; 
}

function outPutDetail()
{
    if(xmlHttpQV.readyState==4)
    {
       if(xmlHttpQV.status==200)
       {
           objtag = document.getElementById("quickView");
           objtag.innerHTML = "<div style=\" width:670px; height:20;background-color:#E0E0E0; \"><img style=\"float:right; margin-right:10px;cursor:pointer\" src=\"/Controls/ctrlImg/delete.gif\" title=\"关闭\" onclick=\"mouseClick(event);document.getElementById('quickView').style.display='none';\" /></div>";
           objtag.innerHTML += ("<div id=\"introduce_space\" style=\"width:670px;height:auto; overflow:auto;text-align:left\">"+xmlHttpQV.responseText+"</div>");
           intro_show();
       }
    }
}

function outPutSearch()
{      
    if(xmlHttpSearch.readyState==4)
    {
       if(xmlHttpSearch.status==200)
       {       
           document.getElementById("ajaxLayer").innerHTML = xmlHttpSearch.responseText;
           document.getElementById("divshow").className = show=='0'?'productList':'productGrid';
           var cp = document.getElementById('page'+currentPage.toString());   

              cp.className = 'current';
              cp.title = '当前页'; 
       }
    }
}



