
function SortChange(){
document.getElementById("startIndex").value=0;
document.getElementById("startIndexmes").value=0;
document.getElementById("act").value="list";
document.proListActionForm.action=shopServer+"/shop/proList.do";
document.proListActionForm.target="_self";
document.proListActionForm.submit();
}

function SortListChange(id){
document.getElementById("startIndex").value=0;
document.getElementById("startIndexmes").value=0;
document.getElementById("orderBy").value=id;
document.getElementById("act").value="list";
document.proListActionForm.target="_self";
document.proListActionForm.action=shopServer+"/shop/proList.do";
document.proListActionForm.submit();
}

function go(s){
	document.proListActionForm.showWay.value=s;
	document.getElementById("startIndex").value=0;	
	document.getElementById("startIndexmes").value=0;
	document.getElementById("act").value="list";
	document.proListActionForm.target="_self";
	document.proListActionForm.action=shopServer+"/shop/proList.do";
	document.proListActionForm.submit();
}
function Compare(){
	   document.proListActionForm.target="_blank";
	   document.proListActionForm.method="post";
	   document.proListActionForm.action=prdServer+"/prd/compare.do";  
	   document.proListActionForm.submit();
}

function gotoPage(obj,formName){
	
		var page = document.getElementById("pageNumber").value;
		var type="^\s*[+-]?[0-9]+\s*$";
		var re = new RegExp(type);
		if(page.match(re)==null)
		{
			alert("请输入整数!");
			return false;
		}
	
		if(page == ""){
			alert("请输入页码数字!");
			return false;
		}

	
		else{
			
			if(page>maxpage)
			{
				page = maxpage;
			}
			if ( formName != null && formName != '' ) {	
				if ( page < 1 )
					document.getElementById("startIndex").value=0;				
				else
					document.getElementById("startIndex").value=(page-1)*obj;	
				if ( startIndexmes == 'null' || startIndexmes == '' || startIndexmes == null )
				{
					startIndexmes = 0;
				}
				document.getElementById("startIndexmes").value = startIndexmes;
				document.getElementById("act").value="list";
				document.proListActionForm.target="_self";
				document.proListActionForm.action=shopServer+"/shop/proList.do";
				formName.submit();
			
			}else{	
			if(page<1)
				window.location="?startIndex=0";				
			else
				window.location="?startIndex="+(page-1)*obj;	
			}					
			return true;
		}
		
		return false;
	}

	function pageUpandDown(index,formName){	
		if(formName != null && formName != ''){	
			document.getElementById("startIndex").value = index;
			if(startIndexmes == 'null'||startIndexmes == ''||startIndexmes == null)
			{
				startIndexmes = 0;
			}
			document.getElementById("startIndexmes").value=startIndexmes;
			document.getElementById("act").value="list";
			document.proListActionForm.target="_self";
			document.proListActionForm.action=shopServer+"/shop/proList.do";
			formName.submit();
		}else{
			window.location="?startIndex="+index;
		}
			
	}	
	


//// script for message board below



