﻿// JScript 文件
var readerID = '1';
var data,inquirydata;
var inquiryId;

var iHeight = 200;
var iWidth = 550;
var bResizable = 0;
var bScrollbars = 0;
var iTop  = (screen.height - iHeight) / 2 ;
var iLeft = (screen.width  - iWidth) / 2 ;

var sOptions = "toolbar=no" ;
sOptions += ",width=" + iWidth ; 
sOptions += ",height=" + iHeight ;
sOptions += ",resizable="  + (bResizable  ? "yes" : "no") ;
sOptions += ",scrollbars=" + (bScrollbars ? "yes" : "no") ;
sOptions += ",left=" + iLeft ;
sOptions += ",top=" + iTop ;


//初始化网上调查
function inquiryInit()
{
    var row=null,cell=null,control=null;
    inquirydata = AjaxClass.GetBrowseInquiry_Pre(readerID);
    if(inquirydata.value)
    {
        if(inquirydata.value.Tables[0].Rows.length > 0)
        {
            inquiryId = inquirydata.value.Tables[0].Rows[0].inquiryId;
            //设置第一行
            row = document.createElement("tr");
            if(document.uniqueID)//IE浏览器
            {
                row.style.cssText = "height:30px;";
            }
            else//其他浏览器
            {
               row.setAttribute("style","height:30px;");
            }  
            cell = document.createElement("td");
            cell.appendChild(document.createTextNode(inquirydata.value.Tables[0].Rows[0].question));
            if(document.uniqueID)//IE浏览器
            {
                cell.setAttribute("colSpan", '2');
            }
            else//其他浏览器
            {
                cell.setAttribute("colspan", '2');
            }            
            cell.setAttribute("align","left");
            row.appendChild(cell); 
            document.getElementById("inquiry").appendChild(row);     
             
            data = AjaxClass.GetInquiryContentByInquiryId_Pre(inquiryId);
            //设置第二行
            if( inquirydata.value.Tables[0].Rows[0].typeId == 1)
            {
                for(var i=0;i<data.value.Tables[0].Rows.length;i++)
                {
                    row = document.createElement("tr");
                    if(document.uniqueID)//IE浏览器
                    {
                        row.style.cssText = "height:20px;";
                    }
                    else//其他浏览器
                    {
                       row.setAttribute("style","height:20px;");
                    }  
                    cell = document.createElement("td");
                    cell.setAttribute("align","right");
                    if(document.uniqueID)//IE浏览器
                    {
                        control = document.createElement("<input id='Radioinquiry" + i + "' type='radio' value='" + data.value.Tables[0].Rows[i].contentId + "' onclick='radioButtonClick(" + i + ")'/>");
                    }
                    else
                    {                
                        control = document.createElement("input");
                        control.setAttribute("type","radio");
                        control.setAttribute("id","Radioinquiry"+i);
                        control.setAttribute("value",data.value.Tables[0].Rows[i].contentId);
                        control.onclick = new Function("radioButtonClick("+i+")");
                    }
                    cell.appendChild(control);
                    row.appendChild(cell);
                    
                    cell = document.createElement("td");
                    cell.setAttribute("align","left");
                    cell.appendChild(document.createTextNode(data.value.Tables[0].Rows[i].content));
                    row.appendChild(cell);
                    document.getElementById("inquiry").appendChild(row);
                }
            }
            else
            {
                for(var i=0;i<data.value.Tables[0].Rows.length;i++)
                {
                    row = document.createElement("tr");
                    if(document.uniqueID)//IE浏览器
                    {
                        row.style.cssText = "height:20px;";
                    }
                    else//其他浏览器
                    {
                       row.setAttribute("style","height:20px;");
                    }  
                    cell = document.createElement("td");
                    cell.setAttribute("align","right");
                    control = document.createElement("input");
                    control.setAttribute("type","checkbox");
                    control.setAttribute("id","Checkbox"+i);
                    control.setAttribute("value",data.value.Tables[0].Rows[i].contentId);
                    control.onclick = new Function("CheckboxClick("+i+")");
                    cell.appendChild(control);
                    row.appendChild(cell);
                    
                    cell = document.createElement("td");
                    cell.setAttribute("align","left");
                    cell.appendChild(document.createTextNode(data.value.Tables[0].Rows[i].content));
                    row.appendChild(cell);
                    document.getElementById("inquiry").appendChild(row);
                }
            }
            //设置第三行
            row = document.createElement("tr");
            if(document.uniqueID)//IE浏览器
            {
                row.style.cssText = "height:50px;";
            }
            else//其他浏览器
            {
                row.setAttribute("style","height:50px;");
            }
            cell = document.createElement("td");
            if(document.uniqueID)//IE浏览器
            {
                cell.setAttribute("colSpan","2");
            }
            else//其他浏览器
            {
                cell.setAttribute("colspan","2");
            }
            cell.setAttribute("align","center");
            control = document.createElement("input");
            control.setAttribute("type","button");
            control .setAttribute("id","Button_Vote");
            control .setAttribute("value","投 票");
            control.onclick = function() { vote(); };
            if(document.uniqueID)//IE浏览器
            {
                control.style.cssText = "width:50px;";
            }
            else//其他浏览器
            {
                control.setAttribute("style","width:50px;");
            }
            cell.appendChild(control);
            cell.appendChild(document.createTextNode("     "));
            control = document.createElement("input");
            control.setAttribute("type","button");
            control .setAttribute("id","Button_Result");
            control .setAttribute("value","查 看");
            control.onclick = function() { result(); };
            if(document.uniqueID)//IE浏览器
            {
                control.style.cssText = "width:50px;";
            }
            else//其他浏览器
            {
                control.setAttribute("style","width:50px;");
            }
            cell.appendChild(control);        
            row.appendChild(cell);
                    
            document.getElementById("inquiry").appendChild(row);

        }
        else
        {
            inquiry.innerHTML = "";    
        }
    }
} 
//单选
function radioButtonClick(index)
{
    var id;
    for(var j=0;j<data.value.Tables[0].Rows.length;j++)
    {
        id = "Radioinquiry";
        id = id + j;
        document.getElementById(id).checked = false;

    }
    id = "Radioinquiry" + index;
    document.getElementById(id).checked = true;

}
//多选
function CheckboxClick(index)
{
//alert(index);
//    var id = "Checkbox" + index;
//    if(document.getElementById(id).checked)
//    {
//        document.getElementById(id).checked = false;
//    }
//    else
//    {
//        document.getElementById(id).checked = true;
//    }
}
//投票
function vote()
{
    var contentId="";
    if(inquirydata.value.Tables[0].Rows[0].typeId == 1)
    {
        var id; 
        for(var j=0;j<data.value.Tables[0].Rows.length;j++)
        {
            id = "Radioinquiry";
            id = id + j;
            if(document.getElementById(id).checked)
            {
                contentId = document.getElementById(id).value;
                break;
            }
        }
    }
    else
    {
        for(var j=0;j<data.value.Tables[0].Rows.length;j++)
        {
            id = "Checkbox";
            id = id + j;
            if(document.getElementById(id).checked)
            {
                contentId = contentId + document.getElementById(id).value + ",";
            }
        }
        if(contentId != "")
        {
            contentId = contentId.substring(0,contentId.length-1);
        }
    }
    if( contentId != "")
    {    	
        var path = window.open("../inquiry/VoteResult.aspx?inquiryId="+inquiryId+"&idList="+contentId,"",sOptions);
    }
    else
    {
        alert('请选择投票项！');
    }
}
//查看投票结果
function result()
{	
    var path = window.open("../inquiry/VoteResult.aspx?inquiryId="+inquiryId,"",sOptions);
}