// -----------------------------------------------------------
//  Calcular Importe total
// -----------------------------------------------------------
Libros_01_arreglo = new Array('L0001');
Libros_01_valor= 15.00;

Libros_02_arreglo = new Array('L0002');
Libros_02_valor= 15.00;

Libros_03_arreglo = new Array('L0003');
Libros_03_valor= 12.00;

Cuaderno_05_arreglo = new Array('C0005');
Cuaderno_05_valor = 6.00;

Libro_04_arreglo = new Array('L0004');
Libro_04_valor = 15.00;

Cuaderno_01_arreglo = new Array('C0001');
Cuaderno_01_valor = 2.00;

Cuaderno_02_arreglo = new Array('C0002');
Cuaderno_02_valor = 2.00;

Libro_05_arreglo = new Array('L0005');
Libro_05_valor = 20.00;

Libro_06_arreglo = new Array('L0006');
Libro_06_valor = 20.00;

function isDigit (c)
{	return ((c >= "0") && (c <= "9"))
}
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function checknumber(s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! isDigit(c) ) {
        return; }
    }
    return true;
}

function calcula(item) {
	arreglo = eval(item+"_arreglo");
	valor = eval(item+"_valor");
	largo = arreglo.length;
	var sumax=0;
	for (i=0;i<largo;i++) {
		j=eval("document.formSKY."+arreglo[i]+"_cantidad.value");
		if ( checknumber(j) ) {
			eval("document.formSKY."+arreglo[i]+"_suma.value=document.formSKY."+arreglo[i]+"_cantidad.value*valor");
			sumax = sumax + eval("document.formSKY."+arreglo[i]+"_suma.value")*1; }
		else {
			alert ("Error : ingrese solamente numeros");
			eval("document.formSKY."+arreglo[i]+"_cantidad.focus()");
			//eval("document.formSKY."+arreglo[i]+"_cantidad.select()");
			i=largo;
			return;
			}
		
	}
	eval("document.formSKY."+item+".value = +sumax");
	eval("document.formSKY."+item+"_resumen.value = +sumax");
	total();
}

function total(){
document.formSKY.TOTAL_GENERAL.value  = document.formSKY.Libros_01_resumen.value *1 + document.formSKY.Libros_02_resumen.value *1 + document.formSKY.Libros_03_resumen.value *1 + document.formSKY.Cuaderno_05_resumen.value *1 + document.formSKY.Libro_04_resumen.value *1 + document.formSKY.Cuaderno_01_resumen.value *1 + document.formSKY.Cuaderno_02_resumen.value *1 + document.formSKY.Libro_05_resumen.value *1 + document.formSKY.Libro_06_resumen.value *1;
}


// -----------------------------------------------------------------------------
// SKYmedia Form 
// -----------------------------------------------------------------------------

function Form_Validator(SkyForm) {

// Configuracion del lenguaje ************
	var language			= new Array();
	language.spanish		= new Array();

		language.spanish.header	= "Se ha producido un error: \n   -> El campo ";
		language.spanish.require	= " es obligatorio   \n";


// -----------------------------------------------------------
//  Validar campo IMPORTE
// -----------------------------------------------------------

	if (SkyForm.TOTAL_GENERAL.value == "" || SkyForm.TOTAL_GENERAL.value == "0" ) {
		alert("Se ha producido un error: \n   -> El importe \"Total\" de su orden no es valido. \n   Recuerde que debe calcular el importe Total.");
		SkyForm.L0001_cantidad.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo nombre
// -----------------------------------------------------------

	if (SkyForm.nombre.value == "") {
		alert(language.spanish.header +"\"Nombre\""+language.spanish.require);
		SkyForm.nombre.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo apellido
// -----------------------------------------------------------

	if (SkyForm.apellido.value == "") {
		alert(language.spanish.header +"\"Apellido\""+language.spanish.require);
		SkyForm.apellido.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo direccion
// -----------------------------------------------------------

	if (SkyForm.direccion.value == "") {
		alert(language.spanish.header +"\"Dirección\""+language.spanish.require);
		SkyForm.direccion.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo ciudad
// -----------------------------------------------------------

	if (SkyForm.ciudad.value == "") {
		alert(language.spanish.header +"\"Ciudad\""+language.spanish.require);
		SkyForm.ciudad.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo estado
// -----------------------------------------------------------

	if (SkyForm.estado.value == "") {
		alert(language.spanish.header +"\"Estado/Provincia\""+language.spanish.require);
		SkyForm.estado.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo pais
// -----------------------------------------------------------

	if (SkyForm.pais.value == "") {
		alert(language.spanish.header +"\"Pais\""+language.spanish.require);
		SkyForm.pais.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo codigo
// -----------------------------------------------------------

	if (SkyForm.codigo.value == "") {
		alert(language.spanish.header +"\"Código Postal\""+language.spanish.require);
		SkyForm.codigo.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo telefono
// -----------------------------------------------------------

	if (SkyForm.telefono.value == "") {
		alert(language.spanish.header +"\"Teléfono\""+language.spanish.require);
		SkyForm.telefono.focus();
		return (false);
	}


// -----------------------------------------------------------
//  Validar campo email
// -----------------------------------------------------------

	if (!SkyForm.email.value.match(/\b(^(\S+@).+((\..{2,4}))$)\b/gi)) {
		alert(language.spanish.header +"\"E-mail\""+language.spanish.require+"   Debe contener una dirección Valida.");
		SkyForm.email.focus();
		return (false);
	}


}
