String.prototype.trim=function(){
	return this.replace(/^\s*(.*)\s*$/,"$1");
}
String.prototype.leftTrim=function(){
	return this.replace(/^\s*(.*)/,"$1");
}
String.prototype.rightTrim=function(){
	return this.replace(/(.*)\s*$/,"$1");
}
String.prototype.isNumber=function(){
	pattern=/^-?\d+(\.\d*)?$/;
    return pattern.test(this);
}
String.prototype.isInteger=function(){
    pattern=/^-?\d+$/;
    return pattern.test(this);
}
String.prototype.isNotNull=function(){
	return(this!="");
}
String.prototype.isNull=function(){
	return(this=="");
}

/*
returns true if element e is in array a
*/
function inArray(e,a){
	res=false;
	for(i in a){
		if(a[i]==e){
			res=true;
			break;
		}
	}
	return res;
}

/*
returns checked value in the radio group of rad
*/
function getRadioChecked(rad){
	res=null;
	n=rad.name;
	g=document.getElementsByName(n);
	for(i=0;i<g.length;i++){
		if(g[i].checked){
      res=g[i].value;
			break;
		}		
	}
	return res;
}

/*
returns checked values array in the checkbox group of chb
*/
function getCheckboxChecked(chb){
	res=new Array();
	n=chb.name;
	g=document.getElementsByName(n);
	for(i=0;i<g.length;i++){		
		if(g[i].checked){
			res[res.length]=g[i].value;
		}		
	}
	return res;
}

/*
returns check value (for radio) or values array (checkbox) in the group of obj
*/
function getChecked(obj){
	switch(obj.type){
		case "checkbox": 
			res=getCheckboxChecked(obj); 
			break;
		case "radio": 
			res=getRadioChecked(obj);
			break;
		default: 
			res=null; 
			break;
	}
	return res;
}

/*
returns selected value in select-one sel
*/
function getSelectOneSelected(sel){
	res=null;	
	for(i in sel.options){
		if(sel.options[i].selected){
			res=sel.options[i].value;
			break;
		}
	}
	return res;
}

/*
returns selected values array in select-multiple sel
*/
function getSelectMultipleSelected(sel){
	res=new Array();	
	for(i in sel.options){
		if(sel.options[i].selected){
			res[res.length]=sel.options[i].value;
		}
	}
	return res;
}

/*
return selected value, or values array in select sel
*/
function getSelected(sel){
	c=new Array();
	l=sel.options.length;
	for(i=0;i<l;i++){
		if(sel.options[i].selected){
			c[c.length]=sel.options[i].value;
		}
	}
	return c;
}

/*
displays box box when select sel values one of values
hide box otherwise
*/
function selectShowBox(sel,box,values){
	e=document.getElementById(sel);
	s=getSelected(e);
	d=inArray(s[0],values)? "block" : "none";		
	document.getElementById(box).style.display=d;	
}

/*
displays box box when radio rad values one of values
hide box otherwise
*/
function radioShowBox(rad,box,values){
	e=document.getElementById(rad);
	s=getChecked(e);
	d=inArray(s[0],values)? "block" : "none";		
	document.getElementById(box).style.display=d;	
}


function refreshNotation(pid,grade,tab_station)
{
	for(i=0;i<tab_station.length;i++)
	{
		elem = document.getElementById('notation_'+pid+'_'+tab_station[i]);
		if( elem ) elem.value=grade;
	}		
}

function refreshPreStatus(pid,tab_station,sname)
{
	for(i=0;i<tab_station.length;i++)
	{
		elem = document.getElementById('pre_decision_'+pid+'_'+tab_station[i]);
		if( elem ) elem.options[document.getElementById('pre_decision_'+pid+'_'+sname).selectedIndex].selected=true;
	}
}
