﻿
//0  disabled; 1  enabled;
var popupStatus = 0;
var DivActivo;


//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(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.8"});
		$("#backgroundPopup").css({"height": "1500px"});
		$("#backgroundPopup").fadeIn(300);
		$(DivActivo).fadeIn(300);
		popupStatus = 1;
	}
}




//disabling popup 
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(DivActivo).fadeOut("slow");
		popupStatus = 0;
	}
}
//centering popup
function centerPopup(LeftRecuadro, IDObj){

if (IDObj=="LinkContacto") {DivActivo= document.getElementById("DivContacto")};          //Contacto
if (IDObj=="LinkClientes") {DivActivo= document.getElementById("DivClientes")};          //Clientes
   
         
	var windowWidth = document.documentElement.getAttribute("Width");   
    var windowHeight = document.documentElement.getAttribute("height");
//	var popupHeight = "100px";
//	var popupWidth = $(DivActivo).width();

	//centering
	$(DivActivo).css({
		"position": "absolute",
		"height": "770px",
		"width": "780px", 
		"margin-left": "25%",	
		"margin-top": "50px"							
	});	
}
$(document).ready(function(){	
    //Click en Recuadro	
	$(".Rec").click(function(){
		centerPopup($(this).css('left'),$(this).attr('id'));
		loadPopup();
	});
	

	
	//Click en contacto
	$("#LinkContacto").click(function(){
		centerPopup(0,$(this).attr('id'));
		loadPopup();
	});
	
		//Click en Nuestros clientes
	$("#LinkClientes").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();
		}
	});

});
