﻿// JScript 文件
ie4=(document.all)?true:false;
ns4=(document.layers)?true:false;

//显示单选题末项开放
function ShowRadioInput(){
	var args=ShowRadioInput.arguments;
	var id=args[1].replace('TextBoxOpen', '');
	if(args[0]==1){
		document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display='';
		ValidatorEnable($('<%=RequiredFieldValidatorOpen150123.ClientID%>'), true);
	}
	else{
		document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display='none';
		//document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidatorOpen150123').dispose();
		//alert('ctl00_ContentPlaceHolder1_RequiredFieldValidatorOpen' + id);
		//alert(document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidatorOpen' + id).ID);
		//document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidatorOpen' + id).style.display='none';
		ValidatorEnable($('<%=RequiredFieldValidatorOpen150123.ClientID%>'), false);
	}
}     

//显示下拉框末项开放
function ShowSelectInput(){
	var args=ShowSelectInput.arguments;
	var intIndex=args[0].options.length;
	if(args[0].selectedIndex == intIndex -1){
		document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display='';
	}
	else{
		document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display='none';
	}
}     

//排序题下拉框互斥
function SelectMutex(){
	var args=SelectMutex.arguments;
	var arraySelectId = args[0].id.split("_");
	var SelectId = arraySelectId[0] + "_" + arraySelectId[1] + "_" + arraySelectId[2].substring(0, arraySelectId[2].lastIndexOf("n"));
	var SelectIndex = "|" + arraySelectId[2].substring(arraySelectId[2].lastIndexOf("n") + 1) + "|";
	var SelectNum = args[1];
	var intSelectedValue = args[0].options[args[0].selectedIndex].value;
	var intMaxValue = args[0].options[args[0].options.length - 1].value;
	for(i = intSelectedValue;i <= intMaxValue;i++)
	{
	    var isExist = false;
	    for(j = 1; j <= SelectNum; j++)
	    {
	        if(SelectIndex.indexOf("|" + j + "|") < 0)
	        {
        		if(document.getElementById(SelectId + "n" + j) != null)
		        {
		            var thisSelect = document.getElementById(SelectId + "n" + j);
		            if(thisSelect.options[thisSelect.selectedIndex].value == i)
	                {
	                    if(thisSelect.selectedIndex + 1 < thisSelect.options.length)
	                    {
	                        thisSelect.options[thisSelect.selectedIndex + 1].selected = true;
	                    }
                        SelectIndex += j + "|";
                        isExist = true;
                        break;
	                }
	            }		    
		    }
		}
		if(!isExist)
		{
		    break;
		}
	}
}     

//显示多选题末项开放题
function ShowCheckBoxInput(){
	var args=ShowCheckBoxInput.arguments;
	var isChecked=args[0].checked
	if(isChecked == true){
		document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display='';
	}
	else{
		document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display='none';
	}
}     

//多选题末项排他 选中末项则去除其他项选中状态
function DisabledList(){
	var args=DisabledList.arguments;
	var CheckBoxNum=args[0].id.split("_");
	var CheckBoxID=CheckBoxNum[0]+"_"+CheckBoxNum[1]+"_"+CheckBoxNum[2];
	var CheckBoxMax=CheckBoxNum[3];
	var isChecked=args[0].checked
	
    if(isChecked == true){
		for(i=0;i<CheckBoxMax;i++){
    		document.getElementById(CheckBoxID+"_"+i).disabled = true;
		}
	}
	else{
		for(i=0;i<CheckBoxMax;i++){
    		document.getElementById(CheckBoxID+"_"+i).disabled = false;
		}
	}
}

//限制多选题最多选择项数
function LimitCheckBoxList(){
	var args=LimitCheckBoxList.arguments;
	var CheckBoxNum=args[0].id.split("_");
	var CheckBoxID=CheckBoxNum[0]+"_"+CheckBoxNum[1]+"_"+CheckBoxNum[2];
	var CheckBoxLength = args[1];
	var CheckBoxLimit=args[2];
	var isChecked=args[0].checked;
	var CheckedCount = 0;
	
    if(isChecked == true){
		for(i=0;i<CheckBoxLength;i++){
    		if(document.getElementById(CheckBoxID+"_"+i).checked)
    		{
    		    CheckedCount++;
    		}
		}
		if(CheckedCount > CheckBoxLimit)
		{
		    alert(args[3]);
		    args[0].checked = false;
		}
	}
}


