//////////////////////////////////////////////////////////////////////////////////
//                            免刷新图库程序V3.3                                //
//    本程序由金足工作室出品,采由现今流行的XML技术.可达到数据更新网页画面无闪烁,//
//并有声音提示.后台采用ASP制作,服务器配置极其简单.                              //
//                              QQ:47383172                                     //
//////////////////////////////////////////////////////////////////////////////////
var BL_PicUpData;
var BL_UserId = readCookie("userid");
var BL_PicId  = FUN_GetUrl(document.location,"id");
var BL_Leng;	//图片数目
var BL_PicName;
var BL_PicTime;
var BL_Lable;
var BL_Path,BL_File;
var BL_NowPage = readCookie("NowPage");
if (!BL_NowPage) BL_NowPage = 0;		//默认显示的页码
var BL_ReLoad,BL_PicUpId;
var BL_TimeOut = 2000;
var BL_RowLen;
var BL_CellLen;
var BL_MouseCode = new Object();
//var BL_Img = document.createElement("IMG");
//TAB_PicTab.appendChild(BL_Img);
    //BL_Img.style.display = "none";

if(!isNaN(BL_PicId) && BL_PicId >=0){
	BL_PicId = Math.floor(BL_PicId);
}else{
	BL_PicId = 0
}

function FUN_GetPicTime(BL_GetTime){
	BL_Leng   = TAB_PicTab.cells.length; //图片数目


for(i=0;i<BL_PicPath.length;i++){
	BL_PicName = BL_PicPath[i];

if(BL_PicId==i){
	BL_PicName[0]=BL_PicName[0].toUpperCase();
	BL_File=BL_PicName[1];
	BL_Path=BL_PicName[2]+"/";
	BL_RowLen = BL_PicName[3];
	BL_CellLen = BL_PicName[4];
	BL_PicName[0]="<span class='style2'>"+BL_PicName[0]+"</span>";
}
	TD_PicName.innerHTML += "　<a href='?id="+ i +"' target='_self'>" + BL_PicName[0] + "</a>";
}

if(BL_UserId){
	TD_PicName.innerHTML += "　<a href='http://"+ document.location.hostname + ":16880/vip.htm?user="+ BL_UserId +"' target='_top'>进入自选图区</a>";
}else{
	TD_PicName.innerHTML += "　<a href='http://"+ document.location.hostname + ":16880/Login.htm' target='_top'>进入自选图区</a>";
}

var BL_PageStr="<table width='100%'><tr align='center' id='TR_Page'><td><a href='javascript:FUN_Page(0)' target='_self'>显示全部</a></td>";
for(i=0;i<TAB_PicTab.rows.length/BL_RowLen;i++){
 	BL_PageStr+="<td><a href='javascript:FUN_Page("+(i+1)+")' target='_self'>第"+(i+1)+"页</a></td>";
}
BL_PageStr+="</tr></table>";
DIV_PageList.innerHTML=BL_PageStr;
    FUN_Page(BL_NowPage);

	if(readCookie("sound")=="true") sound.checked = true;
	if(readCookie("download")=="true") download.checked = true;
	
        BL_PicTime = BL_GetTime.split(",");
	var BL_RowStr = "<table id='TAB_NewTab'>";

	for(i=0;i<BL_PicTime.length-1;i++){
		if (i>=BL_RowLen-1) break;	
		BL_RowStr+="<tr><td>"+TAB_PicTab.cells[Math.floor(BL_PicTime[i])].innerHTML+"</td></tr>";
	}

	TD_NewList.innerHTML=BL_RowStr+"</table>";
	BL_PicUpId="";//清空缓存
	BL_ReLoad="";
	BL_TempUrl = "xml/"+Math.random()+"/../changer"+ BL_PicId + ".htm?Date=" + new Date();
    Ifr_Changer.document.location.replace(BL_TempUrl);
}

function FUN_Changer(BL_GetTime){
var BL_TempTrue = FUN_AddNew(BL_GetTime);
if(BL_TempTrue) setTimeout("Ifr_Changer.document.location.reload()",BL_TimeOut);
}

