var isExplorer = (navigator.appName.search("Explorer") > 0) ;

function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
/*******************************************************************************************/
function CambiarOrden(script,id,op,filter,value){
 divContenido = document.getElementById('masItems');
 ajax=objetoAjax();
 ajax.open("GET", script+"?id="+id+"&op="+op+"&filter="+filter+"&value="+value);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   $(document).ready( function(){
   divContenido.innerHTML = ajax.responseText
   $('.listado div:even').addClass('alt');
	  $('.listado div').mouseover(function(){
		  $(this).addClass("over");}).mouseout(function(){
		  $(this).removeClass("over");
	  });
	});
  }
 }
 ajax.send(null)
}

function setOrderDB(script,order){
 divContenido = document.getElementById('ajaxResult');
 ajax=objetoAjax();
 ajax.open("GET", script+"?order="+order);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   $(document).ready( function(){
   divContenido.innerHTML = ajax.responseText
   $('.listado div:even').addClass('alt');
	  $('.listado div').mouseover(function(){
		  $(this).addClass("over");}).mouseout(function(){
		  $(this).removeClass("over");
	  });
	});
  }
 }
 ajax.send(null)
}


function setFilter(script,filter,value){
 divContenido = document.getElementById('ajaxResult');
 ajax=objetoAjax();
 ajax.open("GET", script+"?filter="+filter+"&value="+value);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
	$(document).ready( function(){
    divContenido.innerHTML = ajax.responseText;
	$('.listado div:even').addClass('alt');
	  $('.listado div').mouseover(function(){
		  $(this).addClass("over");}).mouseout(function(){
		  $(this).removeClass("over");
	  });
	});
  }
 }
 ajax.send(null)
}

function SubmitQry(scriptname,form){
 var divForm = document.getElementById(form);
 var divContenido = document.getElementById('ajaxResult');
 
 var qry    = divForm.qry.value;
 var filter = divForm.filter.value;
 var valor  = divForm.valor.value;
 if(qry==''){
	divForm.qry.focus();
	jAlert('Debe ingresar texto para buscar','Aviso');
	return false;													  
 }else{
 	ajax=objetoAjax();
	ajax.open("GET", scriptname+"?qry="+qry+"&filter="+filter+"&value="+valor);
	ajax.onreadystatechange=function() {
	  if (ajax.readyState==4) {
	    $(document).ready( function(){
		divContenido.innerHTML = ajax.responseText;
		$('.listado div:even').addClass('alt');
		  $('.listado div').mouseover(function(){
			  $(this).addClass("over");}).mouseout(function(){
			  $(this).removeClass("over");
		  });
		});
	  }
	 }
	ajax.send(null);
 }
}

function pagItem(scriptname,nropagina,qry,filter,value,order){
 var divContenido = document.getElementById('ajaxResult');
 ajax=objetoAjax();
	ajax.open("GET", scriptname+"?pag="+nropagina+"&qry="+qry+"&filter="+filter+"&value="+value+"&order="+order);
	ajax.onreadystatechange=function() {
	  if (ajax.readyState==4) {
		$(document).ready( function(){
		divContenido.innerHTML = ajax.responseText;
		$('.listado div:even').addClass('alt');
		  $('.listado div').mouseover(function(){
			  $(this).addClass("over");}).mouseout(function(){
			  $(this).removeClass("over");
		  });
		});
	  }
	 }
	ajax.send(null);
}

function eliminarItem(scriptname,id,pag,qry,filter,value,order){
	var divContenido = document.getElementById('ajaxResult');
	jConfirm('Desea <b>Eliminar</b> el Item?', 'Confirmar accion', function(r) {
		if(r){
			ajax=objetoAjax();
				ajax.open("GET", scriptname+"?id="+id+"&pag="+pag+"&qry="+qry+"&filter="+filter+"&value="+value+"&order="+order);
				ajax.onreadystatechange=function() {
				if (ajax.readyState==4) {
					$(document).ready( function(){
					divContenido.innerHTML = ajax.responseText;
					$('.listado div:even').addClass('alt');
					  $('.listado div').mouseover(function(){
						  $(this).addClass("over");}).mouseout(function(){
						  $(this).removeClass("over");
					  });
					});
				}
			}
			ajax.send(null);
		}else{
			return false;
		}
	});
}

