
function addSearchKeyword(keyword)
{
	var myReg1 = "^(KEY:)((.)+)(URL:)";
	var myReg2 = "(URL:)((.)+)";
	if(keyword.length>0)
	{
		var chongfu = false;
		var strSearchKey = "";
		var newSearchKey = "KEY:" + keyword + "URL:" + window.location.href;
		if(GetCookie("searchkey")!=null)
		{
			var keyarray = GetCookie("searchkey").split('|');
			for(i=0;i<keyarray.length;i++)
			{
				if(myRegex(keyarray[i],myReg1,2)==myRegex(newSearchKey,myReg1,2))
				{
					var chongfu = true;
					return;
				}
			}
			if(chongfu==false)
			{
				strSearchKey = newSearchKey + "|" + GetCookie("searchkey");
			}
			else
			{
				strSearchKey = GetCookie("searchkey");
			}
		}
		else
		{
			strSearchKey = newSearchKey;
		}
		var searchkeyArray = strSearchKey.split('|');
		if(searchkeyArray.length > 6)
		{
			strSearchKey = strSearchKey.replace("|" + searchkeyArray[6],"")
		}
		SetCookie("searchkey",strSearchKey, expdate, "/");
	}
}

function getSearchKeyword(controlname)
{
	var myReg1 = "^(KEY:)((.)+)(URL:)";
	var myReg2 = "(URL:)((.)+)";
	var searchkeyArray = "";
	var textobj;
	var hrefobj;
	if(GetCookie("searchkey") != null)
	{
		searchkeyArray = GetCookie("searchkey").split("|");
	}

	for(var i=0;i<searchkeyArray.length;i++)
	{
		if(i<6)
		{
			if(i!=5)
				textobj = document.getElementById("span_href_" + controlname + "_" + i);
			hrefobj = document.getElementById("text_href_" + controlname + "_" + i);
			parentobj = document.getElementById("a_" + controlname);
			if(i!=searchkeyArray.length-1)
				textobj.innerText = ", ";
			hrefobj.href = myRegex(searchkeyArray[i],myReg2,2);
			hrefobj.innerText = myRegex(searchkeyArray[i],myReg1,2);
			parentobj.className = "sortopen";
			hrefobj.parentNode.style.display = "";
			hrefobj.style.display="";
		}
	} 
}

function addCategory(categoryName)
{
	var myReg1 = "^KEY:((.)+);";
	var myReg2 = "URL:((.)+)";
	var strhref = window.location.href;
	var strCategory = "";
	if(categoryName != null && categoryName.length > 0)
	{
		var repeat = false;
		var newItem = "KEY:" + categoryName + ";URL:" + strhref;
		if(GetCookie("category") != null && GetCookie("category") != "")
		{
			var categoryCookieArray = GetCookie("category").split("|");
			for(var i=0;i<categoryCookieArray.length;i++)
			{
				if(categoryName == myRegex(categoryCookieArray[i],myReg1,1))
				{
					repeat = true;
					return;
				}
				strCategory = newItem + "|" + GetCookie("category");
			}
		}
		else
		{
			strCategory = newItem;
		}
		var newCategoryArray = strCategory.split("|");
		if(newCategoryArray.length > 4)
		{
			strCategory = strCategory.replace("|" + newCategoryArray[4],"");
		}
		SetCookie("category",strCategory,expdate,"/");
	}
}

function getCategory(controlname)
{
	var myReg1 = "^KEY:((.)+);";
	var myReg2 = "URL:((.)+)";
	var categoryArray = "";
	if(GetCookie("category") != null && GetCookie("category") != "")
		categoryArray = GetCookie("category").split("|");
	for(var i=0;i<categoryArray.length;i++)
	{
		if(i<4)
		{
			var liobj = document.getElementById("li_" + controlname + "_" + i);
			var hrefobj = document.getElementById("text_href_" + controlname + "_" + i);
			var parentobj = document.getElementById("a_" + controlname);
			hrefobj.href = myRegex(categoryArray[i],myReg2,1);
			hrefobj.innerText = myRegex(categoryArray[i],myReg1,1);
			parentobj.className = "sortopen";
			liobj.parentNode.style.display = "";
			liobj.style.display = "";
		}
	}
}

