function xmlDataReader(){
	this.xmlList = null;
	this.htmlTemplate = null;
	this.xmlObjct = null;
	this.xmlLoadFinishCallBack = null;
	this.loader = 0;
}

xmlDataReader.prototype.load = function(xmlPath, callBack){
	this.xmlLoadFinishCallBack = callBack;
	
	if(xmlPath.indexOf("?") != -1){xmlPath = xmlPath+"&v="+Math.random();}
	else{xmlPath= xmlPath+"?v="+Math.random();}
	
	if (window.XMLHttpRequest)
	{
		this.loader = new XMLHttpRequest();
		this.loader.onreadystatechange = this.xmlLoadFinished;
		this.loader.open("GET",xmlPath,true);
		this.loader.send(null);
	}
		// Procura por uma versão ActiveX (IE)
	else if (window.ActiveXObject)
	{
		this.loader = new ActiveXObject("Microsoft.XMLHTTP");
		if (this.loader)
		{
			this.loader.onreadystatechange = this.xmlLoadFinished;
			this.loader.open("GET",xmlPath,true);
			this.loader.send();
		}
	}
	this.loader.supra = this;
}

xmlDataReader.prototype.xmlLoadFinished = function(){
	// apenas quando o estado for "completado"
	if (this.readyState == 4)
	{
		// apenas se o servidor retornar "OK"
		if (this.status == 200)
		{
			//this.xmlList = this.loader.responseText;
			if(this.supra.xmlLoadFinishCallBack != null){eval(this.supra.xmlLoadFinishCallBack);}
			this.supra.xmlList = this.supra.parseXml(this.responseText);
		}
		else
		{
			alert("Ocorreu um erro ao carregar dados XML.");
		}
	}
	if(this.readyState == 1){
		//
	}
}

xmlDataReader.prototype.parseXml = function(xml){
   var dom = null;
   if (window.DOMParser) {
	  try { 
		 dom = (new DOMParser()).parseFromString(xml, "text/xml"); 
	  } 
	  catch (e) { dom = null; }
   }
   else if (window.ActiveXObject) {
	  try {
		 dom = new ActiveXObject('Microsoft.XMLDOM');
		 dom.async = false;
		 if (!dom.loadXML(xml)) // parse error ..
			window.alert(dom.parseError.reason + dom.parseError.srcText);
	  } 
	  catch (e) { dom = null; }
   }
   else
	  alert("oops");
   return dom;
}

xmlDataReader.prototype.parseXmlTemplate = function(itemRef, div, callBack){
	if(this.xmlList != null){json = xml2json(this.xmlList, " ");}else{alert('XMLNeed to Load First!');return;}
	
	this.xmlObjct = eval('(' + json + ')');
	
	this.htmlTemplate = this.xmlObjct.content.htmlTemplate["#cdata"];
	
	for(var i=0; i < this.xmlObjct.content.item.length; i++){
		if(this.xmlObjct.content.item[i]["@itemRef"] == itemRef){
		
			for(var j=0; j < this.xmlObjct.content.item[i].node.length; j++){
				this.htmlTemplate = this.htmlTemplate.replace(this.xmlObjct.content.item[i].node[j]["@ref"], 
															  this.xmlObjct.content.item[i].node[j]["#cdata"]);
			}
			
		}
	}
	document.getElementById(div).innerHTML = this.htmlTemplate;
	if(callBack != null){callBack();}
}

function showFicha(){
$('.teste').css({'display':'none'});
$('.screenContainer').fadeOut('slow', function(){
		$.smoothScroll({offset: -100});
    	$('.teste').fadeIn('slow',function(){
    	if (jQuery.browser.msie)
    		this.style.removeAttribute('filter');
    	});
    	})  								  
};

function hideFicha(){
$('.teste').fadeOut('slow', function(){
    	$('.teste').css({'display':'none'});
    	$('.screenContainer').fadeIn('slow', function(){
    	if (jQuery.browser.msie)
    		this.style.removeAttribute('filter');
    	});
    	}) 									  
};
