﻿//--活页代码--
	function getNames(obj,name,tij)
	{	
		var p = document.getElementById(obj);
		var plist = p.getElementsByTagName(tij);
		var rlist = new Array();
		for(i=0;i<plist.length;i++)
		{
			if(plist[i].getAttribute("name") == name)
			{
				rlist[rlist.length] = plist[i];
			}
		}
		return rlist;
	}

		function huoye(obj,name)
		{
			var p = obj.parentNode.getElementsByTagName("td");
			var p1 = getNames(name,"f","table");
			for(i=0;i<p1.length;i++)
			{
				if(obj==p[i])
				{
					p[i].className = "s";
					p1[i].className = "show";
				}
				else
				{
					p[i].className = "";
					p1[i].className = "unshow";
				}
			}
		}
		function huoyea(obj,name)
		{
			var p = obj.parentNode.getElementsByTagName("td");
			var p1 = getNames(name,"fa","div");
			for(i=0;i<p1.length;i++)
			{
				if(obj==p[i])
				{
					p[i].className = "sa";
					p1[i].className = "show";
				}
				else
				{
					p[i].className = "";
					p1[i].className = "unshow";
				}
			}
		}
		function huoyeb(obj,name)
		{
			var p = obj.parentNode.getElementsByTagName("td");
			var p1 = getNames(name,"fb","div");
			for(i=0;i<p1.length;i++)
			{
				if(obj==p[i])
				{
					p[i].className = "sb";
					p1[i].className = "show";
				}
				else
				{
					p[i].className = "";
					p1[i].className = "unshow";
				}
			}
		}
//--活页代码结束-->

/*menu start*/
var number=11;
var number2=10;
function LMYC() {
var lbmc;
for (i=1;i<=number;i++) {
lbmc = eval('LM' + i);
lbmc.style.display = 'none';
}
}
function LMYC2() {
var lbmc;
for (i=1;i<=number2;i++) {
lbmc = eval('P' + i);
lbmc.style.display = 'none';
}
}
function ShowFLT(i) {
lbmc = eval('LM' + i);
if (lbmc.style.display == 'none') {
LMYC();
lbmc.style.display = '';
}
else {
lbmc.style.display = 'none';
}
}
function ShowFLT_P(i) {
lbmc = eval('P' + i);
if (lbmc.style.display == 'none') {
LMYC2();
lbmc.style.display = '';
}
else {
lbmc.style.display = 'none';
}
}
/*menu end*/


function goNavTab(cat){
    var list;
    list = document.getElementsByTagName("li");
    for(var i=0; i<list.length; i++){
        if(list[i].id.indexOf("navItem_") == 0){
            if(list[i].id == "navItem_" + cat)
                list[i].className = "hot";
            else
                list[i].className = "";
        }
    }
    
    list = document.getElementsByTagName("ul");
    for(var i=0; i<list.length; i++){
        if(list[i].id.indexOf("navSubItem_") == 0){
            if(list[i].id == "navSubItem_" + cat)
                list[i].className = "";
            else
                list[i].className = "displayNone";
        }
    }
}

String.prototype.trim = function()
{
	return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}

String.prototype.len = function()
{
    return this.replace(/[^\x00-\xff]/g,"**").length;
}

function choice(v) {
	if(v > 0) location.href = "index2.php?cate_id=" + v;
}

/*
 * 产品对比
 */
function compare() {
	var chk_sum = 0;
	var str = '';
	for (var i=0;i<document.getElementsByName('pro_chk[]').length;i++) {
		var e = document.getElementsByName('pro_chk[]')[i];
		if (e.checked == true) {
			str += (str ? ',' : '') + e.value;
			chk_sum += 1;
		}
	}
	if(chk_sum == 0) {
		alert("请至少选择两个对比产品！");
	} else {
		location.href = "compare.php?pro_id=" + str;
	}
}

/*
 * 提交搜索
 */
function gosearch(choice) {
	switch(choice) {
		case 1:
			location.href = 'http://product.5351.net/search.php?keyword=' + escape(s1.value);
			break;
		case 2:
			location.href = 'http://product.5351.net/advice/';
			break;
		case 3:
			break;
		case 4:
			break;
	}
}

function newReq() {
	var req = false;
	try {
		req = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				req = false;
			}
		}
	}
	return req;
}

/*满意度调查*/
function sitevote() {
	var r = document.vote.radio_vote;
	var radio_choice = 0;
	var value_choice;
	var topic_id = document.vote.topic_id.value;
	for(i=0;i<r.length;i++) {
		if(r[i].checked) {
			radio_choice = 1;
			value_choice = r[i].value;
		}
	}
	if(!radio_choice) {
		alert('您还没有选择！')
	} else {
		var xmlHttp = newReq();
		xmlHttp.onreadystatechange = function () {
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					alert(xmlHttp.responseText)
				}
			}
		};
		var qurl = "vote/sitevote.php";
		var post = "topic_id=" + topic_id + "&value=" + value_choice;
		xmlHttp.open("POST", qurl, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(post);
	}
}

/*
 * 产品推荐投票
 */
function provote(id, vote) {
	//alert(parseInt(document.getElementById('vote_yes').innerHTML) + 1)
	var xmlHttp = newReq();
	xmlHttp.onreadystatechange = function () {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				vote_yes_text = document.getElementById('vote_yes');
				vote_no_text = document.getElementById('vote_no');
				yes_img = document.getElementById('vote_yes_img');
				no_img = document.getElementById('vote_no_img');
				if(xmlHttp.responseText == 1) {				
					vote_yes_text.innerHTML = parseInt(vote_yes_text.innerHTML) + 1;
				}
				if(xmlHttp.responseText == 0) {				
					vote_no_text.innerHTML = parseInt(vote_no_text.innerHTML) + 1;
				}
				if(parseInt(vote_yes_text.innerHTML) == parseInt(vote_no_text.innerHTML)) {
					yes_img.width = 70;
					no_img.width = 70;
				}
				if(parseInt(vote_yes_text.innerHTML) > parseInt(vote_no_text.innerHTML)) {
					yes_img.width = 70;
					no_img.width = parseInt(vote_no_text.innerHTML) * 70 / parseInt(vote_yes_text.innerHTML);
				}
				if(parseInt(vote_yes_text.innerHTML) < parseInt(vote_no_text.innerHTML)) {
					no_img.width = 70;
					yes_img.width = parseInt(vote_yes_text.innerHTML) * 70 / parseInt(vote_no_text.innerHTML);
				}
				alert('感谢您的投票！')
			}
		}
	};
	var qurl = "provote.php?id=" + id + "&value=" + vote;
	xmlHttp.open("POST", qurl, true);
	xmlHttp.send(null);
}
