﻿//--活页代码--
	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(url) {
	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 if(chk_sum > 4) {
		alert("最多对4个产品进行比较");
	} else {
		location.href = "compare.php?pro_id=" + str +"&backurl=" + url;
	}
}

function checkcompare(chk) {
	var chk_sum = 0;
	for (var i=0;i<document.getElementsByName('pro_chk[]').length;i++) {
		var e = document.getElementsByName('pro_chk[]')[i];
		if (e.checked == true) {
			chk_sum += 1;
		}
	}
	if(chk_sum > 4) {
		alert('最多选择4个对比产品')
		chk.checked = false;
	}
}

/*
 * 提交搜索
 */
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 vote_a = r[0].checked;
	var vote_b = r[1].checked;
	if(!vote_a && !vote_b) {
		alert('您还没有选择满意度！')
	} else {
		if(vote_a) v = r[0].value;
		if(vote_b) v = r[1].value;
		var xmlHttp = newReq();
		xmlHttp.onreadystatechange = function () {
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					alert(xmlHttp.responseText)
				}
			}
		};
	    var qurl = "user/sitevote.php?value=" + v;
	    xmlHttp.open("POST", qurl, true);
	    xmlHttp.send(null);
	}
}

/*
 * 产品推荐投票
 */
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);
}

function setIframeHeight(id){
	var ifr=document.getElementById(id);
	if (document.getElementById){
		if (ifr && !window.opera){
			if (ifr.contentDocument && ifr.contentDocument.body.offsetHeight){
				ifr.height = ifr.contentDocument.body.offsetHeight;
			}else if(ifr.Document && ifr.Document.body.scrollHeight){
				ifr.height = ifr.Document.body.scrollHeight;
			}
		}
	}
}

function comment_post() {
	var comment_content = document.comment.comment_content.value.trim();
	var pro_id = document.comment.pro_id.value;
	if(comment_content.length < 5) {
		alert('评论过短，至少5个字');
		document.comment.comment_content.focus();
	} else {
		var xmlHttp = newReq();
		xmlHttp.onreadystatechange = function () {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				document.getElementById('comment_list').innerHTML = xmlHttp.responseText;
				document.comment.comment_content.value = '';
				sum = document.getElementById('comment_total');
				sum = sum.innerHTML = parseInt(sum.innerHTML) + 1;
				alert('评论已提交。');
			}
		};
		
		var qurl = "commentpost.php";
		var post = "uid=1"+"&pro_id="+pro_id+"&content=" + encodeURIComponent(comment_content);
		xmlHttp.open("POST", qurl, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(post);
	}
}
