﻿// Archivo JScript

function clearAll(){
    var texts=document.getElementsByTagName('input');
    for (var i_tem = 0; i_tem < texts.length; i_tem++)
    {
        if (texts[i_tem].type=='text')
            texts[i_tem].value='';      
    }     
     
    var texts=document.getElementsByTagName('textarea');
    for (var i_tem = 0; i_tem < texts.length; i_tem++)
    {
        texts[i_tem].value='';      
    }     
     
     return false;
}

function onHover(obj)
{
    obj.style.background = '#666666';
    //obj.style.borderBottom = '1px solid #666666';
    obj.style.color = 'white';
}

function onNoHover(obj, color)
{
    obj.style.background = color;
    //obj.style.borderBottom = '1px solid ' + color;
    obj.style.color = '#4d4d4d';
}

function onHoverDiario(obj)
{
    obj.style.background = '#999999';
    //obj.style.borderBottom = '1px solid #666666';
    obj.style.color = 'white';
}

function printIt(printThis, pedido)
  {
    var win = window.open();
    
    self.focus();
    win.document.open();
    win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
    win.document.write('body, td { font-family: Calibri, Arial; font-size: 14pt;}');
    win.document.write('<'+'/'+'style'+'>');
     win.document.write('<title>Pedido Mémora.es</title>');
     win.document.write('<link href="css/StyleSheet.css" rel="stylesheet" type="text/css" />');   
     win.document.write('<'+'/'+'head'+'><'+'body'+'>');
     win.document.write('<div>Pedido: ')
     win.document.write(pedido);
     win.document.write('</div><br />');
    win.document.write(printThis);
    win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
    win.document.close();
    win.print();
    win.close();
  }



var objImage;

function popup(url) 
{
    objImage = new Image();
    objImage.src=url;

    imageLoaded(url);
}

// function invoked on image load
function imageLoaded(url)
{    
    if (objImage.complete) {
        
         var width  = objImage.width;
         var height = objImage.height;
         var left   = (screen.width  - width)/2;
         var top    = (screen.height - height)/2;
         var params = 'width='+width+', height='+height;
         params += ', top='+top+', left='+left;
         params += ', directories=no';
         params += ', location=no';
         params += ', menubar=no';
         params += ', resizable=no';
         params += ', scrollbars=no';
         params += ', status=no';
         params += ', toolbar=no';
         params += ', modal=yes';
          params += ', centerscreen=yes';
         
        if (window.showModalDialog) 
        {
            window.showModalDialog('popup.htm?' + url,"Image","dialogWidth:"+width+"px;dialogHeight:"+height+"px;center:yes;scroll:no;status:no;");
        } else {
            newwin=window.open('popup.htm?' + url,'Image', params);
            if (window.focus) {newwin.focus()}
        }
         
     }
    else {
        window.setTimeout("imageLoaded('"+url+"')", 500);
    } 
}


function modalWin(obj) 
{   var left;
    var top;
 
    if (window.showModalDialog) 
    {
        window.showModalDialog(obj.href,"name","dialogWidth:700px;dialogHeight:630px;center:yes;scroll:no;status:no;");
    } else {
        left = (screen.width/2)-(700/2);
        top = (screen.height/2)-(630/2);
        window.open(obj.href,'name','height=630,width=700,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no, centerscreen=yes, modal=yes, top='+top+', left='+left+'');
    }
}

function modalWinVaiableSize(obj, w, h) 
{   var left;
    var top;
 
    if (window.showModalDialog) 
    {
        window.showModalDialog(obj.href,"name","dialogWidth:"+w+"px;dialogHeight:"+h+"px;center:yes;scroll:no;status:no;");
    } else {
        left = (screen.width/2)-(w/2);
        top = (screen.height/2)-(h/2);
        window.open(obj.href,'name','height='+h+',width='+w+',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no, centerscreen=yes, modal=yes, top='+top+', left='+left+'');
    }
}

function openFactura(url)
{
    var left;
    var top;
    
    if (window.showModalDialog) 
    {
        window.showModalDialog(url,"factura","dialogWidth:600px; dialogHeight:650px;center:yes;scroll:yes;status:no;");
    } else {
        left = (screen.width/2)-(600/2);
        top = (screen.height/2)-(650/2);
        window.open(url,'factura','height=650,width=600,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no, centerscreen=yes, modal=yes, top='+top+', left='+left+'');
    }
}



// VALIDAR CIF    
function validarcif(abc)
{
    par = 0;
    non = 0;
    letras = "ABCDEFGHKLMNPQS";
    let = abc.charAt(0);
     
    if (abc.length!=9){
        return false;
    }
    if (letras.indexOf(let.toUpperCase())==-1){
        return validarNIF(abc);
    }
    for (zz=2;zz<8;zz+=2) {
        par = par+parseInt(abc.charAt(zz));
    }
    for (zz=1;zz<9;zz+=2) {
        nn = 2*parseInt(abc.charAt(zz));
        if (nn > 9) nn = 1+(nn-10);
        non = non+nn;
    } 
    parcial = par + non;
    control = (10 - ( parcial % 10));
    if (control==10) control=0;
     
    if (control!=abc.charAt(8)){
        return false;
    }
    return true;
}


// VALIDAR NIF
function validarnif(abc)
{
    dni=abc.substring(0,abc.length-1);
    let=abc.charAt(abc.length-1);
    
    if (!isNaN(let)){
        return false;
    }
    else
    {
        cadena="TRWAGMYFPDXBNJZSQVHLCKET";
        posicion = dni % 23;
        letra = cadena.substring(posicion,posicion+1);
        if (letra!=let.toUpperCase()){
            return false;
        }
    }
    return true;
}

// VALIDAR NIE
function validarnie(abc)
{
    var temp = abc.toUpperCase();              
    var letraNIF = temp.substring(8, 9);
    
    if (temp.indexOf("X") >= 0) temp = temp.replace("X", "0");
    if (temp.indexOf("Y") >= 0) temp = temp.replace("Y", "1");
    if (temp.indexOf("Z") >= 0) temp = temp.replace("Z", "2");
               
    var valorNIF = temp.substring(0, 8);
                
    var cadenadni="TRWAGMYFPDXBNJZSQVHLCKE";
    var ok = false;
    var pos = parseInt(valorNIF % 23);
                                                                                    
    if (letraNIF == cadenadni.substring(pos, pos + 1))
    { 
            ok = true;
    }
     
    return ok;
}

