 // 通用js函数和头部搜索处理

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}


function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds * 1000);
	//domain = !domain ? cookiedomain : domain;
	//path = !path ? cookiepath : path;
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function mb_strlen(str) {
	var len = 0;
	for(var i = 0; i < str.length; i++) {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
	}
	return len;
}

function mb_cutstr(str, maxlen, dot) {
	var len = 0;
	var ret = '';
	var dot = !dot ? '...' : '';
	maxlen = maxlen - dot.length;
	for(var i = 0; i < str.length; i++) {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
		if(len > maxlen) {
			ret += dot;
			break;
		}
		ret += str.substr(i, 1);
	}
	return ret;
}

function strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}


function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}

// 用于头部搜索检查
function do_head_search()
{
	// if(mb_strlen($("#head_search").find("input").val())>=2) return true;
	if($("#head_search").find("input").val().length>=1) return true;
    else return false;	
}

function display_msg(msgobj,msg,msec)
{
	if(typeof(msec)=='undefined') msec = 5000;
	msgobj.show();
	msgobj.html(msg);
	msgobj.fadeOut(msec);	
}

$(document).ready(function(){
	if(typeof User=='object'){
		if(User.vip){
			$("#yourid").addClass("vip");
		}	
		else{
			$("#yourid").removeClass("vip"); 
		}	
		$("#yourid").html(User.username);
	}	
	
	$(".download").after("<span class='arrow'></span>").click(function(){
			$("#download-child").slideToggle("fast");
			$(this).parent("a").toggleClass("active");
			$(this).toggleClass("active");
			return false;
	});
		
});