function carregaConteudoDivComAjax(target_div, url){
    $(target_div).innerHTML = '';
    /*
    new Effect.Scale(target_div, 100, {
                    scaleFrom: 0,
                    scaleFromCenter: true,
                    scaleContent: false,
                    //transition: Effect.Transitions.sinoidal,
                    scaleX: true,
                    scaleY: true
            }
    );
    */
    new Effect.BlindDown(target_div, {duration:1, from:0.0, to:1.0});
    window.setTimeout(
            function() {
                    new Ajax.Updater(target_div, url, {	asynchronous: false , evalScripts: true } );
            }
            ,1000
    );
}
function popup(url, popup_width, popup_height) {
    windowname = 'popUpDiv';
    createDiv('blanket');
    createDiv(windowname);
    var divPopUp = document.getElementById(windowname);
    divPopUp.style.width = popup_width + 'px';
    divPopUp.style.height = popup_height + 'px';

    blanket_size(windowname, popup_height);
    window_pos(windowname, popup_width);
    toggle('blanket');
    toggle(windowname);
    carregaConteudoDivComAjax(windowname, url);
}
function createDiv(divName){
    var divTag = document.createElement("div");
    divTag.id = divName;
    divTag.style.display = "none";
    document.body.appendChild(divTag);
}
function popDown(windowname){
	windowname = 'popUpDiv';
	toggle('blanket');
	toggle(windowname);
}
function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar, popup_height) {
	if (typeof window.innerWidth != 'undefined') { viewportheight = window.innerHeight; }
        else {	viewportheight = document.documentElement.clientHeight;	}
        if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	}
        else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		}
                else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';

//Posicionamento do popup no centro do blanket
	var popUpDiv       = document.getElementById(popUpDivVar);
	popUpDiv.style.top = blanket_height/2-(popup_height/2) + 'px';
}
function window_pos(popUpDivVar, popup_width) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-(popup_width/2);
	popUpDiv.style.left = window_width + 'px';
}
function popDownIframe() {
    //Escondemos a div que tem a iframe
	var el = parent.document.getElementById('popUpDiv');
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
    //Escondemos o blanket
	el = parent.document.getElementById('blanket');
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
        
}
function popUpIFrame(url, iframe_width, iframe_height) {
//'popups/separar_encomendas.php', 650, 650
    windowname = 'popUpDiv';
    createDiv('blanket');
    createDiv(windowname);
    var divPopUp = document.getElementById(windowname);
    divPopUp.style.width = iframe_width + 'px';
    divPopUp.style.height = iframe_height + 'px'; //style='position: absolute;' ....por na iframe de baixo
    divPopUp.innerHTML = "<iframe src='popups/" + url + "' width='" + iframe_width + "' height='" + iframe_height + "' scrolling='no' marginwidth='0' marginheight='0' frameborder='0'></iframe>";

    blanket_size(windowname, iframe_height);
    window_pos(windowname, iframe_width);
    toggle('blanket');
    toggle(windowname);

    new Effect.BlindDown(windowname, {duration:1, from:0.0, to:1.0});
}
