﻿function SetFormValue( pElem, pValue )
{
	var obj = document.getElementById( pElem );
	
	if ( obj != null )
	{
		obj.value = pValue;
	}
}

function SetFormValue2( pElem, pValue )
{
	var obj = document.getElementById( pElem );
	
	if ( obj != null )
	{
	    for ( var i = 0; i < obj.length; ++i )
	    {
	        alert( obj.options[i].value + " | " + pValue );
	        if ( obj.options[i].value == pValue )
	        {
                obj.selectedIndex = i;
                break;
	        }
	    }
	}
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'body_text';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,null);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
	{
	    this.value = this.value.substring( 0, maxLength );
	    currentLength = this.value.length;
	}
	this.relatedElement.firstChild.nodeValue = currentLength;
}

