var $=function(id){return document.getElementById(id);}
//大分类隐藏效果
function ft_class(i,k){
$("class_"+i).style.display=k>0?'none':'';
}
//AJAX连接池 ---------太阳光----------------
function getData(dataSource,id){
	var request = false;
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var MSXML = ['MSXML2.XMLHTTP','Microsoft.XMLHTTP','MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0'];
		for(var n=0; n<MSXML.length; n++){
			try{
				request = new ActiveXObject(MSXML[n]);
				break;
			}catch(e){}
		}
	}
	if(request) {
		request.open("GET", dataSource,true);
		request.onreadystatechange = function()
		{
		if (request.readyState == 4 && request.status == 200) {
			$(id).style.display="";
			$(id).innerHTML = request.responseText;
			delete request;
			request = null;
		}
	}
	request.send(null);
	}
}
//支持多种浏览器的方式创建 XMLHttpRequest 对象
var request;
function createRequest() {
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
	try {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (failed) {
		request = false;
	}
	}
	}
	if (!request)
		alert("Error initializing XMLHttpRequest!");
}
//-------投票过程----
function ft_tp(id){
	if (id==2){
	var str="";
	var Item = document.getElementsByName("item_id");
	for(var i=0;i<Item.length;i++){ 
		if(Item[i].checked) 
		str=Item[i].value;
	}
	if (str==""){
		alert("请先选择投票!");
	}else{
		createRequest();
		request.open("GET","ajax.asp?action=ft_tp&id=2&str="+str+"&"+Math.random(),true);
		request.onreadystatechange = function(){
		if (request.readyState == 4 && request.status == 200) {
			alert(request.responseText);
			getData("ajax.asp?action=ft_tp&id=0&"+Math.random(),"ft_tp");
			}
		}
		request.send(null);
		}
	}else{
		getData("ajax.asp?action=ft_tp&id="+id+"&"+Math.random(),"ft_tp");
	}
}
//---显示评论提交表----
function pl_list(str){
	getData("ajax.asp?action=Nremark&str="+str+"&"+Math.random(),"pl_list");
}
//---显示评论提交表----
function RemarkTable(id,str){
	getData("ajax.asp?action=RemarkTable&id="+id+"&filename="+str+"&"+Math.random(),"pl_table");
}
//----保存评论----
function Remark(){
	var id=$("pl_id").value;
	var FileName=$("FileName").value;
	var Remarker=$("Remarker").value;
	var remark=$("remark").value;
	var xCode=$("xCode").value;
	if (Remarker==""){alert("请填写您的大名！");return false;}
	if (remark==""||remark=="切忌不要胡乱提交评论，否则后果自负！"||remark.length<5)
	{
		alert("请填写5-150字内的评论内容！");
	}else{
		createRequest();
	request.open("GET","ajax.asp?action=Remark&id="+id+"&FileName="+FileName+"&Remarker="+Remarker+"&remark="+remark+"&xCode="+xCode+"&"+Math.random(),true);
		request.onreadystatechange = function(){
		if (request.readyState == 4 && request.status == 200) {
			if (request.responseText=="ok"){
				//评论成功
				alert("您已经成功提交评论信息，感谢您的评论!");
				RemarkList(id,FileName,1);
				//清除评论内容
				$("Remark").value="";
				$("xCode").value="";
				$("Remarker").value="";
				colse("pl_table");
			}else{
				alert(request.responseText);
				if(request.responseText=="验证码错误"){$("pl_code").src="inc/Ft_Getcode.asp?"+Math.random();}
				return false;
			}
		}
	}
    request.send(null);
   }
}
//-----评论列表-----
function RemarkList(id,str,p){
	createRequest();
	request.open("GET","ajax.asp?action=RemarkList&id="+id+"&page="+p+"&FileName="+str+"&"+Math.random(),true);
	request.onreadystatechange = function(){
	if (request.readyState == 4 && request.status == 200) {
		document.getElementById("RemarkList").innerHTML = request.responseText;
	}
	}
	request.send(null);
}
//--------------软件报错------
function soft_err(id){
	createRequest();
	request.open("GET","ajax.asp?action=soft_err&id="+id+"&"+Math.random(),true);
	request.onreadystatechange = function(){
	if (request.readyState == 4 && request.status == 200) {
		alert(request.responseText);
	}
	}
	request.send(null);
}
//-----------------登陆界面------
function userlogin(str){
	getData("ajax.asp?action=userlogin&id="+str+"&"+Math.random(),"ft_user");
}
//----------------提交登陆------
function login(str){
	var ft_username=$("ft_username").value;
	var ft_password=$("ft_password").value;
	var ft_Code=$("ft_Code").value;
	if (ft_username==""||ft_password==""){
		alert("请填写完整！");
	}else{
		createRequest();
	request.open("GET","ajax.asp?action=login&ft_username="+ft_username+"&"+"ft_password="+ft_password+"&ft_Code="+ft_Code+"&"+Math.random(),true);
		request.onreadystatechange = function(){
			if (request.readyState == 4 && request.status == 200) {
				if (request.responseText=="ok"){
					userlogin(str);
				}else{
					alert(request.responseText);
					if(request.responseText=="验证码错误！"){$("img_code").src="inc/Ft_Getcode.asp?"+Math.random();}
						return false;
					}
				}
			}
			request.send(null);
	}
}
//----------------退出登陆------
function loginout(str){
	createRequest();
	request.open("GET","ajax.asp?action=loginout&"+Math.random(),true);
	request.onreadystatechange = function(){
		if (request.readyState == 4 && request.status == 200) {
			if (request.responseText=="ok"){
				userlogin(str);
			}else{
				alert("退出失败,未知错误!");
				return false;
			}
		}
	}
    request.send(null);
}
//----关闭id-----
function colse(id){
	$(id).style.display="none";
}
//flash
function CreateFlash(bgcolor, swfurl, wad, had, vs){
	var str = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + wad + "\" height=\"" + had + "\" id=\"player\" align=\"middle\">";
	str += "<param name=\"allowScriptAccess\" value=\"always\">";
	str += "<param name=\"wmode\" value=\"Opaque\">";
	str += "<param name=\"quality\" value=\"high\">";
	str += "<param name=\"movie\" value=\"" + swfurl + "\">";
	str += "<param name=\"flashvars\" value=\"" + vs + "\">";
	str += "<embed src=\"" + swfurl + "\" flashvars=\"" + vs + "\" wmode=\"transparent\" quality=\"high\" width=\"" + wad + "\" height=\"" + had + "\" name=\"player\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";
	str += "</object>";
	document.write(str);
}
// 页面字体放大
function doZoom(size){
	document.getElementById('zoom').style.fontSize=size+'px'
}
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
var n   = 0;
function findIt() {
	if (searchstr.value != "")
	findInPage(searchstr.value);
}
// 图片缩放脚本
var flag=true; 
function DrawImage(ImgD){ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
        flag=true; 
      if(image.width>=700){ 
        ImgD.width=700; 
        ImgD.height=(image.height*700)/image.width; 

        }else{ 
            ImgD.width=image.width; 
            ImgD.height=image.height; 
        }  
    } 
} 
//内容里的图片缩放效果-------------将删除
function ContentImage(ImgD){ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
        flag=true; 
    if(image.width>=500){ 
         ImgD.width=500; 
        ImgD.height=(image.height*500)/image.width; 

        }else{ 
            ImgD.width=image.width; 
            ImgD.height=image.height; 
        }  
    } 
} 
//function cgimg(o){
//	var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
//	return false;
//}
//图片模糊，鼠标移上去变清晰效果
function  toup2(theobject){
	logo=1
	gogo(theobject)
}
function  todown2(theobject){
	logo=0
	down(theobject)
}
function gogo(image){
	theobject=image
	if  (logo==1&&theobject.filters.alpha.opacity<100){
	theobject.filters.alpha.opacity+=20;
	var upalpha=setTimeout("gogo(theobject)",300)
	}
}
function down(theobject){
	if (logo==0&&theobject.filters.alpha.opacity>80){
	theobject.filters.alpha.opacity-=20;
	var downalpha=setTimeout("down(theobject)",300)
	}
}
//多行文本框字数统计
function gbcount(message,total,used,remain){
	var max;
	max = total.value;//总字数
	//if (used.value>4){$("pl_ok").style.disabled="false";}
	if (message.value.length > max) {
		message.value = message.value.substring(0,max);
		used.value = max;
		remain.value = 0;
		alert("字符不能超过" +max+ "个字!");
		}
	else {
		used.value = message.value.length;
		remain.value = max - used.value;
		}
	if(used.value>4){
		$("pl_ok").disabled="";
	}else{
		$("pl_ok").disabled="true";
	}
}
//时间
function ft_time(){
var Ntime=new Date();
var week=new Array("日","一","二","三","四","五","六")
$("Ntime").innerHTML="今天是"+Ntime.getYear()+"年"+(Ntime.getMonth()+1)+"月"+Ntime.getDate()+"日 星期"+week[Ntime.getDay()]
}
//链接颜色

