﻿/*======================================================================*/
function ShowAutoTable (m,n,count)
{
	for(var i=1;i<=count;i++)
	{
		if (i==n)
		{
			getObject(m+"_"+i).className = "ShowBigTD";
			getObject("a_"+m+"_"+i).className = "ShowBigColor";
			getObject("tab_"+m+"_"+i).style.display = "";
		}
		else 
		{	
			getObject(m+"_"+i).className = "DisplayBigTD";
			getObject("a_"+m+"_"+i).className = "DisplayBigColor";
			getObject("tab_"+m+"_"+i).style.display = "none";			
		}
	}
}
function AddElement(id,name,price){
	var strCookie="";
	getObject("CompareAuto").style.display = "";
	if (checkType("hidden",id)){
		var pTag = document.getElementById("Compare");
		var newUL = document.createElement("ul");
		pTag.appendChild(newUL);
		listCreation(name+' '+price+' ',id);
		if (null == GetCookie("auto")){
			strCookie = id+','+name+','+price;
		}
		else{
			strCookie = GetCookie("auto") + '|' +id+','+name+','+price;
		}
		SetCookie("auto",strCookie);
	}
}
function listCreation(data,id){
	var pTag = getObject("Compare");
	var ulTag = pTag.getElementsByTagName("ul").item(0);
	var newLI = document.createElement("li");
	newLI.id = id;
	var newText = document.createTextNode(data);
	var hidInput = document.createElement("input");
	hidInput.id = id;
	hidInput.name = id;
	hidInput.type="hidden";
	hidInput.value=id;
	
	var newInput = document.createElement("input");
	newInput.id = "del";
	newInput.name="del";
	newInput.type="button";
	newInput.value="删除";
	newInput.onclick = function () {
		del(newLI.id);
	};
	newLI.appendChild(newText);
	newLI.appendChild(hidInput);
	newLI.appendChild(newInput);
	ulTag.appendChild(newLI);
}
function del(id){
	var new_tr = getObject(id);
	try {
		var tmp = new_tr.parentNode;
		tmp.removeChild(new_tr);	
	} catch(e) {}
	delCompareCookie(id)
}
function closeWin(id){ 
	getObject(id).style.display = "none"; 
}
function checkType(type,id){
	var ArrID='';
	var n=0,o=document.getElementById("FrmCompareAuto").getElementsByTagName("input");
	for(i=0;i<o.length;i++){
		if(o[i].type==type){
			n++;
			ArrID += o[i].id +'|';
		}
	}
	if (n >= 3 ){
		alert('本系统最多只能是三条车型数据对比！');
		return false;
	}
	if (ArrID.indexOf(id) >= 0){
		alert('此车型数据您已添加过！');
		return false;
	}
	return true;
}
function FormCheck(){
	var strCookie,ArrCompare;
	strCookie = GetCookie("auto");
	if (null == strCookie){
		alert('最少选择二条车型数据才能开始对比！');
		return false;
	}
	else{
		ArrCompare = strCookie.split("|");
		if (ArrCompare.length < 2 || ArrCompare.length > 3){
			alert('最少选择二条车型数据才能开始对比！');
			return false;
		}
	}
}
function initCompare()
{
	var strCookie,ArrCompare;
	strCookie = GetCookie("auto");
	DeleteCookie("auto");
	if (null != strCookie){
		ArrCompare = strCookie.split("|");
		for (var i = 0; i < ArrCompare.length; i++){
			AddElement(ArrCompare[i].split(",")[0],ArrCompare[i].split(",")[1],ArrCompare[i].split(",")[2]);
		}
	}
}
function delCompareCookie(id)
{
	var strCookie,ArrCompare;
	var c_Cookie=""
	strCookie = GetCookie("auto");
	DeleteCookie("auto");
	if (null != strCookie){
		ArrCompare = strCookie.split("|");
		for ( var i = 0; i < ArrCompare.length; i++){
			if (id != ArrCompare[i].split(",")[0])
				if ("" == c_Cookie)
					c_Cookie = ArrCompare[i].split(",")[0]+','+ArrCompare[i].split(",")[1]+','+ArrCompare[i].split(",")[2];
				else
					c_Cookie += '|'+ArrCompare[i].split(",")[0]+','+ArrCompare[i].split(",")[1]+','+ArrCompare[i].split(",")[2];
		}
		SetCookie("auto",c_Cookie);
	}
}