function init(){
	/*if(document.getElementById("im")){
		var left=parseInt(document.body.clientWidth,10)-120;
		document.getElementById("im").style.left=left;
		
	}*/
	
	showCategory();
}


function login(){
	var url=window.location.href;
	if(url.indexOf("register")>=0||url.indexOf("lost")>=0){
		url=context+"/";
	}
	
	
	setCookie("tmp_url",url,getExpDate(0,60,0),"/");
	window.location.href=context+"/user/login.jsp";
}

function is_number(str)
{
	exp=/[^0-9()-]/g;
	if(str.search(exp) != -1)
	{
		return false;
	}
	return true;
}

function hiddadv(){
	if(document.getElementById("im")){
		var left=parseInt(document.body.clientWidth,10)-120;
		document.getElementById("im").style.display='none';
		
	}
	
	
}


// 关键字检索
function checkKeyWord(key) {
	var keyWord = trim(key.value);
	if (keyWord == "" || keyWord == null) {
		key.value = "请输入关键字！";
	}
}

function checkKeyWordEn(key) {
	var keyWord = trim(key.value);
	if (keyWord == "" || keyWord == null) {
		key.value = "Please fill in Keyword！";
	}
}
/**
 * 删除所有空格
 */
function trim(str) {
	return str.replace(/^\s+|\s+$/g, "")
}

// 取出当前时间及星期
function getDate() {
	var now = new Date(); // 获取系统日期
	var yy = now.getYear(); // 获取年
	var mm = now.getMonth() + 1; // 获取月
	var week = getWeek(now.getDay()); // 获取该天的星期值
	var dd = now.getDate();
	var date_time = yy + "-" + mm + "-" + dd + " " + week;
	return date_time;
}
function getWeek(week) {
	var weekDay = "";
	if (week == "0") {
		weekDay = "星期天";
	} else if (week == "1") {
		weekDay = "星期一";
	} else if (week == "2") {
		weekDay = "星期二";
	} else if (week == "3") {
		weekDay = "星期三";
	} else if (week == "4") {
		weekDay = "星期四";
	} else if (week == "5") {
		weekDay = "星期五";
	} else {
		weekDay = "星期六";
	}
	return weekDay;
}




/**
 * checkemail 函数校验此框输入的是否为email型的数据,返回的值为真和假,true和false;
 * 
 * object目标对象,desc中文的描述.
 */
function checkemail(strvalue) {
	var pattern = /[a-za-z0-9_.]{1,}@[a-za-z0-9_]{1,}.[a-za-z0-9_]{1,}/;
	return _check(strvalue,pattern); 
}



function checkPoseCode(strvalue) {
	var pattern = /[1-9]{1}[0-9]{5}/;
	return _check(strvalue,pattern);
}


function _check(strvalue,pattern){
	if (strvalue.length == 0)
		return true;
	if (strvalue.match(pattern) == null) {
		return false;
	} else {
		return true;
	}
	
}

function DrawImage(ImgD,x,y) {
	var _x=112;
	var _y=112;
	if(arguments.length>1){
		_x=x;
	}
	if(arguments.length>2){
		_y=y;
	}
	var image = new Image();
	image.src = ImgD.src;
	if (image.width > 0 && image.height > 0) {
		if (image.width / image.height >= _x / _y) {
			if (image.width > _x) {
				ImgD.width = _x;
				ImgD.height = (image.height * _x) / image.width;
			} else {
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
			//ImgD.alt = image.width + "×" + image.height;
		} else {
			if (image.height > _y) {
				ImgD.height = _y;
				ImgD.width = (image.width * _y) / image.height;
			} else {
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
			//ImgD.alt = image.width + "×" + image.height;
		}
	}
	ImgD.style.display="";
}


function cBoard(n) {
	for (i = 0; i < 5; i++) {
		if (i == n) {
			document.all('d' + n).className = "c4";
		} else {
			document.all('d' + i).className = "c3";
		}
	}

	for (i = 0; i < 5; i++) {
		if (i == n) {
			document.all('bo' + n).style.display = "";
		} else {
			document.all('bo' + i).style.display = "none";
		}
	}

}





function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" &&
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}

  

// utility function called by getCookie( )

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

  

// primary function to retrieve cookie by name
/*
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 "";
}
*/

function getCookie(sName) {
    var sRE = "(?:; )?" + sName + "=([^;]*);?";
    var oRE = new RegExp(sRE);
    if (oRE.test(document.cookie)) {
        return decodeURIComponent(RegExp["$1"]);
        } else {
        return null;
    }
}

  

// store cookie value with optional details as needed

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

  



// remove the cookie by setting ancient expiration date
/*
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }

}*/


function deleteCookie(sName, sPath, sDomain) {
	var tempDate = new Date();
	tempDate.setTime(tempDate.getTime()-1);
    var sCookie = sName + "=; expires=" + tempDate.toGMTString();
    if (sPath) {
        sCookie += "; path=" + sPath;
    }
    if (sDomain) {
        sCookie += "; domain=" + sDomain;
    }
    document.cookie = sCookie;
}
function nextPage(){
	var url=getCookie("tmp_url");
	if(url==null||url.indexOf("register")>=0||url.indexOf("lost")>=0){
		url=context+"/";
	}
	window.location.href=url;
}




function xmlReq(url,func){
    var oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", url, true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
            	var msg=oXmlHttp.responseText;
            	msg =eval("(" + msg + ")");
            	func(msg.root,msg.message);
            } else {
            	func(false,msg.message); //statusText is not always accurate
            }
        } 
    };
    oXmlHttp.send(null);
}


function doFav(productId){
	xmlReq(context+"/action/XmlAction.do?action=saveFavorite&productId=" + productId,_doFav);
}
function doDelFav(productId){
	xmlReq(context+"/action/XmlAction.do?action=deleteFavorite&productId=" + productId,_doFav);
}

function _doFav(ret,msg){
	if(ret){
		
	}else{
		
	}
	alert(msg);
	
}



function loginCheck(){
	if(trim(loginForm.loginName.value)==""||trim(loginForm.userPassword.value)==""){
		alert("请输入用户名和密码");
		return false;
	}
	return true;
}

function loginCheckEn(){
	if(trim(loginForm.loginName.value)==""||trim(loginForm.userPassword.value)==""){
		alert("Please fill in Login Name and Password");
		return false;
	}
	return true;
}


function setButtonStatus(obj,status){
	var className=(status?"tab_over":"tab_out");
	obj.className=className;
	
}


function showCategory(index){
	if(index!=undefined){
	var obj=document.getElementById("category_"+index);
	if(obj){
		obj.style.display=obj.style.display!="block"?"block":"none";
	}
	
	}
	
}
