﻿// JavaScript Document
function resetButtons(){
	$('bt12').style.display=$('bt22').style.display=$('bt32').style.display=$('bt42').style.display=$('bt52').style.display='none';
	$('bt1').style.display=$('bt2').style.display=$('bt3').style.display=$('bt4').style.display=$('bt5').style.display='block';
	$('bt1').style.zIndex=$('bt2').style.zIndex=$('bt3').style.zIndex=$('bt4').style.zIndex=$('bt5').style.zIndex='5';
	$('bt12').style.zIndex=$('bt22').style.zIndex=$('bt32').style.zIndex=$('bt42').style.zIndex=$('bt52').style.zIndex='12';
}
function ocultarPosteriores(n){
	for(var i=n+1;i<6;i++){
		$('bt'+i).style.display='none';
	}	
}
function pngFix(img){
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && typeof window.XMLHttpRequest=='undefined')
      {
         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='crop');\"></span>" 
         img.outerHTML = strNewHTML
      }	
}
function cubrir(id){
	$(id).cobertura=document.createElement('div');
	$(id).cobertura.style.position='absolute';
	var pos=getElementPositionRelativeTo.call($(id),$('izquierda'));
	$(id).cobertura.style.left=pos.left+'px';
	$(id).cobertura.style.top=pos.top+'px';
	$(id).cobertura.style.zIndex=10;
	$(id).cobertura.style.width=$(id).offsetWidth+'px';
	$(id).cobertura.style.height=$(id).offsetHeight+'px';
	$(id).cobertura.style.backgroundColor='#caf6f7';
	panino.getO($(id).cobertura).alfa(.4);
	$(id).parentNode.appendChild($(id).cobertura);
}
function descubrir(id){
	try{$(id).parentNode.removeChild($(id).cobertura);}catch(err){}
}
function clearTools(){
	for(var i=0,l=nameSpace1.imPersonas.length;i<l;i++)	{	  
		removeTool.call($('p'+nameSpace1.imPersonas[i].id));
	}
	for( i=0,l=nameSpace1.imGlobos.length;i<l;i++)	{	  
		removeTool.call($('g'+nameSpace1.imGlobos[i].id));
	}
	$('verquittools').checked=1;
}
function getElementPositionRelativeTo(contenedor) {
		var offsetTrail = this;
		var offsetLeft = 0;
		var offsetTop = 0;
		while (offsetTrail && offsetTrail!=contenedor) {
			offsetLeft += offsetTrail.offsetLeft;
			offsetTop += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		return {left:offsetLeft, top:offsetTop};
}
var Dragable={
		makeDragable:function (){
		this.style.cursor='move';
		
		var o=panino.getO(this);
		var pos=getElementPositionRelativeTo.call(o,o.parentNode);
		o.style.position='absolute';
		o.style.top=pos.top+'px';
		o.style.left=pos.left+'px';
		this.addEvent('mousedown',
				 function(e){
					panino.act=this;
					e=e || window.event; 
        			cancelEvent(e); 
        			stopEvent(e); 
        			this.cx0=e.clientX; 
        			this.cy0=e.clientY; 
        			this.ox=parseInt(o.style.left) || 0; 
        			this.oy=parseInt(o.style.top) || 0;
					panino.getO(document).addEvent('mousemove',function(e){if(panino.act)panino.act.arrastrar(e);});
					panino.getO(document).addEvent('mouseup',function(e){if(panino.act)panino.act.soltar(e);});
				 }
		);
		return this;
	},
	arrastrar:function(e){
		e=e || window.event;
		clearSelection();
		var o=panino.getO(this);
        cancelEvent(e); 
        stopEvent(e); 
        o.style.left=this.ox-this.cx0+e.clientX+'px'; 
        o.style.top=this.oy-this.cy0+e.clientY+'px'; 
		if(parseInt(o.style.left)<13)o.style.left=13+'px';
		if(parseInt(o.style.top)<13)o.style.top=13+'px';
		if(parseInt(o.style.left)>$('canvas').offsetWidth-o.offsetWidth-13)o.style.left=$('canvas').offsetWidth-o.offsetWidth-13+'px';
		if(parseInt(o.style.top)>$('canvas').offsetHeight-o.offsetHeight-13)o.style.top=$('canvas').offsetHeight-o.offsetHeight-13+'px';
		return this;
	},
	soltar:function(e){
		e=e || window.event; 
        cancelEvent(e); 
        stopEvent(e); 
       	panino.getO(document).removeEvent('mousemove',function(e){if(panino.act)panino.act.arrastrar(e);});
		panino.getO(document).removeEvent('mouseup',function(e){if(panino.act)panino.act.soltar(e);});
		panino.act=null;
		return this;
	},
	finalPosition:function(){
		return {x:parseInt(this.style.left),y:parseInt(this.style.top)}
	}
	
}
panino.add(Dragable);
function addTools(e){
	stopEvent(e); 
	this.style.border='1px dashed #FFF';
	if(!this.del){
		var del=document.createElement('img');
		this.del=del;
		del.src='icons/delete.png';
		del.style.cursor='pointer';
		del.style.position='absolute';
		del.style.top='-8px';
		del.style.left=this.img.offsetWidth-8+'px';
		del.title='Eliminar';
		del.onclick=function(){this.parentNode.parentNode.removeChild(this.parentNode);
			for(var i=0,l=nameSpace1.imPersonas.length;i<l;i++){
				if(this.parentNode.img==nameSpace1.imPersonas[i]){
					nameSpace1.imPersonas.splice(i,1);
				}	
			}
			ctrlChecks();
		}
		this.appendChild(del);
		var flip=document.createElement('img');
		this.flip=flip;
		flip.src='images/flip.png';
		flip.style.cursor='pointer';
		flip.style.position='absolute';
		flip.style.top='-8px';
		flip.style.left='-8px';
		flip.title='Invertir';
		flip.onclick=function(){
			for(var i=0,l=nameSpace1.imPersonas.length;i<l;i++){
				if(this.parentNode.img==nameSpace1.imPersonas[i]){
					if(nameSpace1.imPersonas[i].src.indexOf('_flip')!=-1){
						nameSpace1.imPersonas[i].src=this.parentNode.img.src=nameSpace1.imPersonas[i].src.split('_flip').join('');
					}else{
						nameSpace1.imPersonas[i].src=this.parentNode.img.src=nameSpace1.imPersonas[i].src.split('.png').join('_flip.png');
					}
					if(typeof window.XMLHttpRequest !='undefined')
						this.parentNode.getElementsByTagName('img')[0].src=this.parentNode.img.src;
					else{
						var strNewHTML = "<span " + " style=\"" + "display:inline-block;width:" + this.parentNode.img.offsetWidth + "px; height:" + this.parentNode.img.offsetHeight + "px;" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" +  this.parentNode.img.src + "\', sizingMethod='crop');\"></span>" 
         				this.parentNode.getElementsByTagName('span')[0].outerHTML = strNewHTML;
					}
						
					
				}	
			}
		}
		this.appendChild(flip);
	}else{
		this.del.style.display='inline';
		if(this.flip && this.flip.style)
			this.flip.style.display='inline';
	}
}
function addTools2(e){
	stopEvent(e); 
	this.style.border='1px dashed #FFF';
	if(!this.del){
		var del=document.createElement('img')
		this.del=del;
		del.src='icons/delete.png';
		del.style.cursor='pointer';
		del.style.position='absolute';
		del.style.top='-8px';
		del.style.left=this.img.offsetWidth-8+'px';
		del.title='Eliminar';
		del.onclick=function(){this.parentNode.parentNode.removeChild(this.parentNode);
			for(var i=0,l=nameSpace1.imGlobos.length;i<l;i++){
				if(this.parentNode.img==nameSpace1.imGlobos[i]){
					nameSpace1.imGlobos.splice(i,1);
				}	
			}
			ctrlChecks();
		}
		this.appendChild(del);
	}else{
		this.del.style.display='inline';
	}
}
function removeTool(){
	if(!this.style || !this.del)
		return;
	this.style.border='none';
	this.del.style.display='none';
	if(this.flip && this.flip.style)
		this.flip.style.display='none';
}
var nameSpace1={}
nameSpace1.imPersonas=[];
nameSpace1.imGlobos=[];
function posicionarGlobo(im){
	if(nameSpace1.imGlobos.length>=1){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:91%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px; overflow:hidden;">	<img src="images/dialog-warning.png" width="48" style="margin:5px; width:48px;" height="48" /><span style="position:relative; top:-50px; left:58px;display:block; width:320px; overflow:hidden;">Ya seleccionaste la cantidad m&aacute;xima de di&aacute;logos permitida.<br />Para agregar uno nuevo primero tendr&aacute;s que borrar el que hayas seleccionado antes.</span></div>';restaurarTools();
		return;
	} 
	if(in_array(im,nameSpace1.imGlobos)){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:90%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px; overflow:hidden;">	<img src="images/dialog-warning.png" width="48" style="margin:5px; width:48px;" height="48" /><span style="position:relative; top:-33px; left:58px;display:block; width:320px; overflow:hidden;">Ya seleccionaste este di&aacute;logo.</span></div>';restaurarTools();
		return;
	}
	nameSpace1.imGlobos.push(im);
	var globo=document.createElement('div');
	globo.onclick=function(e){addTools2.call(globo,e);};
	globo.style.position='relative';
	globo.style.width=(im.width || im.offsetWidth)+'px';
	globo.style.height=(im.height || im.offsetHeight)+'px';
	globo.style.position='absolute';
	globo.style.top=($('canvas').offsetHeight-im.offsetHeight)-Math.floor(($('canvas').offsetHeight-im.offsetHeight)*Math.random())+'px';
	globo.style.left=($('canvas').offsetWidth-im.offsetWidth)-Math.floor(($('canvas').offsetWidth-im.offsetWidth)*Math.random())+'px';
	if(parseInt(globo.style.left)<13)globo.style.left=13+'px';
	if(parseInt(globo.style.top)<13)globo.style.top=13+'px';
	if(parseInt(globo.style.left)>$('canvas').offsetWidth-im.offsetWidth-13)globo.style.left=$('canvas').offsetWidth-im.offsetWidth-13+'px';
	if(parseInt(globo.style.top)>$('canvas').offsetHeight-im.offsetHeight-13)globo.style.top=$('canvas').offsetHeight-im.offsetHeight-13+'px';
	globo.img=im;
	globo.style.zIndex=getNextHighestDepth();
	globo.id='g'+im.id;
	
	var i=document.createElement('img');
	i.src=im.src;
	globo.appendChild(i);
	addTools2.call(globo);
	$('canvas').appendChild(globo);
	$(globo.id).makeDragable();
	pngFix($(globo.id).getElementsByTagName('img')[0])
	if(nameSpace1.imGlobos.length==1){
		descubrir('bt4');
		resetButtons();$('ch3').style.display='block';
	}
	
}
function in_array(el,arr){
	for(var i in arr){
		if(arr[i]==el)
			return true;
	}	
	return false;
}
function posicionarPerson(im){
	
	if(nameSpace1.imPersonas.length>=2){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:91%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px; overflow:hidden;">	<img src="images/dialog-warning.png" width="48" style="margin:5px; width:48px;" height="48" /><span style="position:relative; top:-50px; left:58px;display:block; width:320px; overflow:hidden;">Ya seleccionaste la cantidad m&aacute;xima de personajes permitida.<br />Para agregar uno nuevo primero tendr&aacute;s que borrar alguno de los que hayas seleccionado antes.</span></div>';restaurarTools();
		return;
	} 
	if(in_array(im,nameSpace1.imPersonas)){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:90%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px; overflow:hidden;">	<img src="images/dialog-warning.png" width="48" style="margin:5px; width:48px;" height="48" /><span style="position:relative; top:-33px; left:58px;display:block; width:320px; overflow:hidden;">Ya seleccionaste este personaje.</span></div>';restaurarTools();
		return;
	}
	nameSpace1.imPersonas.push(im);
	var globo=document.createElement('div');
	globo.style.position='relative';
	globo.onclick=function(e){addTools.call(globo,e);};
	globo.style.width=(im.width || im.offsetWidth)+'px';
	globo.style.height=(im.height || im.offsetHeight)+'px';
	globo.style.position='absolute';
	globo.style.top=($('canvas').offsetHeight-im.offsetHeight)-Math.floor(($('canvas').offsetHeight-im.offsetHeight)*Math.random())+'px';
	globo.style.left=($('canvas').offsetWidth-im.offsetWidth)-Math.floor(($('canvas').offsetWidth-im.offsetWidth)*Math.random())+'px';
	if(parseInt(globo.style.left)<13)globo.style.left=13+'px';
	if(parseInt(globo.style.top)<13)globo.style.top=13+'px';
	if(parseInt(globo.style.left)>$('canvas').offsetWidth-im.offsetWidth-13)globo.style.left=$('canvas').offsetWidth-im.offsetWidth-13+'px';
	if(parseInt(globo.style.top)>$('canvas').offsetHeight-im.offsetHeight-13)globo.style.top=$('canvas').offsetHeight-im.offsetHeight-13+'px';
	globo.style.zIndex=getNextHighestDepth();
	globo.id='p'+im.id;
	var i=document.createElement('img');
	globo.img=im;
	i.src=im.src;
	globo.appendChild(i);
	
	addTools.call(globo);
	$('canvas').appendChild(globo);
	$(globo.id).makeDragable();
	pngFix($(globo.id).getElementsByTagName('img')[0]);
	if(nameSpace1.imPersonas.length==2){
		descubrir('bt3');
		resetButtons();
		$('ch2').style.display='block';
	}
	
}
function defineEscenario(im){
	$('derecha').style.background='url('+im+') 5px 5px no-repeat';
	nameSpace1.kanvas=im;
	descubrir('bt2');
	resetButtons();
	$('ch1').style.display='block';
	
}
function restaurarTools(){
		var col=$('canvas').getElementsByTagName('img');
		for(var i=0,l=col.length;i<l;i++){
			if(nameSpace1.imPersonas[0] && col[i].src==nameSpace1.imPersonas[0].src){
				addTools.call(col[i].parentNode);
			}
			if(nameSpace1.imPersonas[1] && col[i].src==nameSpace1.imPersonas[1].src){
				addTools.call(col[i].parentNode);
			}
			if(nameSpace1.imGlobos[0] && col[i].src==nameSpace1.imGlobos[0].src){
				addTools2.call(col[i].parentNode);
			}
		}
		if(typeof window.XMLHttpRequest=='undefined'){
			col=$('canvas').getElementsByTagName('span');
			l=col.length;
			for(i=0;i<l;i++){
					if(col[i].id && col[i].id.indexOf('g')!=-1)
						addTools2.call(col[i].parentNode);
					else
						addTools.call(col[i].parentNode);
			}
		}
		$('verquittools').checked=0;
}
function ctrlChecks(){
	if(nameSpace1.imPersonas.length<2){
		$('ch4').style.display='none';
		$('ch2').style.display='none';
	}
	if(nameSpace1.imGlobos.length<1){
		$('ch4').style.display='none';
		$('ch3').style.display='none';
	}
	if($('area').value.length<3){
		$('ch4').style.display='none';
	}
}
function validar(){
	clearTools();
	if(nameSpace1.imPersonas.length<2){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:80%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px"><img src="images/dialog-warning.png" width="48" style="margin:5px" height="48" /><span style="position:relative; top:-25px">Deb&eacute;s seleccionar <span style="color:red; font-weight:bold">2</span> personajes.</span></div>';
		$('ch4').style.display='none';
		$('ch2').style.display='none';
		restaurarTools();
		return false;
	}
	if(nameSpace1.imGlobos.length<1){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:90%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px; overflow:hidden;">	<img src="images/dialog-warning.png" width="48" style="margin:5px; width:48px;" height="48" /><span style="position:relative; top:-33px; left:58px;display:block; width:320px; overflow:hidden;">Deb&eacute;s seleccionar un di&aacute;logo para tus personajes.</span></div>';
		$('ch4').style.display='none';
		$('ch3').style.display='none';
		restaurarTools();
		return false;
	}
	if($('area').value.length<3){
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:90%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px; overflow:hidden;">	<img src="images/dialog-warning.png" width="48" style="margin:5px; width:48px;" height="48" /><span style="position:relative; top:-33px; left:58px;display:block; width:320px; overflow:hidden;">Por favor escrib&iacute; tu mensaje.</span></div>';
		$('ch4').style.display='none';
		restaurarTools();
		return false;
	}
	return true;
}
function fbs_click(u,t){
	if(t)
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	else
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
	}
function twitter_click(u,t){
	window.open('http://twitter.com/home?status='+encodeURIComponent(t)+' '+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=900,height=436,scrollbars=yes');return false;
} 
function validateData(){
	$('ch5').style.display='block';
	if($('nombre').value.length<2){
		$('ch5').style.display='none';
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:80%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px"><img src="images/dialog-warning.png" width="48" style="margin:5px" height="48" /><span style="position:relative; top:-25px">Por favor completá el campo nombre.</span></div>';
		return false;
	}	
	if($('apellido').value.length<2){
		$('ch5').style.display='none';
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:80%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px"><img src="images/dialog-warning.png" width="48" style="margin:5px" height="48" /><span style="position:relative; top:-25px">Por favor completá el campo apellido.</span></div>';
		return false;
	}	
	if($('email').value.length<2 || $('email').value.indexOf('@')==-1 || $('email').value.indexOf('.')==-1){
		$('ch5').style.display='none';
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:80%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px"><img src="images/dialog-warning.png" width="48" style="margin:5px" height="48" /><span style="position:relative; top:-25px">Por favor completá el campo e-mail.</span></div>';
		return false;
	}
	if($('ano').value.length<1 || $('mes').value.length<1 || $('dia').value.length<1 || isNaN($('ano').value) ||  isNaN($('mes').value) ||  isNaN($('dia').value)){
		$('ch5').style.display='none';
		ventana(400,130);$('exifr').innerHTML='<div style="background:#FFF; width:80%; height:80%; font-family: Verdana, Geneva, sans-serif; color:#333; font-size:11px; position:absolute; top:25px"><img src="images/dialog-warning.png" width="48" style="margin:5px" height="48" /><span style="position:relative; top:-25px">Por favor completá tu fecha de nacimiento.</span></div>';
		return false;
	}	
	return true;
}
addLoadEvent(
	function(){
		$('bt1').addEvent('click',function(){resetButtons();ocultarPosteriores(1);this.style.display='none';$('bt12').style.display='block';});
		$('zactbt12').addEvent('click',resetButtons);
		
		
		$('bt2').addEvent('click',function(){resetButtons();ocultarPosteriores(2);this.style.display='none';$('bt22').style.display='block';});
		$('zactbt22').addEvent('click',resetButtons);
		
		$('bt3').addEvent('click',function(){resetButtons();ocultarPosteriores(3);this.style.display='none';$('bt32').style.display='block';});
		$('zactbt32').addEvent('click',resetButtons);
		
		$('bt4').addEvent('click',function(){resetButtons();ocultarPosteriores(4);this.style.display='none';$('bt42').style.display='block';});
		$('zactbt42').addEvent('click',resetButtons);
		
		$('bt5').addEvent('click',function(){resetButtons();ocultarPosteriores(5);this.style.display='none';$('bt52').style.display='block';});
		$('zactbt52').addEvent('click',resetButtons);
		
		
		cubrir('bt2');
		cubrir('bt3');
		cubrir('bt4');
		cubrir('bt5');
		window.personajes=$('precarga').getElementsByTagName('img');
		window.globos=$('precarga2').getElementsByTagName('img');
		$('canvas').addEvent('click',clearTools);
		$('area').value='';
		
		$('enviar0').hover(function(){this.style.background='url(images/continuar_over.jpg) no-repeat';},function(){this.style.background='url(images/continuar.jpg) no-repeat';});
			
		$('enviar').hover(function(){this.style.background='url(images/enviar_over.jpg)';},function(){this.style.background='url(images/enviar.jpg)';});
		$('enviar0').addEvent('click',function(){if(validar()){
	var fpp1=$('p'+nameSpace1.imPersonas[0].id).finalPosition();
	var fpp2=$('p'+nameSpace1.imPersonas[1].id).finalPosition();
	var fpg=$('g'+nameSpace1.imGlobos[0].id).finalPosition();
	var personaje1='{"src":"'+nameSpace1.imPersonas[0].src+'","x":'+fpp1.x+',"y":'+fpp1.y+'}';
	var personaje2='{"src":"'+nameSpace1.imPersonas[1].src+'","x":'+fpp2.x+',"y":'+fpp2.y+'}';
	var globo='{"src":"'+nameSpace1.imGlobos[0].src+'","x":'+fpg.x+',"y":'+fpg.y+'}';;
	requestCallbackParam('proceso.php',function(){
					descubrir('bt5');
					resetButtons();
					$('ch4').style.display='block';						/*ventana(630,490);$('ch4').style.display='block';requestCallbackParam('lightboxtpl.php',function(r){$('exifr').innerHTML=r;},{});*/
												
												},{'proceso':'generarImagen','kanvas':nameSpace1.kanvas,'personaje1':personaje1,'personaje2':personaje2,'globo':globo,'area':$('area').value});
																																															   
																																															   }});
		$('enviar').addEvent('click',
							function(){
								if(validateData() ){
									if(validar()){
									if($('acepto').checked)
										$('acepto').value=1;
									else
										$('acepto').value=0;
									if(isNaN($('codpais').value)){
										$('codpais').value=0;
									}
									if(isNaN($('codarea').value)){
										$('codarea').value=0;
									}
										requestCallbackParam('proceso.php',function(){ventana(630,490);$('ch4').style.display='block';requestCallbackParam('lightboxtpl.php',function(r){$('exifr').innerHTML=r;resetButtons();},{});},{'nombre':$('nombre').value,'email':$('email').value,'dia':$('dia').value,'mes':$('mes').value,'ano':$('ano').value,'telefono':$('telefono').value,'acepto':$('acepto').value,'nombre':$('nombre').value,'proceso':'grabar_datos','codarea':$('codarea').value,'codpais':$('codpais').value,'codareacel':$('codareacel').value,'celular':$('celular').value,'apellido':$('apellido').value});
								}	} 
							});
		
		//grabar_datos
	}		
	
);
addLoadEvent(function(){
	$('verquittools').addEvent('click',function(){if(this.checked){clearTools();}else{restaurarTools();}});
});
/*-- Custom Scrollbars by panino: --*/
function getPosInside(e){ 
    var ev=e || window.event; 
    var obj=ev.target || ev.srcElement; 
    posX=ev.layerX || ev.offsetX || 0; 
    posY=ev.layerY || ev.offsetY || 0; 
    return {x:posX,y:posY} 
}
function initDragBar(ts,ti,area,e){
	var o=panino.getO(this);
	e=e || window.event; 
	cancelEvent(e); 
	stopEvent(e); 
	this.cx0=e.clientX; 
	this.cy0=e.clientY;
	this.limitH=parseInt(getCSS(this,'left'));
	this.limitV1=parseInt(getCSS(ts,'top'))+parseInt(getCSS(ts,'height'));
	this.limitV2=parseInt(getCSS(ti,'top'))-parseInt(getCSS(this,'height'));
	this.altobar=parseInt(getCSS(this,'height'));
	this.area=area;		
	var distance=this.limitV2-this.limitV1;
	var _this=this;
	if(this.intervalo)clearInterval(this.intervalo);
	this.intervalo=setInterval(function(){
		var f=(_this.area.scrollHeight-_this.area.clientHeight)*Math.abs(_this.limitV1-parseInt(o.style.top))/distance;
		_this.area.scrollTop+=(f-_this.area.scrollTop)*.3;
	},(60));
	this.ox=parseInt(o.style.left) || parseInt(getCSS(this,'left')) || 0; 
	this.oy=parseInt(o.style.top) || parseInt(getCSS(this,'top')) || 0;
	panino.act=this;
	panino.getO(document).addEvent('mousemove',
										function(e){
											if(panino.act)
												arrastrarBar.call(panino.act,e);
										});
	panino.getO(document).addEvent('mouseup',
									 	function(e){
											if(panino.act)
												soltarBar.call(panino.act,e);
										})

}
function arrastrarBar(e){
		e=e || window.event;
		clearSelection();
		var o=panino.getO(this);
        cancelEvent(e); 
        stopEvent(e); 
       	o.style.left=this.limitH+'px'; 
        o.style.top=this.oy-this.cy0+e.clientY+'px'; 
		if(parseInt(o.style.top)<this.limitV1)o.style.top=this.limitV1+'px';
		if(parseInt(o.style.top)>this.limitV2)o.style.top=this.limitV2+'px';
}
function soltarBar(e){
	e=e || window.event; 
        cancelEvent(e); 
        stopEvent(e); 
       	panino.getO(document).removeEvent('mousemove',function(e){
											if(panino.act)
												arrastrarBar.call(panino.act,e);
										});
		panino.getO(document).removeEvent('mouseup',function(e){
											if(panino.act)
												soltarBar.call(panino.act,e);
										});
		panino.act=null;
}
function hitDawnBar(bar,ts,ti,area,e){
	e=e || window.event; 
	cancelEvent(e); 
	stopEvent(e);
	bar.limitH=parseInt(getCSS(bar,'left'));
	bar.limitV1=parseInt(getCSS(ts,'top'))+parseInt(getCSS(ts,'height'));
	bar.limitV2=parseInt(getCSS(ti,'top'))-parseInt(getCSS(bar,'height'));
	bar.altobar=parseInt(getCSS(bar,'height'));
	bar.area=area;		
	var distance=bar.limitV2-bar.limitV1;
	var _this=bar;
	if(bar.intervalo)clearInterval(bar.intervalo);
	bar.intervalo=setInterval(function(){
		var f=(_this.area.scrollHeight-_this.area.clientHeight)*Math.abs(_this.limitV1-parseInt(_this.style.top))/distance;
		_this.area.scrollTop+=(f-_this.area.scrollTop)*.3;
	},(60));
	bar.style.top=(parseInt(this.style.top) || parseInt(getCSS(this,'top')) || 0)+getPosInside(e).y-bar.offsetHeight/2+'px'; 
	if(parseInt(_this.style.top)<_this.limitV1)_this.style.top=_this.limitV1+'px';
	if(parseInt(_this.style.top)>_this.limitV2)_this.style.top=_this.limitV2+'px';
}


function upscroll(bar,ts,ti,area,e){
	e=e || window.event; 
	cancelEvent(e); 
	stopEvent(e);
	bar.limitH=parseInt(getCSS(bar,'left'));
	bar.limitV1=parseInt(getCSS(ts,'top'))+parseInt(getCSS(ts,'height'));
	bar.limitV2=parseInt(getCSS(ti,'top'))-parseInt(getCSS(bar,'height'));
	bar.altobar=parseInt(getCSS(bar,'height'));
	bar.area=area;		
	var distance=bar.limitV2-bar.limitV1;
	var _this=bar;
	if(bar.intervalo)clearInterval(bar.intervalo);
	bar.intervalo=setInterval(function(){
		var f=(_this.area.scrollHeight-_this.area.clientHeight)*Math.abs(_this.limitV1-parseInt(_this.style.top))/distance;
		_this.area.scrollTop+=(f-_this.area.scrollTop)*.3;
	},(60));
	this.intervalo=setInterval(function(){
		var correr=parseInt(bar.style.top) || parseInt(getCSS(bar,'top')) || 0;
		bar.style.top=(correr-10)+'px';
		if(parseInt(_this.style.top)<_this.limitV1)_this.style.top=_this.limitV1+'px';
		if(parseInt(_this.style.top)>_this.limitV2)_this.style.top=_this.limitV2+'px';
	},30);
}
function downscroll(bar,ts,ti,area,e){
	e=e || window.event; 
	cancelEvent(e); 
	stopEvent(e);
	bar.limitH=parseInt(getCSS(bar,'left'));
	bar.limitV1=parseInt(getCSS(ts,'top'))+parseInt(getCSS(ts,'height'));
	bar.limitV2=parseInt(getCSS(ti,'top'))-parseInt(getCSS(bar,'height'));
	bar.altobar=parseInt(getCSS(bar,'height'));
	bar.area=area;		
	var distance=bar.limitV2-bar.limitV1;
	var _this=bar;
	if(bar.intervalo)clearInterval(bar.intervalo);
	bar.intervalo=setInterval(function(){
		var f=(_this.area.scrollHeight-_this.area.clientHeight)*Math.abs(_this.limitV1-parseInt(_this.style.top))/distance;
		_this.area.scrollTop+=(f-_this.area.scrollTop)*.3;
	},(60));
	this.intervalo=setInterval(function(){
		var correr=parseInt(bar.style.top) || parseInt(getCSS(bar,'top')) || 0;
		bar.style.top=(correr+10)+'px';
		if(parseInt(_this.style.top)<_this.limitV1)_this.style.top=_this.limitV1+'px';
		if(parseInt(_this.style.top)>_this.limitV2)_this.style.top=_this.limitV2+'px';
	},30);
}
function initScrollBar(dbs,bs,ts,ti,area){
	$(dbs).addEvent('mousedown',function(e){hitDawnBar.call(this,$(bs),$(ts),$(ti),$(area),e);});
	$(bs).addEvent('mousedown',function(e){initDragBar.call(this,$(ts),$(ti),$(area),e);});
	$(ts).addEvent('mousedown',function(e){upscroll.call(this,$(bs),$(ts),$(ti),$(area),e);})
	$(ts).addEvent('mouseup',function(e){clearInterval(this.intervalo)});
	$(ts).addEvent('mouseout',function(e){clearInterval(this.intervalo)});
	$(ti).addEvent('mousedown',function(e){downscroll.call(this,$(bs),$(ts),$(ti),$(area),e);})
	$(ti).addEvent('mouseup',function(e){clearInterval(this.intervalo)});
	$(ti).addEvent('mouseout',function(e){clearInterval(this.intervalo)});
}
addLoadEvent(function(){
	initScrollBar('downBarPersonajes','barPersonajes','upPersonajes','downPersonajes','scrollPersonajes');
	initScrollBar('downBarDialogos','barDialogos','upDialogos','downDialogos','scrollDialogos');
	$('loading').style.display='none';

});
