var curCropper,errores='';

function buscarObjeto(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=buscarObjeto(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ValidarForma() {
  var i,p,q,nm,test,num,min,max,errors='',args=ValidarForma.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=buscarObjeto(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una direccion de correo electronico.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe contener un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe contener un numero entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es un dato requerido.\n'; }
  } if (errors) alert('Ocurrieron los siguientes errores:\n'+errors);
  document.valorRetorno = (errors == '');
}


//function $(objeto)
//{/
//	return document.getElementById(objeto);
//}



function validarFormularios(formulario)
{
	errores='';
	//alert("Entro");
	var p;
	if(!$ ) return;
	var f = $( formulario );  // Buscar Los Elementos 
for( var i = 0; i < f.elements.length; i++ )  
	{
	//errores+=f.elements[i].type;
	var password;
	f.elements[i].style.background= "#FFFFFF";
	if (f.elements[i].type=='text' || f.elements[i].type=='file' || f.elements[i].type=='password')
	{
		if (f.elements[i].alt=='R')
			{
			if  (f.elements[i].value=="")
				{
				f.elements[i].style.background= "#FFFF99";
				errores+='- ' + f.elements[i].id + ' es un dato necesario<br>'; 
				}
			}
			
		if (f.elements[i].alt=='RNum')
			{
			if  (f.elements[i].value=="")
				{
				f.elements[i].style.background= "#FFFF99";
				errores+='- ' + f.elements[i].id + " es un dato necesario<br>";
				}
			if (isNaN(f.elements[i].value))
				{
				f.elements[i].style.background= "#FFFF99";
				errores+='- '+f.elements[i].id+' debe contener un numero.<br>';  
				}
			}
			
		if (f.elements[i].alt=='REmail')
			{
			if  (f.elements[i].value=="")
				{
				f.elements[i].style.background= "#FFFF99";
				errores+='- ' + f.elements[i].id + " es un dato necesario<br>";
				}
			else
				{
				p=f.elements[i].value.indexOf('@');
				if (p<1 || p==(f.elements[i].length-1)) 
					{
					f.elements[i].style.background= "#FFFF99";
					errores+='- '+f.elements[i].id+' debe contener una direccion de correo electronico.<br>';  
					}
				}
			}
		if (f.elements[i].alt=='RPass')
			{
				if  (f.elements[i].value=="")
				{
				f.elements[i].style.background= "#FFFF99";
				errores+='- ' + f.elements[i].id + " es un dato necesario<br>";
				}
			else
				{
				password=f.elements[i].value;
				}
			}
		if (f.elements[i].alt=='RPass2')
			{
				//errores+=password;
				if  (f.elements[i].value!=password)
				{
					f.elements[i].style.background= "#FFFF99";
					errores+="- El password y la confirmacion del password deben ser identicas<br>";
				}
			}
			else
			{
				
			}
		}
	}
	if (errores) $("resumenErrores").innerHTML='Ocurrieron los siguientes errores:<br><br>'+errores + '<br><br>';
	else
	errores='';
	
}


function deshabilitarFormularios(formulario)
{
	var errores;
	if(!$ ) return;
	var f = $( formulario );  // Buscar Los Elementos 
for( var i = 0; i < f.elements.length; i++ )  
	{
	if (f.elements[i].type=='text'||f.elements[i].type=='select-one'||f.elements[i].type=='checkbox'||f.elements[i].type=='radio')
		{
			f.elements[i].disabled=true;
		}
	}
  document.valorRetorno = (errores == '');
}

function habilitarFormularios(formulario)
{
	var errores;
	if(!$ ) return;
	var f = $( formulario );  // Buscar Los Elementos 
for( var i = 0; i < f.elements.length; i++ )  
	{
	if (f.elements[i].type=='text'||f.elements[i].type=='select-one'||f.elements[i].type=='checkbox'||f.elements[i].type=='radio')
		{
			f.elements[i].disabled=false;
		}
	}
  document.valorRetorno = (errores == '');
}

function appendinputTypeClasses() { 
 if (!document.getElementsByTagName ) 
  return; 
 var inputs = document.getElementsByTagName('input'); 
 var inputLen = inputs.length; 
 for ( i=0;i<inputLen;i++ ) { 
  if ( inputs[i].getAttribute('type')=='text' || inputs[i].getAttribute('type')=='password' || inputs[i].getAttribute('type')=='file') 
  	if (inputs[i].getAttribute('className')==''){
   inputs[i].className = 'text'; 
   }
   //alert("[" + inputs[i].className + "]");
 } 
} 

function togglePanel(idPanel)
{
if ($(idPanel).style.display=='none')
	new Effect.SlideDown(idPanel);
else
	new Effect.SlideUp(idPanel);

}

function togglePanel2(idPanel)
{
if ($(idPanel).style.display=='none')
	$(idPanel).style.display='block';
else
	$(idPanel).style.display='none';

}




AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}


function showAjaxLoader(divContainer,idLoader,claseCSS)
{
	var objCont=$(divContainer);
	var tamano= Element.getDimensions(divContainer);
	var d = document.createElement('DIV');
	d.id=idLoader+"panel";
	d.className="ajaxPanel";
	d.style.width=tamano.width;
	d.style.height=tamano.height;
	var l = document.createElement('DIV');
	l.id=idLoader+"loader";
	l.className=claseCSS;
	l.style.width=tamano.width;
	l.style.height=tamano.height;
	objCont.appendChild(d);
	objCont.appendChild(l);
}

function hideAjaxLoader(idLoader)
{
	Element.remove(idLoader+"panel");
	Element.remove(idLoader+"loader");
}

function cargaTerminada( resp )	
{
hideAjaxLoader('ajaxLoaderDiv');
}

function toggleCheckBox (idCheck)
{
if ($(idCheck).checked==true)
	$(idCheck).checked=false;
else
	$(idCheck).checked=true;
}


function formularioNuevoAspecto(){
var cadena;

cadena="<form name=form1 method=post action=><table width=230 border=0><tr> <td width=66><div align=right>Nombre</div></td> <td width=154><input name=nombreAspecto type=text id=nombreAspecto> </td> </tr><tr>  <td><p align=right>Altura</p></td> <td><input name=altoAspecto type=text id=altoAspecto></td></tr><tr> <td><div align=right>Anchura</div></td><td><input name=anchoAspecto type=text id=anchoAspecto></td></tr><tr> <td><div align=right></div></td><td><input type=submit name=Submit value=Enviar></td></tr></table></form>";
return cadena;
}


var divActivo=null;

function confirm_entry(){
input_box=confirm('Al recordar tu contraseņa la pagina automaticamente iniciara tu sesion incluyendo en computadoras publicas, estas seguro de querer continuar?');
if (input_box==true){ 
	$('mantener').checked=true; 
	}
else{
	$('mantener').checked=false;
	}
}


function newRespuesta(divContainer,idRespuestas)
{
	var objCont=$(divContainer);
	var idResp=$(idRespuestas).value;
	idResp++;
	var d = document.createElement('DIV');
	var l = document.createElement('input');
	l.id="r"+idResp;
	l.name="r"+idResp;
	l.type="text";
	l.size="50";
	d.innerHTML="Respuesta " + idResp + ": "
	d.appendChild(l);
	objCont.appendChild(d);
	$(idRespuestas).value=idResp;
}


function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
	  {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		 {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle    	
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
		 }
	  }
   }
