function ValidarBusqueda() {

    //{!VALIDATION_SCRIPT!}
    d = document.searchBar;

    //valida e-mail
    if( d.keyword.value == '' ) {
        alert( 'Search is required' );
        d.keyword.focus();
        return false;
    }

    d.submit();

    }

//-------- item nuevo
function addItem ( nombre, target ) {
    html = '<input type="text" name="o_' + nombre + '" size="20" maxlength="60" class="inputs_x2" value="">&nbsp;';
    target.innerHTML = html;
}

function CheckNew ( valor, target, nombre ) {
    if ( valor == "new" ) {
        addItem ( nombre, target );
    }else{
        target.innerHTML = '&nbsp;';
    }
}
//--------------------

function CheckField ( target, type, texto ) {
    if ( type == "select" ) {
        //document.formname.dropdownName.selectedIndex

        if(target){
        if ( target.selectedIndex == "" || isNaN( target.selectedIndex ) ) {
            showError ( target, texto );
            return ( false );
        }
        }else{
        //alert('no target');
        }
    }

    if ( type == "numerico" ) {
        if ( target.value == "" || isNaN( target.value ) ) {
            showError ( target, texto );
            return ( false );
        }
    }

    if ( type == "string" ) {
        if ( target.value == "" ) {
            showError ( target, texto );
            return ( false );
        }
    }

    return ( true );
}

function showError ( target, eltext ) {
    alert ( eltext );
    target.focus();
    return;
}


function OpenCalendar ( target ) {
    if ( showModalDialog ){
        var sRtn;
        sRtn = showModalDialog( "calendar.php","","center=yes;dialogWidth=185pt;dialogHeight=225pt;scrolling=no" );
        if (sRtn){
            cambios = true;
            if (sRtn == 'nothing'){
                target.value = '';
            } else {
                target.value = sRtn;
            }
        }
    }
    return;
}

function Cancel(){
    location.href = document.frmMain.target_url.value;
}

function PopUp( url, features, windowName ) {
    var screenX = screen.width/2;
    var screenY = screen.height/2;

    if( windowName == "" ) {
        windowName = "WIN_" + Math.random().toString().slice(3,7);
    }

    // analiza si hay ancho y largo
    if( features != "" ) {
        aFeatures = features.split( "," );
        for( a=0; a < aFeatures.length; a++ ) {
            aValues = aFeatures[a].split( "=" );
            if( aValues[0] == "width" ) {
                screenX = screenX - ( Number( aValues[1] ) / 2 );
            }
            if( aValues[0] == "height" ) {
                screenY = screenY - ( Number( aValues[1] ) / 2 );
            }
        }
    }

    var tmp = features;
    tmp += ",screenX=" + screenX + ",left=" + screenX;
    tmp += ",screenY=" + screenY  +",top=" + screenY + ", scrollbars=yes, resizable=yes";
    tmp += ", scrollbars=yes, resizable=yes";

    hWin = window.open( url, windowName, tmp );

    return( hWin );
}


function Close() {
    window.close();
}


/* --------- flujo de focos para liquidacion */
var flujos_liq = new Array();
flujos_liq["proveedor_id"] = "GotoElement( document.frmMain.fecha_cierre )";
flujos_liq["fecha_cierre"] = "GotoElement( document.frmMain.tipo_cambio )";
flujos_liq["tipo_cambio"] = "GotoElement( document.frmMain.but_aceptar )";
flujos_liq["but_aceptar"] = "AltaLiquidacion()";



/* administra el foco al presionar enter */
function EnterHandler( flujo ) {
    var c = document.layers ? evt.which : document.all ? event.keyCode : evt.keyCode;
    var campo = document.layers ? evt.srcElement : document.all ? event.srcElement : evt.srcElement;

    if( c == 13 ) {
        eval( flujo[campo.name] );
    }
    return;
}

function GotoElement( elem ) {
    elem.focus();
}

function GotoSelElement( elem ) {
    elem.focus();
    elem.select();
}

function noEnter()
{
    if (event.keyCode == 13)
    {
    event.returnValue = false;
    }
}

function Navigate( num ) {
    document.frmMain.page.value = Number( document.frmMain.page.value ) + num;
    document.frmMain.submit();
}

