﻿function confirmDelete() {
	return confirm("Tem a certeza que deseja apagar este item?");
}

function selectPage(page) {
	$('#page').attr('value', page);
	var itemsPerPage = $('#itemsPerPageMain').val();
	$('[name=itemsPerPage]').val(itemsPerPage);
	$('#resultsButton').click();
}

function deleteParent(element) {
	$(element).parent().remove();
}

function previewDialog(dialogId) {
    var dialogWidth = window.screen.availWidth * 0.75;
    var dialogHeight = window.screen.availHeight * 0.75;
    $("#" + dialogId).dialog({
        autoOpen: false,
        bgiframe: true,
        modal: false,
        draggable: true,
        width: dialogWidth,
        height: dialogHeight,
        buttons: { "Fechar": function() { $(this).dialog('close'); } },
        close: function(event, ui) {
            $(this).dialog('option', 'width', window.screen.availWidth * 0.75);
            $(this).dialog('option', 'height', window.screen.availHeight * 0.75);
        }
    });
}

function printPage(baseLocation) {
    var url = window.document.URL;
    var content = $('#printable-area').html();
    var ang; var cv; var gb; var moz; var stp;
    
    
//    if (url.indexof("country=Angola") < 0
//    && url.indexof("country=CaboVerde") < 0
//    && url.indexof("country=GuineBissau") < 0
//    && url.indexof("country=Mocambique") < 0
//    && url.indexof("country=SaoTomeEPrincipe") < 0) {
//        ang = cv = gb = moz = stp = 0;

//    } else {

        ang = content.search("country=Angola");
        cv = content.search("country=CaboVerde");
        gb = content.search("country=GuineBissau");
        moz = content.search("country=Mocambique");
        stp = content.search("country=SaoTomeEPrincipe");
//    }

    var flags = "<div style='display: block; margin: 20px auto; '>";
    if (ang != -1)
        flags += '<img style="margin: 10px;" height="30" width="45" alt="Angola" title="Angola" src="' + baseLocation + 'Content/Images/bandeiras/Angola.png" />';
    if (cv != -1)
        flags += '<img style="margin: 10px;" height="30" width="45" alt="Cabo Verde" title="Cabo Verde" src="' + baseLocation + 'Content/Images/bandeiras/CaboVerde.png" />';
    if (gb != -1)
        flags += '<img style="margin: 10px;" height="30" width="45" alt="Guiné-Bissau" title="Guiné-Bissau" src="' + baseLocation + 'Content/Images/bandeiras/GuineBissau.png" />';
    if (moz != -1)
        flags += '<img style="margin: 10px;" height="30" width="45" alt="Moçambique" title="Moçambique" src="' + baseLocation + 'Content/Images/bandeiras/Mocambique.png" />';
    if (stp != -1)
        flags += '<img style="margin: 10px;" height="30" width="45" alt="São Tomé e Príncipe" title="São Tomé e Príncipe" src="' + baseLocation + 'Content/Images/bandeiras/SaoTomeEPrincipe.png" />';
    flags += "</div>";

    baseLocation = baseLocation.replace("//", "/");
    var printPageContent =
        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' +
        '<html xmlns="http://www.w3.org/1999/xhtml">' +
        '<head>' +
	    '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' +
	    '<title>Página de Impressão</title>' +
    	'<link rel="stylesheet" type="text/css" href="' +
    	baseLocation + 'Content/Css/Site-print.css" />' +
	    '<link rel="stylesheet" type="text/css" href="' +
	    baseLocation + 'Content/Css/smoothness/jquery-ui-1.7.1.custom.css" />' +
	    '<!--[if lt IE 7]>' +
	    '<script src="' +
	    baseLocation + 'Content/Scripts/IE7.js" type="text/javascript"></script>' +
	    '<![endif]-->' +
        '</head>' +
        '<body onload="window.print()">' +
	    '<div id="printable-area" class="main_content">' +
	    flags +
	    content +
	    '</div>' +
        '</body>' +
        '</html>';
    var printWindow = window.open();
    printWindow.document.write(printPageContent);
    printWindow.document.close();
    //alert('oi3');
    //$.get('/PrintPage', function(data) {
    //    data = data.replace('CONTEUDO', content);
    //    printWindow.document.write(data);
    //    printWindow.document.close();
    //});
   return false;
}