/* $Id : contrast.js www.mvmmall.com $ */
var ContList = new Array(); //存放数据
var ContUrl = 'contrast.php';
var ContOpenMode = 'new'; //在新窗口打开对比页(new为新窗口，其它为当前窗口)
loadCont();
ContHTML();
function GetObj(objName){
	if(document.getElementById){
		return eval('document.getElementById("'+objName+'")')
	}else{
		return eval('document.all.'+objName)
	}
}
function ContAdd(i,I,b){
	if(ContList.length>=5){
		alert(user_msg['contadd_err']);return
	}
	var l;
	for(l=0;l<ContList.length;l++){
		if(ContList[l][1]==I)return;
		if(ContList[l][2] != b){
			alert(user_msg['arrt_err']);
			return;
		}
	}
	ContList.push([i,I,b]);
	ContHTML();
	saveCont();
	if(document.getElementById('contrast').style.display=='none'){
	   document.getElementById('contrast').style.display="block";
	}
}
function ContDelId(i){
	var I;
	if(i==null)return;
	for(I=0;I<ContList.length;I++){
		if(ContList[I][1]==i)ContList.splice(I,1)
	}
	ContHTML();
	saveCont()
}
function ContBegin(){
	var I,i='';
	if(ContList.length<=1){
		alert(user_msg['addnums_err']);
		return
	}
	for(I=0;I<ContList.length;I++){
		i+=I!=0?',':'';
		i+=ContList[I][1]
	}
	if(ContOpenMode=='new'){
		window.open(ContUrl+"?id="+i)
	}else{
		window.location=ContUrl+'?id='+i
	}
}
function ContClear(){
	ContList=[];ContHTML();
	saveCont()
}
function ContHTML(){
	var I,i='';
	for(I=0;I<ContList.length;I++){
		i+='<p class="dbge"><span class="con_words">'+ContList[I][0]+'</span><span class="con_del"><a href="javascript:" onclick="ContDelId('+ContList[I][1]+')"> <img src="images/admincp/delet.gif" align="absmiddle" /></a></span></p>';
	}
	if(ContList.length<=0){
		i='<p></p><p></p><p align="center">'+user_msg['add_empty']+'</p>'
	}
	if(ContList.length>0){
	    if(document.getElementById('contrast').style.display=='none'){
	        document.getElementById('contrast').style.display="block";
	    }
	}
	GetObj('ContrastBox').innerHTML=i
}
function saveCont(){
	var I,i='';
	i='';
	for(I=0;I<ContList.length;I++){
		i+=((I!=0)?"|":"")+ContList[I][0]+","+ContList[I][1]+","+ContList[I][2]
	}
	writeCookie('ContList',i,24)
}
function loadCont(){
	var i=[],l;
	var I=readCookie('ContList');
	if(I==""||I==null)return;
	i=I.split('|');
	for(l=0;l<i.length;l++){
		i[l]=i[l].split(',');
		if(i[l].length!=3)return
	}
	ContList=i
}
function readCookie(l){
	var i="",I=l+"=";
	if(document.cookie.length>0){
		offset=document.cookie.indexOf(I);
		if(offset!=-1){
			offset+=I.length;
			end=document.cookie.indexOf(";",offset);
			if(end==-1)
				end=document.cookie.length;
			i=unescape(document.cookie.substring(offset,end))
		}
	}
	return i
}
function writeCookie(o,l,I){
	var i="";
	if(I!=null){
		i=new Date((new Date).getTime()+I*3600000);
		i="; expires="+i.toGMTString()
	}
	document.cookie=o+"="+escape(l)+i
}
NS6 = (document.getElementById&&!document.all);
IE = (document.all);
NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4");

function truebody(){
	return (document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function initSlide() {
	if (NS6){
		bssm=document.getElementById("contrast").style;
	}else if (IE) {
		bssm=document.all("contrast").style;
	}else if (NS) {
		//bssm=document.layers["contrast"];
		bssm=document.getElementById("contrast").style;
	}
	makeStatic();
}

function makeStatic() {
	if (NS||NS6) {winY = window.pageYOffset;}
	if (IE) {winY = truebody().scrollTop;}
	if (NS6||IE||NS) {
		if (winY!=lastY && winY > YOffset-staticYOffset) {
			smooth = .1 * (winY - lastY - YOffset + staticYOffset);
		} else if (YOffset-staticYOffset+lastY>YOffset-staticYOffset) {
			smooth = .1 * (winY - lastY - (YOffset-(YOffset-winY)));
		}
	else {
		smooth=0
	}
	if(smooth > 0) smooth = Math.ceil(smooth);
	else smooth = Math.floor(smooth);

	if (IE) bssm.pixelTop+=smooth;
	if (NS6) bssm.top=parseInt(bssm.top)+smooth+"px"
	if (NS) bssm.top=parseInt(bssm.top)+smooth

	lastY = lastY+smooth;
	setTimeout('makeStatic()', 1)
	}
}

YOffset=0;
XOffset=0;
staticYOffset=20;
lastY=0;
setTimeout('initSlide();', 1);
