//if (window.top != window){
//	window.top.location.href = document.location.href;
//}
//if (window.top.location !== window.self.location){
//	window.top.location.href = document.location.href;
//}

// 导航菜单
function chgMenuSrc(obj, type, bol){
	if (bol == null){
		bol = false;
	}
	type = type.toUpperCase();
	var src = obj.src.toUpperCase();
	if (!bol){
		if (type == 'OVER'){
			obj.src = src.replace('_OUT', '_OVER');
		}else{
			obj.src = src.replace('_OVER', '_OUT');
		}
	}
}

// 商品搜索
function checkSearch(theForm){
	if (theForm.Keyword.value == ""){
		alert('请输入关键字!');	
		theForm.Keyword.focus();
		return false;
	}
	return true;
}

function chgOrderType(obj){
	var url = obj.value.toString();
	location.href = url;
}

//使用方式：browseListItem(this)
//使用场合：左侧我查看过的列表和购特的列表
function browseListItem(obj){
    if(obj){
        var childnodes = obj.parentNode.childNodes;
        for(var i = 0; i < childnodes.length; i ++){
            if(childnodes[i].nodeName.toLowerCase() == "dl"){
                childnodes[i].style.display = 'none';
            }else if(childnodes[i].nodeName.toLowerCase() == "ul"){
                childnodes[i].style.display = '';
            }
        }
        obj.style.display = 'none';
        if(document.all){
            obj.nextSibling.style.display = 'block'; //不把持FF
        }else{
            obj.nextSibling.nextSibling.style.display = 'block';
        }
    }
}

function left(mainStr, lngLen){
	if (lngLen>0){
		return mainStr.substring(0, lngLen);
	}else{
		return null;
	}
}

function right(mainStr, lngLen){
	if (mainStr.length - lngLen >= 0 && mainStr.length >= 0 && mainStr.length - lngLen <= mainStr.length){
		return mainStr.substring(mainStr.length - lngLen, mainStr.length);
	}else{
		return null;
	} 
} 

function mid(mainStr, starnum, endnum){
	if (mainStr.length >= 0){
		return mainStr.substr(starnum, endnum);
	}else{
		return null;
	}
}

// JS 容错
//function killErrors(){
//	return true;
//}
//window.onerror = killErrors;

// TagName标签名Div, classNameCSS类名, cClearBoth
function getStyle(TagName,className,innerHTML) {
	var HackDiv = document.getElementsByTagName(TagName);
	for(var i = 0; i < HackDiv.length; i ++){
		if(HackDiv[i].className == className){
			HackDiv[i].innerHTML = innerHTML;
		}
	}    
}

//批量解决IE6 height最小高度的办法。
var Ie6HeightHackHtml = "<img src=\"images/Dot1x1.gif\" width=\"1\" height=\"1\" border=\"0\" />";    
getStyle("div","cClearBoth", Ie6HeightHackHtml); 

function getCookie(name){
	var cookieValue = "";
	var search = name +"=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if (offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function setCookie(cookieName, cookieValue, DayValue){
	var expire = "";
	var day_value = 1;
	if(DayValue != null){
		day_value = DayValue;
	}
	expire = new Date((new Date()).getTime() + day_value * 86400000);
	expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape(cookieValue) +";path=/"+ expire;
}

function delCookie(cookieName){
	var expire = "";
	expire = new Date((new Date()).getTime() - 1 );
    expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape("") +";path=/"+ expire;
	// path=/
}

function setHTML(obj, val){
	if(document.getElementById(obj) && document.getElementById(val)){
		document.getElementById(obj).innerHTML = document.getElementById(val).innerHTML;
		document.getElementById(val).innerHTML = '';
	}
}

function $(s){
	return document.getElementById(s);
};

function Offset(e){
	var t = e.offsetTop;
	var l = e.offsetLeft;
	var w = e.offsetWidth;
	var h = e.offsetHeight;
	while(e = e.offsetParent){
		t += e.offsetTop;
		l += e.offsetLeft;
	}
	return{
		top : t,
		left : l,
		width : w,
		height : h
	}
};