var pwd_co='amt125'
var pwd_vb='amt125'
var config = 'center:yes; resizable:no; help:no; dialogWidth:300px; dialogHeight:200px'
//Quitar espacios en blanco de un campo
function espacios(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(v = 0; v < splitstring.length; v++)
	temp += splitstring[v];
	//devuelve vacio o relleno
	return temp;
}

function ignoreSpaces(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(v = 0; v < splitstring.length; v++)
	temp += splitstring[v];
	//devuelve vacio o relleno
	return temp;
}

//Introduccion de fecha correcta
function fecha(campo){
	if (!/\d{2}\/\d{2}\/\d{4}/.test(campo)){
		return true
	}else{
		return false
	}
}

//Introduccion de hora correcta
function tiphora(campo){
	var t=campo
	t=t.replace(".","$")
	t=t.replace(",","$")
	var h=t
	var m=t
	var p=h.indexOf(":")
	h=h.substring(0,p)
	m=m.substring(p+1)
	if (h > 23 || h < 0 || m > 59 || m < 0 || isNaN(h) || isNaN(m)) {
		return true;		
	}else{
		return false;
	}
}

//Introducción de e-mail correcto
function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
     return false;
   else 
      return true;
}
//------------------------------------------------
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0;
   } 
   return this;
}

function daysInFebruary(whichYear) {
    return (whichYear % 4 == 0 && (!(whichYear % 100 == 0)
 || (whichYear % 400 == 0)) ? 29 : 28);
}

function isDate(campo) {
	dd=campo.substring(0,2)*1
	mm=campo.substring(3,5)*1
	yyyy=campo.substring(6,10)*1
	if (mm !="" && !(mm > 0 && mm < 13)){
		alert ("¡Fecha no existente!");
		return false;
	}
	if (dd !="" && !(dd > 0 && dd < 32)){
		alert ("¡Fecha no existente!");
		return false;
	}
	if ((dd!="" && mm!="") && dd > daysInMonth[mm]){
		alert ("¡Fecha no existente!")
		return false;
	}
	if ((mm=="2" || mm=="02" && dd!="" && yyyy!="") && dd > daysInFebruary(yyyy)){
		alert ("¡Fecha no existente!")
		return false;
	}
return true;
}
function ventana(page, x, y){
		posx = (screen.availWidth-x)/2;
	   	posy = (screen.availHeight-y)/2;
		window.open(page, 'DATOS','toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, width='+x+', height='+y+', top='+posy+', left='+posx);
}
function ventanar(page, x, y){
		posx = (screen.availWidth-x)/2;
	   	posy = (screen.availHeight-y)/2;
		window.open(page, 'DATOS','toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=1, width='+x+', height='+y+', top='+posy+', left='+posx);
}

function mueveReloj(){
	if(document.getElementById('mueve').value==0){
		momentoActual = new Date()
		hora = momentoActual.getHours()
		minuto = momentoActual.getMinutes()
		segundo = momentoActual.getSeconds()
		
		str_segundo = new String (segundo) 
	    if (str_segundo.length == 1) 
    	   segundo = "0" + segundo 

	    str_minuto = new String (minuto) 
    	if (str_minuto.length == 1) 
	       minuto = "0" + minuto 

    	str_hora = new String (hora) 
	    if (str_hora.length == 1) 
    	   hora = "0" + hora
	
		horaImprimible = hora + ":" + minuto + ":" + segundo
		document.getElementById('hor').value = horaImprimible
		setTimeout("mueveReloj()",1000)
	}
}

function salto (tamano, campo, sig){
	val = campo.value.replace(".",",")
	nval = campo.value.length
	if (isNaN(val)){
		alert('Ha de ser un valor numérico')
		campo.value = campo.value.substring(0, nval-1)
		return false
	}
	if(nval*1>tamano*1){
		alert('Longitud del campo incorrecta')
		campo.value = campo.value.substring(0, nval-1)
		return false
	}
	if (nval*1==tamano*1 && sig!=''){
		document.getElementById(sig).focus()
	}
}

function redondear(cantidad, decimales) {
	var cantidad = parseFloat(cantidad);
	var decimales = parseFloat(decimales);
	decimales = (!decimales ? 2 : decimales);
	return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
} 

function conver_tot(valor,cod){
	//tot = document.getElementById('tot_linea_'+cod).value.replace(',','.')*1
	total=document.getElementById('tot_linea_'+cod).value.split('.')
	tot=total.join('')
	tot = tot.replace(',','.')*1
	iva = document.getElementById('iva_'+cod).value.replace(',','.')*1
	if (isNaN(tot)){
		alert('El valor del total ha de ser numérico')
	}else{
		final=tot/((iva/100)+1)
		final=final.toFixed(2)
		/*final= Math.round(final * Math.pow(10, 2)) / Math.pow(10, 2);
		final="a"+final
		fin=final.split('.')
		final=fin.join(',')
		final=final.replace("a","")*/

		document.getElementById('imp_'+cod).value = final
		if (document.getElementById('id').value==0){
			//document.getElementById('pre_nueva').value=0
			for (i=1;i<=5;i++){
				j=(i*1)-1
				lin=document.getElementById('tot_linea_nueva_'+i).value.replace(',','.')*1
				if (isNaN(lin)==false){
					/*valor=(document.getElementById('pre_nueva').value*1)+(lin*1)
					valor= Math.round(valor * Math.pow(10, 2)) / Math.pow(10, 2);
					valor="a"+valor
					va=valor.split('.')
					valor=va.join(',')
					valor=valor.replace("a","")

					document.getElementById('pre_nueva').value=valor*/
				}
			}
		}
	}
}
function fun_concepto(){
	if (document.getElementById('id').value==0){
		document.getElementById('con_nueva_1').value=document.getElementById('concepto').value
	}
}
function conver_iva(valor,cod){
	impo = document.getElementById('imp_'+cod).value.replace(',','.')*1
	iva = document.getElementById('iva_'+cod).value.replace(',','.')*1
	if (isNaN(iva)){
		alert('El valor del iva ha de ser numérico')
	}else{
		final=impo+((impo*iva)/100)
		final=final.toFixed(2)
		document.getElementById('tot_linea_'+cod).value = final
	}
}
function conver_imp(valor,cod){
	impo = document.getElementById('imp_'+cod).value.replace(',','.')*1
	iva = document.getElementById('iva_'+cod).value.replace(',','.')*1
	if (isNaN(impo)){
		alert('El valor del importe ha de ser numérico')
	}else{
		final=impo+((impo*iva)/100)
		final=final.toFixed(2)
		document.getElementById('tot_linea_'+cod).value = final
	}
}
function mktg(){
	alert('Pestaña deshabilitada temporalmente\nPerdone las molestias')
}