//funciones de ligthbox
function poneEncuesta1() 
{
	$('paso2').hide();
	$('paso1').show();	
}

function poneEncuesta2() 
{
	var msg = '';
	if($RF('frm_encuesta', 'edad')== null)  msg = 'error';
	if($RF('frm_encuesta', 'sexo')== null)  msg = 'error';
	if($RF('frm_encuesta', 'preg1')== null) msg = 'error';
	if($F('preg2_monterrey')==null && $F('preg2_guadalajara')==null && $F('preg2_mexico')==null) msg = 'error';
	if($F('preg3_periodico')==null && $F('preg3_radio')==null && $F('preg3_universidad')==null && $F('preg3_tienda')==null && $F('preg3_amigos')==null && $F('preg3_website')==null && $F('preg3_facebook')==null && $F('preg3_google')==null && $F('preg3_otro')== null) msg = 'error';
		
	if(msg=='')	
	{	
		$('paso1').hide();
		$('paso2').show();
	} else 
		$('errorMsg').show();	
}

function showBox(){
    $('overlay').show();        
    center('box');    
    return false;    
}

function hideBox(){
    
    //ponerle un efecto de cerrado con dos o tres segundos    
    Effect.toggle('box','appear', { duration: 1 });
    Effect.toggle('overlay','appear', { duration: 1 });
    return false;
}

function enviarComentarioBlog(idpost)
{
	var msg = '';
	
	if($RF('frm_encuesta', 'preg4')== null) msg = 'error';
	if($RF('frm_encuesta', 'preg5')== null) msg = 'error';
	if($RF('frm_encuesta', 'preg6')== null) msg = 'error';
				
	if(msg=='')	
	{	
		var pars = '?'+Form.serialize($('frm_encuesta'));	
		var url = 'php/guardar.php';
		var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: vuelve,
			onFailure: ErrorFunc
		});		
		
	} else 
		$('errorMsg2').show();	
}

function vuelve()
{
	$('paso2').hide();
	$('gracias').show();		
}

function cierra()
{
	hideBox();	
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){        
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement &&
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    
    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;
		
    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;
		setY = 20;
    element.style.left = setX + "px";
    element.style.top  = setY + "px";    
    Effect.Appear($('box'));    
}

function ErrorFunc()
{
	alert('hubo un error al enviar los datos, intente nuevamente.');
}


/**

* Returns the value of the selected radio button in the radio group, null if

* none are selected, and false if the button group doesn't exist

*

* @param {radio Object} or {radio id} el

* OR

* @param {form Object} or {form id} el

* @param {radio group name} radioGroup

*/ 

function $RF(el, radioGroup) { 

    if($(el).type && $(el).type.toLowerCase() == 'radio') { 

        var radioGroup = $(el).name; 

        var el = $(el).form; 

    } else if ($(el).tagName.toLowerCase() != 'form') { 

        return false; 

    } 

 

    var checked = $(el).getInputs('radio', radioGroup).find( 

        function(re) {return re.checked;} 

    ); 

    return (checked) ? $F(checked) : null; 

}  
