﻿function montaMPagAdd(divName, city, title)
{    
    var width = 505;
    if (city == "Grande São Paulo")
        width = 520;
    $("divPagAddInt").style.width = width;
    
    var mPag = new MPaginationControl(divName, '', 'text-align: center', 10);
    
    var t = new MTable(width,'cellspacing="0" cellpadding="0" align="center"');
    if(city.toUpperCase() == "GRANDE SÃO PAULO") {
        t.add(new MColumn('<b>Logradouro</b>', '25%', 'left', M_TP_STREET, M_LABEL));      
        t.add(new MColumn('<b>N&ordm;</b>', '7%' ,'left', M_TP_NUMBER, M_LABEL));
        t.add(new MColumn('<b>Cidade</b>', '23%', 'left', M_TP_CITY, M_LABEL));
        t.add(new MColumn('<b>Bairro</b>', '18%', 'left', M_TP_DISTRICT, M_LABEL));
        t.add(new MColumn('<b>CEP</b>', '14%', 'left', M_TP_ZIP,M_LABEL));
        t.add(new MColumn('<b>' + title + '</b>', '13%', 'right', M_TP_LINK)); 
    }
    else {
        t.add(new MColumn('<b>Logradouro</b>', '35%', 'left', M_TP_STREET, M_LABEL));      
        t.add(new MColumn('<b>N&ordm;</b>', '10%' ,'left', M_TP_NUMBER, M_LABEL));
        t.add(new MColumn('<b>Bairro</b>', '28%', 'left', M_TP_DISTRICT, M_LABEL));
        t.add(new MColumn('<b>CEP</b>', '14%', 'left', M_TP_ZIP,M_LABEL));
        t.add(new MColumn('<b>' + title + '</b>', '13%', 'right', M_TP_LINK));        
    }             
	t.setLineSeparator('<tr><td height="1px" bgcolor="#CCCCCC" colspan="6"><\/td><\/tr>\n');   
	t.setLineStyle('height: 11px; padding: 2px 2px 2px 2px; background-color: #F4F4F4'); 
	t.setLineAlterStyle('height: 11px; padding: 2px 2px 2px 2px; background-color: #FFFFFF');
    t.setLineClass("");
    t.setLineAlterClass("");
    t.setTitleClass("");
    mPag.table = t;   

    return mPag;
}

function support()
{
    var winHeight = 210;
    var winWidth = 600;
    
    var winLeft = screen.width/2 - winWidth/2;
    var winTop = screen.height/2 - winHeight/2;
    
    window.open('suporte_email.aspx', 'SuporteEmail' ,'top=yes,toolbar=no,resizable=no,scrollbars=no,width='+winWidth+',height='+winHeight+',left='+winLeft+',top='+winTop);
}

function objValido(obj)
{
    if(typeof obj == 'undefined')
        return false;
    else if(typeof obj == 'string' && obj.toUpperCase() == 'UNDEFINED')
        return false;  
    else if(typeof obj == 'string' && obj.toUpperCase() == 'NULL')
        return false;      
    else if(!obj)
        return false;
    else
        return true;
}

function isNumberKey(evt)
{
    var e;
    if(evt)
        e = evt;
    else
        e = window.event;
    
    var charCode = (e.which) ? e.which : e.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
       return false;
       
    return true;
}

function criaGeoCodeString(cidade, estado)
{
    var cidadeSemAcento = removeAcentos(cidade);
    var estadoSemAcento = removeAcentos(estado);
    var strGeoCode = estadoSemAcento.toUpperCase() + '_' + cidadeSemAcento.replace(/\s/g, '_').toUpperCase();
    
    return strGeoCode;
}

// função que remove os acentos, etc
function removeAcentos(strTexto)
{
    //Conjunto de Caracteres com acentos
    var strComAcentos = "ÁÍÓÚÉÄÏÖÜËÀÌÒÙÈÃÕÂÎÔÛÊáíóúéäïöüëàìòùèãõâîôûêÇç";
    //Conjunto de Caracteres sem acentos
    var strSemAcentos = "AIOUEAIOUEAIOUEAOAIOUEaioueaioueaioueaoaioueCc";
    var letra='';
    var resultado=''; 
    for(var i=0; i< strTexto.length;i++)
    {
        letra= strTexto.charAt(i);
        pos=strComAcentos.indexOf(letra);

        if(pos != -1){
                   resultado+=strSemAcentos.charAt(pos);
        }else{
                   resultado+=letra;
        }
    }           
    return resultado;
}

function checkEmail(strEmail) 
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmail)){
        return (true);
    }
    return (false);
}
