 //图片按比例缩放
function DrawImage(ImgD,iwidth,iheight)
{
	var flag=false;
	var image=new Image();
	if(!iwidth)
		iwidth = 100;
	if(!iheight)
		iheight = 80;
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
	flag=true;
	if(image.width/image.height>= iwidth/iheight){
	if(image.width>iwidth){ 
		ImgD.style.width = iwidth + "px";
		ImgD.style.height=Math.floor((image.height*iwidth)/image.width) + "px";
	}else{
		ImgD.style.width = image.width + "px"; 
		ImgD.style.height = image.height + "px";
	}



	}else{
	if(image.height>iheight){ 
		ImgD.style.height=iheight + "px";
	    ImgD.style.width=Math.floor((image.width*iheight)/image.height) + "px"; 
	}else{
		ImgD.style.width = image.width + "px"; 
		ImgD.style.height = image.height + "px";
	}
	}
	}

}

function commentuseful(id,i)
{
　if (getCookie('commentuse'+id)=='') {
	　var usefulspan = document.getElementById('usefulspan'+id); 
	  var cntspan = document.getElementById('cntspan'+id); 
　	  var ajax = InitAjax();
      var url="/productdetail1.php?do=ajaxcommentuseful&id="+id+"&i="+i;
　	  ajax.open("GET", url, true); 
　    ajax.onreadystatechange = function() { 
	　　if (ajax.readyState == 4 && ajax.status == 200) {
	      if (ajax.responseText!='0') {
			  setCookie('commentuse'+id, (i>0?1:0));
		　　　usefulspan.innerHTML = parseInt(usefulspan.innerHTML,10)+(i>0?1:0);
			  cntspan.innerHTML = parseInt(cntspan.innerHTML,10)+1;
		  } else {
		  	alert('请先登录!');
		  }
	　　}
　	  }
　　  ajax.send(null); 
  } else {
  	alert('您已经选定!');
  }
}

function goPage(obj)

{

	location = '<!--{$WWW_URL}-->/productdetail<!--{$PEXT}-->?do=index&np=' + obj.value;

}

function getChannel()

{

	document.getElementById('channelInfo').style.display='block';

}

function hiddenChannel()

{

	document.getElementById('channelInfo').style.display='none';

}
function checkForm()
{
	var frm = document.getElementById('commentForm');
	if(parseInt(frm.id.value) <= 0){
		alert('错误：Id 丢失');
		return false;
	}
	if(frm.title.value.trim().length<2){
		alert('请填写标题，最少2个字符');
		frm.title.value = frm.title.value.trim();
		frm.title.focus();
		return false;
	}
	if(parseInt(frm.product_score.value) <= 0){
		alert('请给商品评分');
		return false;
	}
	if(parseInt(frm.service_score.value) <= 0){
		alert('请给服务评分');
		return false;
	}
	if(parseInt(frm.transfer_score.value) <= 0){
		alert('请给发货速度评分');
		return false;
	}
	
	if(frm.content.value.trim().length<10){
		alert('评论内容不能少于10个字符');
		frm.content.value = frm.content.value.trim();
		frm.content.focus();
		return false;
	}
	return true;
}

function checkMax(obj){
	var len = parseInt(obj.getAttribute('maxLength'));
	if(obj.value.length > len){
		obj.value = obj.value.substr(0,len).trim();
	}
	document.getElementById('worldCount').innerHTML = (len - obj.value.length) 
}

function checkMax1(obj){
	var len = parseInt(obj.getAttribute('maxLength'));
	if(obj.value.length > len){
		obj.value = obj.value.substr(0,len).trim();
	}
	document.getElementById('worldCount1').innerHTML = (len - obj.value.length) 
}

function setCookie(name, value){
	var days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
	document.cookie = name + "="+ escape(value) + ";expires=" + exp.toGMTString();
}

//读取cookies
function getCookie(name){
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	
	if(arr=document.cookie.match(reg)) return decodeURIComponent(unescape(arr[2]));
	else return '';
}
//删除cookies
function deleteCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

var flags=[false,false,false];
var commentscores=['product_score','service_score','transfer_score'];
function initScore(percent,i){
	if (!flags[i]) {
		document.getElementById('scorepanel'+i).style.width = percent * 10 + '%';
		document.getElementById('scoretxt'+i).innerHTML = percent * 0.5 + '分';
		if (percent==0) document.getElementById('scoretxt'+i).innerHTML = '';
		document.getElementById(commentscores[i]).value = percent * 0.5;
	}
}
//----------------------------------------------------------------------------------------------------
function overScore(d,score,i){
	if (!flags[i]) {
		document.getElementById('scorepanel'+i).style.width = score * 21 + 'px';
		document.getElementById('scoretxt'+i).innerHTML = score + '分'+'('+d.title+')';
		if (score==0) document.getElementById('scoretxt'+i).innerHTML = '';
		document.getElementById(commentscores[i]).value = score;
	}
}
function setflag(i) {
   if (!flags[i]) setTimeout("resetflag("+i+")",2000);
   flags[i]=true;
}
function resetflag(i) {
   flags[i]=false;
}


