recordPositionY = 0;
var ption=20;
var appName = navigator.appName.toLowerCase();
var isapp=false;
if(appName=='netscape')
{
  isapp=true;
}
function FixPosition()
{

var scrollPos; 
if (typeof window.pageYOffset != 'undefined') { 
   scrollPos = window.pageYOffset; 
} 
else if (typeof document.compatMode != 'undefined' && 
     document.compatMode != 'BackCompat') { 
   scrollPos = document.documentElement.scrollTop; 
} 
else if (typeof document.body != 'undefined') { 
   scrollPos = document.body.scrollTop; 
} 

	 movePixY = 0.2*(scrollPos-recordPositionY);
	if(movePixY>0)
	{
		movePixY = Math.ceil(movePixY);
	}
	else
	{
		movePixY = Math.floor(movePixY);
	}
	//document.all.Div_compare.style.pixelTop+= movePixY;
	obj=document.getElementById("Div_compare");
	ption +=movePixY;	
	obj.style.top=ption;
	recordPositionY = recordPositionY+movePixY;
}
document.getElementById("Div_compare").style.top=30;
document.getElementById("Div_compare").right=document.documentElement.scrollLeft+5;
document.getElementById("Div_compare").style.width=162;
window.setInterval("FixPosition()",2);

// unicode 编码程序
function BasketEncodeCookie(InputString)
{
	var strRtn="";
	for (var i=InputString.length-1;i>=0;i--)
	{
		strRtn+=InputString.charCodeAt(i);
		if (i) strRtn+="a"; // 用 a 作分隔符
	}
	return strRtn;
}

// unicode 解码程序
function BasketDecodeCookie(InputString)
{
	var strArr;
	var strRtn="";

	strArr=InputString.split("a");

	for (var i=strArr.length-1;i>=0;i--)
		strRtn+=String.fromCharCode(eval(strArr[i]));

	return strRtn;
}