function FUN_AddNew(BL_GetTime){
	var BL_TheCode = BL_GetTime.split(",");
	var BL_TempId=Math.floor(BL_TheCode[BL_TheCode.length-2]);
	
	if(!BL_ReLoad) BL_ReLoad = BL_TheCode[BL_TheCode.length-1];
	if(BL_ReLoad!=BL_TheCode[BL_TheCode.length-1]){
		document.location.reload();
		return(false);
	}
	
	if(!BL_PicUpId){
		BL_PicUpId = BL_TempId;
		FUN_PlaySound(BL_TheCode[BL_TheCode.length-3],false);//播放提示
		return(true);
	}
	
	if(BL_PicUpId == BL_TempId) return(true);

	if(BL_PicUpId > BL_TempId || (BL_TempId-BL_PicUpId)>1){
		FUN_PlaySound(BL_TheCode[BL_TheCode.length-3],true); //播放提示
		document.location.reload();
		return(false);
	}
	
	for(i=0;i<BL_TheCode.length-3;i++){
		if (BL_TheCode[i].substr(0,1)!="-"){
		BL_TheCode[i]=Math.abs(BL_TheCode[i]);
		TAB_PicTab.cells(BL_TheCode[i]).innerHTML = FUN_IsSplit(TAB_PicTab.cells(BL_TheCode[i]).innerText,BL_TheCode[i],1);
			for(a=0;a<TAB_NewTab.rows.length;a++){
			    if(TAB_NewTab.rows(a).cells(0).innerText.indexOf(TAB_PicTab.cells(BL_TheCode[i]).innerText)!=-1){
		 			TAB_NewTab.deleteRow(a);
	   			 }
			}
		TempTab=TAB_NewTab.insertRow(0);
		TempTab=TempTab.insertCell(0);
		TempTab.innerHTML=TAB_PicTab.cells(BL_TheCode[i]).innerHTML;
		if(TAB_NewTab.cells.length > BL_RowLen-1) TAB_NewTab.deleteRow();
		}else{
		BL_TheCode[i]=Math.abs(BL_TheCode[i]);
			for(a=0;a<TAB_NewTab.rows.length;a++){
	   			if(TAB_NewTab.rows(a).cells(0).innerText.indexOf(TAB_PicTab.cells(BL_TheCode[i]).innerText)!=-1){
		 		TAB_NewTab.deleteRow(a);
		 		TempTab=TAB_NewTab.insertRow();
		 		TempTab=TempTab.insertCell();
	    		}
	  		}
		TAB_PicTab.cells(BL_TheCode[i]).innerHTML=TAB_PicTab.cells(BL_TheCode[i]).innerText;		
		}
	}
	
	FUN_PlaySound(BL_TheCode[BL_TheCode.length-3],true); //播放提示
	
	BL_PicUpId = BL_TempId;
	return(true);
}

function FUN_PlaySound(BL_LastTime,BL_True){
	if(sound.checked && BL_True) {
	TD_LastTime.innerHTML="最后更新："+BL_LastTime+"<embed width=0 height=0 src='XML/NEW.swf'>";
	}else{
	TD_LastTime.innerHTML="最后更新："+BL_LastTime;
	}	
}

function FUN_Page(BL_P){
try{
var BL_TempTr;
	BL_P = Math.floor(BL_P);
	BL_NowPage=BL_P;
	writeCookie("NowPage", BL_P);
	if(BL_P==0){
		for(i=0;i<TAB_PicTab.rows.length;i++) TAB_PicTab.rows(i).style.display="";
	}else{
		for(i=0;i<TAB_PicTab.rows.length;i++) TAB_PicTab.rows(i).style.display="none";
		for(i=0;i<BL_RowLen;i++){
			BL_TempTr = (BL_P-1)*BL_RowLen+i;
			if(BL_TempTr<TAB_PicTab.rows.length) TAB_PicTab.rows(BL_TempTr).style.display="";
		}
	}
	for(i=0;i<TR_Page.cells.length;i++) TR_Page.cells(i).style.backgroundColor='';
	TR_Page.cells(BL_P).style.backgroundColor='#CCFFFF';
}catch(e){
	FUN_Page(0);
}
}

