var globalCallbacks = {
	onCreate: function(){ Loading(true, 1) },
	onComplete : function(){ Loading(false, Ajax.activeRequestCount) }
}
window.onerror=function(){return true; }
function Loading(status, activeRequestCount)
{
	if(status)
		$('loadOn').style.display = 'block';
	else
	{
		if (activeRequestCount == 0)
			$('loadOn').style.display = 'none';	
	}
}
//////////////////////////////////////////////////////////////////////////////////
var timeform;
function setContent(container, page, params, method, asyn)
{
	//analytics
	if(!arguments[5])
	{
		var pages = params.split('&');
		var pages_1 = pages[0].split('=');
		if(pages[1]){ var pages_2 = pages[1].split('=');
		var analytics = '/'+pages_1[1]+'/'+pages_2[1]; }
		else var analytics = '/'+pages_1[1];
	}
	else var analytics = '/'+arguments[5];
	try {
	pageTracker._trackPageview(analytics);
	} catch(err) {}
	new Ajax.Updater(container, page, {asynchronous:asyn, parameters:params, method:method, onFailure:setError, evalScripts: true});
}
function irOpcion(container, params)
{
	if(arguments[2])
		setContent(container, 'axpage.php', params, 'get', true, arguments[2]);
	else
		setContent(container, 'axpage.php', params, 'get', true);
	//selMenu(arguments[2]);
}
function selMenu(opc)
{
	var arropc = new Array('quienes');
	var arropcclass = new Array('mn_quienes_off.jpg','mn2','mn3','mn4');
	for(var i=0; i<arropc.length; i++)
		$(arropc[i]).src = "images/menu2/"+arropcclass[i];
	if(opc)
		$(opc).src = "images/menu2/mn_"+opc+"_on.jpg";
}
function formCallback(result, form)
{
	var c_status = form.name+'_estado';
	var c_cuerpo = form.name+'_cuerpo';
	if($(c_status)) var boolStatus = true;
	else var boolStatus = false;
	if(!result)
	{
		if(boolStatus == true){
			new Effect.Appear(c_status);
			$(c_status).innerHTML = 'Hay campos obligatorios sin llenar';
			$(c_status).className = 'validation-advice';
			clearTimeout(timeform);
			timeform = setTimeout("new Effect.Fade('"+c_status+"')",5000);
		}
	}
	else
	{		
		
		if(boolStatus == true){
			new Effect.Appear(c_status);
			$(c_status).innerHTML = 'Los datos han sido validados, el formulario se guardara correctamente';
			$(c_status).className = 'custom-advice';
			window.status = "Los datos han sido validados, el formulario se guardara correctamente";		
		}
		if($('submit')) new Element.hide('submit');
		enviarFormulario(form,$F(c_cuerpo));
	}
}
function formCallbackMaestros(result, form)
{
	if(!result)
	{
		new Effect.Appear('c_maestro_datos');
		$('c_maestro_datos').innerHTML = 'Hay campos obligatorios sin llenar';
		$('c_maestro_datos').className = 'validation-advice';
	}
	else
	{
		new Effect.Appear('c_maestro_datos');
		$('c_maestro_datos').innerHTML = 'Los datos han sido validados, el formulario se guardara correctamente';
		$('c_maestro_datos').className = 'custom-advice';
		window.status = "Los datos han sido validados, el formulario se guardara correctamente";
		enviarFormulario(form,'ax_panel');
	}	
}
function enviarFormulario(form,capa)
{
	if(arguments[2]) var method = arguments[2];
	else var method = form.method;
	var params = Form.serialize($(form));
	var action = $(form).action;
	//alert(capa+", "+action+", "+params+", "+method);
	new Ajax.Updater(capa, action, {asynchronous:true, parameters:params, method:method, onComplete: setRespuesta, evalScripts: true});
}
function setError(resp)
{
	//resp.responseText o resp.responseXML
	alert("Oops, Ha ocurrido en un error.");
}
function setRespuesta(resp)
{
	//resp.responseText o resp.responseXML
}
function chmenu(tipo, obj)
{
	obj.className = 'text_menu_'+tipo;
}
function enlace(url)
{
		alert('s');
	//document.location.href = url;
}
function showObjArray(vecCapa,boolean)
{
	for(i=0; i<vecCapa.length; i++)
	{			
		objC=document.getElementById(vecCapa[i]);
		if(boolean == true)
			objC.style.display='';
		else
			objC.style.display = 'none'
	}
}
function showObjArrayEfecto(enlace,vecCapa,obj)
{
	var bgcolor = "#9DB172";
	for(i=0; i<vecCapa.length; i++)
	{			
		objC=document.getElementById(vecCapa[i]);			
		if(objC.length > 0)
		{
			for(x=0; x<objC.length; x++)
				objC[x].style.display = 'none'
		}
		else
		{
			objC.style.display = 'none';
		}
		document.getElementById(enlace+vecCapa[i]).style.borderBottom = '0px solid';
	}
	objN = document.getElementById(obj);
	objN.style.display='';
	document.getElementById(enlace+obj).style.borderBottom = '3px solid '+bgcolor;
}
function showObj(obj)
{
	if(obj != '[object]')
		obj = document.getElementById(obj);
	if(obj.style.display == 'none')
		obj.style.display='';
	else
		obj.style.display='none';
}
function showObjTrue(obj,boolean)
{
	if(obj != '[object]')
		obj = document.getElementById(obj);
	if(boolean == true)
		obj.style.display='';
	else
		obj.style.display='none';
}
function traerDisplay(obj)
{
	if(obj != '[object]')
		obj = document.getElementById(obj);
	if(obj.style.display == '')
		return true;
	if(obj.style.display == 'none')
		return false;
}
function ms_delete()
{
    return agree = confirm('¿Desea eliminar el registro?');
}
function retirarMenu(div_menu){
   if (document.getElementById(div_menu).style.visibility=="visible")
      document.getElementById(div_menu).style.visibility="hidden";
}
function mostrarMenu(div_menu, upd, del, view, act, inact, varupdate, varview, vardelete, varincativar)
{
   var valores = "";
   var id = 0;
   var eveover = " onMouseOver='menuOver(this, 1);' ";
   var eveout = " onMouseOut='menuOver(this ,0);' ";
   var tabla = "<table style='border:1px solid #999999' width=150 border=0 cellpadding=2 cellspacing=0>"+
   "<tr>"+
    "<td width=70% class='encabezado'>&nbsp;<font size='1'><b>Acciones</b></td>"+
    "<td width=30% class='encabezado' style='cursor:pointer;'><font size='1' onclick='retirarMenu(\""+div_menu+"\")'>"+
   		"<b>Cerrar</b>"+
    "</td>"+
   "</tr>"+
   "<tr>"+
   	"<td colspan=2>"+
		"<table width='100%' border='0' cellpadding='2' cellspacing='0'>";
		if(varupdate == 1) {
		  tabla += "<tr "+eveover+eveout+">"+
			'<td valign="top" onClick="retirarMenu(\''+div_menu+'\');'+upd+';"><font size="1" face="verdana,arial,helvetica" color="black">'+
         		"Modificar"+
			 "</font></td>"+
		  "</tr>";
		}
		if(varview == 1) {		
		  tabla += "<tr "+eveover+eveout+">"+
			'<td valign="top" onClick="retirarMenu(\''+div_menu+'\');'+view+';"><font size="1" face="verdana,arial,helvetica" color="black">'+
         		"Consultar"+
			 "</font></td>"+
		  "</tr>";
		}
		if(vardelete == 1) {
		  tabla += "<tr "+eveover+eveout+">"+
			'<td valign="top" onClick="retirarMenu(\''+div_menu+'\');if(ms_delete()) '+del+';"><font size="1" face="verdana,arial,helvetica" color="black">'+
         		"Eliminar"+
			 "</font></td>"+
		  "</tr>";
		}
		if(varincativar == 1)
		{				
			if(act != "")
			{
				tabla += "<tr "+eveover+eveout+">"+
				'<td valign="top" onClick="retirarMenu(\''+div_menu+'\');if(ms_confirmar(\'activar el registro\')) '+act+';"><font size="1" face="verdana,arial,helvetica" color="black">'+
				"Activar"+
				"</font></td>"+
				"</tr>";
			}
			if(inact != "")
			{
				tabla += "<tr "+eveover+eveout+">"+
				'<td valign="top" onClick="retirarMenu(\''+div_menu+'\');if(ms_confirmar(\'inactivar el registro\')) '+inact+';"><font size="1" face="verdana,arial,helvetica" color="black">'+
				"Inactivar"+
				"</font></td>"+
				"</tr>";
			}				
		}		 
		tabla += "</table>"+
	 "</td>"+
	"</tr>"+
	"</table>";
   var textmenu = tabla;
   document.getElementById(div_menu).innerHTML=textmenu;
   if (document.getElementById(div_menu).style.visibility=="hidden")
      document.getElementById(div_menu).style.visibility="visible"
   else
      document.getElementById(div_menu).style.visibility="hidden"
}
function menuOver(ctr,tipo)
{
	if(tipo == 1)
	{
		ctr.style.background = '#efefef';
		ctr.style.color = "#98AD13";
		ctr.style.cursor = "hand";
	}
	else
	{
		ctr.style.background = "#ffffff";		
		ctr.style.color = "#000000";
		ctr.style.cursor = "default";
	}
}
function flupload(upVar,fsProg,btnAdj,btnCan,divSta,id,rand,destino,input,limit,tipo)
{
	if(tipo == 'images'){
		var fileTypes = "*.jpg;*.jpeg;*.png;*.gif";
		var fileDescription = "Archivos de imagen";
	}
	
	if(document.all) //IE
		var up_url = "includes/swfupload/upload.php?destino="+destino+"&randomi="+rand+"&nameAlt=";
	else //FIREFOX
		var up_url = "upload.php?destino="+destino+"&randomi="+rand+"&nameAlt=";
	
	var settings = {
		flash_url : "includes/swfupload/swfupload.swf?RandID="+rand,
		upload_url: up_url,	// Relative to the SWF file
		post_params: {"PHPSESSID" : id},
		file_size_limit : "2 MB",
		file_types : fileTypes,
		file_types_description : fileDescription,
		file_upload_limit : limit,
		file_queue_limit : 1,
		custom_settings : {
			progressTarget : fsProg,
			cancelButtonId : btnCan,
			statusDIV : divSta,
			ruta: destino,
			input_file: input,
			randomi: rand
		},
		debug: false,
	
		// Button settings
		button_image_url: "includes/swfupload/images/TestImageNoText_65x29.png",	// Relative to the Flash file
		button_width: "67",
		button_height: "29",
		button_placeholder_id: btnAdj,
		button_text: '<span class="theFont">Adjuntar</span>',
		button_text_style: ".theFont { font-size:12;font-family:Arial; }",
		button_text_left_padding: 12,
		button_text_top_padding: 3,
		
		// The event handler functions are defined in handlers.js
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		queue_complete_handler : queueComplete	// Queue plugin event
	};
	eval(upVar+' = new SWFUpload(settings);');
}
function ImprimirCapa(capa, w, h)
{
	var html = $(capa).innerHTML;
   newWindow = window.open("","Imagenes","width="+w+",height="+h+",left=100,top=60,menubar=1,toolbar=1");
   newWindow.document.open();
   newWindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="css/PDigital_Styles.css"><script src="js/functions.js" type="text/javascript"></script></head><body style="margin:0px;">'+ html +'</body></html>');
   newWindow.document.close();
   newWindow.focus();
   // onload="window.print()"
}
function slideshow()
{
	//SLIDE SHOW ---------------------------------------
	var feed  = "http://www.erpip.com/accounts/plazadigital/slideshow_foto.php";
	var options = {
		displayTime:4000, transistionTime:600, scaleImages:true, fullControlPanel: true
	};
	var ss = new GFslideShow(feed, "slideShow", options);
	//*------------------------------------------------
}
function CambiarImagen(identificador, imagen, width, height, identificador2, imagenbig)
{
	identificador.width = identificador.width;
	identificador.heigth = identificador.height; 
	identificador.src = imagen;
	if(imagenbig != ''){
			identificador2.href = imagenbig;
			$('c_ampliar').style.display='';
	}
	else $('c_ampliar').style.display='none';
}
function toggleEditor(id) {
	if (!tinyMCE.get(id))
	tinyMCE.execCommand('mceAddControl', false, id);
	else
	tinyMCE.execCommand('mceRemoveControl', false, id);
}
function openWindow(url, params, method, w, h, theme) {
    new UI.Window({theme:theme, shadow: true, width:w, height:h, activeOnClick:false }).setAjaxContent(url,{asynchronous:true, parameters:params, method:method, onFailure:setError, evalScripts: true}).center().show();
}
function subir(){
	if( document.documentElement.scrollTop < 10 ){
	   window.scrollTo(0,0);
	}else{
	   window.scrollBy(0,-50);
	   setTimeout("subir()",10);
	}
}
function cambiaImg(src)
{
	$('i_big').innerHTML = '<img src="'+src+'" height="417" />';	
}
function abreFoto(foto,w,h)
{
		//,"width="+w+",height="+h+",left=100,top=60,menubar=1,toolbar=1"
   newWindow = window.open("","Imagenes","width="+w+",height="+h+"left=100,top=60");
   newWindow.document.open();
   newWindow.document.write('<html><head><link rel="stylesheet" type="text/css"></head><body style="margin:0px;"><img src="'+ foto +'"></body></html>');
   newWindow.document.close();
   newWindow.focus();
}
document.write('<div id="loadOn">Cargando...</div>');
