function changeImage(src){
   $id('pic').src = 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 = '';
	 }
	 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).onclick = function(){
    $id(obj).removeChild($id('bigimg'));
	$id(obj).innerHTML = '';
	SetDisplay(obj,'none');
  }
  showdiv(obj,'otherpicFocus','absolute','block','auto','auto',370,210,false);
  $id(obj).title = '单击隐藏';
}

function addCart(pid){
 if(parseInt($id('isLack').value)==1){
	  showmsg('buymsg','Error','对不起,该产品却货!');return;}
 var pCount = $id('pCount').value;
 var pSize = $id('pSize').options[$id('pSize').selectedIndex].value;
 var pColor = $id('pColor').options[$id('pColor').selectedIndex].value;
 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;
 $id('pBox').style.zIndex = max_zIndex();
 SetVisibility('pSize','hidden');
 SetVisibility('pColor','hidden');
 $id('cart').style.top = document.body.scrollTop + 150;
 $id('cart').style.left = 200;
 $id('cart').style.display = 'block';
}