//window.attachEvent("onload", correctPNG);



function formularioContacto(formulario)
{
	alert();
	var errores='';
	if(!$ ) return;
	var f = $( formulario ).getelements();  // Buscar Los Elementos 
for( var i = 0; i < f.length; i++ )  
	{
		
	if (f[i].name!='elementos' && f[i].type!='submit')
		{
		if (i==0)
			{
			$('elementos').value=f[i].name;
			}
		else
			{
			$('elementos').value=$('elementos').value + '|' + f[i].name;
			}
		}
	}
	//alert($('elementos').value);
  document.valorRetorno = (errores == '');
}

function switchTabs(actualTab)
{
	for (x=1;x<5;x++)
		{
		$('specTab'+x).className='';
		$('specTab'+x+'content').className='tabContent';
		}
	$(actualTab+'content').className='description';
	$(actualTab).className='chosen';
}

function thumbImagen(idImagen)
{
	$('div'+idImagen).style.display='block';
	var objImagen=$(idImagen);
	var dimensions = $(idImagen).getDimensions();
	var ancho=$(idImagen).height;
	//dimensions.height;
	var porcen = ((100 * 100) /(ancho))/100 ;
	ancho=$(idImagen).width;
	objImagen.width='100';
	if ($(idImagen).getHeight()>100)
	{
	objImagen.height='100';
	objImagen.width=ancho*porcen;
	}
	
}

