<!-- alterValue(this, 'nome'); -->

function alterValue(component, val) {
    if (component.value == '') {
        component.value = val;
    } else if (component.value == val) {
        component.value = '';
    }
}

/**
 * Preenche uma combo box a partir de um array
*/
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
    var i, j;
    var prompt;
    
    if ((itemArray == '0') || (itemArray == -1) || (itemArray == null)) {
        selectCtrl.disabled = true;
    } else {
        selectCtrl.disabled = false;
    }
    
    // empty existing items
    for (i = selectCtrl.options.length; i >= 0; i--) {
        selectCtrl.options[i] = null; 
    }
    prompt = (itemArray != null) ? goodPrompt : badPrompt;
    if (prompt == null) {
        j = 0;
    } else {
        selectCtrl.options[0] = new Option(prompt);
        j = 1;
    }
    if (itemArray != null) {
        // add new items
        for (i = 0; i < itemArray.length; i++) {
            selectCtrl.options[j] = new Option(itemArray[i][0]);
            if (itemArray[i][1] != null) {
                selectCtrl.options[j].value = itemArray[i][1]; 
            }
            j++;
        }
        // select first item (prompt) for sub list
        selectCtrl.options[0].selected = true;
    }
}
 
function loadjscssfile(filename, filetype){
     if (filetype=="js"){ //if filename is a external JavaScript file
             var fileref=document.createElement('script')
             fileref.setAttribute("type","text/javascript")
             fileref.setAttribute("src", filename)
     }
     else if (filetype=="css"){ //if filename is an external CSS file
             var fileref=document.createElement("link")
             fileref.setAttribute("rel", "stylesheet")
             fileref.setAttribute("type", "text/css")
             fileref.setAttribute("href", filename)
     }
     if (typeof fileref!="undefined")
             document.getElementsByTagName("head")[0].appendChild(fileref)
}

/* code from qodo.co.uk */
//create as many regular expressions here as you need:
var digitsOnly = /[1234567890]/g;
var integerOnly = /[0-9\.]/g;
var alphaOnly = /[A-Z]/g;

function restrictCharacters(myfield, e, restrictionType) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);

	// if they pressed esc... remove focus from field...
	if (code==27) { this.blur(); return false; }
	
	// ignore if they are press other keys
	// strange because code: 39 is the down key AND ' key...
	// and DEL also equals .
	if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
		if (character.match(restrictionType)) {
			return true;
		} else {
			return false;
		}
		
	}
}