// JavaScript Document
<!--

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
if (restore) selObj.selectedIndex=0;
}

function selectItemByValue(elto, value) {
	var element = document.getElementById(elto);
  if(element.options.length) {
		for(var i=0;i<element.options.length;i++) {
			if(element.options[i].value == value) {
				element.options[i].selected = true;
			}
		}
	}
}

function borrar() {
return window.confirm("Esta seguro?") // Pregunta, si devuelve false no borra nada
} 
function modificar() {
return window.confirm("Esta seguro de modificar el usuario seleccionado?") // Pregunta, si devuelve false no borra nada
} 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function fecha(){
if (parseInt(document.form1.messalida.value)>parseInt(document.form1.mesllegada.value)){
alert ("El mes de llegada no puede ser anterior al mes de salida");
return (false);
}
if ((parseInt(document.form1.diasalida.value)>parseInt(document.form1.diallegada.value))&&(parseInt(document.form1.messalida.value)==parseInt(document.form1.mesllegada.value))){
alert ("El dia de llegada no puede ser anterior al dia de salida en el caso del mismo mes");
return (false);
}

if (parseInt(document.form1.horaencuentro.value)>parseInt(document.form1.horasalida.value)){
alert ("La hora de salida no puede ser anterior a la hora de encuetro");
return (false);
}
if ((parseInt(document.form1.minutoencuentro.value)>parseInt(document.form1.minutosalida.value))&&(parseInt(document.form1.horaencuentro.value)==parseInt(document.form1.horasalida.value))){
alert ("El minuto de encuetro no puede ser anterior al minuto de salida en el caso de la misma hora");
return (false);
}
else{
return true;
 }
 }

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function selectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
		
		
		function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}
	
		function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}
	
		function copySelectedOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}
	
function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 
	
// JavaScript Document
PositionX = 100;
PositionY = 100;
defaultWidth  = 500;
defaultHeight = 500;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Cargando ...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["imagenes"].width;');writeln('window.innerHeight=document.images["imagenes"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="imagenes" src='+imageURL+' style="display:block"></body></html>');
close();		
}}


/*************** Funciones para RMA de 5 articulos - MAC  ******************/
function ValidarArticulo(){

	if (document.getElementById('factura').value.length == 0) {
		alert("Ha de escribir el n\u00famero de la factura.");
		document.getElementById('factura').focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return (false);
		}

	if (document.getElementById('material').value.length == 0 && false) {
		alert("Ha de escribir el nombre del material.");
		form1.material.focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return (false);
	}
	
	

	cantidad=document.getElementById('cantidad').value
	if (isNaN(cantidad)){
		alert("El campo cantidad s\u00f3lo puede estar compuesto por n\u00fameros.");
		document.getElementById('cantidad').focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return (false);
		}
	if (document.getElementById('cantidad').value.length == 0) {
		alert("El campo cantidad no puede estar vac\u00edo.");
		document.getElementById('cantidad').focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return (false);
	}
	if (document.getElementById('referencia').value == -1) {
		alert("Ha de seleccionar la referencia.");
		document.getElementById('referencia').focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return (false);
	}
		/*
		var indice = document.getElementById('material').selectedIndex;
		var valor = document.getElementById('material').options[indice].value;
		if (valor=='9999'){
			
			if(document.getElementById('materialManual').value.length == 0){
				alert("El campo Material no puede estar vac\u00edo.");
				document.getElementById('cantidad').focus();
				document.getElementById('dialog').style.display= 'none';
				document.getElementById('mask').style.display= 'none';
				return(false);
				}
			
			
			}
		*/
	if (document.getElementById('fechacompra').value.length != 10) {
		alert("Ha de seleccionar la fecha de compra.");
		document.getElementById('fechacompra').focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return false;
	}
	if (document.getElementById('averia').value.length <= 30) {
		alert("La descripci\u00f3n de la aver\u00eda ha de ser m\u00e1s larga (+30 caracteres).");
		document.getElementById('averia').focus();
		document.getElementById('dialog').style.display= 'none';
		document.getElementById('mask').style.display= 'none';
		return (false);
	}else{ 
			if(document.getElementById('averia').value.length >4000){
				alert("La descripci\u00f3n de la aver\u00eda es demasiado larga (4000 caracteres max).");
				document.getElementById('averia').focus();
				document.getElementById('dialog').style.display= 'none';
				document.getElementById('mask').style.display= 'none';
				return (false);
 			}else{
				return (true);
			}
	}

 }
 
 var Items = new Array();
