 include("admin/_js/_core/core.js");
 include("admin/_js/_core/Cookie.js");
 include("admin/_js/_core/Event.js");
 include("admin/_js/_core/Form.js");
 include("admin/_js/_core/Util.js");
 //include("admin/_js/_core/Common.js");
 //include("admin/_js/_utils/sha2.js");
 include("admin/_js/_utils/pngfix.js");
 //include("admin/_js/_utils/format.js");
 include("admin/_js/_core/_components/elements.js");
 include("admin/_js/_core/_components/window.js");
 
 function doPrint(u){
 core.Ajax.get(u,function(o){
 var win = core.window.create({name:'Impressao',top:100,content:o,align:'center center',width:550,height:400});
						win.onClose=function(){
							enableRoot();
						}
						disableRoot();
						});
 
 }
 var noIframe=0;
 function postPrint(u){
 loading(true,'Preparando ...');

		noIframe++;
		try{
			
			var iFrame = document.createElement("iframe");
			iFrame.name="print_"+noIframe;
			iFrame.id="print_"+noIframe;
			iFrame.src= u;
			iFrame.style.width="1px";
			iFrame.style.height="1px";
			iFrame.style.border="0";
			document.body.appendChild(iFrame);
		}catch(e){
		alert(e);
		}
 loading(false);
 }
 
 function addFavorite(u,el){
	var cl = el.className;
	var label;
	var action;
	if(cl=="btn_remov_list"){
		label = "Removendo";
		action = "delete";
	}else{
		label = "Salvando";
		action = "save";
	}
	loading(true,label + ' im&oacute;vel');
	try{
		core.Ajax.get(u,function(o){
			swapFavorito(el);
			loading(false);
			return true;
		});
	}catch(e){
		loading(false);
	}
	return true;
	//alert(core.Cookie.getCookie('favoritos'))
 }
 function deleteFavoriteFromList(n,u){
	var favs = core.Cookie.getCookie('favoritos');
	var itens = favs.split(',');
	var item = itens.indexOf(n);
	itens.splice(item, 1),
	core.Cookie.setCookie('favoritos',itens.toString());
	loading(true,'Atualizando...');
	try{
		core.Ajax.get(u,function(o){
			$('content').innerHTML = o;
			loading(false);
			return true;
		});
	}catch(e){
		loading(false);
	}
 }
 function clearFavorites(){
 try{
	core.Cookie.deleteCookie('favoritos');
	}catch(e){
	alert(e);
	}
 }
function swapFavorito(el){
	var cl = el.className;
	if(cl=="btn_remov_list"){
		el.className = "btn_add_list";
		el.innerHTML = "Adicionar a favoritos";
	}else{
		el.className = "btn_remov_list";
		el.innerHTML = "Remover dos favoritos";
	}
}
 function popUpDestaque(url){
 var html = "<div class=\"menu_botoes_red\"><table id=\"popUpDestaque\" cellspacing=\"0\" cellpadding=\"0\"><tr><th colspan=\"3\">Selecione</th></tr><tr><td>";
 html +="<table class=\"bt\" cellspacing=\"0\" cellpadding=\"0\" onclick=\"getUrl('"+url+"?f=0',$('content'),event);core.window.removeActive();\"><tr><td class=\"left\"></td><td class=\"center\">Alugar</td><td class=\"right\"></td></tr></table></td>";
 html +="<th style=\"width:20px;\">OU</th>";
 html +="<td><table class=\"bt\" cellspacing=\"0\" cellpadding=\"0\" onclick=\"getUrl('"+url+"?f=1',$('content'),event);core.window.removeActive();\"><tr><td class=\"left\"></td><td class=\"center\">Comprar</td><td class=\"right\"></td></tr></table></td></tr></table></div>";
 
	var win = core.window.create({name:'Destaque',top:100,content:html,align:'center center',width:300,height:100});
						win.onClose=function(){
							enableRoot();
						}
						disableRoot();
 }
 function swith_finalidade(val){
	//var elem = el[el.selectedIndex].text.toLowerCase();
	if(val=="1"){
		$("valorde_comprar_custom").style.display='';
		$("valorate_comprar_custom").style.display='';
		$("valorde_alugar_custom").style.display='none';
		$("valorate_alugar_custom").style.display='none';
		
	}else{
		$("valorde_comprar_custom").style.display='none';
		$("valorate_comprar_custom").style.display='none';
		$("valorde_alugar_custom").style.display='';
		$("valorate_alugar_custom").style.display='';
	}
 }
 
function activeMenu(el,e){
	var target = (typeof(el)=="string")? $(el) : el;
	
	var last = $('menu').getElementsByTagName("table");
	//alert(last.length);
	for(i=0;i<last.length;i++){
		
		last[i].className="tab";
	}
	if(target)target.className="tabActive";	
}