iTolerancia = 3;

function ItemInvalido() {
    if( iTolerancia == 0 ) {
        alert( "No podra continuar si no ingresa un codigo valido" );
    } else {
        iTolerancia--;
    }
    return;
}


function Cancelar( url ) {
    document.location.href = url;
}

//--------------------------------------
function AddItem( source, target ) {
    var x;
    if ( !existeitem( target, source.value ) && source.value != "" ) {
        var oOption = document.createElement("OPTION");
        oOption.value = source.value;
        oOption.text = source.value;
        target.options[target.length] = oOption;
    }
}
function existeitem( otarget, valor ) {
    var x=0;
    for( x=0; x < otarget.length; x++ ) {
        if( String( otarget[x].value ) == String( valor ) ){
            return( true );
        }
    }
    return( false );
}

function EliItem( target ) {
    var x;
    cnt = target.length - 1;
    for( x=cnt; x>=0; x-- ) {
        if( target[x].selected ){
            target.remove( x );
        }
    }
}

function ConcatIds( target ) {
    var tmpStr = "", x;
    for( x=0; x < target.length; x++ ) {
        if( String(target[x].key) == "undefined" ) {
            tmpStr += String(target[x].value);
        }
        else {
            tmpStr += String(target[x].key);
        }
        if (x!= ( target.length - 1 ) ) {tmpStr += ","}
    }
    return( tmpStr );
}

//--------------------------------------

function Navigate( num ) {
    document.frmMain.page.value = Number( document.frmMain.page.value ) + Number( num );
    document.frmMain.mode.value = "Search";
    document.frmMain.submit();
}


function Export() {
    document.frmMain.mode.value = "Export";
    document.frmMain.submit();
}


function fMailTo( email ) {
    if(confirm('You are about to open your default e-mail program. Do you wan\'t to continue?')){
    document.location.href = 'mailto:' + email;
    }
}

/*----------------------*/
function fncEmulation (){
    if (!hasRun){
        //Browsing detection
        var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;
        d = document;
        n = navigator;
        na = n.appVersion;
        nua = n.userAgent;
        win = ( na.indexOf( 'Win' ) != -1 );
        mac = ( na.indexOf( 'Mac' ) != -1 );
        lin = ( na.indexOf( 'Linux' ) != -1 );

        if ( !d.layers ){
            dom = ( d.getElementById );
            op = ( nua.indexOf( 'Opera' ) != -1 );
            konq = ( nua.indexOf( 'Konqueror' ) != -1 );
            saf = ( nua.indexOf( 'Safari' ) != -1 );
            moz = ( nua.indexOf( 'Gecko' ) != -1 );// will be true for safari as well
            ie = ( d.all && !op );
            ie4 = ( ie && !dom );

            /*
            ie5x tests only for functionality. ( dom||ie5x ) would be default settings.
            Opera will register true in this test if set to identify as IE 5
            */
            ie5x = ( d.all && dom );
            ie5mac = ( mac && ie5x );
            ie5xwin = ( win && ie5x );
        }
        //End Browsing detection

        if (moz||saf||konq||op){
            EmulateElements();
        }
        hasRun = true;
    }
    return null;
}

