/* 
 * 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] = "04";
            }

            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;
    }

    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;
}

function in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}

function runFlash(nomeSWF,Width,Height) // tutorial by IVI CONCEPT - www.ivi-concept.com
  {
  // ---sólo hay que modificar los parametros ----------------
  // --inicio parametros--------------------------------------------------
  var archivo= nomeSWF + ".swf"; // nombre de la pelicula swf que quieres incluir (incluir ruta si es necesario)
  var ancho=Width; // ancho de la peli swf en píxeles o en porcentaje
  var alto=Height; // alto de la peli swf en píxeles o en porcentaje
  var version="6,0,0,0"; // version del flash player
  var quality="high"; // calidad de visualización de la peli
  var bgcolor="#ffffff"; // color de fondo de la peli
  var wmode="transparent"; // color de fondo de la peli
  // --fin parametros--------------------------------------------------
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" width='+ancho+' height='+alto+'>\n');
document.write('<param name="movie" value='+archivo+' />\n');
document.write('<param name="quality" value='+quality+'>\n');
document.write('<param name="bgcolor" value='+bgcolor+'>\n');
document.write('<param name="wmode" value='+wmode+'>\n');
document.write('<embed src='+archivo+' wmode='+wmode+' bgcolor='+bgcolor+' quality='+quality+' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+ancho+' height='+alto+'></embed>');
document.write('</object>\n');
}