﻿function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function chkNum(o){
	if(isnum(o.value)==false) o.value='1';
	/*o.value=o.value.replace(/\D/g,'');
	o.onkeypress=function(){
		this.value=this.value.replace(/\D/g,'');
		if(this.value.length>5) this.value=this.value.substr(0,4);
	}
	o.onkeyup=function(){this.value=this.value.replace(/\D/g,'');}
  o.onpaste=function(){return !clipboardData.getData('text').match(/\D/);}*/
}
function isnum(val){
	var reg=/^\d+(\.\d+)?$/;
	return reg.test(val);
}
 //设置名称为name,值为value的Cookie
function SetCookie (name, value) {
	var argc = SetCookie.arguments.length;
	var argv = SetCookie.arguments;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + value + ((path == null) ? "" : ("; path=" + path)) + ((secure == true) ? "; secure" : "");
}
 //取得名称为name的cookie值
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
//取得项名称为offset的cookie值
function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
//删除名称为name的Cookie
function DeleteCookie (name) { 
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
 //清除COOKIE
function Clearcookie(){
	var temp=document.cookie.split(";");
	var loop3;
	var ts;
	for (loop3=0;loop3<temp.length;loop3++){
		ts=temp[loop3].split("=")[0];
		if (ts.indexOf('mycat')!=-1)
		DeleteCookie(ts); //如果ts含“mycat”则执行清除
	}
	window.location.reload();
}
function Cart(catid,number){
	if (number<=0) DeleteCookie("mycat"+catid);
	else SetCookie("mycat"+catid,catid+","+number);	
	window.location.href='/shop.asp';
}
function EditCart(catid,number){
	if (number<=0) DeleteCookie("mycat"+catid);
　　else SetCookie("mycat"+catid,catid+","+number);	
	window.location.reload();
}
function getpronum(o,id){
	var tmp=GetCookie(id);
	if (tmp) document.getElementById(o).value=tmp.split(',')[1];
}
function gval(o){
	return document.getElementById(o).value;	
}