function EmulateElements() {

    // document.all
    var allGetter = function () {
       var a = this.getElementsByTagName("*");
       var node = this;
       a.tags = function (sTagName) {
      return node.getElementsByTagName(sTagName);
       };
       return a;
    };
    HTMLDocument.prototype.__defineGetter__("all", allGetter);
    HTMLElement.prototype.__defineGetter__("all", allGetter);

    // parentElement
    HTMLElement.prototype.__defineGetter__("parentElement", function () {
       if (this.parentNode == this.ownerDocument) return null;
       return this.parentNode;
    });

    // outerHTML
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
       var attrs = this.attributes;
       var str = "<" + this.tagName;
       for (var i = 0; i < attrs.length; i++)
      str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";

       if (_emptyTags[this.tagName])
      return str + ">";

       return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });

    HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
       var r = this.ownerDocument.createRange();
       r.setStartBefore(this);
       var df = r.createContextualFragment(sHTML);
       this.parentNode.replaceChild(df, this);
    });


    //----------- outerText
    HTMLElement.prototype.__defineSetter__("outerText", function (sText) {
       this.outerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    });

    // insertAdjacentHTML
    HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {
       var df;   // : DocumentFragment
       var r = this.ownerDocument.createRange();

       switch (String(sWhere).toLowerCase()) {  // convert to string and unify case
      case "beforebegin":
         r.setStartBefore(this);
         df = r.createContextualFragment(sHTML);
         this.parentNode.insertBefore(df, this);
         break;

      case "afterbegin":
         r.selectNodeContents(this);
         r.collapse(true);
         df = r.createContextualFragment(sHTML);
         this.insertBefore(df, this.firstChild);
         break;

      case "beforeend":
         r.selectNodeContents(this);
         r.collapse(false);
         df = r.createContextualFragment(sHTML);
         this.appendChild(df);
         break;

      case "afterend":
         r.setStartAfter(this);
         df = r.createContextualFragment(sHTML);
         this.parentNode.insertBefore(df, this.nextSibling);
         break;
       }
    };
}

function reDoPage(init) {
    if (init==true) with (navigator) {
        if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.pgW=innerWidth; document.pgH=innerHeight; onresize=reDoPage; }
    }
    else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}

/*
FUNCION Resize
Autor: Hernan Calabrese(hernanc aRr0ba tekar.net) para Westbase
Fecha: 29/07/2005
Calcula la posicion de algo para que cambie cuando se hace un resize de la ventana,
para esto poner esta linea en el BODY de la pagina:
    onresize="Resize()"
*/
function Resize(){
    //Obtengo el largo actual de la ventana
    var w_newWidth;

    //Largo maximo de la ventana
    var w_maxWidth=1600;

    //Ancho preprogramado en el disenio
    var w_designWidth=810;

    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        w_newWidth=document.body.clientWidth;
    }else{
        var netscapeScrollWidth=30;
        w_newWidth=window.innerWidth-netscapeScrollWidth;
    }

    if (w_newWidth>w_maxWidth) w_newWidth=w_maxWidth;

    //Calcula el offset
    var varoffset;
    varoffset = (w_newWidth - w_designWidth) / 2;

    //Aplica el offset a cada DIV que es un menu
    var objtbl = document.getElementById( 'main_table' );
    var objtbl2 = document.getElementById( 'shadow1' );
    objtbl.style.left = (15 + varoffset) + "px";
    objtbl2.style.left = (15 + varoffset) + "px";

    //document.all.tbl.style.left = (15 + varoffset) + "px";
    //document.all.tbl2.style.left = (15 + varoffset) + "px";
    Show( 'main_table' );
    Show( 'shadow1' );
}

function Show( id ) {
    var obj = document.getElementById( id );
    obj.style.visibility = "";
    return;
}

function PopUp( url, features, windowName ) {
    var screenX = screen.width/2;  //1280 /2 = 640
    var screenY = screen.height/2; //1024 /2 = 512
    if( windowName == "" ) {
        windowName = "WIN_" + Math.random().toString().slice(3,7);
    }

    // analiza si hay ancho y largo
    if( features != "" ) {
        aFeatures = features.split( "," );
        for( a=0; a < aFeatures.length; a++ ) {

            aValues = aFeatures[a].split( "=" );
            if( aValues[0] == "width" ) {
                screenX = screenX - ( Number( aValues[1] ) / 2 );
            }
            if( aValues[0] == "height" || aValues[0] == " height") {
                screenY = screenY - ( Number( aValues[1] / 2 ));
            }
        }
    }

    var tmp = features;
    tmp += ",screenX=" + screenX + ",left=" + screenX;
    tmp += ",screenY=" + screenY  +",top=" + screenY + ", resizable=yes";
    tmp += ", resizable=yes";

    hWin = window.open( url, windowName, tmp );

    //return( hWin );
}


function HideShow( id ) {
    var obj = document.getElementById( id );
    if( obj.style.display == "" ) {
        obj.style.display = "none";
    } else {
        obj.style.display = "";
        Effect.Appear( id );
    }
    return;
}

/*----------------------*/