function addSellInfo(subject,imgpath)
{
	var myReg1 = "^KEY:((.)*?);";
	var myReg2 = "URL:((.)*?);";
	var myReg3 = "IMG:((.)+)";
	var strhref = window.location.href;
	var allSellInfo = "";
	if(subject != null && subject.length > 0)
	{
		var repeat = false;
		var newItem = "KEY:" + subject + ";URL:" + strhref + ";IMG:" + imgpath;
		if(GetCookie("sellinfo") != null && GetCookie("sellinfo") != "")
		{
			var sellInfoCookieArray = GetCookie("sellinfo").split("|");
			for(var i=0;i<sellInfoCookieArray.length;i++)
			{
				if(subject == myRegex(sellInfoCookieArray[i],myReg1,1))
				{
					repeat = true;
					return;
				}
				allSellInfo = newItem + "|" + GetCookie("sellinfo");
			}
		}
		else
		{
			allSellInfo = newItem;
		}
		var newSellInfoArray = allSellInfo.split("|");
		if(newSellInfoArray.length > 4)
		{
			allSellInfo = allSellInfo.replace("|" + newSellInfoArray[4],"");
		}
		SetCookie("sellinfo",allSellInfo,expdate,"/");
	}	
}

function getSellInfo(controlname)
{
	var myReg1 = "^KEY:((.)*?);";
	var myReg2 = "URL:((.)*?);";
	var myReg3 = "IMG:((.)+)";
	var sellInfoArray = "";
	if(GetCookie("sellinfo") != null && GetCookie("sellinfo") != "")
		sellInfoArray = GetCookie("sellinfo").split("|");
	for(var i=0;i<sellInfoArray.length;i++)
	{
		if(i<4)
		{
			var liobj = document.getElementById("li_" + controlname + "_" + i);
			var imghrefobj = document.getElementById("img_href_" + controlname + "_" + i);
			var imgobj = document.getElementById("img_" + controlname + "_" + i);
			var parentobj = document.getElementById("a_" + controlname);
			var dvobj = document.getElementById("dv_" + controlname + "_" + i);
			var texthrefobj = document.getElementById("text_href_" + controlname + "_" + i);
			
			imghrefobj.href = myRegex(sellInfoArray[i],myReg2,1);
			imghrefobj.title = myRegex(sellInfoArray[i],myReg1,1);
			texthrefobj.href = myRegex(sellInfoArray[i],myReg2,1);
			texthrefobj.innerText = myRegex(sellInfoArray[i],myReg1,1);
			imgobj.src = "/uploadpicture/S_productpicture/F_" + myRegex(sellInfoArray[i],myReg3,1);
			imgobj.width = 50;
			parentobj.className = "sortopen";
			document.getElementById(controlname).style.display = "";
			liobj.style.display = "";
		}
	}
}

function getSellInfo_opener(controlname)
{
	try
	{
		var myReg1 = "^KEY:((.)*?);";
		var myReg2 = "URL:((.)*?);";
		var myReg3 = "IMG:((.)+)";
		var sellInfoArray = "";
		if(GetCookie("sellinfo") != null && GetCookie("sellinfo") != "")
			sellInfoArray = GetCookie("sellinfo").split("|");
		for(var i=0;i<sellInfoArray.length;i++)
		{
			if(i<4)
			{
				var liobj = window.opener.document.getElementById("li_" + controlname + "_" + i);
				var imghrefobj = window.opener.document.getElementById("img_href_" + controlname + "_" + i);
				var imgobj = window.opener.document.getElementById("img_" + controlname + "_" + i);
				var parentobj = window.opener.document.getElementById("a_" + controlname);
				var dvobj = window.opener.document.getElementById("dv_" + controlname + "_" + i);
				var texthrefobj = window.opener.document.getElementById("text_href_" + controlname + "_" + i);
				
				if(liobj!=null && imghrefobj!=null && imgobj!=null && parentobj!=null && texthrefobj!=null)
				{
					imghrefobj.href = myRegex(sellInfoArray[i],myReg2,1);
					imghrefobj.title = myRegex(sellInfoArray[i],myReg1,1);
					texthrefobj.href = myRegex(sellInfoArray[i],myReg2,1);
					texthrefobj.innerText = myRegex(sellInfoArray[i],myReg1,1);
					imgobj.src = "/uploadpicture/S_productpicture/F_" + myRegex(sellInfoArray[i],myReg3,1);
					imgobj.width = 50;
					parentobj.className = "sortopen";
					window.opener.document.getElementById(controlname).style.display = "";
					liobj.style.display = "";
				}
				else
				{
					break;
				}
			}
		}
	}
	catch(e)
	{
		return;
	}
}

function myRegex(str,regex,getstr)
{
	var test = new RegExp(regex,"i");
	var matchCollection = str.match(test);
	var returnValue = "";
	if(matchCollection!=null)
	{
		returnValue = matchCollection[getstr];
	}
	return returnValue;
}
