function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
//var wint = (screen.height - h) / 2;
var wint=0;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',menubar=yes';
win = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function NewWindow2(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
//var wint = (screen.height - h) / 2;
var wint=0;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll;
win = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function roundOff(value, precision) 
{ 
value = "" + value //convert value to string 
precision = parseInt(precision); 

var whole = "" + Math.round(value * Math.pow(10, precision)); 

var decPoint = whole.length - precision; 

if(decPoint != 0) 
{ 
result = whole.substring(0, decPoint); 
result += "."; 
result += whole.substring(decPoint, whole.length); 
} 
else 
{ 
result = whole; 
} 
return result; 
} 

function formatoimporte(imp) {
var pos = imp.indexOf(",");
var result;
if (pos>-1) {
   result = imp.substring(0,pos)+"."+imp.substring(pos+1,imp.length);
} else {
   result=imp;
}
return result;
}

function validaremail(ema) {
    /* Validamos el formato de correo electrónico*/

    /* Verificamos si email tiene formato usuario@dominio. */
    var emailPat=/^(.+)@(.+)$/; 

    /* Verificamos la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; 

    /* Verificamos los caracteres que son válidos en un email */
    var validChars="\[^\\s" + specialChars + "\]"; 
    var quotedUser="(\"[^\"]*\")"; 

    /* Verificamos si el e-mail está representado con una IP vàlida */ 
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* Verificamos caracteres inválidos */ 
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    var matchArray=ema.value.match(emailPat);
    if (matchArray==null) {
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    /* Validamos si la parte "usuario" es correcta */
    if (user.match(userPat)==null) {
    // Si no
        return false;
    }

    /* Si la dirección IP es válida */
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                return false;
            }
        }
        return true;
    }
    var domainArray=domain.match(domainPat);
    if (domainArray==null) {
        return false;
    }
    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { 
        return false;
    }
    if (len<2) {
        return false;
    }
    else {
        return true;
    }
}

