	//添加cookie
//objHours为0时不设定过期时间，浏览器关闭时cookie自动消失
function addCookie(objName,objValue,objHours)
{
    var str = objName + "=" + escape(objValue);
    str += ";domain=service.qq.com";
    if(objHours > 0)
    {
     var date = new Date();
     var ms = objHours*3600*1000;
     date.setTime(date.getTime() + ms);
     str += ";expires=" + date.toGMTString();
    }
    document.cookie = str;
}

 //获取指定名称的cookie的值
function getCookie(objName)
{
    var arrStr = document.cookie.split("; ");
    for(var i = 0;i < arrStr.length;i ++)
    {
     	var temp = arrStr[i].split("=");
     	if(temp[0] == objName) 
     	{
     		return unescape(temp[1]);
    	}
    } 
    return '';
}
 
function choise_check(qid)
{	
	  if (getRadioValue(qid)==2)
	  {
	  	document.getElementById("q1b").style.display='';
	  }
		else
		{
			document.getElementById("q1b").style.display='none';
		}
	  return true;

}

function do_close()
{
	window.opener = null;   
	window.close();
	return;
}

function getRadioValue(qname)
{
	 var rs = document.getElementsByName(qname);  
   for (var i=0; i<rs.length; i++)  
   {  
       if(rs[i].checked)
       {
       	   return rs[i].value; 
       }
   }  
}

function setRadioValue(qname,cvalue)
{
	var rs = document.getElementsByName(qname);
	if (cvalue>rs.length)
	{
		return;
	}
	else
	{
		rs[cvalue-1].checked=true;
	}
}

//是否选择了Radio
function IsSeleRadio(bname)
{
    
    var bn = document.getElementsByName(bname);
    var k = 0;//全部都没有
    var i;
    for(i=0;i<bn.length;i++)
    {
        if(!bn[i].checked)
        {
            k++;
        }
    }
    if(k == bn.length)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function checkInput()
{
    if(!IsSeleRadio("q1"))
    {
        alert("请您完成问题后再提交，谢谢！");
        return false;
    } 

    return true;
}

function do_submit()
{
	if( false == checkInput())
	{
		return false;
	}
	var c1 = getRadioValue("q1");
	var c2 = 0;
	if (c1 == 2)
	{
		c2 = document.getElementById("q1b").value;
	}
	
	if (c2 == 9999)
	{
		alert("请您先选择原因再提交，谢谢！");
		return true;
	}
	
	var faqid = document.getElementById("faqid").value;
	var sid   = document.getElementById("sid").value;
	
	var cgi_url = "http://service.qq.com/cgi-bin/ResearchSubmit?rand=" + Math.random();
	var params = "c1="   + c1  +
	             "&c2="  + c2  +
	             "&sys=3&faqid=" + faqid +
	             "&sid=" + sid;
	             
	var loder = new net.ContentLoader(cgi_url,research_submit_cb,params);
	
	// 写cookie
	/*
	var submitedlist = getCookie("research_submited");
	submitedlist += ">||<";
	submitedlist += faqid;
	addCookie("research_submited", submitedlist, 1);
	init_page();
	*/

	document.getElementById("show_question").style.display='none';
	var show_done2 = document.getElementById("show_done2");
	if(c1 == 2 && show_done2 != null)
		show_done2.style.display='';
	else
		document.getElementById("show_done").style.display='';
	return true;
}

function research_submit_cb()
{
	if ( this.req.readyState == 4)
	{
		
				if ( this.req.status == 200)
				{
					var isFirefox=(navigator.userAgent.indexOf("Firefox")>0);
					if (isFirefox)  // firefox
					{
						var rText = this.req.responseText;
						var xml_doc = new DOMParser().parseFromString(rText ,   "text/xml"); 
	  				var xml_msg = xml_doc.getElementsByTagName("MSG_ENTRY")[0];
			
						if ( xml_msg != null)
						{
							var sActionCode = xml_msg.childNodes[1].firstChild == null?0:  xml_msg.childNodes[1].firstChild.nodeValue;
							var sErrCode    = xml_msg.childNodes[2].firstChild == null?0:  xml_msg.childNodes[2].firstChild.nodeValue;
							var sMsg        = xml_msg.childNodes[3].firstChild == null?"": xml_msg.childNodes[3].firstChild.nodeValue;	
							var sToURL      = xml_msg.childNodes[4].firstChild == null?"": xml_msg.childNodes[4].firstChild.nodeValue;	
						
							if ( sActionCode == 0 )
							{
								parent.window.location.href = sToURL;
							}
							if ( sActionCode == 1 && sToURL.length > 0 )   // 弹出式登录
							{
								openLogin(sToURL);
							}
							if ( sActionCode == 2 && sToURL.length > 0 )   // 跳转
							{
								parent.window.location.replace(sToURL);
							}
							if ( sActionCode == 3 )
							{
								return true;
				      }
							
						}
					}
					else  // ie
					{
						 var xml_doc  = this.req.responseXML.documentElement;
						 var xml_msg = xml_doc.getElementsByTagName("MSG_ENTRY")[0];
						 
						 if ( xml_msg != null)
						 {
							 var sActionCode = xml_msg.childNodes[0].firstChild == null?0:  xml_msg.childNodes[0].firstChild.nodeValue;
							 var sErrCode    = xml_msg.childNodes[1].firstChild == null?0:  xml_msg.childNodes[1].firstChild.nodeValue;
							 var sMsg        = xml_msg.childNodes[2].firstChild == null?"": xml_msg.childNodes[2].firstChild.nodeValue;	
							 var sToURL      = xml_msg.childNodes[3].firstChild == null?"": xml_msg.childNodes[3].firstChild.nodeValue;	
							
							 if ( sActionCode == 0 )
							 {
								 parent.window.location.href = sToURL;
							 }
							 if ( sActionCode == 1 && sToURL.length > 0 )   // 弹出式登录
							 {
								 openLogin(sToURL);
							 }
							 if ( sActionCode == 2 && sToURL.length > 0 )   // 跳转
							 {
								 parent.window.location.replace(sToURL);
							 }
							 if ( sActionCode == 3 )
							 {
					  		 return true;
				       }
						 }
					 }
				}
				else
				{
					alert("系统忙,请您稍候再试!");
				}
	}

}

function checkNum(KeyCode)
{
    //如果输入的字符是在0-9之间，或者是backspace、DEL键 
    if(((KeyCode > 47)&&(KeyCode < 58))||(KeyCode==8)||(KeyCode==46)||
       (KeyCode==37)||(KeyCode==39)||((KeyCode > 95)&&(KeyCode < 106))||(KeyCode==9))
    {
          return true;
    }
    else
    {
          return false;
     }
}

function init_page()
{
	var submitedlist = getCookie("research_submited");
	
	if (submitedlist == '')
	{
		return true;
	}
	
	var paras    = submitedlist.split(">||<");
		
	for(i = 0; i < paras.length; ++i)
	{
		if (paras[i] == document.getElementById("faqid").value)
		{
			// 显示或隐藏问卷
			document.getElementById("show_question").style.display='none';
			return true;
		}
		else
		{
			document.getElementById("show_question").style.display='';
		}
	}
}