////////////////////////////////////////////////////////////////////
// Setting

var rate = 20;  // Increase amount(The degree of the transmutation)


////////////////////////////////////////////////////////////////////
// Main routine

if (document.getElementById)
window.onerror=new Function("return true")

var objActive;  // The object which event occured in
var act = 0;    // Flag during the action
var elmH = 0;   // Hue
var elmS = 128; // Saturation
var elmV = 255; // Value
var clrOrg;     // A color before the change
var TimerID;    // Timer ID


if (document.all) {
    document.onmouseover = doRainbowAnchor;
    document.onmouseout = stopRainbowAnchor;
}
else if (document.getElementById) {
    document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
    document.onmouseover = Mozilla_doRainbowAnchor;
    document.onmouseout = Mozilla_stopRainbowAnchor;
}


//=============================================================================
// doRainbow
//  This function begins to change a color.
//=============================================================================
function doRainbow(obj)
{
    if (act == 0) {
        act = 1;
        if (obj)
            objActive = obj;
        else
            objActive = event.srcElement;
        clrOrg = objActive.style.color;
        TimerID = setInterval("ChangeColor()",100);
    }
}


//=============================================================================
// stopRainbow
//  This function stops to change a color.
//=============================================================================
function stopRainbow()
{
    if (act) {
        objActive.style.color = clrOrg;
        clearInterval(TimerID);
        act = 0;
    }
}


