function Validar(Obj) { 
	if(Obj.value == ''){
		return false;
	}
	else{
		return true;
	}
}

function openPopup(u,n,w,h,o,c){
  var l = t = 18; 
 if(c){
   l=(screen.availWidth-w)/2;
   t=(screen.availHeight-h)/2;
 }
 p=window.open(u,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=1'+((o)?','+o:''));
}

function ampliaFoto(tipo, index){
  openPopup('foto_'+tipo+'_'+index+'.html','foto', 450, 250, 'scrollbars=0', 1); 
}

function trimString(str){
  str=this!=window?this:str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function adEvento(tO, tE, tF, tPs) { //2.0 - tObject, tEvent, tFunction, tParams
  var tnF=(tPs) ? function(e) { tF.apply(tO, Array(e).concat(tPs)); } : tF;
  if (tO.addEventListener) { tO.addEventListener(tE, tnF, true); return true; }
  else if (tO.attachEvent) { return tO.attachEvent('on'+tE, tnF); }
  else { /* alert('Erro!'); */ return false; }
}

function pl(e, u){parent.location=u;}

function submitForm(e, f, a, obl){if(DFckForm(f,obl)){f.action=a;f.submit();}}

function getSrc(e) { /* event */ return (e.target) ? e.target : (window.event && event.srcElement) ? event.srcElement : false; }

function delImage(id){
		if(confirm('Confirma a exclusão da imagem?')){
  		var d=new Date(),url="delImage.php?idImage="+id+"&t="+ d.getSeconds();
  		xmlHttp.open('GET', url, true);
  		xmlHttp.onreadystatechange=removeImageTag(id);
  		xmlHttp.send(null);
		}
}

function removeImageTag(id){
	 if (xmlHttp.readyState == 4)
	 getElm('boxImages').removeChild(getElm('img'+id));
}

function newXmlHttpObject() {
    if(window.XMLHttpRequest){
       xmlHttp = new XMLHttpRequest();
    }else{
	   try{
	      xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
	   }catch(e){
		  try{
		     xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		  }catch(e){
		     xmlHttp = null;
		  }
	   }
   }   
   return xmlHttp;
}

function popularCombo(){
	if (xmlHttp.readyState == 4){
		var xmlResp = xmlHttp.responseXML.documentElement;
		var elItem = xmlResp.getElementsByTagName('item');
		if (elItem){
			for (i = 0; i < elItem.length; i++) {
				var id = elItem[i].getAttribute('idItem');
				var path = elItem[i].getAttribute('path');
				getElm('selTexto').options.add(new Option(path, id));
			}
		} 
	}
}

function getInfo(idItem){
	var d=new Date(),url="list_item.php?idItem="+idItem+"&t="+ d;
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange=popularFormTexo;
	xmlHttp.send(null);
}

function popularFormTexo(){
	getElm('boxForm').style.display='';
	if (xmlHttp.readyState == 4){
		var xmlResp = xmlHttp.responseXML.documentElement;
		var elTexto = xmlResp.getElementsByTagName('textos');
		if(elTexto[0])
		{
				getElm('dscItem').value = elTexto[0].getElementsByTagName('item')[0].getElementsByTagName('dscItem')[0].firstChild.data;
				getElm('dscTexto').value = elTexto[0].getElementsByTagName('item')[0].getElementsByTagName('dscTexto')[0].firstChild.data;
		}
		else
		{
				getElm('dscItem').value = "";
				getElm('dscTexto').value = "";
		}
	}
}

function removeItem(e){
	f=getElm('frm');
	if(confirm('confirma a exclusão do item?')){
		if(DFckForm(f,true)){
			f.action='action.do';//action q exclui o item
			f.submit();
		}
	}
}

function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
   
   // ie 4.5 and 5.0 mac - windows are 2 pixels too short; if a statusbar is used, the window will be an additional 15 pixels short
   var agent = navigator.userAgent.toLowerCase();
   if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
      height += (status) ? 17 : 2;
   }

   // Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
   width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;

   var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
   var reference = openWindow(url, name, properties, openerName);
   
   // resize window in ie if we can resize in ns; very messy
   // commented out because openPositionedWindow() doesn't set the resizable attribute
   // left in for reference
   /*if (resizable && agent.indexOf("msie") != -1) {
      if (agent.indexOf("mac") != -1) {
         height += (status) ? 15 : 2;
         if (parseFloat(navigator.appVersion) > 5) width -= 11;
      }
      else {
         height += (status) ? 49 : 31;
         width += 13;
      }
      setTimeout('if (reference != null && !reference.closed) reference.resizeTo(' + width + ',' + height + ');', 150);
   }*/

   return reference;
}


// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
   var width = 600;
   var height = 300;
   var name = "pop";
   var status = 0;
   var scrollbars = 0;
   var x, y = 0;
   if (screen) {
      x = (screen.availWidth - width) / 2;
      y = (screen.availHeight - height) / 2;
   }
   if (!status) status = '';
   if (!openerName) openerName = '';
   var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
}   

// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {

   // ie4.x pc can't give focus to windows containing documents from a different domain
   // in this case, initially load a local interstisial page to allow focussing before loading final url
   var agent = navigator.userAgent.toLowerCase();
   if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
      winReference = window.open('about:blank', name, properties);
      
      setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
   }
   else {
      winReference = window.open(url, name, properties);
   }

   // ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
   setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
   
   if (openerName) self.name = openerName;
   return winReference;
}