var PostalPopupStatus = 0;
var PostalX=0;

function PostalGetDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function PostalGetDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}

function PostalSetOpacity(id,value ) {
	document.getElementById(id).style.opacity = value / 10;
 	document.getElementById(id).style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function PostalFadeIn(id) {
	for( var i = 0 ; i <= 100 ; i++ ){
   		setTimeout( "PostalSetOpacity('"+id+"'," +(i / 10) + ")" , 8 * i );
	}
}

function PostalFadeOut(id) {
	for( var i = 0 ; i <= 100 ; i++ ) {
   		setTimeout( "PostalSetOpacity('"+id+"'," + (10 - i / 10) + ")" , 8 * i );
 	}
}
 
function PostalLoadPopup(){
	if(PostalPopupStatus==0){
		PostalSetOpacity("popupContact",0);
 		document.getElementById("popupContact").style.display = "block";
		document.getElementById("backgroundPopup").style.display = "block";
		PostalSetOpacity("backgroundPopup",3 );
		PostalFadeIn("popupContact");
		PostalPopupStatus = 1;
	}
}
function PostalCerrarPopup(){
	if(PostalPopupStatus==1){
		PostalFadeOut("popupContact");
		PostalSetOpacity("backgroundPopup",0);
		document.getElementById("popupContact").style.display = "none";
		document.getElementById("backgroundPopup").style.display = "none";
		PostalPopupStatus = 0;
	}
}
function PostalCenterPopup(){
	var windowWidth =  PostalGetDocWidth();
	var windowHeight = PostalGetDocHeight();
	var popupHeight =  document.getElementById("popupContact").style.height;
	var popupWidth =   document.getElementById("popupContact").style.width;
	popupHeight=popupHeight.substr(0,popupHeight.length-2);                   
	popupWidth=popupWidth.substr(0,popupWidth.length-2);         
	
	document.getElementById("popupContact").style.position="absolute";
	document.getElementById("popupContact").style.top= "75px";
	document.getElementById("popupContact").style.left=(Math.round(windowWidth/2)-Math.round(popupWidth/2))+"px";
}

function PostalMostrarPopup(id_imagen){
	PostalCenterPopup();
	PostalLoadPopup();
	PostalX++;
	document.getElementById("postal").src="http://www.losajaches.com/postales/postales.php?imagen="+id_imagen+"&tmp="+PostalX;
}
