function addFavorite (prdId, index)
{
	var url = '?xcambo/product/user/update/&add:' + prdId
	var id = 'bodyContentMessage'

	if (index) {
		id = index
	}

	setElementData (id, url)
}


function resizeWindow (width, height)
{
	if (parseInt(navigator.appVersion) > 3)
	{
		if (navigator.appName == 'Netscape')
		{
			window.outerWidth  = width;
			window.outerHeight = height;
		}
		else {
			window.resizeTo(width, height);
		}
	}
}
function formatData(obj) {

	var data = new String(obj.value);

	var x = 0;

	var newData = "";

	for(x = 0 ; x<data.length ; x++) {

		if(!isNaN(parseInt(data.charAt(x)))) {

			newData += data.charAt(x);

			if(newData.length == 2 || newData.length ==5)

				newData += "/";

		}

	}

	obj.value = newData;

}

function formataCep(obj) {

	var cep = new String(obj.value);

	var x = 0;

	var newCep = "";

	for(x = 0 ; x<cep.length ; x++) {

		if(!isNaN(parseInt(cep.charAt(x)))) {

			newCep += cep.charAt(x);

			if(newCep.length ==5)

				newCep += "-";

		}

	}

	obj.value = newCep;	

}



function formataNumero(obj) {

	

	var numero = new String(obj.value);

	var x = 0;

	var newNumero = "";

	for(x = 0 ; x<numero.length ; x++) {

		if(!isNaN(parseInt(numero.charAt(x)))) {

			newNumero += numero.charAt(x);

		}

	}

	obj.value = newNumero;	

}



function verificaNumeroProtocolo(obj) {

	

	ajaxRequest('?admin/recursos/ajax/geraprotocolo/&cd_protoc_pro:' + obj.value, 'updateProtocolo');

}



function updateProtocolo(html) {

	html = unescape(html);

	html = unescape(html);

	

	var texto = new String(html).split("::");

	if(texto[0] == "ajax") {

		dhtmlGetElement('CD_PROTOC_PRO').value = texto[1];

		dhtmlGetElement('ID_PROTOC_PRO').value = texto[1];

	} else if(texto[0] == "msg") {

		alert(texto[1]);

	}

}

function trim(sString)

{

	while (sString.substring(0,1) == ' ')

	{

		sString = sString.substring(1, sString.length);

	}

	while (sString.substring(sString.length-1, sString.length) == ' ')

	{

		sString = sString.substring(0,sString.length-1);

	}

	return sString;

}



function txtBoxFormat(strField, sMask, evtKeyPress) {

    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;



    if(window.event) { // Internet Explorer

      nTecla = evtKeyPress.keyCode; }

    else if(evtKeyPress.which) { // Nestcape / firefox

      nTecla = evtKeyPress.which;

    }

    //se for backspace não faz nada

    if (nTecla != 8){

	    sValue = document.getElementById(strField).value;

	    // alert(sValue);

	

	    // Limpa todos os caracteres de formatação que

	    // já estiverem no campo.

	    sValue = sValue.toString().replace( "-", "" );

	    sValue = sValue.toString().replace( "-", "" );

	    sValue = sValue.toString().replace( ".", "" );

	    sValue = sValue.toString().replace( ".", "" );

	    sValue = sValue.toString().replace( "/", "" );

	    sValue = sValue.toString().replace( "/", "" );

	    sValue = sValue.toString().replace( "(", "" );

	    sValue = sValue.toString().replace( "(", "" );

	    sValue = sValue.toString().replace( ")", "" );

	    sValue = sValue.toString().replace( ")", "" );

	    sValue = sValue.toString().replace( " ", "" );

	    sValue = sValue.toString().replace( " ", "" );

	    sValue = sValue.toString().replace( ":", "" );

	    fldLen = sValue.length;

	    mskLen = sMask.length;

	

	    i = 0;

	    nCount = 0;

	    sCod = "";

	    mskLen = fldLen;

	

	    while (i <= mskLen) {

	      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))

	      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == ":"))

	

	      if (bolMask) {

	        sCod += sMask.charAt(i);

	        mskLen++; }

	      else {

	        sCod += sValue.charAt(nCount);

	        nCount++;

	      }

	

	      i++;

	    }

	

	    document.getElementById(strField).value = sCod;

	

	    if (nTecla != 8) { // backspace

	      if (sMask.charAt(i-1) == "9" || sMask.charAt(i-1) == "Y") { // apenas números...

	        return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9

	      else { // qualquer caracter...

	        return true;

	      } 

	    }

	    else {

	      return true;

	    }

    }//fim do if que verifica se é backspace

}

//

//Valida Data

//

function valida_data(date) {

	//var date = document.getElementById('data').value;

	var array_data = new Array;

	var ExpReg = new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");

	//vetor que contem o dia o mes e o ano

	var array_data = date.split("/");

	erro = false;

	//Valido se a data esta no formato dd/mm/yyyy e se o dia tem 2 digitos e esta entre 01 e 31

	//se o mes tem d2 digitos e esta entre 01 e 12 e o ano se tem 4 digitos e esta entre 1000 e 2999

	if ( date.search(ExpReg) == -1 ) {

		erro = true;



	//Valido os meses que nao tem 31 dias com execao de fevereiro

	} else if ( ( ( array_data[1] == 4 ) || ( array_data[1] == 6 ) || ( array_data[1] == 9 ) || ( array_data[1] == 11 ) ) && ( array_data[0] > 30 ) ) {

		erro = true;



	//Valido o mes de fevereiro

	} else if ( array_data[1] == 2 ) {

		//Valido ano que nao e bissexto

		if ( ( array_data[0] > 28 ) && ( ( array_data[2] % 4 ) != 0 ) )

			erro = true;

		//Valido ano bissexto

		if ( ( array_data[0] > 29 ) && ( ( array_data[2] % 4 ) == 0 ) )

			erro = true;

	}

	return erro;

}

//

//Valida Hora

//

function valida_hora(hora) {



	var hasHora = new String(hora).split(":");

    

    if (hasHora.length != 2) {

        alert("A hora deve estar no formato hh:mm");

        return false;

    }

    

    for (var i = 0; i < hasHora.length; i++) {

        if (/[^0-9]/.test(hasHora[i])) {

            alert("Use somente números e dois pontos");

            return false;

        }

    }

    

    if (hasHora[0] < 0 || hasHora[0] > 23) {

        alert("Horas inválidas");

        return false;

    } else if (hasHora[1] < 0 || hasHora[1] > 59) {

        alert("Minutos inválidos");

        return false;

    }

	return true;

}