function changeImage(src){
   $id('pic').src = src;
   $id('pic').alt = src;
   $id('myviewer').style.backgroundImage='url('+src+')';
   var otherpic = $tag($id('otherpic'),'img');
   var index = otherpic.length;
   var Index,isFocus;
   for(var i=0;i<index;i++){
     if(otherpic[i].src==src){
	   isFocus = 'Focus';
	   (i==index-1) ? Index = 0 : Index = i + 1;
	   $id('NextImage').src = otherpic[Index].src;
	 }else{
	   isFocus = '';
	 }zz
	 otherpic[i].className = 'otherpic'+isFocus;
   }
}
function EnlargeImage(src){
  var img = $createElement('img');
  var obj = 'bimg';
  img.src = src;
  img.id = 'bigimg';
  $id(obj).innerHTML = '';
  $id(obj).appendChild(img);
  $id(obj).style.zIndex = max_zIndex();
  $id(obj).onclick = function(){
    $id(obj).removeChild($id('bigimg'));
	$id(obj).innerHTML = '';
	SetDisplay(obj,'none');
  }
  showdiv(obj,'otherpicFocus','absolute','block','auto','auto',188,288,false);
  $id(obj).title = '单击隐藏';
}

function EnlargeMirror(obj){
return;
var ev = ev || window.event;
var mousePos = mouseCoords(ev);
var x = mousePos.x;
var y = mousePos.y;

var documentScrollLeft = parseInt(document.body.scrollLeft);
var documentScrollTop = parseInt(document.body.scrollTop);

var picStyleLeft = parseInt($id('pic').style.left);
var picStyleTop = parseInt($id('pic').style.top);
var picWidth = parseInt($id('pic').width);
var picHeight = parseInt($id('pic').height);

var objStyleLeft = parseInt(obj.style.left);
var objStyleTop = parseInt(obj.style.top);
var objWidth = parseInt(obj.width);
var objHeight = parseInt(obj.height);

var getsizeWidth = parseInt($id('getsize').width);
var getsizeHeight = parseInt($id('getsize').height);
var Boundaries = 50;
SetVisibility('myviewer','visible');
if(objStyleLeft<picStyleLeft-Boundaries){obj.style.left = $id('pic').style.left;reset();return;}
if(objStyleLeft>(picStyleLeft+picWidth-objWidth+Boundaries)){obj.style.left = picStyleLeft+picWidth-objWidth;reset();return;}
if(objStyleTop<picStyleTop-Boundaries){obj.style.top = $id('pic').style.top;reset();return;}
if(objStyleTop>picStyleTop+picHeight-objHeight+Boundaries){obj.style.top = picStyleTop+picHeight-objHeight;reset();return;}

$id('pic').style.filter='alpha(opacity=50)';
obj.style.left=event.x+documentScrollLeft-objWidth/2;
obj.style.top=event.y+documentScrollTop-objHeight/2;
var Nx = getsizeWidth/picWidth;
var bgx=(-1)*(Nx-1)*(event.x-picStyleLeft+documentScrollLeft)-objStyleLeft+picStyleLeft;
var Ny=getsizeHeight/picHeight;
var bgy=(-1)*(Ny-1)*(event.y-picStyleTop+documentScrollTop)-objStyleTop+picStyleTop;
obj.style.backgroundPosition = bgx+' '+bgy;
}
function reset(){
  $id('pic').style.filter='alpha(opacity=100)';
  SetVisibility('myviewer','hidden');
}
function getSize(ClassID){
  $id('bimg').innerHTML = '';
  showmsg('buymsg','smallLoading','加载尺寸对照表..');
  var Url = 'ajax.asp?ClassID='+ClassID+'&Action=getSize';
  ajax.response(Url,getSized);
}
function getSized(){
  var html = ajax.request();
  var obj = 'bimg';
  SetVisibility('pSize','hidden');
  SetVisibility('pColor','hidden');
  showmsg('buymsg','msg','');
  showdiv(obj,'otherpicFocus','absolute','block',0,'auto',500,280,html);
  $id(obj).onclick = function(){
	$id(obj).innerHTML = '';
	SetVisibility('pSize','visible');
    SetVisibility('pColor','visible');
	SetDisplay(obj,'none');
  }
}

function addCart(pid){
 var pCount = $id('pCount').value;
 var pSize = $id('pSize').options[$id('pSize').selectedIndex].value;
 var pColor = $id('pColor').options[$id('pColor').selectedIndex].value;
 if(parseInt(pSize)==0){
	   showmsg('buymsg','Error','请选择需要的尺寸');return;
  }
 if(IsNull(pCount)||pCount==0){
    showmsg('buymsg','Error','请输入要购买的数量');
	return;
 }
 if(!IsNumeric(pCount)){
    showmsg('buymsg','Error','订购数量必须是数字!');
	return;
 }
  showmsg('buymsg','smallLoading','正在处理,请稍候..');
  var Url = 'ajax.asp?pid='+pid+'&pCount='+pCount+'&pSize='+pSize+'&pColor='+pColor+'&Action=addCart';
  ajax.response(Url,addCarted);
}

function addCarted(){
var html = ajax.request();
 showmsg('buymsg','msg',html);
 if(html.indexOf('已')!=-1){
   showmsg('buymsg','right',html);
   showCart();
 }else{
   showmsg('buymsg','Error',html);
 }
}

function showCart(){
  ajax.response('myCart.asp',showCarted);
  initDrag();
}
function showCarted(){
 var html = ajax.request();
 $id('pBox').innerHTML = html;
 SetVisibility('pSize','hidden');
 SetVisibility('pColor','hidden');
 $id('cart').style.top = document.body.scrollTop + 150;
 $id('cart').style.left = $id('body').offsetLeft;
 $id('cart').style.display = 'block';
 $id('cart').style.zIndex = 9999;
}