//=============================================================================
// doRainbowAnchor
//  This function begins to change a color. (of a anchor, automatically)
//=============================================================================
function doRainbowAnchor()
{
    if (act == 0) {
        var obj = event.srcElement;
        while (obj.tagName != 'A' && obj.tagName != 'BODY') {
            obj = obj.parentElement;
            if (obj.tagName == 'A' || obj.tagName == 'BODY')
                break;
        }

        if (obj.tagName == 'A' && obj.href != '') {
            objActive = obj;
            act = 1;
            clrOrg = objActive.style.color;
            TimerID = setInterval("ChangeColor()",100);
        }
    }
}


//=============================================================================
// stopRainbowAnchor
//  This function stops to change a color. (of a anchor, automatically)
//=============================================================================
function stopRainbowAnchor()
{
    if (act) {
        if (objActive.tagName == 'A') {
            objActive.style.color = clrOrg;
            clearInterval(TimerID);
            act = 0;
        }
    }
}


//=============================================================================
// Mozilla_doRainbowAnchor(for Netscape6 and Mozilla browser)
//  This function begins to change a color. (of a anchor, automatically)
//=============================================================================
function Mozilla_doRainbowAnchor(e)
{
    if (act == 0) {
        obj = e.target;
        while (obj.nodeName != 'A' && obj.nodeName != 'BODY') {
            obj = obj.parentNode;
            if (obj.nodeName == 'A' || obj.nodeName == 'BODY')
                break;
        }

        if (obj.nodeName == 'A' && obj.href != '') {
            objActive = obj;
            act = 1;
            clrOrg = obj.style.color;
            TimerID = setInterval("ChangeColor()",100);
        }
    }
}


//=============================================================================
// Mozilla_stopRainbowAnchor(for Netscape6 and Mozilla browser)
//  This function stops to change a color. (of a anchor, automatically)
//=============================================================================
function Mozilla_stopRainbowAnchor(e)
{
    if (act) {
        if (objActive.nodeName == 'A') {
            objActive.style.color = clrOrg;
            clearInterval(TimerID);
            act = 0;
        }
    }
}


//=============================================================================
// Change Color
//  This function changes a color actually.
//=============================================================================
function ChangeColor()
{
    objActive.style.color = makeColor();
}


//=============================================================================
// makeColor
//  This function makes rainbow colors.
//=============================================================================
function makeColor()
{
    // Don't you think Color Gamut to look like Rainbow?

    // HSVtoRGB
    if (elmS == 0) {
        elmR = elmV;    elmG = elmV;    elmB = elmV;
    }
    else {
        t1 = elmV;
        t2 = (255 - elmS) * elmV / 255;
        t3 = elmH % 60;
        t3 = (t1 - t2) * t3 / 60;

        if (elmH < 60) {
            elmR = t1;  elmB = t2;  elmG = t2 + t3;
        }
        else if (elmH < 120) {
            elmG = t1;  elmB = t2;  elmR = t1 - t3;
        }
        else if (elmH < 180) {
            elmG = t1;  elmR = t2;  elmB = t2 + t3;
        }
        else if (elmH < 240) {
            elmB = t1;  elmR = t2;  elmG = t1 - t3;
        }
        else if (elmH < 300) {
            elmB = t1;  elmG = t2;  elmR = t2 + t3;
        }
        else if (elmH < 360) {
            elmR = t1;  elmG = t2;  elmB = t1 - t3;
        }
        else {
            elmR = 0;   elmG = 0;   elmB = 0;
        }
    }

    elmR = Math.floor(elmR).toString(16);
    elmG = Math.floor(elmG).toString(16);
    elmB = Math.floor(elmB).toString(16);
    if (elmR.length == 1)    elmR = "0" + elmR;
    if (elmG.length == 1)    elmG = "0" + elmG;
    if (elmB.length == 1)    elmB = "0" + elmB;

    elmH = elmH + rate;
    if (elmH >= 360)
        elmH = 0;

    return '#' + elmR + elmG + elmB;
}
