function changeFormAction( formId, newAction )
{
	document.getElementById( formId ).action = newAction;
}

function setValue( eId, v )
{
	document.getElementById( eId ).value = v;
}

function sendForm( fId )
{
	document.getElementById( fId ).submit();
}

function limitTextArea(textfield, len) {

	t = $(textfield);
	var cid = "chars_for_"+textfield;
	var temp = new Template('<input type="#{type}" id="#{id}" value="#{value}" class="#{cl}" disabled="disabled" size="#{size}" style="width:25px" />');

	var show = {type: 'text', id: cid, value: len - t.value.length, cl: "chars-for-textarea"  };
	
	
	//alert(c)
	new Insertion.After(textfield, temp.evaluate(show));
	
	Event.observe(textfield, 'blur', function(event){ 
		
	});
	
 	Event.observe(textfield, 'keyup', function(event){ 

			var c = countBreaklines(textfield);
			
			if(t.value.length > len) {

  	 		if(event.keyCode == Event.KEY_BACKSPACE) {
  	 		} 
  	 		else { 
				t.value = t.value.substring(0, len);
  	 			Event.stop(event);

  	 		} 

  	 	} else  $(cid).value = len - t.value.length;
  	 }

  	 );

	 t.value = t.value.substring(0, len);

}

function countBreaklines(field) {

	var f = $(field);
	var count = 0;
	var index = f.value.indexOf('\n');
	while(index != -1) {
		count += 1;
		index = f.value.indexOf('\n',index+1);
    }
    return count;
		
}



function textCounter(field,cntfield,maxlimit) {
  var extra = 0;
  if (navigator.appName=="Netscape" && 
      parseInt(navigator.appVersion)>=5) {
     var index = field.value.indexOf('\n');
     while(index != -1) {
       extra += 1;
       index = field.value.indexOf('\n',index+1);
     }
  }
  if (field.value.length + extra > maxlimit)
    field.value = field.value.substring(0, maxlimit-extra);
  else
    cntfield.value = maxlimit - field.value.length - extra;
}

function searchSelect(inp, select) {
	var input = $(inp).value.toLowerCase();
  	var output = $(select).options;
  	
  	Event.observe(inp, 'keyup', function(e) {
		var val = $F(inp).toLowerCase() 		
 		
 		for(var i=0;i<output.length;i++) {
			
			
	    	if(output[i].text.toLowerCase().indexOf(val) >= 0){
	      		output[i].selected=true;
	      		return;
	    	}
		    if(val==''){
		      output[0].selected=true;
		    }
  		}
	});
  	
  	
}

function showColor(hex){
  $('user_border_color').style.backgroundColor='#'+hex;
  true_hex = hex;
}

