// JavaScript Document

//function click(e){if (document.all) if (event.button == 2) return false;if
//(document.layers) if (e.which == 3) return false;}
//function click2(){event.returnValue=false;return false;}if (document.layers)
//document.captureEvents(Event.MOUSEDOWN);document.onmousedown=click;document.oncontextmenu=click2;

function setpointer(td){
td.setAttribute("bgcolor","#FFD7BB", 0);
}

function releasepointer(td,bg){
td.setAttribute("bgcolor", bg, 0);
}

function validate(form){
	var y = 0;
	var pass = 0;
	for(x = 0;x<form.length;x++){
		if(form.elements[x].name=="pass001")
			pass = 1;
		if(form.elements[x].value=="" && !form.elements[x].disabled)
			y++;
	}
	if(y>0){
		alert("Debe llenar correctamente todas las casillas !!!");
		return false;
	}
	if((pass == 1) && (form.pass001.value != form.pass002.value)){
		alert("El password que ingreso no coincide con la confirmación !!!");
		return false;
	}	
return true;
}

function validate_prog(form){
	if(validate(form)){
		if(form.tipo.value == 1){
			var date001 = new Date(form.fecha001.value.replace("-",","));
			var date002 = new Date(form.fecha002.value.replace("-",","));
			if(date002 > date001)
				return true;
			else
				alert("La fecha final debe ser mayor a la fecha inicial !!!");
		} else
			return true;
	}
	return false;
}

function validate_cust(form){
var y = 0;
	for(x = 0;x<form.length;x++){
		if(form.elements[x].value==""){
			switch(form.elements[x].name){
			case "nombre":
			case "apellido":
			case "fecha_nac":
			case "profesion":
			case "numero":
			case "area":
			case "telefono":
				y++;
			break;
			}
		}
	}
	if(y>0){
		alert("Debe llenar correctamente todas las casillas !!!");
		return false;
	}
return true;
}

function modi_user(form){
	if(form.dll.value == 3)
		form.dll.value = 2;
	else
		form.dll.value = 0;
	form.submit();
}

function update_user(form){
	var y = 0;
	var pass = 0;
if((form.pass001.value != "") || (form.pass002.value != "")){
	for(x = 0;x<form.length;x++){
		if(form.elements[x].name=="pass001")
			pass = 1;
		if(form.elements[x].value=="")
			y++;
	}
} else {
	for(x = 0;x<form.length;x++){
		if((form.elements[x].name!="pass001") && (form.elements[x].name!="pass002") && (form.elements[x].value=="")){ 
			y++;
		}
	}
}
	if(y>0){
		alert("Debe llenar correctamente todas las casillas !!!");
		return false;
	}
	if((pass == 1) && (form.pass001.value != form.pass002.value)){
		alert("El password que ingreso no coincide con la confirmación !!!");
		return false;
	}	
return true;
}

function modi_destiny(form){
	form.act.value = 0;
	form.submit();
	return;
}

function modi_form(form){
	form.dll.value = 0;
	form.submit();
	return;
}

function modi_prog(form){
	form.add.value = 0;
	form.submit();	
}

function inic(txt){
var str;
var arr;
var rst = "";
str = txt.form.nombre.value + " " + txt.form.apellido.value;
arr = str.split(" ");
for(x=0; x<arr.length; x++)
	rst += arr[x].substr(0,1);
txt.form.iniciales.value = rst;
return;
}

function inicc(txt){
var str;
var arr;
var rst = "";
str = txt.form.nombre.value;
arr = str.split(" ");
for(x=0; x<arr.length; x++)
	rst += arr[x].substr(0,1);
txt.form.iniciales.value = rst;
return;
}

function allow_nav(form){
form.nav.value = "1";
}

function pay(form, saldo){
if(validate(form)){
	if(isNaN(form.abono.value)|| !(form.abono.value > 0)){
		alert("El valor que ingreso no es válido !!!");
		form.abono.value = number_format(form.abono);
	}
	else if(parseFloat(form.abono.value) > parseFloat(saldo))
		alert("El valor que ingreso es mayor que el saldo !!!");
	else
		form.submit();
}
return false;
}

function check_in(form, id){
if(confirm('Esta seguro de realizar el check in?')){
	form.id_prog.value = id;
	form.submit();}else{window.location.href=window.location.href;}
}
function check_in2(form, id){

	form.id_mnr.value = id;
	form.submit();
}
function clean_seat(form, name, id, idm){
	if (confirm("Esta a punto de limpiar el asiento de \"" + name + "\",\ndesea continuar?")){
		form.cls.value = 1;
		if(idm==undefined)
			form.id_prog.value = id;
		else
			form.id_mnr.value = id;
		form.submit();
	}
}

function number_format(number){
if(isNaN(number.value))
	number.value = 0;
number.value = round(number.value,2);
number.value = curr(number.value);
return number.value;
}

function number_format_int(number){
if(isNaN(number.value))
	number.value = 0;
number.value = Math.round(number.value);
return number.value;
}

function round(number,X) {
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
function curr(number){
	var x;
	var y = number.length - 1;
	for(x=0;x<number.length;x++){
		if(number.substr(x,1) == "."){
			y = x;
		}
	}
	switch((number.length-1) - y){
	case 1:
	number += "0";
	break;
	case 0:
	number += ".00";
	break;
	}
return number;
}

function createWindow(page, name, w, h, s, mb) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	if(mb==undefined)
		mb = 'yes';
	var features =
        'width='        + w +
        ',height='      + h +
		',top='			+ wint +
		',left='		+ winl + 
		',menubar='      + mb +
        ',scrollbars='  + s +
		',resizable='   + 'no';
    window.open (page, name, features);
}
