function mostraFlash(src, larg, alt, wmode){
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ larg +'" height="'+ alt +'">';
	flash += '<param name="movie" value="'+ src +'" />';
	flash += '<param name="allowScriptAccess" value="always" />';
	flash += '<param name="menu" value="false" />';	
	flash += '<param name="wmode" value="'+ wmode +'" />';	
	flash += '<embed src="'+ src +'" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" type="application/x-shockwave-flash" width="'+ larg +'" height="'+ alt +'" menu = "false" wmode = "'+ wmode +'"></embed>';
	flash += '</object>';	
	
	document.write(flash);
}


function setWordIn(ob, tx){
	if(ob.value == tx){
    	ob.value = '';
	}
}

function setWordOut(ob, tx){
	if(ob.value == ''){
    	ob.value = tx;
	}
}

function getUrlParams(link,  name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( link );
  if( results == null )
    return "";
  else
    return results[1];
}

function getCoordGMaps(link){
	var r = getUrlParams(link, 'll');
	if(r == ''){
		r = getUrlParams(link, 'sll');
	}
	return r.split(',');
}


function moedaLimpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

function moedaFormata(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	var numeros = "0123456789";
	vr = moedaLimpar(campo.value, numeros);
	tam = vr.length;
	dec=decimal;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 )
		{ tam = tam - 1 ; }

	if ( (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) && (tecla != 220 && tecla != 222 && tecla != 219) ){
		if ( tam <= dec )
			{ campo.value = vr ; }
	
		if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	} else{
		campo.value = campo.value;
		return false;
	}
	return true;
}

function IsNumeric(strString){
var strValidChars = "0123456789.-,";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

//  test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
   {
   strChar = strString.charAt(i);
   if (strValidChars.indexOf(strChar) == -1)
      {
      blnResult = false;
      }
   }
return blnResult;
}

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 isEmail(str) {
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}


function share(socialNetwork, titulo, mensagem, url){
	if(socialNetwork == "orkut"){
		window.open('http://promote.orkut.com/preview?nt=orkut.com&tt='+titulo+'&cn='+mensagem+'&du='+url,'wOrkut');
	}else if(socialNetwork == "twitter"){
		window.open('http://twitter.com/home?status='+titulo+' - '+mensagem);
	}else if(socialNetwork == 'facebook'){
		window.open('http://www.facebook.com/share.php?u='+url+'&t='+titulo);
	}else if(socialNetwork == 'email'){
		window.open('mailto:?subject='+titulo+'&body='+mensagem);
	}
}

function isNull(valor, preValor){
	if(valor == "")
		return true;
	
	if(preValor != "")
		if(valor == preValor)
			return true;
	
	return false;
}