function FUN_IsSplit(BL_Str,BL_y,BL_x){
var BL_Split,BL_Target;
BL_Split=BL_Str.split("　");
	if(BL_Split.length>=2){
		if(BL_PicTime[BL_y] || BL_x==1){
			if (BL_File.toLowerCase().indexOf("tif")>=0){
				BL_Target = "_self";
			}else{
				BL_Target = "_blank";
			}
		  //BL_Split[1]=("<a href=\"download.asp?index=" + BL_Split[0] + "&cnname=" + escape(BL_Split[1]) + "&type=" + BL_File + "&path=" + BL_Path + "\" target=\""+BL_Target+"\" onmouseover=\"MouseOver(this)\">"+BL_Split[1]+"</a>");
		//BL_Split[1]="<a href=\"javascript:FUN_DownLoad(\'"+BL_Split[0]+"\',\'"+BL_Split[1]+"\')\">"+BL_Split[1]+"</a>"
		BL_Split[1]="<a href=\""+BL_Path+BL_Split[0]+BL_File+"\" onmouseover=\"MouseOver(this,'"+BL_Split[0]+"')\">"+BL_Split[1]+"</a>"
		//v3.0的代码，v3.2后不再使用2008-1-1
		} //end if
	return(BL_Split.join("　"));
	} //end if
return(BL_Split);
} //end function

function FUN_GetUrl(urlstr,instr){
var UrlValue = '';
var search = instr + '=';
var BLUrl=unescape(urlstr).toLowerCase();
var BLStrNum=BLUrl.split('?');
	if (BLStrNum.length==2){
	BLUrl=BLStrNum[1];	
		  if(BLUrl.length > 0)
  { 
    offset = BLUrl.indexOf(search);
      if (offset != -1)
    { 
      offset += search.length;
      end = BLUrl.indexOf('&', offset);
      if (end == -1) end = BLUrl.length;
      UrlValue = BLUrl.substring(offset, end);
    }
  }
	}
return(UrlValue);
}//end function

function FUN_Err(){
err.style.display="";
err.style.top=document.body.scrollTop;
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)  {
    expire = new Date((new Date()).getTime() + hours * 3600000 * 24);
    expire = "; expires=" + expire.toGMTString(); 
	}
  document.cookie = name + "=" + escape(value) + expire;
}

function MouseOver(BL_This,BL_Code)
{
	if (!MouseOver[BL_Code])	MouseOver[BL_Code] = BL_This.href;
		//alert(BL_This.href);
	if (!download.checked){
			BL_This.href = MouseOver[BL_Code];
		}else{
			BL_This.href = "http://"+ document.location.hostname + ":16880/download.asp?index=" + BL_Code + "&cnname=" + escape(BL_This.innerText) + "&type=" + BL_File + "&path=" + BL_Path + "&download=true";
			
		}
	if (BL_File.toLowerCase().indexOf("tif")>=0){		
		BL_This.target = "_self";
	}else{
		BL_This.target = "_blank";
	}
}

function Form_Validator(){ //搜索
var BL_SearchWin,i;
var BL_SearchStr="";
var BL_SearchWord = search.value;
	if(BL_SearchWord){
		for(i=0;i<BL_Leng;i++){
		if(TAB_PicTab.cells(i).innerText.indexOf(BL_SearchWord)!=-1){
			BL_SearchStr+=TAB_PicTab.cells(i).innerHTML+"<br>";
		}
		}
	 if(BL_SearchStr){
	 BL_SearchStr="<base target='_blank'>搜索结果：<p>" + BL_SearchStr;
	 }else{
	 BL_SearchStr="没有找到!"
	 }
	 BL_SearchWin = window.open();
	 BL_SearchWin.document.write(BL_SearchStr);
	 BL_SearchWin.document.write("<script>MouseOver(BL_This){}<\/script>");
	}
}