//渐进多选预置失效状态
function DisabledStepCheckBoxList(){
	var args=DisabledStepCheckBoxList.arguments;
	var CheckBoxNum=args[0].split("_");
	var CheckBoxID=CheckBoxNum[0]+"_"+CheckBoxNum[1]+"_"+CheckBoxNum[2];
	var CheckBoxLength = args[1];
	for(i=1;i<CheckBoxLength;i++){
		document.getElementById(CheckBoxID+"_"+i).setAttribute("disabled", "disabled");
	}
}

//渐进多选
function StepCheckBoxList(){
	var args=StepCheckBoxList.arguments;
	var CheckBoxNum=args[0].id.split("_");
	var CheckBoxID=CheckBoxNum[0]+"_"+CheckBoxNum[1]+"_"+CheckBoxNum[2];
	var CheckBoxIndex = CheckBoxNum[3];
	var CheckBoxLength = args[1];
	var isChecked=args[0].checked;		
    if(isChecked == true){
        if(CheckBoxIndex < CheckBoxLength-1){
		    document.getElementById(CheckBoxID+"_"+(Number(CheckBoxIndex)+1)).removeAttribute("disabled");
		}
    }
	else
	{
    	for(i=Number(CheckBoxIndex)+1;i<CheckBoxLength;i++){
    		document.getElementById(CheckBoxID+"_"+i).checked = false;
    		document.getElementById(CheckBoxID+"_"+i).disabled = true;
		}
	}
}

//配比题总和等于100%
function Sum100(){
	var args = Sum100.arguments;
	var arrayTextBoxId = args[0].id.split("_");
	var TextBoxId = arrayTextBoxId[0] + "_" + arrayTextBoxId[1] + "_" + arrayTextBoxId[2].substring(0, arrayTextBoxId[2].indexOf("n"));
	var TextBoxNum = args[1];
 	var doubleSum = 0;
 	var isAllFill = true;
	for(i = 1;i <= TextBoxNum;i++)
	{
		if(document.getElementById(TextBoxId + "n" + i) != null)
		{
    		if(document.getElementById(TextBoxId + "n" + i).value != "")
	    	{
		        doubleSum += Number(document.getElementById(TextBoxId + "n" + i).value);
		    }
		    else
		    {
		        if(document.getElementById(TextBoxId + "n" + i).style.display != 'none')
		        {
		            isAllFill = false;
		        }
		    }
		}
	}
	if(doubleSum != 100 && isAllFill)
	{
	    for(i = TextBoxNum;i >= 1;i--)
	    {
    		if(document.getElementById(TextBoxId + "n" + i) != null)
	    	{
		        if(document.getElementById(TextBoxId + 'n' + i).style.display != 'none')
		        {
		            document.getElementById(TextBoxId + 'n' + i).focus();
		            document.getElementById(TextBoxId + 'n' + i).select();
		            break;
		        }
		    }
	    }
	    alert(args[2]);
	    //return false;
	}
}

//多选配比
function CheckBoxListRatioTextBox(){
	var args=CheckBoxListRatioTextBox.arguments;
	var isChecked=args[0].checked;
    if(isChecked == true){
        document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display = '';
    }
	else
	{
    	document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).value = '';
        document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).style.display = 'none';
	    var TextBoxId = 'ctl00_ContentPlaceHolder1_' + args[1].substring(0, args[1].indexOf('n'));
	    var TextBoxNum = args[2];
	    //alert(TextBoxId + ' ' + args[2]);
	    for(i = TextBoxNum;i >= 1;i--)
	    {
		    if(document.getElementById(TextBoxId + 'n' + i).style.display != 'none')
		    {
		        document.getElementById(TextBoxId + 'n' + i).focus();
		        break;
		    }
	    }
	}
}

//保存Rating值
function SaveRating(){
	var args=SaveRating.arguments;
	//alert($find(args[0]).get_Rating());
    document.getElementById('ctl00_ContentPlaceHolder1_' + args[1]).value = $find(args[0]).get_Rating();
}

//展开折叠面板
function ShowPanel(){
	var args=ShowPanel.arguments;
	var objectPanel = document.getElementById(args[0]);
	var objectHandle = document.getElementById(args[1]);
	if(objectPanel.style.display == 'none'){
		objectPanel.style.display='';
		objectHandle.innerHTML = '调查助手<br /><<<';
	}
	else{
		objectPanel.style.display='none';
		objectHandle.innerHTML = '调查助手<br />>>';
	}
}