function gotoPage4Message(obj,formName){
		
		var page = document.getElementById("pageNumbermes").value;
		var type="^\s*[+-]?[0-9]+\s*$";
		var re = new RegExp(type);
		if(page.match(re)==null)
		{
			alert("请输入整数!");
			return false;
		}

		if(page == ""){
			alert("请输入页码数字!");
			return false;
		}else{
			if(page>maxpagemes)
			{
				page = maxpagemes;
				
			}
			if(formName != null && formName != ''){	
				if(page<1)
					document.getElementById("startIndexmes").value=0;				
				else
					document.getElementById("startIndexmes").value=(page-1)*obj;	
				if(startIndex=='null'||startIndex==""||startIndex==null)
				{
					startIndex = 0;
				}	
				document.getElementById("startIndex").value = startIndex;
				document.getElementById("act").value="list";
				document.proListActionForm.target="_self";
				document.proListActionForm.action=shopServer+"/shop/proList.do";
		
				formName.submit();
			
			}else{	
			if(page<1)
				window.location="?startIndexmes=0";				
			else
				window.location="?startIndexmes="+(page-1)*obj;	
			}					
			return true;
		}
		
		return false;
	}

	function pageUpandDown4Message(index,formName) {	

		if ( formName != null && formName != '' ) {	
			document.getElementById("startIndexmes").value = index;
			if ( startIndex == 'null' || startIndex == "" || startIndex == null )
			{
				startIndex = 0;
			}
			document.getElementById("startIndex").value = startIndex;
			document.getElementById("act").value="list";
			document.proListActionForm.target="_self";
			document.proListActionForm.action=shopServer+"/shop/proList.do";
			formName.submit();
		}else{
			window.location="?startIndexmes="+index;
		}
			
	}		

	function submitQuestion(){
		document.getElementById("startIndexmes").value=0;
		document.getElementById("startIndex").value=0;
		document.getElementById("act").value="sendMessage";
		document.proListActionForm.action=shopServer+"/shop/proList.do";

		if(document.getElementById("message").value == '')
		{
			Str = "<font color='red'>请填写留言内容！</font>";
			document.getElementById("msgError").innerHTML = Str;
		}else if(document.getElementById("message").value.length > MAX_LENGTH)
		{
			Str = "<font color=red>字数不得超过"+MAX_LENGTH+"!</font>";
			document.getElementById("msgError").innerHTML = Str;
		}else if(document.getElementById("randomCode").value == '')
		{
			Str = "<font color='red'>请填写验证码！</font>";
			document.getElementById("msgError").innerHTML = Str;
		}else{
			document.proListActionForm.target="_self";
			document.proListActionForm.submit();
		}
	}

	function cleanUp(){
		document.getElementById("message").value="";
	}

	function reloadImage() { 
	  document.reloadImage.src = shopServer+'/RandomCode?'+Math.random(); 
	 }


	function setPrdType(pt){
	document.getElementById("startIndexmes").value=0;
	document.getElementById("startIndex").value=0;	
	document.getElementById("act").value="list";
	document.proListActionForm.prdType.value = pt;
	document.proListActionForm.action=shopServer+"/shop/proList.do";
	document.proListActionForm.target="_self";
	document.proListActionForm.submit();
	
	}

function search(){
	document.getElementById("startIndexmes").value=0;
	document.getElementById("startIndex").value=0;	
	document.getElementById("act").value="list";
	document.proListActionForm.prdShow.value="all";
	document.proListActionForm.action=shopServer+"/shop/proList.do";
	document.proListActionForm.target="_self";
	document.proListActionForm.submit();
	
	}

function fnHandler(ctrl)
{

  var i;
  i=ctrl.value.length;
  var left = MAX_LENGTH - i;
  if(ctrl.value.length > MAX_LENGTH){
    	left=0;
    	Str = "<font color=red>字数不得超过"+MAX_LENGTH+"!</font>";
    	document.getElementById("msgError").innerHTML = Str;
  }else{
    	document.getElementById("msgError").innerHTML = "";
  }
  Str = "剩下 "+left+" 个字符,不能使用HTML标签";
  document.getElementById("leftwords").innerHTML = Str;
}

/*输出物品下架的剩余时间. 参数endTime对应物品下架时间,以秒为单位*/
function getRemainTime(endTime){
 if(isFinite(endTime)){
   var now = new Date().getTime()/1000;
   var remain = endTime - now;
   if(remain<0)
     return;
   var days = Math.floor(remain/(60 * 60 *　24));
   remain = remain % (60 * 60 *　24);
   var hours = Math.floor(remain / (60 * 60));
   remain = remain % (60 * 60);
   var minutes = Math.floor(remain / 60);
   var seconds = Math.floor(remain % 60);
   if(days){
     document.write(days + "天" + hours + "小时"+minutes + "分钟" + seconds +"秒");
   }else if(hours){
     document.write(hours + "小时"+minutes + "分钟" + seconds +"秒");
   }else if(minutes){
     document.write(minutes + "分钟" + seconds +"秒");
   }else{
     document.write(seconds +"秒");
   }
 }
}