function getUrl(u,t,e){
	loading(true);
	try{
		core.Ajax.get(u,function(o){
					t.innerHTML=o;
					try{
						//if(o.search("<!-- mceEditor -->")!=-1) loadMCE();
						if(o.search("<script>")!=-1) appendScript(o);
						var content = $('content');
			
					}catch(e){
					}
					loading(false);
					//core.Element.Convert();
					});
	}catch(e){
		loading(false);
	}

}

function doSearch(f){
	loading(true);
	var params=core.Form.serialize(f);
	
	core.Ajax.post(params,function(o){
		$('content').innerHTML=o;
		try{
			//if(o.search("<!-- mceEditor -->")!=-1) loadMCE();
			if(o.search("<script>")!=-1) appendScript(o);
		}catch(e){
		}
			loading(false);
	});
}
function doPost(f){
	loading(true,'Processando...');
	var params=core.Form.serialize(f);
	core.Ajax.post(params,function(e){
		loading(false);
		eval(e);
	});
	return false;
}
var myScript=null;
function appendScript(objText){
	var re = new RegExp('<script[^>]*>([\\S\\s]*?)<\\/script>', 'ig');
	var scriptLoaded = objText.match(re);
	var head = (document.getElementsByTagName)?document.getElementsByTagName("head").item(0):document.head;
	if(myScript!=null) head.removeChild(myScript);
	var sNode=document.createElement('script');
	sNode.setAttribute("type","text/javascript");
	
	for(i=0;i<scriptLoaded.length;i++){
		var stripped = scriptLoaded[i].toString().replace(/(<([^>]+)>)/ig,""); 
		var tNode = document.createTextNode(stripped);
			try{
				sNode.appendChild(tNode); 
			}catch(er){
				sNode.text += stripped;
			}
	}
	myScript = sNode;
	head.appendChild(sNode);
	
/*
	var x = document.body.getElementsByTagName("script");
	if(myScript!=null) head.removeChild(myScript);
	var sNode=document.createElement('script');
	alert(x.length);
	var tNode = document.createTextNode(x[0].innerHTML);
	sNode.setAttribute("type","text/javascript");


	try{
		sNode.appendChild(tNode); 
	}catch(er){
	alert(er);
		sNode.text = x[0].innerHTML;
	}
	myScript = sNode;
	head.appendChild(sNode);
	*/
}


function swapImage(src){
	var isIE = (core.Browser.get().search("Internet Explorer")==-1)?false : true;
	$('img').style.opacity = '0.5';
	if(isIE) $('img').style.filter = 'alpha(opacity=50)';
	var img=new Image();
	img.src = src;
	
	img.onload=function(){
		$('img').src = src;
		$('img').style.opacity = '1';
	}
	if(core.Browser.get()=="Opera"){
		$('img').src = src;
		$('img').style.opacity = '1';
	}
		$('img').src = src;
		if(isIE) $('img').style.filter = 'alpha(opacity=100)';
}

function preloadImages(arr,folder){

	for(i=0;i<arr.length;i++){
		var img=new Image();
		img.src=folder + arr[i];
	}
}


function showIndique(u){
	loading(true);
	try{
		core.Ajax.get(u,function(o){
					loading(false);
					try{
						//if(o.search("<!-- mceEditor -->")!=-1) loadMCE();
						
						if(o.search("<script>")!=-1) appendScript(o);
						var win = core.window.create({name:'Indique',top:100,content:o,align:'center center',width:480,height:310});
						win.onClose=function(){
							enableRoot();
						}
						disableRoot();
					}catch(e){
					}
						
					});
	}catch(e){
		loading(false);
	}
}

//********************************************LOADING*************************************************//
	
	var objLoadSplash;
	var objLoad;
	function enableRoot(){
		try{
		
		var bl = getElementsByClassName('box_loading');
		for(i=0;i< bl.length;i++){
			document.body.removeChild( bl[i]);
		}
		var ls = getElementsByClassName('loading-plash');
		for(i=0;i< ls.length;i++){
			document.body.removeChild(ls[i]);
		}
		
		}catch(e){
		//alert(e.message);
		}
	}
	
	function getElementsByClassName(name){
		var body = document.body;//first node (root)
		var itens = Array();
		for(i=0;i<body.childNodes.length;i++){
			if(body.childNodes[i].className==name){
				itens.push(body.childNodes[i]);
			}
		}
		return itens;
	}
	function disableRoot(e){
		objLoadSplash=document.createElement('div');
		objLoadSplash.className='loading-plash';
		document.body.appendChild(objLoadSplash); 
		//addEvent('onkeyup',window,disableTabKey);
	}

	function loading(){
		if(arguments[0]==true){
			var label = (arguments[1])? arguments[1] : 'Carregando...';
			objLoad=document.createElement('div');
			objLoad.className='box_loading';
			objLoad.innerHTML="<div class='preloader'></div><div class='label'>"+ label +"</div>";
			this.disableRoot();
			document.body.appendChild(objLoad);
		}else{
			enableRoot();
		}
	}

