﻿
//0  disabled; 1  enabled;
var popupStatus = 0;
var DivActivo;
var Divcierre;

//Encotnrar Posicion X
function findPosX(obj)
  {
    obj=document.getElementById(obj);
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

//Enontrar posicion y
  function findPosY(obj)
  {
    obj=document.getElementById(obj);
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


//loading popup 
function loadPopup(){
	if(popupStatus==0){
		//$("#backgroundPopup").css({"opacity": "0.4"		});
		
		$("#backgroundPopup").fadeIn(300);	
		$(DivActivo).fadeIn(100);
		popupStatus = 1;		   
	}
}

//disabling popup 
function disablePopup(){

	if(popupStatus==1){
	    popupStatus = 0;
	    $("#backgroundPopup").fadeOut("slow");	
	    FadeOutPopups()
        $(DivActivo).fadeOut(100);		
	}
}

function FadeOutPopups(){ 
             $("#DivLibros").fadeOut(0);	         
		     $("#DivPedidos").fadeOut(0);	         
           }


//centering popup
function centerPopup(LeftRecuadro, IDObj){
      FadeOutPopups()
             
	  popupStatus = 0;
    		            
            //Descarga de libros        
           if (IDObj=="downlibros") {
                  DivActivo= $("#DivLibros",window.top.document);                                           
                  $("#IframeLibros",window.top.document).attr('src', 'http://www.todoumpc.com/descargas/ebooks/ebooks.asp') ;
              };  
			  
		   //Mis pedidos         
           if (IDObj=="mispedidos") {
                  DivActivo= $("#DivPedidos",window.top.document);                                           
                  $("#IframePedidos",window.top.document).attr('src', 'support/pedidos.asp') ;
              };  
            var popupHeight = $(DivActivo).height();
	        var popupWidth = $(DivActivo).width();
	        
}

$(document).ready(function(){	
   
	//Click en Nuestros clientes
	$("#downlibros").click(function(){
		centerPopup(0,$(this).attr('id'));
		loadPopup();
	});
	
	//Click en Nuestros clientes
	$("#mispedidos").click(function(){
		centerPopup(0,$(this).attr('id'));
		loadPopup();
	});
	
	
	//CLOSING POPUP
	$(".popupContactClose").click(function(){
		disablePopup();	 	
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
