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(".") > 2) && (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;
}

function isCPF(cpf){
	cpf = cpf.replace(".", "");
	cpf = cpf.replace(".", "");
	cpf = cpf.replace("-", "");
	cpf = cpf.replace("/", "");
	
	var numeros, digitos, soma, i, resultado, digitos_iguais;
	digitos_iguais = 1;
	if (cpf.length < 11){
		return false;
	}
	for (i = 0; i < cpf.length - 1; i++){
		if (cpf.charAt(i) != cpf.charAt(i + 1)){
			digitos_iguais = 0;
			break;
		}
	}
	if (!digitos_iguais){
		numeros = cpf.substring(0,9);
		digitos = cpf.substring(9);
		soma = 0;
		for (i = 10; i > 1; i--){
			soma += numeros.charAt(10 - i) * i;
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0)){
			return false;
		}
		numeros = cpf.substring(0,10);
		soma = 0;
		for (i = 11; i > 1; i--){
			soma += numeros.charAt(11 - i) * i;
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1)){
			return false;
		}
		return true;
	}else{
		return false;
	}
}

function isCNPJ(cnpj){
	cnpj = cnpj.replace(".", "");
	cnpj = cnpj.replace(".", "");
	cnpj = cnpj.replace("-", "");
	cnpj = cnpj.replace("/", "");
	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
	digitos_iguais = 1;
	if (cnpj.length < 14){
		return false;
	}
	for (i = 0; i < cnpj.length - 1; i++){
		if (cnpj.charAt(i) != cnpj.charAt(i + 1)){
			digitos_iguais = 0;
			break;
		}
	}
	if (!digitos_iguais){
		tamanho = cnpj.length - 2;
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos < 2){
				pos = 9;
			}
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0)){
			return false;
		}
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos < 2){
				pos = 9;
			}
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1)){
			return false;
		}
		return true;
	}else{
		return false;
	}
}

function formCarregando(){
	$('<div></div>').appendTo('BODY')
					.css({
						'background': 'white',
						'opacity': '0.85',
						'width': '100%',
						'height': '100%',
						'position': 'absolute',
						'top':'0',
						'left':'0',
						'z-index': '7000',
						'font-size': '14px',
						'font-weight': 'bold'
					})
					.html('<table width="100%" height="100%"><tr><td><center><img src="http://www.maisfruta.com.br/loading.gif"/> Enviando. Por favor, aguarde!</center></td></tr></table>');
	$('BODY').css('overflow', 'hidden');
}
