function toggleDisplay(objeto) {  
	var objVisible = document.getElementById(objeto);
	var estVisible = objVisible.style.display;	
	if (estVisible == "none") {
		objVisible.style.display = "block";
	} else {
		objVisible.style.display = "none";
	}	
}

/* AJAX */
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 	try {
 		 xmlhttp = new XMLHttpRequest();
 	} catch (e) {
 		 xmlhttp=false;
 	}
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
if (!xmlhttp){
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
}
@end @*/


function creaAjax(){
         var objetoAjax=false;
         try {
          /*OTROS NAVEGADORES INTERNET*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*EXPLORER*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}

var please_wait = '<div style="width:100%; text-align:center; vertical-align:middle;"><img src="http://www.28sport.com/images/ajax_loader.gif">';


function ajax(url, targetId) {
  if(!xmlhttp)return false;
    var e=document.getElementById(targetId);if(!e)return false;
    if(please_wait)e.innerHTML = please_wait;
    xmlhttp.open("GET", url, true);

    xmlhttp.onreadystatechange = function() { response(url, e); }
	try{

      xmlhttp.send(null);
    }catch(l){
    while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
    e.appendChild(document.createTextNode("request failed"));
  }
}

function confirmar(url, targetId, objeto){
con=confirm("¿Seguro que desea borrar?\nEstá acción no puede deshacerse!"); 
 	if(con){
 		ajax(url, targetId);
		if(objeto){
 			toggleDisplay(objeto);
		}
	}else{
		return;  
	}
}

function destacar(url, targetId, objeto){
con=confirm("Confirma que desea destacar?"); 
 	if(con){
 		ajax(url, targetId);
		if(objeto){
 			toggleDisplay(objeto);
		}
	}else{
		return;  
	}
}

function response(url, e) {
  if(xmlhttp.readyState != 4)return;
    var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "<table width='90%' height=''><tr><td align='center' valign='middle'>No se encuentra la pagina solicitada</td></tr><tr><td align='center' valign='middle'>" + xmlhttp.status+" "+xmlhttp.statusText+"</td></tr></table>";
    var d=document.createElement("div");
    d.innerHTML=tmp;
    
	setTimeout(function(){
	while(e.firstChild)e.removeChild(e.firstChild);
	e.appendChild(d);}
	,10);
}

/* VALIDADORES */

function addModelo(){
ok=true

if (document.addModelo.modeloesp.value=="") { que = "Debe llenar el campo Nombre"; ok=false; 
};
if (ok!=false) {
	document.addModelo.submit();
}else{
	alert (que);
}
return ok;
}

function val_producto(){
ok=true

if (document.producto.codigo.value=="") { que = "Debe llenar el campo Codigo"; ok=false; 
}else if 
	(document.producto.idcategoria.value=="0") { que = "Debe selecionar una categoria"; ok=false;
};
if (ok!=false) {
	document.producto.submit();
}else{
	alert (que);
}
return ok;
}

function val_ModeloUnico(){
ok=true

if (document.modeloUnico.codigo.value=="") { que = "Debe llenar el campo Codigo"; ok=false; 
}else if 
	(document.modeloUnico.archivo.value=="0") { que = "Debe agregar una imagen"; ok=false;
};
if (ok!=false) {
	document.modeloUnico.submit();
}else{
	alert (que);
}
return ok;
}

function validar_archivo(){
ok=true

if (document.archivoProgress.tituloarchivoeng.value=="") {
que = "Debe llenar el campo Titulo";
ok=false;
};
	if (ok!=false) {
		document.archivoProgress.submit();
	}else{
		alert (que);
	}
return ok;
}


function validar_archivo_subir(){
ok=true

if (document.arc.Nombre.value=="") {
que = "Debe llenar el campo Nombre";
ok=false;
}else if (document.arc.userfile.value=="") {
que = "Debe elegir un archivo a subir";
ok=false;
}
	if (ok!=false) {
		document.arc.submit();
	}else{
		alert (que);
	}
return ok;
}

function val_local(){
ok=true

if (document.local.nombre.value=="") {
que = "Debe llenar el campo nombre";
ok=false;
} else if (document.local.ciudad.value=="") {
que = "Debe llenar el campo ciudad";
ok=false;
}
	if (ok!=false) {
		document.local.submit();
	}else{
		alert (que);
	}
return ok;
}

function val_prensaA(){
ok=true

if (document.prensa.tituloesp.value=="") {
que = "Debe llenar el campo Titulo Esp";
ok=false;
} else if (document.prensa.archivo.value=="") {
que = "Debe subir un archivo";
ok=false;
}
	if (ok!=false) {
		document.prensa.submit();
	}else{
		alert (que);
	}
return ok;
}

function val_prensaM(){
ok=true

if (document.prensa.tituloesp.value=="") {
que = "Debe llenar el campo Titulo Esp";
ok=false;
};
	if (ok!=false) {
		document.prensa.submit();
	}else{
		alert (que);
	}
return ok;
}


function val_archivo(){
ok=true

if (document.archivoEdit.tituloarchivo.value=="") {
que = "Debe llenar el campo título";
ok=false;
}else if (document.archivoEdit.tituloarchivoeng.value=="") {
que = "Debe llenar el campo título en inglés";
ok=false;
}
	if (ok!=false) {
		document.archivo.submit();
	}else{
		alert (que);
	}
return ok;
}
