﻿function setImgSize( img,W,H,_type){
var mywidth=0;
var myheight=0;
var image=new Image(); 
image=img; 
if(image.width>0 && image.height>0)
{ 
  flag=true; 
  if(image.width/image.height<= W/H){ 
     if(image.width>W){ mywidth=W; myheight=(image.height*W)/image.width; }
     else{ mywidth=image.width;myheight=image.height; } 
   /*ImgD.alt="bigpic" */
  } 
  else{ 
    if(image.height>H){ myheight=H; mywidth=(image.width*H)/image.height; }
    else{  mywidth=image.width;myheight=image.height;  } 
    /*ImgD.alt="bigpic" */ 
  } 
}
mywidth=parseInt( mywidth);
myheight=parseInt( myheight); 
var pw =0;
var ph =0; 

var mw=0;
var mh=0;
var mystyle;
if(mywidth!=0){pw =parseInt( mywidth);ph =parseInt( myheight); }
else{pw =parseInt( mywidth);ph =300; }

if(_type=="1"){
 if(pw-200>0){mw=parseInt((pw-200)/2);}
 if(ph-270>0){mh=parseInt((ph-270)/2);}
 mystyle={ margin:"-"+ mh+"px 0 0 -"+ mw+"px" , height:ph+"px"};
}

if(_type=="2"){
  if(pw-200>0){mw=parseInt((pw-200)/2);}
  if(ph-270>0){mh=parseInt((ph-270)/2);}
  mystyle="margin:-"+ mh+"px 0 0 -"+ mw+"px;height:"+ph+"px";
}
return mystyle;
}

//////////////////////////产品鼠标样式
function promouse(_pro){ var mydiv =Ext.select(_pro);mydiv.hover(enter, leave);}
function enter(e,t){ el=Ext.get(this); el.removeClass('mypro');  el.addClass('myproon'); }
function leave(e,t){ el=Ext.get(this); el.removeClass('myproon');el.addClass('mypro');   }
/////////////////////////翻页
function webpage(_pagebox)
{
var divbox2= Ext.get(_pagebox); 
var divproshow=divbox2.select('div.proshow');
divproshow.each(function(num)
{ 
  var strid=num.dom.id;
  var stringArray = strid.split("_");
  var strsupplyerid=stringArray[1];
  var allcount=stringArray[2];
  var myproshow= Ext.get(strid); 
  var btps=myproshow.select('div.btps');
  var btnt=myproshow.select('div.btnt');
  var pagecount=parseInt(myproshow.select('div.nowpage').item(0).dom.innerHTML);
  btps.on('click', function(e, t) {
     if(pagecount>1){pagecount=pagecount-1;pshow("supplyer",strsupplyerid,strid,pagecount); myproshow.select('div.nowpage').item(0).dom.innerHTML=pagecount;}
     if(pagecount>1){btnt.item(0).removeClass("noNext");btnt.item(0).addClass("Next");btps.item(0).removeClass("noPrevious");btps.item(0).addClass("Previous");}
     else{btps.item(0).removeClass("Previous");btps.item(0).addClass("noPrevious");} 
  });
  btnt.on('click', function(e, t) {
    if(pagecount<allcount){pagecount=pagecount+1;pshow("supplyer",strsupplyerid,strid,pagecount);myproshow.select('div.nowpage').item(0).dom.innerHTML=pagecount;}
     if(pagecount<allcount){btnt.item(0).removeClass("noNext");btnt.item(0).addClass("Next");btps.item(0).removeClass("noPrevious");btps.item(0).addClass("Previous");}
    else{btnt.item(0).removeClass("Next");btnt.item(0).addClass("noNext");} 
  });
});
}
function pshow(_supplyer,_supplyerid,_strid,_pagecount)
{
  var myproshow= Ext.get(_strid); 
  var mywidth200=myproshow.select('div.width200');
  var myproname=myproshow.select('div.proname');
  var mybig=myproshow.select('a.big');
  var myprotype=myproshow.select('div.protype');
  var mytextprice=myproshow.select('span.textprice');
  
  Ext.Ajax.request({
    url: 'jspage.aspx',
    params:{Parampagecount:_pagecount,Paramsupplyerid:_supplyerid,Parampagecount:_pagecount,Paramsupplyer:_supplyer},
    success: function(response, opts) {
      var strpros = Ext.util.JSON.decode(response.responseText);//返回的信息
      var intcount=0; 
      Ext.each(strpros , function(strpro){
         var image1=new Image(); 
         image1.src='http://www.e-dou.cn/propic/'+strpro.Prourl;
         var strSize= setImgSize(image1,220,300,"2");
         if(intcount<4)
         {
            mywidth200.item(intcount).dom.innerHTML="<img  src='http://www.e-dou.cn/propic/" + strpro.Prourl+ "' class='proimg' style='"+strSize+"'/>";
            mybig.item(intcount).dom.href='http://www.e-dou.cn/propic/'+strpro.Prourl;
            myproname.item(intcount).dom.innerHTML="<a href='productshow.aspx?id=" +strpro.id+"' >"+strpro.proname+"</a>";
            myprotype.item(intcount).dom.innerHTML=strpro.protype;mytextprice
            mytextprice.item(intcount).dom.innerHTML="商城价格："+strpro.price;
          }
          intcount++;
       });
     },
   failure: function(response, opts) {alert("NO1");}
  });
}

//////////新闻自动翻页
function newspage(_news)
{
var divnews= Ext.get(_news); 
var Licount =0;
var newstype=divnews.select('div.newstype');
var task = {
    run: function(){

         if(Licount< newstype.getCount()-1)
           { Licount++;}
         else
           {Licount=0;}
           newstype.addClass('noshow');
           newstype.item(Licount).removeClass('noshow');
           
    },
    interval:5000 // 周期为5秒
   };
var runner = new Ext.util.TaskRunner();
runner.start(task);
}