//Returns the value from the slider and loads it into the label
function clientValueChange(sender, eventArgs) {
    var sliderValueLabel = findObjWithClientId("sliderValueLabel")
    sliderValueLabel.innerHTML = sender.get_value();
}

// Used to swap the section of the tabs on the main page
function swapSection( intSection ){	
	var arrSections = new Array();
	
	arrSections[0] = "agriculture";
	arrSections[1] = "pestcontrol";
	arrSections[2] = "amenity";
	
	for( i=0; i<arrSections.length;i++ ){
		// reset the section layer order
		var objThisSection = document.getElementById( 'section' + arrSections[i] );
		if( i != intSection ){
			objThisSection.style.display = 'none';
		} else {
			objThisSection.style.display = 'block';
		}
		
		
		// reset the tab state
		var objThisTab = document.getElementById( 'tab' + arrSections[i] );
		if( i != intSection ){
			objThisTab.className = '';
		} else {
			objThisTab.className = 'over';
		}
	}
	
	return true;
}


// Used to swap the forms on the organiser login page
function swapLogin( intSection ){	
	var arrSections = new Array();
	
	arrSections[0] = "login";
	arrSections[1] = "register";
	arrSections[2] = "forgot";
	
	for( i=0; i<arrSections.length;i++ ){
		// reset the section layer order
		var objThisSection = document.getElementById( 'section' + arrSections[i] );
		if( i != intSection ){
			objThisSection.style.display = 'none';
		} else {
			objThisSection.style.display = 'block';
		}
		
		
		// reset the tab state
		var objThisTab = document.getElementById( 'tab' + arrSections[i] );
		if( i != intSection ){
			objThisTab.className = '';
		} else {
			objThisTab.className = 'over';
		}
	}
	
	return true;
}


// Used for single selection of cpd instances in dynamic table within the organisers area
function singleSelectCpdInstance( intId ){  
    var checkboxName = 'selectCheckBoxCeid' + intId;       
    for(i=0; i<document.forms[0].elements.length; i++) {        
        var objThisElement = document.forms[0].elements[i];                
        if(objThisElement.type=="checkbox") {
            var elementName = objThisElement.name;                    
            if (elementName.indexOf(checkboxName) == -1) {
                objThisElement.checked=false;
            } 
        }
    }
}


// Go to anchor function
function goToAnchor(pageName, anchorName) {
    location.href = pageName + "#" + anchorName;
}

// Finds a server control on the client side by id
function findObjWithClientId(Id) {
    var ctrls = document.getElementsByTagName("body")[0].getElementsByTagName("*");
    for (var count = 0; count < ctrls.length; count++) {
        var index = ctrls[count].id.indexOf(Id);
        if (index != -1) {
            if ((ctrls[count].id.length - index) == Id.length) {
                return ctrls[count];
            }
        }
    }
    return null;
}

// Checks for enter key and forces a postback to occur with the target event argument to be the same as the actionName parameter
function performPostbackOnEnter(e, actionName) {
    var characterCode;

    if (e && e.which) {
        e = e;
        characterCode = e.which;
    }
    else {
        e = event;
        characterCode = e.keyCode;
    }

    if (characterCode == 13) {
        __doPostBack('__Page', actionName);
        return false;
    }
    else {
        return true;
    }
}


// Submit Postback routine
// (causes a postback for page load to pick up)
function submitPostback(actionName) {
    __doPostBack('__Page', actionName);
}


// Online Assessment Finish Routine
function onlineAssessmentFinish() {
    var answerOneRadio = findObjWithClientId('uiAnswerOneRadioButton');
    var answerTwoRadio = findObjWithClientId('uiAnswerTwoRadioButton');
    var answerThreeRadio = findObjWithClientId('uiAnswerThreeRadioButton');
    var answerFourRadio = findObjWithClientId('uiAnswerFourRadioButton');

    var answered = false;
    if (answerOneRadio.checked == true) {
        answered = true;
    }
    if (answerTwoRadio.checked == true) {
        answered = true;
    }
    if (answerThreeRadio.checked == true) {
        answered = true;
    }
    if (answerFourRadio.checked == true) {
        answered = true;
    }
    if (answered == false) {
        alert('Please select an answer to the question!');
        return false;
    }
    return confirm('Are you sure that you have finished the assessment?\n\nClick OK to finish the assessment.');
}