function EstadoItem(scriptname,id,action,pag,qry,filter,value,order){
	var divContenido = document.getElementById('ajaxResult');
	jConfirm('El item sera <b>'+action+'</b>', 'Confirmar accion', function(r) {
		if(r){
			ajax=objetoAjax();
			ajax.open("GET", scriptname+"?id="+id+"&action="+action+"&pag="+pag+"&qry="+qry+"&filter="+filter+"&value="+value+"&order="+order);
			ajax.onreadystatechange=function(){
				if (ajax.readyState==4) {
					$(document).ready(function(){
					divContenido.innerHTML = ajax.responseText;
					$('.listado div:even').addClass('alt');
					  $('.listado div').mouseover(function(){
						  $(this).addClass("over");}).mouseout(function(){
						  $(this).removeClass("over");
					  });
					});
				}
			}
			ajax.send(null);
		}else{
			return false;
		}
	});
}

/*******************************************************************************************/

function checkUsername(usercheck){
	
	divContenido = document.getElementById('ajaxResultCheckUser');
	ajax=objetoAjax();
	ajax.open("GET", "ax_checkUsername.php?usuario="+usercheck);
	ajax.onreadystatechange=function() {
	if (ajax.readyState==4) {
		divContenido.innerHTML = ajax.responseText;
	}
	}
	ajax.send(null);
}

function getDatosCliente(idAnuncio){
	var divContenido = document.getElementById('axDatosCliente');
	
	if(idAnuncio == 'otro'){
		AgregarAnuncioFRM();
		DisplayDiv('axDatosCliente','none');
	}else{
		mostrardiv('cargando');
		DisplayDiv('axDatosCliente','block');
		ajax=objetoAjax();
		ajax.open("GET", "axDatosCliente.php?idAnuncio="+idAnuncio);
		ajax.onreadystatechange=function() {
		  if (ajax.readyState==4) {
			ocultardiv('cargando');
			divContenido.innerHTML = ajax.responseText;
		  }
		}
		ajax.send(null);
	}
}

/***********************************************************************************************************************
											Funciones Standard
***********************************************************************************************************************/


function AbrirVentanaCentrada(theURL, winName, features, myWidth, myHeight, isCenter) { 
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features = 'left='+myLeft+', top='+myTop;
  }
  if(isExplorer){
	window.open(theURL,"",'width='+myWidth+', height='+myHeight);
  }else{
  	window.open(theURL, winName, features+((features!='')?',':'')+'width='+myWidth+', height='+myHeight);
  }
}
function goToURI(uri,param){
	if(param != 'false'){
		window.location.href = uri+'?param='+param;
	}else{
		window.location.href = uri;
	}
}
function mostrardiv(id){
	var n4 = (document.layers)? true:false;
 	var ie = (document.all)? true:false;
 	var n6 = (document.getElementById)? true:false;
		
	 	if (n4){
            document.ventana.document.layers[id].display = "block";
		}else if (ie){
            document.all[id].style.display = "block";
		}else if (n6){
            document.getElementById(id).style.display = "block";
		}else{
			document.getElementById(id).style.display = "block";
		}
}
function ocultardiv(id){
	var n4 = (document.layers)? true:false;
 	var ie = (document.all)? true:false;
 	var n6 = (document.getElementById)? true:false;
		
	 	if (n4)
            document.ventana.document.layers[id].display = "none";
     	else if (ie)
            document.all[id].style.display = "none";
        else if (n6)
            document.getElementById(id).style.display = "none";
		else
			document.getElementById(id).style.display = "none";
}