if ($ == undefined){
	var $ = function(id){return document.getElementById(id);}
}
if ($$ == undefined){
	var $$ = function(name){return document.getElementsByName(name);}
}

//去左右空格; 
function trim(s){
 	return rtrim(ltrim(s));
}
//去左空格; 
function ltrim(s){
 	return s.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(s){ 
 	return s.replace( /\s*$/, ""); 
}
//验证信息;
//空字符值; 
function isEmpty(s){
	s = trim(s); 
	return s.length == 0;
}
//Email;
function isEmail(s){
	s = trim(s); 
 	var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i;
 	return p.test(s);
}
//数字;
function isNumber(s){
	return !isNaN(s);
}
//颜色值;
function isColor(s){
	s = trim(s); 
	if (s.length !=7) return false;
	return s.search(/\#[a-fA-F0-9]{6}/) != -1;
}
//手机号码; 
function isMobile(s){
	s = trim(s);
	var p = /13\d{9}/;
	return p.test(s);
}
//身份证;
function isCard(s){
	s = trim(s); 
	var p = /^\d{15}(\d{2}[xX0-9])?$/;
	return p.test(s);
}
//URL;
function isURL(s){
	s = trim(s).toLowerCase();
	var p = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	return p.test(s);
}
//Phone;
function isPhone(s){
	s = trim(s);
	var p = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/;
	return p.test(s);
}
//Zip;
function isZip(s){
	s = trim(s);
	var p = /^[1-9]\d{5}$/;
	return p.test(s);
}
//Double;
function isDouble(s){
	s = trim(s);
	var p = /^[-\+]?\d+(\.\d+)?$/;
	return p.test(s);
}
//Integer;
function isInteger(s){
	s = trim(s);
	var p = /^[-\+]?\d+$/;
	return p.test(s);
}
//English;
function isEnglish(s){
	s = trim(s);
	var p = /^[A-Za-z]+$/;
	return p.test(s);
}
//中文;
function isChinese(s){
	s = trim(s);
	var p = /^[\u0391-\uFFE5]+$/;
	return p.test(s);
}
//双字节
function isDoubleChar(s){
	var p = /^[^\x00-\xff]+$/;
	return p.test(s);
}
//含有中文字符
function hasChineseChar(s){
	var p = /[^\x00-\xff]/;
	return p.test(s);
}
//含有数字、英文、中划线、下划线
function hasAccountChar(s){
	var p = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,15}$/;
	return p.test(s);
}
//判断字符长度是否合法
function limitLen(s,Min,Max){
	s=trim(s);
	if(s=="") return false;
	if((s.length<Min)||(s.length>Max))
		return false;
	else
		return true;
}
//显示AJAX结果
function showResult(result,resultInfo){
	var resultCnt = resultInfo.length;
	if (resultCnt > 0){
		for (i=0;i<resultCnt;i++){
			if (resultInfo[i].id == result){
				if (resultInfo[i].msg != ''){
					alert(resultInfo[i].msg);	
				}
				if (resultInfo[i].url != ''){
					window.location.replace(resultInfo[i].url);	
				}
			}
		}
	}
}

function showItem(parentId,childCount,obj,className){
	for(var i=0;i<childCount;i++){
		$(parentId).childNodes[i].className = '';
	}
	obj.className = className;
}

function display_menu(domId,thisId,count){
	if(count > 0 && domId != '' && thisId != ''){
		for(var i=1;i<=count;i++){
			$('sub_'+i).style.display = 'none';
		}
		$(thisId).style.display = '';
	}
}

function openDialog(url,width,height,parameter){
	var parameter,selProdWnd;
	if (parameter != ''){
		parameter = '?'+parameter
	}
	selProdWnd = window.open(url+parameter, "mcePopup", "scrollbars=yes,dialog=yes,modal=yes,width="+width+",height="+height+",resizable=no");
}

function goPre(parentId,childId,height,showCount){
	var i = 0,timer = null;
	var getChildId = $(parentId).getElementsByTagName(childId);
	if ($(parentId).scrollTop == (getChildId.length - showCount) * height){
		$(parentId).scrollTop = 0;
	}
	timer = setInterval(function(){
		if (i < parseInt(height / 5)){
			i++;
			$(parentId).scrollTop +=5;
		} else{
			i=0;
			clearInterval(timer);
		}
	},10);
}
function goNext(parentId,childId,height,showCount){
	var i = 0,timer = null;
	var getChildId = $(parentId).getElementsByTagName(childId);
	if ($(parentId).scrollTop == 0) {
		$(parentId).scrollTop = (getChildId.length - showCount) * height;
	}
	timer = setInterval(function(){
		if (i < parseInt(height / 5)){
			i++;
			$(parentId).scrollTop -=5;
		} else{
			i=0;
			clearInterval(timer);
		}
	},10);
}

function showBigPic(imgIndex,imgPath,bigImg,primePic){
	MagicZoom_stopZooms();
	var bigImgInner = '<a href="'+imgPath+splitStr(imgIndex,primePic,',')+'" class="MagicZoom" id="zoom1" rel="zoom-width:388px;zoom-height:408px;"><img src="'+imgPath+splitStr(imgIndex,bigImg,',')+'" alt="goods" /></a>';
	$('bigPic').innerHTML = bigImgInner;
	setTimeout('MagicZoom_findZooms()', 100);
}

function splitStr(imgIndex,str,splitSTR){
	var imgArr = new Array();
	if(imgIndex >= 0 && str != '' && splitSTR != ''){
		imgArr = str.split(splitSTR);
		return imgArr[imgIndex];
	}
}

/*
function getCookie(name){
	var cookieString,cookieVale,strSearch;
	cookieString=document.cookie;
	if (cookieString==""){
		return false;
	}
	else{
		cookieValue = "";
		strSearch		= name + "=";
		offset			= cookieString.indexOf(strSearch);
		if (offset != -1){
			offset += strSearch.length;
			end = cookieString.indexOf(";", offset);
			if (end == -1) end = cookieString.length;
			return unescape(cookieString.substring(offset, end));
		}
		else{
			return false;
		}
	}
}

function setCookie(cookieName, cookieValue, DayValue){
	var expire,day_value;
	expire		= "";
	day_value	=1;
	if (DayValue != null && DayValue > 1){
		day_value=DayValue;
	}
	expire = new Date((new Date()).getTime() + day_value * 86400000); // UTC 一天的值 86400000
	expire = "; expires=" + expire.toUTCString();
	document.cookie = cookieName + "=" + escape(cookieValue) +";path=/"+ expire;
}

function delCookie(cookieName){
	var expire = "";
	expire = new Date((new Date()).getTime() - 1 );
	expire = "; expires=" + expire.toUTCString();
	document.cookie = cookieName + "=" + escape("") +";path=/"+ expire;
}


//添加cookie
function setCookie(objName,objValue,objDay){
	var strResult,objHour,objDate,tmpDay;
	if(!isEmpty(objName) || !isEmpty(objValue)){
		strResult	= objName + "=" + escape(objValue);
		tmpDay		= (objDay == '' || objDay <= 0) ? 90 : objDay;
		tmpDay		= tmpDay*24*60*60*1000; // UTC一天的计算方法
		objDate		= new Date();
		objDate.setTime(objDate.getTime() + tmpDay);
		strResult += "; expires=" + objDate.toUTCString();
		document.cookie = strResult;
		return true;
	}
	else{
		return false;	
	}
}

//获取cookie
function getCookie(objName){
	var strResult,strLength,i,result;
	strArr = document.cookie.split("; ");
	strLength = strArr.length;
	if(strLength > 0){
		for(i=0;i<strArr.length;i++){
			result = strArr[i].split("=");
			if(result[0] == objName) return unescape(result[1]);
		}
	}
	else{
		return false;
	}
}
*/