// JavaScript Document

function newImage(strSrc){
	
	ni = new Image();
	ni.src = strSrc;
	
	return ni;
	
}


function isDate(day, month, year){
    //IsDate(29, 2, 2005)
    //IsDate(29, 2, 2004)
    var date = new Date();
    var blnRet = false;
    var blnDay;
    var blnMonth;
    var blnYear;

    date.setFullYear(year, month -1, day);

    blnDay   = (date.getDate()  == day);
    blnMonth = (date.getMonth() == month -1);
    blnYear  = (date.getFullYear()  == year);

    if (blnDay && blnMonth && blnYear)
        blnRet = true;

    return blnRet;
}

function isDatePtBr(strData){
	
	var sday, smonth, syear;
	var arr;
	
	strData = trim(strData);
	if(strData.indexOf("/") > -1){
		arr = strData.split("/");
		sday   = '0'; 
		smonth = '0'; 
		syear  = '0';
		if(arr.length == 3){
			sday   = arr[0]; 
			smonth = arr[1]; 
			syear  = arr[2]; 
		}
		if(isDate(sday, smonth, syear)){
			return true;
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
	
}

function setDisplay(strNome, strStatus){
	
	var ly = getLayer(strNome);
	
	if(ly){ 
		ly.style.display = strStatus;
	}
	
}

function setInnerHTML(strNome, strTexto){
	
	var ly = getLayer(strNome);
	
	if(ly){ 
		ly.innerHTML = strTexto;
	}
	
}

function setLayer(id,strURL){

	if(document.layers){
		document.layers[id].src=strURL;
	}
	else if(document.all){
		document.all[id].src=strURL;
	}
	else if(document.getElementById){
		document.getElementById(id).src=strURL;
	}
	
}

function getLayer(id){
	
	  if (document.getElementById){
		    return document.getElementById(id);
	  }
	  else if (document.all){
		    return document.all[id];
	  }
	  else if (document.layers){
		    return document.layers[id];
	  }
	  return null;
}

function FormSelect(form, origem, valor){ 

	if(valor == ""){
		valor = 0;
	}

	var ate = form[origem].length;

    for(j=0; j < ate; j++){
       if(form[origem].options[j].value == valor){ 
            form[origem].options[j].selected = true
       }
    }
    
    return;
}

function trim(str){

	if(typeof(str) != "string") return "";
	
	var regexp = /[\n\r\t ]+$/; 		
	str = str.replace(regexp, "");
	
	regexp = /^[\n\r\t ]+/; 		
	str = str.replace(regexp, "");
	
	return str;

}

function ehEmail(v){

	if(v.indexOf("..") > -1 ) return false;
	if(v.indexOf("@") == -1 )  return false;
	if(v.indexOf("@.") > -1 ) return false;
	if(v.indexOf(" ") > -1 )  return false;
	
	v = trim(v);
	var re = /^[a-zA-Z._0-9-]+@[a-zA-Z0-9]{1}[a-zA-Z._0-9-]+\.[a-zA-Z]+[.]?[a-zA-Z]{0,3}$/;
	return re.test(v); 
	
}

function ehVazio(valor){
	
	valor = trim(valor);
	
	if(valor == ''){
		return true;
	}
	else{
		return false;
	}

}

function ehNumero(valor){
	
	var i;
	var tamanho;
	var caracter;
	
	valor = valor.toString();
	tamanho = valor.length;
	
	for(i = 0; i < tamanho; i++){
		caracter = valor.charAt(i);
		if(caracter < "0" || caracter > "9"){
			return false;
		}
	}

	return true;
	
}

function FormCheck(form, origem, valor){ 

	if(valor == ""){
		return; 
	}
	else{
		var r = /[ ]{1,}/gi;
		valor = valor.replace(r, "");
		valor = ',' + valor + ',';
	}

	var ate = form[origem].length;
	var comp = '';
	if(form[origem].value == valor){
		form[origem].checked = true;
	}
    
    return;
	
}

function FormCheckRadio(form, origem, valor){
	
	var ate = form[origem].length; 
    for(j=0; j < ate; j++){
       if(form[origem][j].value == valor){ 
            form[origem][j].checked = true;
       }
    }
    
    return;
	
}

