/* Odpowiednik trim`a w Javie
 * @author Mateusz Nowakowski
 */
function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );
  return sInString.replace( /\s+$/g, "" );
}

/* Wyczyszcza wszystkie pola w formularzu podanym jako pierwszy parametr,
 * procz pol, ktorych nazwy sa podane po pierwszym parametrze.
 *
 * @author Mateusz Nowakowski
 */
function clearForm(form){
	var map = new Array();
	map['org.apache.struts.taglib.html.TOKEN'] = 'org.apache.struts.taglib.html.TOKEN';
	for(i=1;i<arguments.length;i++)	map[arguments[i]] = arguments[i];
	for(i=0;i<form.length;i++)
	    
		if (
			(form[i].type != 'button')&&
			(form[i].type != 'reset')&&
			(form[i].type != 'submit')&&
			(map[form[i].name] == null)&&
			(form[i].readOnly != true)&&
			(form[i].disabled != true)
		   ) 
		   
			if (form[i].type == 'checkbox') form[i].checked = false; 
			else if ((form[i].type == 'select')||(form[i].type == 'select-one')) {
			form[i].value = form[i].children[0].value;
			}
			else form[i].value='';
}

/*
 * Odpowiednik taga cc:substring, pola length i appender sa opcjonalne
 * @author Mateusz Nowakowski
 *
 */
function ccSubstring(msg,length,appender) {
	if (msg == null) return msg;
	var len = 10;
	var app = "...";
	if (length != null) len = length;
	if (appender != null) app = appender;	
	if (len < msg.length) return msg.substring(0,len)+app;
	else return msg;
}

function disableSubmit() {
    return false;
}

function initLogin()
{
	if(parent!=self)
	{
		parent.location='index.jsp';
	}
	return true;
}

/**
 * @param msg 
 * @param confirmFlag 0/1
 */
function confirmDelete(msg, confirmFlag) {
    
    if (confirmFlag == 0) {
        return true;        
    }

    var agree = confirm(msg);
    
    if (agree) {
	    return true ;
	} else {
    	return false ;
    }
}