function Add2RMA(){
	if (Items.length >= 5){
		alert('S\u00f3lo puede agregar hasta 5 art\u00edculos.');
		return;
		}
	var validado = ValidarArticulo();
	if(validado){
		Items.push(Array(
						 document.getElementById('factura').value,    				//0
//						 document.getElementById('familia').value,					//1
//						 document.getElementById('material').value,					//2
//						 document.getElementById('materialManual').value,			//3
						 document.getElementById('referencia').value,					//1.1
						 document.getElementById('fechacompra').value,					//1.2						 
						 document.getElementById('averia').value,					//4
						 document.getElementById('serie').value,					//5
						 document.getElementById('cantidad').value,					//6 
						 document.getElementById('familia').selectedIndex,			//7
						 document.getElementById('material').selectedIndex			//8
						 )
				   );
		//LimpiarDatos();
		};
	//ArmarTabla();
	return validado;
	};

function LimpiarLista(){
	while (Items.length != 0){
		Items.remove(0);
		}
	ArmarTabla();
	}

function LimpiarDatos(){
	 document.getElementById('factura').value = '';
	 document.getElementById('familia').value = '1';
	 document.getElementById('material').value = '9999';
	 Material();
	 document.getElementById('materialManual').value = '';
	 document.getElementById('averia').value = '';
	 document.getElementById('serie').value ='';
	 document.getElementById('cantidad').value ='';
	}

function ArmarTabla(){
	var obtr, obtd;
	if (Items.length > 0){
			document.all.tblItems.style.display = '';
			document.all.NoItems.style.display = 'none';
		}else{
			document.all.tblItems.style.display = 'none';
			document.all.NoItems.style.display = '';
		};
	while (document.all.tblDetalle.firstChild != null) {
			document.all.tblDetalle.removeChild(document.all.tblDetalle.firstChild)
		};
	
	for(var i=0; i < Items.length; i++){
		obtr = document.createElement('TR');
		obtr.valign = 'top';
		//Orden
		obtd = document.createElement('TD');
		obtd.align = 'right';
		obtd.innerHTML = (i+1).toString();
		obtr.appendChild(obtd);

		//Factura
		obtd = document.createElement('TD');
		obtd.align = 'right';
		obtd.innerHTML = Items[i][0].toString();
		obtr.appendChild(obtd);

		//Cantidad
		obtd = document.createElement('TD');
		obtd.align = 'right';
		obtd.innerHTML = Items[i][6].toString();
		obtr.appendChild(obtd);
		
		//Familia/Materia
		obtd = document.createElement('TD');
		if (Items[i][2] == '9999') {
			obtd.innerHTML = document.getElementById('familia').options[Items[i][7]].text + '/' + Items[i][3];
		}else{
			obtd.innerHTML = document.getElementById('familia').options[Items[i][7]].text + '/' + document.getElementById('material').options[Items[i][8]].text;
			};
		obtr.appendChild(obtd);
		
		//Nº Serie
		obtd = document.createElement('TD');
		obtd.align = 'right';
		obtd.innerHTML = Items[i][5];
		obtr.appendChild(obtd);
		
		//Avería
		obtd = document.createElement('TD');
		obtd.align = 'left';
		obtd.innerHTML = Items[i][4];
		obtr.appendChild(obtd);

		obtr.Codigo = (i).toString();
	
		if(obtr.addEventListener){
			obtr.addEventListener('click', Quitar, true)
			}else{
			obtr.attachEvent('onclick', Quitar)
			};
		
		document.all.tblDetalle.appendChild(obtr);
		
		};

	};

function Quitar(){
	var cual = -1;
	if(window.event){
		if(window.event.srcElement.tagName.toUpperCase() == 'TD'){objTmp = window.event.srcElement.parentNode }else{objTmp = window.event.srcElement}
		cual = parseInt(objTmp.Codigo)
		}else{
		cual = parseInt(this.Codigo)
		};
		
	var msg;
	if (Items[cual][2] == '9999') {
		msg = '\u00bfConfirma que desea quitar el art\u00edculo ' + document.getElementById('familia').options[Items[cual][7]].text + '/' + Items[cual][3] + '?';
	}else{
		msg = '\u00bfConfirma que desea quitar el art\u00edculo ' +document.getElementById('familia').options[Items[cual][7]].text + '/' + document.getElementById('material').options[Items[cual][8]].text + '?';
		};
	if (confirm(msg)){
		Items.remove(cual);
		ArmarTabla();
	}
	}
	
function ArmarArticulos(){
	var Articulos = new Array();
	for (var i = 0; i < Items.length; i++){
		Articulos.push(Items[i].join('\t\t\t'))
		}
	document.getElementById('articulos').value = Articulos.join('\n\n\n');

	}
	
	
Array.prototype.remove = function(from, to) {
	  var rest = this.slice((to || from) + 1 || this.length);
	  this.length = from < 0 ? this.length + from : from;
	  return this.push.apply(this, rest);
};

function confirmardelSubFam ()
{
	return confirm('ATENCI\u00d3N\n\nEsta acci\u00f3n eliminar\u00e1 todos los productos asociados a esta subfamilia.\n\u00bfConfirma que desea continuar?');
}

/*********** FIN Funciones para RMA de 5 articulos - MAC  ******************/



