function checkEmail(email){
	if((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))
		return true;
	else
		return false;
}

function adicionar_column(tabela, valores, excluir){
	
	id = tabela.rows.length;

	var x=tabela.insertRow( id )
	var w=x.insertCell(0)
	var y=x.insertCell(1)
	var t=x.insertCell(2)
	var z=x.insertCell(3)

	cont++;
	rem[cont]	= false;
	
	if ( excluir == 'true' ){
		z.innerHTML= '&nbsp;&nbsp;<a href="#" onclick="remover_column('+cont+')"><font class="texto_azul2">excluir</font></a>';
	} else {
		z.innerHTML= '&nbsp;';
	}
	w.innerHTML= '<input type="text" name="referencia['+cont+']" id="referencia'+cont+'" class="ref" />';
	y.innerHTML= '<input type="text" name="cor['+cont+']" id="cor'+cont+'" class="cor" />';
	t.innerHTML= '<input type="text" name="quantidade['+cont+']" id="quantidade'+cont+'" class="qtd" />';
	
	document.getElementById('referencia'+cont).value = valores[0];
	document.getElementById('cor'+cont).value = valores[1];
	document.getElementById('quantidade'+cont).value = valores[2];
	
	eval ( 'document.getElementById("referencia'+cont+'").focus();' );
	
}
function remover_column(idr){
	var idtmp	= idr;
	var tmp = 0;
	for ( i = 1; i < idr ; i++ ){
		if ( rem[i] == true ){
			tmp++
		}
	}
	idr		= idr - tmp;
	document.getElementById('produtos').deleteRow(idr);
	rem[idtmp]	= true;
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function numerico(e){
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if (tecla > 47 && tecla < 58){ // numeros de 0 a 9
		return true;
	} else {
		if (tecla != 8) // backspace
			event.keyCode = 0; //return false;
		else
			return true;
	}
}