// 读 Cookie
function BasketGetCookie(name)
{
	var strArg=name+"=";
	var nArgLen=strArg.length;
	var nCookieLen=document.cookie.length;
	var nEnd;
	var i=0;
	var j;

	while (i<nCookieLen)
	{
		j=i+nArgLen;
		if (document.cookie.substring(i,j)==strArg)
		{
			nEnd=document.cookie.indexOf (";",j);
			if (nEnd==-1) nEnd=document.cookie.length;
			return BasketDecodeCookie(unescape(document.cookie.substring(j,nEnd)));
		}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

// 写 Cookie
function BasketSetCookie(name,value,expires)
{
	var exp = new Date();
	exp.setTime(exp.getTime()+expires*60*60*1000);
	document.cookie=name+"="+escape(BasketEncodeCookie(value))+";path=/;domain=.autocity.com.cn;expires="+exp.toGMTString();
}

// 判断 Cookie 是否存在并写产品对比 Cookie
function BasketCheckSetCookieValue(name,value,expires)
{
	var nameCookieValue = BasketGetCookie(name);
	if ((nameCookieValue == "") || (nameCookieValue == null))
	{
		var exp = new Date();
		exp.setTime(exp.getTime()+expires*60*60*1000);
		document.cookie=name+"="+escape(BasketEncodeCookie(value))+";path=/;domain=.autocity.com.cn;expires="+exp.toGMTString();
	}
	else
	{
		if (nameCookieValue.indexOf(value) == -1)
		{
			var arrCookies = nameCookieValue.split("；");
			var ValueNum = arrCookies.length;
			if (ValueNum > 4)
			{
				nameCookieValue = "";
				for (loop=0; loop < 4; loop++)
				{
					nameCookieValue += arrCookies[loop] + "；";
				}
				nameCookieValue = nameCookieValue.substring(0,nameCookieValue.length - 1);
			}

			var exp = new Date();
			exp.setTime(exp.getTime()+expires*60*60*1000);
			document.cookie=name+"="+escape(BasketEncodeCookie(value+"；"+nameCookieValue))+";path=/;domain=.autocity.com.cn;expires="+exp.toGMTString();
		}
	}
}

function hide()
{
  obj=document.getElementById("Div_compare");
  obj.style.display='none';
}

function show()
{
  obj=document.getElementById("Div_compare");
  obj.style.display='block';
}

function Empty(cId)
{
    var CompareProducts = BasketGetCookie("au_CompareModel");
    if (CompareProducts == null)
    {
	    CompareProducts = "";
    }
    var arrCookies = CompareProducts.split("；");    
    
    for (i = 0; i < arrCookies.length; i++)
    {
	    if ((arrCookies[i] != "") && (arrCookies[i] != null))
	    {
		    if (arrCookies[i].indexOf("|") >= 0)
		    {
			    var ProductInfo = arrCookies[i].split("|");
			    if (ProductInfo.length = 4)
			    {
				    var ProductSN = ProductInfo[0];

				    if (ProductSN != null)
				    {
				         if( document.getElementById(ProductSN) != null )
				         {
					        document.getElementById(ProductSN).checked = false;
					     }
				    }
			    }
		    }
	    }
    }
	BasketSetCookie("au_SignStr","",24);
	BasketSetCookie("au_CompareModel","",24);
	redraw();
}

// 判断选择的产品和以前选择的产品是否同类同类产品
function CheckCategoryChange(SubCategory)
{
	var SubCategorySN = BasketGetCookie("au_SignStr");
	if ((SubCategory == null) || (SubCategory == ""))
	{
		BasketSetCookie("au_SignStr",SubCategory,24);
	}
	else
	{
		if (SubCategory != SubCategorySN)
		{
			BasketSetCookie("au_SignStr",SubCategory,24);
			BasketSetCookie("au_CompareModel","",24);
		}
	}
}

function AddCompareProduct(ProductSN,ProductName,ProductLink,ProductImg,SubCategory)
{
	CheckCategoryChange(SubCategory);
	var CompareProducts = BasketGetCookie("au_CompareModel");
	if ((CompareProducts != "") && (CompareProducts != null))
	{
		var arrCookies = CompareProducts.split("；");
		if (arrCookies.length < 4)
		{
			if (CompareProducts.indexOf(ProductSN) != -1)
			{
				alert("（" + ProductName + "）已经被选择了！");
			}
			else
			{
				BasketCheckSetCookieValue("au_CompareModel",ProductSN + "|" + ProductName + "|" + ProductLink + "|" + ProductImg,24);
			}
		}
		else
		{
			alert("对不起！您只能选择四款车型进行比较。");
		}
	}
	else
	{
		BasketCheckSetCookieValue("au_CompareModel",ProductSN + "|" + ProductName + "|" + ProductLink + "|" + ProductImg,24);
		
	}
	redraw();
	ShowLayer();
}

function DelProduct(ProductSN)
{
	var nameCookieValue = BasketGetCookie("au_CompareModel");
	if ((nameCookieValue != null) && (nameCookieValue != ""))
	{
		if (nameCookieValue.indexOf(ProductSN) > -1)
		{
			var arrCookies = nameCookieValue.split("；");
			var ValueNum = arrCookies.length;
			nameCookieValue = "";
			for (i=0; i < ValueNum; i++)
			{
				if (arrCookies[i].indexOf(ProductSN) == -1)
				{
					nameCookieValue += arrCookies[i] + "；";
				}
			}
			nameCookieValue = nameCookieValue.substring(0,nameCookieValue.length - 1);
			BasketSetCookie("au_CompareModel",nameCookieValue,24);
			if( document.getElementById(ProductSN) != null )
			{
			    document.getElementById(ProductSN).checked = false;
			}
		}
		redraw();
	}
}

function redraw()
{
	//FixPosition();
	var CompareProducts = BasketGetCookie("au_CompareModel");
	if (CompareProducts == null)
	{
		CompareProducts = "";
	}
	var arrCookies = CompareProducts.split("；");


    var CompareDiv = "<div class=\"compare_box\"><div class=\"compare_box_title\">车型对比篮</div><div class=\"compare_pic\">";
    
    
	for (i = 0; i < arrCookies.length; i++)
	{
		if ((arrCookies[i] != "") && (arrCookies[i] != null))
		{
			if (arrCookies[i].indexOf("|") >= 0)
			{
				var ProductInfo = arrCookies[i].split("|");
				if (ProductInfo.length = 4)
				{
					var ProductSN = ProductInfo[0];
					var ProductName = ProductInfo[1];
					var ProductLink = ProductInfo[2];
					var ProductImg = ProductInfo[3];
					if (ProductSN == null)
					{
						ProductSN = "";
					}
					if (ProductName == null)
					{
						ProductName = "";
					}
					if (ProductLink == null)
					{
						ProductLink = "";
					}
					if (ProductImg == null)
					{
						ProductImg = "";
					}
					if ((ProductName != "") && (ProductSN != "") && (ProductLink != "") && (ProductImg != ""))
					{
							
							CompareDiv = CompareDiv + "<div class=\"compare_img\"><a href=\"" + ProductLink + "\" target='_blank'><img src=\"" + ProductImg + "\" width=\"120\" height=\"80\" border=\"0\"></a><div class=\"compare_img_word\"><a onClick=DelProduct('" + ProductSN + "'); style='cursor: hand'>" + ProductName + "</a></div></div>";
					}
				}
			}
		}
	}


		CompareDiv = CompareDiv + "<div class=\"compare_btn\"><div class=\"compare_btn_pic\"><a href=\"javascript:void(null);\" target=\"_self\" onClick=\"CompareCheck()\"><img src=\"http://car.autocity.com.cn/images/DefaultPage/compare_btn.gif\" width=\"132\" height=\"24\" border=\"0\"></a></div>"
		+ "<div class=\"compare_btn_pic\"><a onClick='Empty(0)' style='color:blue;cursor: hand'><img src=\"http://car.autocity.com.cn/images/DefaultPage/Clear_btn.gif\" width=\"63\" height=\"24\" border=\"0\" ></a> <a onClick='HideLayer()' style='color:blue;cursor: hand'><img src=\"http://car.autocity.com.cn/images/DefaultPage/hide_btn.gif\" width=\"63\" height=\"24\" border=\"0\"></a></div></div></div></div>";

	document.getElementById('Div_compare').innerHTML = CompareDiv;
}

function IsNumber(inputVal)
{
	var inputStr = inputVal.toString();
	var i = 0;
	for (i =0; i<inputStr.length; i++)
	{
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar> "9")
		{
			return false;
		}
	}
	return true;
}

function CompareCheck()
{
	var URL = "http://car.autocity.com.cn/CarModelCompare.aspx";
	var CompareProductsValue = BasketGetCookie("au_CompareModel");
	if ((CompareProductsValue != "") && (CompareProductsValue != null))
	{
		var arrValues = CompareProductsValue.split("；");
		var ValuesNum = arrValues.length;
		if (ValuesNum < 2)
		{
			alert ('请至少选择两款同类别产品进行对比！');
		}
		else
		{
			var QueryString = "?";
			for (i = 1; i <= ValuesNum; i++)
			{
				var ProductInfo = arrValues[i-1].split("|");
				if (IsNumber(ProductInfo[0]))
				{
					QueryString += "&ModelId" + i + "=" + ProductInfo[0];
				}
			}
			window.open(URL + QueryString);
		}
	}
}

redraw();

function HideLayer()
{
	BasketSetCookie("au_HiddenCompare","Hide",24);
	hide();
}

function ShowLayer()
{
	BasketSetCookie("au_HiddenCompare","Show",24);
	show();
}

if ((BasketGetCookie("au_HiddenCompare") == "Hide") || (BasketGetCookie("au_CompareModel") == "") || (BasketGetCookie("au_CompareModel") == null))
{
	HideLayer();
}
else
{
	ShowLayer();
}

function ProductFavorite(Product)
{
alert("添加");
}

function CKAdd(ProductSN,ProductName,ProductLink,ProductImg)
{
    if( document.getElementById(ProductSN).checked == true )
    {
        AddCompareProduct(ProductSN,ProductName,ProductLink,ProductImg,'1');
    }
    else
    {
        DelProduct(ProductSN);
    }
}

function CKCheck(ProductSN)
{
    document.getElementById(ProductSN).checked = true;
}

-->
