//cookie的相关函数

var theitem=0;

function getCookie (name) {
         var arg = name + "="; 
         var alen = arg.length; 
         var clen = document.cookie.length; 
         var i = 0; 
         while (i < clen) { 
             var j = i + alen; 
             if (document.cookie.substring(i, j) == arg) return getCookieVal (j); 
             i = document.cookie.indexOf(" ", i) + 1; 
             if (i == 0) break; 
         } 
	     return null; 
 } 
function setCookie(strname, strvalue) { 
	var date1 = new Date();
	var date2 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate()+100);
	var thepath="/";
	document.cookie = strname + "=" + strvalue + "; path=" + thepath + "; expires=" + date2 + ";"; 
	return true;
}


function clearCookie (name) { 
	vaule="";
	var d = new Date();
	var e = new Date(d.getFullYear(), d.getMonth(), d.getDate()-1);
	var thepath="/"
	document.cookie = name + "=" + vaule + "; expires=" + e.toGMTString() + "; path=" + thepath; 
		 
}


//**************显示或隐藏某个元素区块,同时改变显示的效果图片
function toggleShowHide(div_element,pic_element) {
	var selectedElement = document.getElementById(div_element);
	if (selectedElement.style.display == "block")
		{
		selectedElement.style.display = "none";
		if (pic_element){
		document.getElementById(pic_element).src="/pic/planner-off.gif";		
		}
		}
	else
		{
		selectedElement.style.display = "block";
		if (pic_element){
		document.getElementById(pic_element).src="/pic/planner-on.gif";	
		}
	}
}


//添加网址***********************
function addfavorite()
	{
		var linkname=document.title;
		//linkname=linkname.substr(0,30)+"..."
		var address=document.URL;
		var value=address+"||F||"+linkname;
		setCookie(address,value);
		alert("Added To My Highlights Successful!");
		showproduct("","favorite_url","","","b");
	}


//添加产品***********************
function addProduct(ostr)
	{
		var d = new Date();
		var e = new Date(d.getFullYear(), d.getMonth(), d.getDate()+100);
		var tmpostr=ostr.split("||");
		var thepath="/";
		document.cookie="product" + tmpostr[0]+"="+tmpostr[0]+"||P||"+tmpostr[1]+"||P||"+tmpostr[2]+"||P||"+tmpostr[3]+"||P||"+tmpostr[4]+"; expires=" + e.toGMTString() + " ; path=" + thepath;
		alert("Added To My Highlights Successful!");
		showproduct("","favorite_url","","","b");
	//MM_openBrWindow('selecttours.htm','','scrollbars=yes,width=750,height=170');
	//showproduct("productlist");
	}

//***********删除产品
function delcookie(name){
var d = new Date();
var e = new Date(d.getFullYear(), d.getMonth(), d.getDate()-1);
if (!confirm("Are you ure of delete selected item?")) return false;
var thepath="/";
document.cookie=name+"=\"\"; expires=" + e.toGMTString() + "; path=" + thepath;
showproduct("Product","bookmarked","count-p","count-b","all");
}



//******************显示产品列表以及收藏的网址
function showproduct(element1,element2,count1,count2,strtype)
{
	theitem1=0;
	theitem2=0;
	var tmpcookie=document.cookie.split("; ");
	var favoriteinfo="<table border='0' cellpadding='0' cellspacing='8' class='tableSimple'>";
	var i2;
	i2=tmpcookie.length;
	if (i2>0)
	{
		var productinfo ="<table border=0 cellpadding=8 cellspacing=0 class='table1'>"	+"\n"+
					"    <tr>"	+"\n"+
					"      <th>Code </th>"	+"\n"+
					"      <th>Name</th>"	+"\n"+
					"      <th>Fee</th>"	+"\n"+
					"      <th>Inquiry</th>"	+"\n"+
					"      <th>Operate</th>"	+"\n"+
					"    </tr>";
		var total=0;
		for (var i=i2-1;i>0;i--)
		{
			var tmpstr1=tmpcookie[i].split("||");
			if (tmpstr1.length>2)
			{
				if (tmpstr1[1]=="P")
				{
					//total+=Number(tmpstr1[2]);
					theitem1=theitem1+1;
					if (strtype!="b"){
						tmpstr2=tmpstr1[0].split("=");
						var the_url="<a href=\"/forms/reserve-tour.asp?CLI_SN=" +"\n"+
							tmpstr1[8]+"\"><img src=\"/pic/inquiry-tour.gif\"" +"\n"+
							"alt=\"Inquiry this tour\" border=\"0\" class=\"inputNoborder\"/></a>";
						productinfo=productinfo+"<tr>" +"\n"+
							"<td>"+tmpstr2[1]+"</td>" +"\n"+
							"<td><a href=\"" + tmpstr1[6] + "\">"+tmpstr1[2]+"</a></td>" +"\n"+
							"<td>$"+tmpstr1[4]+"</td>" +"\n"+
							"<td>"+the_url+"</td>" +"\n"+
							"<td><a href=\"#\" onclick=\"delcookie('"+tmpstr2[0]+"')\">Delete</a>" +"\n"+
							"</td>" +"\n"+
							"</tr>";
					}
				}
				else if (tmpstr1[1]=="F")
				{
					theitem2=theitem2+1;
					tmpstr2=tmpstr1[0].split("=");
					if (strtype!="b"){
						favoriteinfo+="<tr><td><a href=\""+tmpstr2[0]+"\">"+tmpstr1[2]+"</a></td>"
						favoriteinfo+="<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#\" onclick=\"delcookie('"+tmpstr2[0]+"')\">Delete</a></td></tr>";
					}
					else{
						favoriteinfo+="<tr><td><a href=\""+tmpstr2[0]+"\">"+tmpstr1[2].substr(0,30)+"..."+"</a></td>"
						favoriteinfo+="</td></tr>"
					}
				}
			 }
		}
		 favoriteinfo+="</table>"
		 productinfo=productinfo+"</table>"
		 //var contentinfo=favoriteinfo+"<br />Product List:<br />"+productinfo;
		 if (strtype=="b"){
		 	document.getElementById(element2).innerHTML=favoriteinfo;
			document.getElementById("mycount").innerHTML=theitem1+theitem2;
		}
		else{
		 	 document.getElementById(element2).innerHTML=favoriteinfo;
			 document.getElementById(element1).innerHTML=productinfo;
			 document.getElementById(count1).innerHTML=theitem1;
			 document.getElementById(count2).innerHTML=theitem2;
		}
		//total+=Number(document.all.gtid.document.all.gtid.innerText);  
	}
}	


//推荐给朋友邮件
function mailtofriend(){   
   var linkurl=location.href;
   window.location.href = "/forms/send-friend.asp?linkurl=" + linkurl;
}
//问一个问题
function askquestion(){
   var linkurl=location.href;
   window.location.href = "/forms/ask.htm";
}
//弹出一个小窗口
function OpenWindow(htmurl,tops,lefts,widths,heights)
{
   var paramet = 'toolbar=no,resizable=yes,scrollbars=yes,top='+ tops + ',left='+ lefts + ',width='+ widths + ',height=' + heights;
   newWindow = window.open(htmurl,"viewfilm",paramet);
   newWindow.focus();
}
