/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *
 *
 * by: pls
 */


//funcoes js...

function $_(obj){
    return document.getElementById(obj);
}
function trim(str) {
    var newStr = new String(str);
    var achou = false;

    var i = newStr.length-1;
    for(; i>=0; i--) {
        if( newStr.charAt(i)!=' ' && newStr.charCodeAt(i)!=9 && newStr.charCodeAt(i)!=13 && newStr.charCodeAt(i)!=10 ) {
            achou = true;
            break;
        }
    }
    if( achou ) {
        newStr = newStr.substring(0, i+1);
    }

    achou = false;
    for(i=0; i<newStr.length; i++) {
        if( newStr.charAt(i)!=' ' && newStr.charCodeAt(i)!=9 && newStr.charCodeAt(i)!=13 && newStr.charCodeAt(i)!=10 ) {
            achou = true;
            break;
        }
    }
    if( achou ) {
        newStr = str.substring(i, newStr.length);
    } else {
        newStr = '';
    }

    return newStr;
}
// isDataValida(string)>> valida data dd/mm/aaaa
function isDataValida(string){
    try{
        if (string.length < 10){
                return false;
        }else{
            var strData = new Array();
            strData = string.split("/");

            // patch pro bug do javascript
            if(strData[0] == "09" || strData[0] == "08"){
                strData[0] = "01";
            }
            if(strData[1] == "08"){
                strData[1] = "01";
            }
            if(strData[1] == "09"){
                strData[1] = "03";
            }

            if(strData.length != 3){
                return false;
            }else if(parseInt(strData[0]) > 29 && parseInt(strData[1]) == 2 ){
                return false;
            }else if(parseInt(strData[0]) > 31 || parseInt(strData[0]) <= 0 || strData[0].length != 2){
                return false;
            }else if(parseInt(strData[0]) == 31 && (parseInt(strData[1]) == 4 || parseInt(strData[1]) == 6 || parseInt(strData[1]) == 9 || parseInt(strData[1]) == 11) ){
                return false;
            }else if(parseInt(strData[1]) > 12 || parseInt(strData[1]) <= 0 || strData[1].length != 2){
                return false;
            }else if(parseInt(strData[2]) <= 0 || strData[2].length != 4 ){
                return false;
            }else{
                return true;
            }
        }
    }catch(err){
        alert(err.description);
        return false;
    }
}
//valida email
function isEmail( email ) {
    if (typeof(email) != "string") {
        return false;
    } else if (!email.match(/^[A-Za-z0-9]+([_.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_.-][A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/)) {
        return false;
    }else{
        return true;
    }
}

function validaNumero(campo, event){

    var strValidos = '0123456789';
    var BACKSPACE = 8;
    var key;
    var tecla;
    CheckTAB = true;
    if(navigator.appName.indexOf('Netscape')!= -1)
    tecla= event.which;
    else tecla = event.keyCode;

    key = String.fromCharCode(tecla);
    if (tecla == "") return true;
    if (tecla == 13) return false;
    if (tecla == BACKSPACE) return true;
    if (strValidos.indexOf(key) == -1) return false;
}

//limpa as tags html da string
function stripHTML(str){
    var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
    str = str.replace(regexp,"");
    str = str.replace(/&nbsp;/g," ");
    return str;
}









function verMapa(mapaX, mapaY) {
    Shadowbox.open({
        player:     'html',
        content:    '',
        height:     400,
        width:      650,
        options:    {
            onFinish: function(item){
                if(GBrowserIsCompatible()){
                    var body = document.getElementById(Shadowbox.contentId());
                    var map = new GMap2(body);
                    map.setCenter(new GLatLng(mapaX, mapaY), 15, G_NORMAL_MAP);
                    var icone = new GIcon(G_DEFAULT_ICON,"/img/carceg.gif");
                    icone.iconSize = new GSize(32, 32);
                    var markerOptions = { icon:icone };
                    var point = new GLatLng(mapaX, mapaY);
                    map.addOverlay(new GMarker(point, markerOptions));
                    // add some simple controls
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());
                }
            }
        }
    });
}

