jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires
				&& (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime()
						+ (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires
			// attribute,
			// max-age is not
			// supported by IE
		}
		var path = options.path ? '; path=' + options.path : '';
		var domain = options.domain ? '; domain=' + options.domain : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [ name, '=', encodeURIComponent(value), expires,
				path, domain, secure ].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for ( var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie
							.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
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);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
			+ (expires ? '; expires=' + expires.toGMTString() : '')
			+ (path ? '; path=' + path : '/')
			+ (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '');
}

function saveCookie(reURL, title, model, imageURL) {
	if (reURL == "") {
		alert("产品详细信息跳转路径（reURL）不能为空");
		return;
	}
	if (title == "") {
		alert("产品标题（title）不能为空");
		return;
	}
	if (model == "") {
		alert("产品型号（model）不能为空");
		return;
	}
	if (imageURL == "") {
		alert("产品图片路径（imageURL）不能为空");
		return;
	}
	var arr2 = new Array();
	var newpro = new Array(reURL, title, model, imageURL);
	var proshuzu = $.cookie('productHistory');
	if (proshuzu != null && proshuzu != '') {
		var ss = proshuzu.split(",");
		for ( var l = 0; l < ss.length; l++) {
			if (model == ss[l]) {// 根据产品型号判断是否重复，如果重复了先把这个产品的四个信息从数组中删除
				ss.splice(l - 2, 4);
			}
		}
		var proinfos = ss.length;
		var pro = proinfos / 4;// 当前数组中有多少产品浏览历史
		if (pro > 3) {// 大于三个，得到最新的三个放在当前的数组中
			for ( var k = 0; k < 3; k++) {
				// var num11 = new
				// Array(ss[pro*4-4],ss[pro*4-3],ss[pro*4-2],ss[pro*4-1]);
				var num11 = new Array(ss[4 * k], ss[4 * k + 1], ss[4 * k + 2],
						ss[4 * k + 3]);
				arr2.push(num11);
				pro = pro - 1;
			}
		} else {// 三个或三个一下直接再把它们重新添加到数组中
			for ( var j = pro; j > 0; j--) {
				var num11 = new Array(ss[j * 4 - 4], ss[j * 4 - 3],
						ss[j * 4 - 2], ss[j * 4 - 1]);
				arr2.unshift(num11);
			}
		}
	}
	arr2.unshift(newpro);// 把当前浏览的产品信息放在数组的最前端
	$.cookie('productHistory', arr2);
}

function saveNewsCookie(reURL, title) {
	if (reURL == "") {
		alert("新闻跳转路径（reURL）不能为空");
		return;
	}
	if (title == "") {
		alert("新闻标题（title）不能为空");
		return;
	}
	var arr2 = new Array();
	var newnews = new Array(reURL, title);
	var newsshuzu = $.cookie('newsHistory');
	if (newsshuzu != null && newsshuzu != '') {
		var ss = newsshuzu.split(",");
		for ( var l = 0; l < ss.length; l++) {
			if (title == ss[l]) {// 根据新闻标题判断是否重复，如果重复了先把这个新闻的二个信息从数组中删除
				ss.splice(l - 1, 2);
			}
		}
		var newsinfos = ss.length;
		var news = newsinfos/2;//当前数组中有多少产品浏览历史
		if(news>8){//大于三个，得到最新的三个放在当前的数组中
			for(var k=0; k<8; k++){
				//var num11 = new Array(ss[pro*4-4],ss[pro*4-3],ss[pro*4-2],ss[pro*4-1]);
				var num11 = new Array(ss[4*k],ss[4*k+1],ss[4*k+2],ss[4*k+3]);

				arr2.push(num11);
				news = news - 1;
			}
		} else {// 8个或8个以下直接再把它们重新添加到数组中
			for ( var j = news; j > 0; j--) {
				var num11 = new Array(ss[j * 2 - 2], ss[j * 2 - 1]);
				arr2.unshift(num11);
			}
		}
	}
	arr2.unshift(newnews);// 把当前浏览的产品信息放在数组的最前端
	$.cookie('newsHistory', arr2);
}
function cleanCookies(obj) {
	$.cookie(obj, null);
	$("#" + obj).html("");
}
