//*************************************************************
// SCRIPTS COMANDOS AUXILIARES
//*************************************************************
var clickMenu = function(url,campo){
	var myArrPageSizes = myPageSize();

	$('#carrega').css({
		backgroundColor:	'#FFFFFF',
		opacity:			0.15,
		width:				myArrPageSizes[0]-150,
		height:				myArrPageSizes[1]-100
	}).show();
	
	$.post(url,
			function(retorno){
				extraiScript(retorno);
				setTimeout("finishAjax('"+campo+"', '#carrega', '"+escape(retorno)+"')", 40);
	});			
}

var logarUsuario = function(){
	var myArrPageSizes = myPageSize();

	$('#carrega').css({
		backgroundColor:	'#FFFFFF',
		opacity:			0.15,
		width:				myArrPageSizes[0]-150,
		height:				myArrPageSizes[1]-100
	}).show();
	
	$.post('/website/pagina/form/acesso.asp',
		{ 	log_usuario	: $("input[@name='txtApelido']").val(), 
			log_senha  	: $("input[@name='txtSenha']").val()
		},
			function(retorno){
				extraiScript(retorno);
				setTimeout("finishAjax('#logar', '#carrega', '"+escape(retorno)+"')", 40);
		}
	);			
	
}


//*************************************************************
// SCRIPTS AUXILIARES DE SISTEMA
//*************************************************************
function finishAjax(to,loads,retorno) { // @DESC = Executa as solicitação de ajax do site
	$(loads).fadeOut();
	$(to).html(unescape(retorno));
} 

function extraiScript(texto){ // @DESC = Extrai as tags javascrip dos códigos ajax
    var ini = 0;
    while (ini!=-1){
        ini = texto.indexOf('<script', ini);
        if (ini >=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</script>', ini);
            codigo = texto.substring(ini,fim);
            var novo = document.createElement('script');
				novo.type 		= 'text/javascript';
				novo.language	= 'javascript';
				novo.text = codigo;
				document.body.appendChild(novo);
        }
    }
} 

function myPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY; 
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight; 
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth; 
		} 
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	tamPage = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return tamPage;
};

function p2q_EmbedFlash(sFile,sWidth,sHeight) {
	var objSWF  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
		objSWF += '  codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"';
		objSWF += '  width="' + sWidth + '" height="' + sHeight + '" >';
		objSWF += '  <param name="movie" value="' + sFile + '">';
			for(i=3;i<arguments.length;i+=2) {
				objSWF += '  <param name="' + arguments[i] + '" value="' + arguments[i+1] + '">';
			}
		objSWF += '<embed width="' + sWidth + '" height="' + sHeight + '"';
		objSWF += '	pluginspage="http://www.macromedia.com/go/getflashplayer"';
		objSWF += '	type="application/x-shockwave-flash"';
		objSWF += '	src="' + sFile + '"';
			for(i=3;i<arguments.length;i+=2) {
				objSWF += '  ' + arguments[i] + '="' + arguments[i+1] + '"';
			}
		objSWF += '	/>';
		objSWF += '</object>';
		
		$("#p2q_EmbedFlash").html(objSWF);
}


function escreveFLV(Layer, arquivoNome, w, h, arquivoId, arquivoWMode, arquivoBGColor, flashVars) { // @DESC = Desenha na tela um filme flash .flv 
	if (arquivoWMode == "")
		arquivoWMode = "transparent"
	if (arquivoBGColor == "")
		arquivoBGColor = "#ffffff"
	
	var objSWF  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
		objSWF += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '
		objSWF += ' width="'+ w +'" height="'+ h+'" id="'+ arquivoId +'" name="'+ arquivoId +'" align="middle"> '
		objSWF += '<param name="allowScriptAccess" value="sameDomain" /> '
		objSWF += '<param name="movie" value="'+ arquivoNome +'" /> '
		objSWF += '<param name="salign" value="lt" /> '
		objSWF += '<param name="menu" value="false" /> '
		objSWF += '<param name="quality" value="high" /> '
		objSWF += '<param name="scale" value="noscale" /> '
		objSWF += '<param name="wmode" value="'+ arquivoWMode +'" /> '
		objSWF += '<param name="bgcolor" value="'+ arquivoBGColor +'" /> '
		objSWF += '<param name="FlashVars" value="'+ flashVars +'" />'
		objSWF += '<embed src="'+ arquivoNome +'" flashvars="'+ flashVars +'" quality="high" scale="noscale" '
		objSWF += 'menu="false" quality="high" wmode="'+ arquivoWMode +'" bgcolor="'+ arquivoBGColor +'" '
		objSWF += 'width="'+ w +'" height="'+ h+'" name="'+ arquivoNome +'" id="'+ arquivoNome +'" '
		objSWF += 'align="middle" allowScriptAccess="sameDomain" salign="LT" '
		objSWF += ' type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" /> '
		objSWF += '</object>'
		
		$(Layer).html(objSWF);
}