
var MANAGER = {};
MANAGER.ready = []; 
MANAGER.rooturl = null;

MANAGER.init = function(){
		//inicialização da imagem de "aguarde..."
		MANAGER.preloadImg();
		
		var re = /(\/modules)?\/([a-zA-Z0-9_-])+\.php/gi;
		var nProtocol = location.protocol + '//';
		var nHost = location.host;
		var nPath = location.pathname.replace(re,'') + '/';
		this.rooturl = nProtocol + nHost + nPath;
};
MANAGER.onReady = function(fn){
		var f = {};
		f.fn = fn;
		this.ready[this.ready.length]=f;
};
MANAGER.preloadImg = function(){
		if(document.images){
				var img1 = new Image(200,200);
				var img2 = new Image(200,200);
				img1.src = '../includes/images/imagem_aguarde.gif';
				img2.src = 'includes/images/imagem_aguarde.gif';
		}
};
/* $_get Function */		
MANAGER._get = function(varname){
		var qy,
				query=[],
				fields=[],
				temp=[],
				varNum,
				i;
		 
		qy = location.search.replace('?','');
		query = qy.split('&');
		varNum = query.length
		for(i=0 ; i<=varNum-1 ; i++){
				temp=query[i].split('=');
				fields[''+temp[0]+'']=temp[1];
		}
		return fields[''+varname+''];		
};
/* END $_get */		

MANAGER.openWindow = function(title,content,w,h,cpadding,cspacing,_bottom){
		jQuery.noConflict();
		cpadding = (cpadding == '') ? '0' : cpadding;
		cspacing = (cspacing == '') ? '0' : cspacing;
		if(title=='')title='&nbsp';
		var nScrollTop=jQuery(window).scrollTop();
		var nW=jQuery(window).width();
		var nH=jQuery(window).height()+(nScrollTop || 0);
		var nW2=parseInt((nW-w)/2);
		var nH2=parseInt((nH-h-nScrollTop)/3);
		jQuery("<div id=shadow>").appendTo('body');
		var tela = jQuery('#shadow');
		tela.css({'background':'#000000',
							'position':'absolute',
							'top' : '0',
							'left' : '0',
							'display' : 'none',
							'width' : jQuery(document).width()-21, /* -21 horizontal scrollbar size */
							'height' : jQuery(document).height()-4, /* -4 vertical scrollbar size */
							'z-index':10000
		});
		tela.fadeTo('slow',0.7);

		jQuery('<div id=nWindow>').appendTo('body');
		var nWindow = jQuery('#nWindow');
		var nContent = content;
		nWindow.css({'position':'absolute',
								 'width':''+w+'',
								 'height':''+h+'',
								 'left':nW2,
								 'top':nH2+nScrollTop,
								 'z-index':10001
		});
		jQuery('<div id=nSombra>').appendTo('body');
		var nSombra = jQuery('#nSombra');
		nSombra.css({'position':'absolute',
								 'width':''+(w+(cpadding*2))+'',
								 'height':''+((h+60)-cpadding)+'',
								 'left':nW2+10,
								 'top':nH2+nScrollTop+10,
								 'background':'#000000',
								 'opacity':0.5,
								 'z-index':10000
		});
		var table='';
		
		table+="<table style='border:1px #555555 solid' border=0 cellpadding='"+cpadding+"' cellspacing='"+cspacing+"' width='"+w+"' height='"+h+"'> \n";
		table+="		<tr bgcolor=#A3A3A3>\n";
		table+="			<td height=1 style='color:#FFFF00;font-size:12px'><div style='position:relative'>"+title+"<div style='position:absolute;left:"+(w-16)+";top:5;z-index:10000'><img src='js/images/logout.gif' align='absmiddle' onclick='javascript:return MANAGER.closeOpenWindow();' class=add_videos></div></div></td>\n";
		table+="		</tr>\n";
		table+="		<tr bgcolor=#E3E3E3>\n";
		table+="			<td valign=top><div id=nBox>"+ nContent +"</div></td>\n";
		table+="		</tr>\n";
		if(_bottom == undefined || _bottom == ''){
				table+="		<tr bgcolor=#D3D3D3>\n";
				table+="			<td style='cursor:hand;cursor:pointer;color:#0000AA' onclick='javascript: return MANAGER.closeOpenWindow();' align=center>Fechar</td>\n";
				table+="		</tr>\n";
		}else{
				table+="		<tr bgcolor=#D3D3D3>\n";
				table+="			<td>"+ _bottom +"</td>\n";
				table+="		</tr>\n";
		}
		table+="</table>";
		
		nWindow.html(table);
		
		var nBox = jQuery('#nBox');
		nBox.css({'position':'relative',
								 'width':''+w+'',
								 'height':''+h+'',
								 'z-index':10002,
								 'overflow-y':'auto'
		});
		return true;
}
MANAGER.closeOpenWindow = function(){
		jQuery.noConflict();
		jQuery("div#nWindow").remove();
		jQuery("div#nSombra").remove();
		jQuery("div#shadow").fadeOut('slow');
		return true;
}


/************************************************* 
* 					FUNÇÕES FORMATAR VALORES             *
**************************************************/

function formatPrice(pressedkey,field,qntdec,m,d){
		var nKey = window.event.keyCode;
		var separadorMil=m;
		var separadorDec=d; 
		var centena;
		var milhar;
		var nContent;
		var content;
		var len;
		var nDecimal='';
		var nCentena='';
		var nMilhar='';
		var price;
		var resto;
		var decimal=qntdec;
		centena = decimal + 3;
		milhar  = centena + 3;

		content = field.value;
		content = content.replace(separadorDec,'');
		content = content.replace(separadorMil,'');
		content = clearNonNum(content);
		len 		= content.length;

		if(len > decimal){
				resto = content.substr(0,len-decimal);
				nDecimal = content.substr(len-decimal,decimal);
				content = resto + separadorDec + nDecimal;
				if(len > centena){
						resto = content.substr(0,len-centena);
						nCentena = content.substr(len-centena,centena+1);
						content = resto + separadorMil + nCentena;
						
				}
		}
		field.value = content;
}
	
function clearNonNum(content){
		var len = content.length;
		var validChars = '0123456789';
		var i,j;
		var result='';
		var valid=true;
		
		for(i=0;i<=len;i++){
				valid=false;
				for(j=0;j<=validChars.length-1;j++){
						if(content.charAt(i)== validChars.charAt(j)){
								valid=true;
								break;
						}
				}
				if(valid)result+=content.charAt(i);
		}
		return result;
}
/*****************************************************/
/*****************************************************/


/* INICIALIZAÇÃO */
jQuery(function(){
		var fnCollection=MANAGER.ready;
		MANAGER.init();
		if(fnCollection[0] != undefined){
				jQuery.each(fnCollection,function(i,e){
						jQuery.call(e.fn());
				});
		}
});

function addFav(){
    var url      = "http://www.valovelho.com";
    var title    = "Valovelho.com";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}




