function clickfoto(obj, pseq, ptitulo) {
	document.getElementById("imgprincipal").src = obj.src;
} 

var request = getXMLHttpRequest();

function getXMLHttpRequest() {

	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 

} 

function seleciona(pobj, vref, vcodsessao) {

	request.open("GET", "model/niseleciona.php?action="+pobj.checked+"&ref="+vref+"&pcodsessao="+vcodsessao, true);
	request.onreadystatechange = function() { 
			if (request.readyState==4) {
				
			} 
	}
			
	request.send(null);
	return true;
}

function seleciona_cont(pobj, vref, vcodsessao) {

	request.open("GET", "model/niseleciona.php?action="+pobj.checked+"&ref="+vref+"&pcodsessao="+vcodsessao, true);
	request.onreadystatechange = function() {
			if (request.readyState==4) {
				document.getElementById("lblselecionado").innerHTML = request.responseText; 
			}
	}
	request.send(null);
	return true;
}
			
function trim(inputString) {

   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
   }
   return retValue; 
} 

function strzero( inputVal, tam ) 

{
	var retValue = "00000000000000000000"+inputVal;
	retValue = retValue.substring(retValue.length-tam, retValue.length);
	return retValue;
} 
function valdata(pbox) 
{
	vdata = window.document.formdados.elements[pbox].value;
	if (vdata.length != 6 && vdata.length != 8 && vdata.length != 10) {window.alert("Data Inválida"); return false;}
	if (vdata.length == 6) {
		vdata = vdata.substring(0,2) + "/" + vdata.substring(2,4) + "/20" + vdata.substring(4,6);
	}
	if (vdata.length == 8) {
		if (vdata.charAt(2) == "/" && vdata.charAt(5) == "/") {
		   vdata = vdata.substring(0,6) + "20" + vdata.substring(6,8);
		}
		else {
    		vdata = vdata.substring(0,2) + "/" + vdata.substring(2,4) + "/" + vdata.substring(4,8);
		} 
	}	
	if (vdata.substring(0,2) < 1 || vdata.substring(0,2) > 31) {window.alert("Data Inválida"); return false;}
	if (vdata.substring(3,5) < 1 || vdata.substring(3,5) > 12) {window.alert("Data Inválida"); return false;}
	if (vdata.substring(6,10) < 2000 || vdata.substring(6,10) > 2100) {window.alert("Data Inválida"); return false;}
	window.document.formdados.elements[pbox].value = vdata;
	return true;
	
}
function date_format(pbox)
{

	DateFormat(pbox);
	return true;
}
	
function DateFormat(pbox) 
{

	vdata = pbox.value;
	if (vdata.length != 6 && vdata.length != 8 && vdata.length != 10) {window.alert("Data Inválida"); return false;}
	if (vdata.length == 6) {
		vdata = vdata.substring(0,2) + "/" + vdata.substring(2,4) + "/20" + vdata.substring(4,6);
	}
	if (vdata.length == 8) {
		if (vdata.charAt(2) == "/" && vdata.charAt(5) == "/") {
		   vdata = vdata.substring(0,6) + "20" + vdata.substring(6,8);
		}
		else {
    		vdata = vdata.substring(0,2) + "/" + vdata.substring(2,4) + "/" + vdata.substring(4,8);
		} 
	}	
	if (vdata.substring(0,2) < 1 || vdata.substring(0,2) > 31) {window.alert("Data Inválida"); return false;}
	if (vdata.substring(3,5) < 1 || vdata.substring(3,5) > 12) {window.alert("Data Inválida"); return false;}
	if (vdata.substring(6,10) < 2000 || vdata.substring(6,10) > 2100) {window.alert("Data Inválida"); return false;}
	pbox.value = vdata;
	return true;
	
}

function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.truncate; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}



function fone_format(obj)
{
	var vfone;
	if (trim(obj.value) != '') 
	{
		vfone_original = obj.value.replace("-", "");
		vfone = obj.value;
		if (vfone_original.length == 8)
		{
			vfone = vfone_original.substring(0,4);
			vfone = vfone + "-" + vfone_original.substring(4,8);
			obj.value = vfone;
		}
		else if (vfone_original.length == 7)
		{
			vfone = vfone_original.substring(0,3);
			vfone = vfone + "-" + vfone_original.substring(3,7);
			obj.value = vfone;
		}
		else 
		{
			window.alert("Telefone Inválido");
			obj.focus();
		}
    }
}
