﻿


function showCharLengthLeft(inputFiled,charCounter,maxTextLength, processmode, errTxt){
	if (processmode == 1){
		if (document.getElementById(inputFiled).value.length > (maxTextLength)){
			document.getElementById(inputFiled).value = document.getElementById(inputFiled).value.substr(0,(maxTextLength));
			alert('- ' + errTxt.replace("%%MAXCHAR%%", maxTextLength));
			document.getElementById(inputFiled).focus();
		}
			document.getElementById(charCounter).value = (maxTextLength - (document.getElementById(inputFiled).value.length));
	}

	if (processmode == 2){		
		document.getElementById(charCounter).value = (maxTextLength - (document.getElementById(inputFiled).value.length));			
	}
}


function hideObject(key, doScrollUp){

    //Hides the button to prevent dubble clicks.
    key.style.visibility = "hidden";

    /*
    When a button submitts the page and the Ajax reload is complete the scroll position is set to the top of the document. 
    The scrollUp function will be removed from the Ajax load event as soon as it has been executed. This is to prevent the function
    to execute when a dynamic question is submitted.
    */
    if (doScrollUp) {
        Sys.Application.add_load(scrollUp); 
    }
}


function scrollUp() {

    //Sets the scroll position to top, left
    window.scroll(0, 0);
    
    //The function is removed from the Ajax load
    Sys.Application.remove_load(scrollUp);

}
