function hasClass(element, className)
{
	return !!element.className.match(new RegExp("\\b"+className+"\\b"));
}

function addClass(element, className) 
{
	if(!hasClass(element, className))
	{
		element.className += (element.className ? ' ' : '') + className;
	}
}
function removeClass(element, className) 
{
    element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').replace(/^\s+/, '').replace(/\s+$/, '');;
}

function form_effect_ie() 
{
	var arr = [].concat(
						$A(document.getElementsByTagName("input")),
						$A(document.getElementsByTagName("button"))
					  );
	arr.forEach(
					function(obj)
					{
						if(obj.readOnly)
						{
							addClass(obj, "readonly");
						}
						if (navigator.userAgent.indexOf('MSIE 6.0') > -1) 
						{
							addClass(obj,obj.type);
							if(obj.disabled)
							{
								addClass(obj,"disabled");
							}
						}
					}
				);
}

function tag_hover_effect() 
{
	var tzArr = $A(document.getElementsByTagName("textarea"));
	var inputArr = $A(document.getElementsByTagName("input"));

	var hoverArr = [].concat(
								$A(document.getElementsByTagName("li")),
								tzArr,
								inputArr
							  );
	hoverArr.forEach(
						function(obj)
						{
							if(obj.tagName.toLowerCase() == "textarea" || 
								obj.tagName.toLowerCase() == "tr" || 
								obj.tagName.toLowerCase() == "li" ||
								obj.type == "password" || 
								obj.type == "text")
							{									
								obj.onmouseenter = function()
								{
									addClass(obj,"hover");
								}
								obj.onmouseleave = function()
								{
									removeClass(obj,"hover");
								}
							}
						}
					 );
}

if(!document.all)
{
	HTMLElement.prototype.contains = function(obj)  
	{  
		return this.compareDocumentPosition(obj) & 16;
	}
}

var CancelBubble = function(e)
{
	e = e || window.event;
	if(document.all)
	{
		e.cancelBubble = true;
	}
	else
	{
		e.stopPropagation();
	}
	return e;
};

function getCurrentStyle(obj, prop) 
{
	if (obj.currentStyle) {
		return obj.currentStyle[prop];
	}
	else 
	{
		return getComputedStyle(obj, "").getPropertyValue(prop.toLowerCase());
	}
	return null;
}

function scrollX()
{
    return document.documentElement.scrollLeft || document.body.scrollLeft;
}

function findPosX(obj) 
{
	var curleft = 0;
	if (obj && obj.offsetParent) 
	{
		while (obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	return curleft;
}

function scrollY()
{
	return document.documentElement.scrollTop || document.body.scrollTop;
}

function findPosY(obj) 
{
	var curtop = 0;
	if (obj && obj.offsetParent) 
	{
		while (obj.offsetParent) 
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} 
	return curtop;
}
function FollowBox(target, html)
{	
	$("follow_box").style.display = "block";
	$("follow_box").onmouseout = function(event)
	{
		event = event || window.event;
		var toElement = event.toElement || event.relatedTarget;
		if(!this.contains(toElement) && event.toElement != target)
		{
			this.style.display = "none";
			if(document.all && !window.XMLHttpRequest)
			{
				$("public_overlay_iframe").style.display = "none";
			}
			removeClass(target, "active");
		}
	}
	$("follow_box").onmouseover = function(event)
	{
		this.style.display = "block";
		if(document.all && !window.XMLHttpRequest)
		{
			$("public_overlay_iframe").style.display = "block";
		}
		addClass(target, "active");
	}
	$("follow_box").innerHTML = html;
	$("follow_box").style.top = (findPosY(target) + target.offsetHeight) + "px";
	$("follow_box").style.left = findPosX(target) + "px";

	if(document.all && !window.XMLHttpRequest )
	{
		$("public_overlay_iframe").style.display = "block";
		$("public_overlay_iframe").style.top = $("follow_box").style.top
		$("public_overlay_iframe").style.left = $("follow_box").style.left;
		$("public_overlay_iframe").style.width = $("follow_box").offsetWidth + "px";
		$("public_overlay_iframe").style.height = $("follow_box").offsetHeight + "px";
	}

	target.onmouseout = function(event)
	{
		event = event || window.event;
		var toElement = event.toElement || event.relatedTarget;
		if(toElement != $("follow_box"))
		{
			$("follow_box").style.display = "none";
			if(document.all && !window.XMLHttpRequest)
			{
				$("public_overlay_iframe").style.display = "none";
			}
		}
	};
}

function SearchBox(target)
{
	$("follow_box").style.display = "block";
	$("follow_box").onmouseout = function(event)
	{
		event = event || window.event;
		var toElement = event.toElement || event.relatedTarget;
		if(!this.contains(toElement) && event.toElement != target)
		{
			this.style.display = "none";
			if(document.all && !window.XMLHttpRequest)
			{
				$("public_overlay_iframe").style.display = "none";
			}
			removeClass(target, "active");
		}
	}
	$("follow_box").onmouseover = function()
	{
		this.style.display = "block";
		if(document.all && !window.XMLHttpRequest )
		{
			$("public_overlay_iframe").style.display = "block";
		}
	}
	target.onmouseout = function(event)
	{
		event = event || window.event;
		var toElement = event.toElement || event.relatedTarget;
		if(toElement != $("follow_box"))
		{
			$("follow_box").style.display = "none";
			if(document.all && !window.XMLHttpRequest)
			{
				$("public_overlay_iframe").style.display = "none";
			}
		}
	}
	$("follow_box").innerHTML = $("choose_search_type").innerHTML;
	$("follow_box").style.top = (findPosY(target) + target.offsetHeight) + "px";
	$("follow_box").style.left = (findPosX(target) + target.offsetWidth - $("follow_box").offsetWidth) + "px";

	if(document.all && !window.XMLHttpRequest )
	{
		$("public_overlay_iframe").style.display = "block";
		$("public_overlay_iframe").style.top = $("follow_box").style.top
		$("public_overlay_iframe").style.left = $("follow_box").style.left;
		$("public_overlay_iframe").style.width = $("follow_box").offsetWidth + "px";
		$("public_overlay_iframe").style.height = $("follow_box").offsetHeight + "px";
	}
}

if(document.all)
{
	window.setInterval("form_effect_ie();if(!window.XMLHttpRequest){tag_hover_effect();}", 500);
}

function SwitchVer(key)
{
	var obj = eval(Sjax("/Ajax/Cache.ashx", "key=" + key, "post", "changeversion"));
	return obj.ver;
}

function GetVer(key)
{	
	var obj = eval(Sjax("/Ajax/Cache.ashx", "key=" + key, "post", "getversion"));
	return obj.ver || 1;
}
function tagsTip(tipId,eventId,top,left) {
	if ($(tipId).style.display == "none")
	{
		$(tipId).style.cssText = "top:"+(findPosY(eventId)-$(eventId).offsetHeight - top)+"px;left:"+(findPosX(eventId)-left)+"px; display:block;";
	}
	else {
		$(tipId).style.display = "none";
	}
	
}

function convertImageSize(url, widthAndHeight)
{
	var index = url.lastIndexOf(".");
	return url.substring(0,index) + widthAndHeight + url.substr(index);
}

function isLogin()
{
	return document.cookie.indexOf("cmfuToken") > -1;
}