function terminarCortarImagen( coords, dimensions ) {
	$( 'corteX1' ).value = coords.x1;
	$( 'corteY1' ).value = coords.y1;
	$( 'corteWidth' ).value = dimensions.width;
	$( 'corteHeight' ).value = dimensions.height;
	$('imgPrev').style.width='100px';
	var porcen = ((100 * 100) /(dimensions.width))/100 ;
	$('imgPrev').style.height=dimensions.height*porcen;
}

function aplicarZoomImagen(idImagen,zoom)
{
	//var objImagen=$(idImagen);
	//curCropper.remove();
	var dimensions = $(idImagen).getDimensions();
	var ancho=dimensions.width;	
	var alto=dimensions.height;
	//alert (dimensions.width);
	
	$(idImagen).width=parseInt(ancho/2);
	$(idImagen).height=parseInt(alto/2);
	new Cropper.ImgWithPreview( 'imagenCrop', {displayOnInit: true, onEndCrop: terminarCortarImagen,minWidth: 100,minHeight: 100,previewWrap:'imgPrev'} );
}

function mostrarPeel()
{
	var d = document.createElement('DIV');
	$('peelMini').style.display='none';
	d.id='peelFlotante';
	d.style.position='absolute';
	d.style.width=800;
	d.style.height=800;
	d.style.zindex=999999;
	d.style.right=0;
	d.style.top=0;
	$('conte').appendChild(d);
	//<div id='peelFlotante' style='position:absolute; right:0px; top:0px; width:800px; height:800px; z-index:99999'>
	var contenido ="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='800' height='800'><param name='movie' value='Peel.swf'><param name='quality' value='high'><param name='menu' value='false'><param name='wmode' value='transparent'><embed src='Peel.swf' width='800' height='800' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' menu='false' wmode='transparent'></embed></object>";
	$('peelFlotante').innerHTML=contenido;
}

function inicializarCalendario(campo,boton,fecha,div)
{
	Calendar.setup({
        inputField     :    campo,   
        ifFormat       :    "%d/%m/%Y",
        button         :    boton,
        step           :    1,
		showsTime	   :	false
    });
}


var color=new Array("333366","333366","333366","444477","555588","666699","7777aa","8888bb","7777aa","666699","555588","444477");

function animarColorTexto(x,div,txt){
	var html="";
	for(i=txt.length-1,j=x;i>=0;i--){
		html="<font color='#"+color[j]+"'>"+txt.charAt(i)+"</font>"+html;
		j+=1;
		if(j==color.length)
			j=0;
	}
	document.getElementById(div).innerHTML=html;
	x=x==color.length-1?0:x+1;
	setTimeout("animarColorTexto("+x+",'"+div+"','"+txt+"')",250);
}

	
function startCallback() {
	//showAjaxLoader("uploadAjaxForm","ajaxLoaderDiv","ajaxLoaderBar");
	return true;
}

function completeCallback(response) {
	// make something useful after (onComplete)
	//document.getElementById('nr').innerHTML = parseInt(document.getElementById('nr').innerHTML) + 1;
	//hideAjaxLoader("ajaxLoaderDiv");
	//alert(response);
	$('#AjaxDiv').html(response);
}
		
function soloNumeros(valor)
{
    if (isNaN(valor))
	{
	window.event.returnValue = false;  
	}			
}

function noinput(){
			window.event.returnValue = false;
		  }
		  
function cambiarMes(fecha)
{
	$('#calendarDiv').load('calendario/calendario.aspx?fecha='+fecha+'&ajax=1');
	
	
}





function mostrarPanelAnuncio(idPanel)
{

	$('#InformacionAnuncio').hide();
	$('#GaleriaAnuncio').hide();
	$('#UbicacionAnuncio').hide();
	switch (idPanel)
	{
		case 3:
				$('#UbicacionAnuncio').show();
				$('#MapaAnuncio').html($('#MapaAnuncioHidden').val());
	}
	
}
