﻿var p1 = Array();
p1[0] = '1603&SAN JOSE-MANUEL ANTONIO #AM&SAN JOSE TO QUEPOS&08:00&11:50&39&19.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S481&S414&p1';
p1[1] = '1604&SAN JOSE-MANUEL ANTONIO #PM&SAN JOSE TO QUEPOS&14:30&18:05&39&19.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S481&S414&p1';
p1[2] = '2604&FORTUNA-MANUEL ANTONIO #AM&FORTUNA TO QUEPOS&08:00&12:50&39&19.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S194&S414&p1';
p1[3] = '2605&FORTUNA-MANUEL ANTONIO #PM&FORTUNA TO QUEPOS&14:30&18:50&29&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S194&S414&p1';
p1[4] = '6611&MONTEVERDE-MANUEL ANTONIO #AM&MONTEVERDE TO QUEPOS&08:30&12:50&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S388&S414&p1';
p1[5] = '1603&SAN JOSE-MANUEL ANTONIO #AM&JACO TO QUEPOS&11:00&11:50&29&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S431&S414&p1';
p1[6] = '5622&LIBERIA-MANUEL ANTONIO #AM&LIBERIA TO QUEPOS&10:00&14:05&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S321&S414&p1';
p1[7] = '5610&FLAMINGO-MANUEL ANTONIO #AM&CONCHAL TO QUEPOS&08:00&14:05&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S479&S414&p1';
p1[8] = '5609&PUERTO CARRILLO-MANUEL ANTONIO #AM&PUERTO CARRILLO TO QUEPOS&09:30&14:35&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S378&S414&p1';

var p2 = Array();
p2[0] = '6104&MANUEL ANTONIO-SAN JOSE #AM&QUEPOS TO SAN JOSE&08:30&12:45&39&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S481&p2';
p2[1] = '6103&MANUEL ANTONIO-SAN JOSE #PM&QUEPOS TO SAN JOSE&13:30&17:30&39&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S481&p2';
p2[2] = '6204&MANUEL ANTONIO-FORTUNA #AM&QUEPOS TO FORTUNA&07:30&13:30&29&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S194&p2';
p2[3] = '6205&MANUEL ANTONIO-FORTUNA #PM&QUEPOS TO FORTUNA&14:30&18:30&29&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S194&p2';
p2[4] = '6614&MANUEL ANTONIO-MONTEVERDE #PM&QUEPOS TO MONTEVERDE&14:30&18:30&39&19.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S388&p2';
p2[5] = '6104&MANUEL ANTONIO-SAN JOSE #AM&QUEPOS TO JACO&08:30&10:00&29&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S431&p2';
p2[6] = '6103&MANUEL ANTONIO-SAN JOSE #PM&QUEPOS TO JACO&13:30&14:45&29&14.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S431&p2';
p2[7] = '6522&MANUEL ANTONIO-LIBERIA #AM&QUEPOS TO LIBERIA&07:30&12:00&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S321&p2';
p2[8] = '6510&MANUEL ANTONIO-FLAMINGO #AM&QUEPOS TO CONCHAL&07:30&13:00&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S479&p2';
p2[9] = '6509&MANUEL ANTONIO-PUERTO CARRILLO #AM&QUEPOS TO PUERTO CARRILLO&07:30&13:45&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S378&p2';
p2[10] = '6601&MANUEL ANTONIO-MONTEZUMA #AM&QUEPOS TO TAMBOR&08:30&14:00&49&24.5&10&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&12/1/2008&11/30/2010 11:59:59 PM&S414&S488&p2';

var eleSegm = new Array("0");
var TotalBook = 0;
var paso = "";
var item = "";
var infoHotel = "";
var numPass = Array(1, 0, 0, 0);
var campPass = Array();
var infoPass = Array();
var infoCard = Array();
var FechaSelec = Array();
var array_place = Array();
var Segm = "";
var itinerario = "";
var infoContHotel = Array();
var codContable = "000415"
var nameCustomer="HOTEL BELMAR"
var usuario = 1;
var tmpConsulta = "empty";
var resultsServicio ="empty";
var resultsDisponibilidad = Array("","");
var respServi="empty";
var placeOriDest = Array();
var horaPlace="empty";
var horasPlaces=Array();
var ctoBorrar="";
var pdcpOriDest=Array();
var tmpId="0";
var Session="";
var respCookies="";
var sec = 0;
var wait ="";
var PosiSegment=0;
var contEsSer=0;
var contNpSer=0;
var variables="";

function book(segment) { 
	table = document.getElementById('tableBook');
	for(var i=1; i<=table.rows.length-1; i++){
		table.tBodies[0].deleteRow(i);
	}
	
	tmpRem=false;
    PosiSegment=1;
    paso = "Hotel";
    item = 1;
    infoHotel = "BELMAR&1&206&S414";
    var pos = segment.split("-");
    var posi = parseInt(pos[1]);
    if (pos[0] == "p1") {
        segment = p1[posi];
    }
    else {
        segment = p2[posi];
    }
    var tmpSegm = segment.split("&");
    Segm = tmpSegm[2];
    eleSegm[1] = segment;
   
    var codOrigen = tmpSegm[14];
    var codOri = parseInt(codOrigen.substring(1, codOrigen.length));
	var codDestino = tmpSegm[15];
    var codDest = parseInt(codDestino.substring(1, codDestino.length));
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/place/llamarSelec.asp?PlaceOrigen=" + codOri+"&PlaceDestino="+codDest,'callbackPlace',post,500); 
}

function callbackPlace(data){
	tmpConsulta="";
	tmpConsulta = data;
	placeOriDest= tmpConsulta.split("|");
    pdcpOriDest[PosiSegment]= placeOriDest[1]+"|"+placeOriDest[2];
    if(PosiSegment==1){
    	bookTmp();
    }
    else{
    	addRow();
    }
}

function bookTmp(){
	tmpConsulta="";
	Segm = "";
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/hoteles/user.asp?codContable=" + codContable+"&customer="+nameCustomer,'callback',post,500);
}

function addRow()   
{   
	var tmpHtl = infoHotel.split("&");
    numRows = table.rows.length;
    cont="";
    cont=numRows;
	rowInfo ="";
	rowInfo = table.insertRow(numRows);  
	rowInfo.setAttribute('id', 'tdServices' + cont); 
	var x = table.rows[numRows].cells; 
	
	var info = eleSegm[PosiSegment].split("&");  
	
	//SERVICIO
	var cellServicio = document.createElement("td");
	cellServicio.innerHTML = 'Service ' + cont;
	rowInfo.appendChild(cellServicio);
	
	//NOMBRE SERVICIO
	var cellNombre = document.createElement("td");
	cellNombre.innerHTML = info[1];
	rowInfo.appendChild(cellNombre);
	
	//HORA
	var cellHora = document.createElement("td");
	cellHora.innerHTML = info[3];
	rowInfo.appendChild(cellHora);
	
	//TARIFA
	var cellRate = document.createElement("td");
	var temp = document.createElement('a');
	temp.setAttribute(dclase, 'hrfaTotal');
	temp.id = 'hrfaServ' + cont;
	temp.valor = eleSegm[cont];
	var tmpRate = numFormat((parseFloat(info[5]) * parseInt(numPass[0])) + (parseFloat(info[6]) * parseInt(numPass[1])) + (parseFloat(info[7]) * parseInt(numPass[2])));
	temp.appendChild(document.createTextNode(numFormat(tmpRate)));
	temp.onclick = fInfoPas;
	cellRate.appendChild(temp);
	rowInfo.appendChild(cellRate);
	
	//HOTELES
	if (info[14] != tmpHtl[3]) {
		var codPlace = info[14];
	    codPlace = codPlace.substring(1, codPlace.length);
	}
	else {//drop off
		var codPlace = info[15];
	    codPlace = codPlace.substring(1, codPlace.length);
	}
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/Place/place.asp?PlaceOrigen=" + codPlace,'callbackCBPlace',post,500); 		
}


function callback(data){
	tmpConsulta="";
	tmpConsulta = data;
	infoContHotel = tmpConsulta.split("&");
	tmpConsulta="";
	fCargarCompra();
}

function fCargarCompra(cambiar) {
    tmpHtl = infoHotel.split("&");
    div = document.getElementById("bookServices");
    table = document.getElementById('tableBook');
    tbody = document.getElementById("bodyBook");
 	cont="";
 	cont = 1;
    if(eleSegm.length != 1){
	    var info = eleSegm[cont].split("&");
	    //INFO
	    rowinfo="";
	    rowInfo = document.createElement("tr");
	    rowInfo.setAttribute('id', 'tdServices' + cont);
	
	    //SERVICIO
	    var cellServicio = document.createElement("td");
	    cellServicio.innerHTML = 'Service ' + cont;
	    rowInfo.appendChild(cellServicio);
	    
	    //NOMBRE SERVICIO
	    var cellNombre = document.createElement("td");
	    cellNombre.innerHTML = info[1];
	    rowInfo.appendChild(cellNombre);
	    
	    //HORA
	    var cellHora = document.createElement("td");
	    cellHora.innerHTML = info[3];
	    rowInfo.appendChild(cellHora);
	    
	    //TARIFA
	    var cellRate = document.createElement("td");
	
	    var temp = document.createElement('a');
	    temp.setAttribute(dclase, 'hrfaTotal');
	    temp.id = 'hrfaServ' + cont;
	    temp.valor = eleSegm[cont];
	    var tmpRate = numFormat((parseFloat(info[5]) * parseInt(numPass[0])) + (parseFloat(info[6]) * parseInt(numPass[1])) + (parseFloat(info[7]) * parseInt(numPass[2])));
	    temp.appendChild(document.createTextNode(numFormat(tmpRate)));
	    temp.onclick = fInfoPas;
	    cellRate.appendChild(temp);
	
	    rowInfo.appendChild(cellRate);
	    
	    //HOTELES
	    if (info[14] != tmpHtl[3]) {//Pickup
			var codPlace = info[14];
			codPlace = codPlace.substring(1, codPlace.length);
		}
	    else {//drop off
	        var codPlace = info[15];
	        codPlace = codPlace.substring(1, codPlace.length);
	    }  
			//'***************aqui vamos ha hacer el place
	    OX.AJAST.call("http://www.interbusonline.com/htgt/asp/Place/place.asp?PlaceOrigen=" + codPlace,'callbackCBPlace',post,500); 
    }
    else{
    	f_cambiarCondi();
    	fCargarTotal();
    }
}
function callbackCBPlace(data){
    resultado = data;
    var divCombo = document.createElement("div");
    divCombo.id = "divComboPlace"+PosiSegment;
    
	var dorigen = document.createElement('select')
	dorigen.id = "ComboPlace"+PosiSegment;
	dorigen.parentId = "Place"+PosiSegment;
	dorigen.onchange = fPickDrop;
    results = resultado.split("|");      
    var other = "";
    var inicio = results[1];
    if (results[0] != "1") {
        //OTHER HOTEL;
        var hotel = document.createElement('option');
        hotel.text = "HOTEL NOT LISTED?, TYPE IT BELOW";
        hotel.value = 0;
        if (isIe) {
            dorigen.add(hotel);
        }
        else {
            dorigen.appendChild(hotel);
        }
        //CONSULTA;
        for (var i = 1; ele = results[i]; i++) {
            var opcion = document.createElement('option');
            resultado = ele.split("-");
            opcion.text = resultado[1] + " (" + resultado[2] + ")";
            opcion.name = resultado[1];
            opcion.value = resultado[0];

            if (isIe) {
                dorigen.add(opcion);
            }
            else {
                dorigen.appendChild(opcion);
            }
        }
    }
    else {
        var opcion = document.createElement('option');
        opcion.text = "Select One...";
        opcion.value = resultado[0];
        if (isIe) {
            dorigen.add(opcion);
        }
        else {
            dorigen.appendChild(opcion);
        }
        dorigen.disabled = true;
    }
    
    var br = document.createElement('br');
    var input = document.createElement('input');
    input.value = "Type hotel name if not listed"
    input.id = "inputPlace"+PosiSegment;

    divCombo.appendChild(dorigen)
    divCombo.appendChild(br)
    divCombo.appendChild(input)
    
    tmpConsulta="";
    
    cellPickup = document.createElement("td");
    cellPickup.appendChild(divCombo);
    rowInfo.appendChild(cellPickup);
	post_fcargar_compra();
}

function post_fcargar_compra(){
	//FECHA
	var cellFecha = document.createElement("td");
	var etiquetaFecha = document.createElement("FECHA");
	etiquetaFecha.setAttribute('id', 'fecha' + PosiSegment);
    if (FechaSelec == "") {
        etiquetaFecha.setAttribute('valor', '');
    }
    else {
        if (FechaSelec[cont] == null) {
            etiquetaFecha.setAttribute('valor', incFecha(FechaSelec[PosiSegment- 1]));
        }
        else {
            etiquetaFecha.setAttribute('valor', FechaSelec[PosiSegment]);
        }
    }

    etiquetaFecha.setAttribute('fin', '11/20/2011');
    etiquetaFecha.setAttribute('encabezado', 'false');
    cellFecha.appendChild(etiquetaFecha);
    rowInfo.appendChild(cellFecha);
    
    //BOTON REMOVE
	var cellRemove = document.createElement("td");
	var Button = document.createElement("input");
	Button.setAttribute(dclase, 'btnRemo');
	Button.id = 'Btn' + PosiSegment;
	Button.pos = PosiSegment;
	Button.type = "button";
	Button.onclick = fRemove;
	cellRemove.appendChild(Button);
	rowInfo.appendChild(cellRemove);
	
	tbody.appendChild(rowInfo);
	table.appendChild(tbody);
    div.appendChild(table);
   
    fCrearFormulario();
    if (array_place != "" || typeof (array_place) != "undefined") {
        fCambiarPlace();
    }
	posic=PosiSegment;
	fObtenerDispo();
	fMostrarAdd();
	fCargarTotal();
	
	if(tmpRem==false){
		if(PosiSegment==1){
		    WindowsPopup('How to Get There');
		    desbloquear();
	    }
    }
}

function fPickDrop() {
	var place=this.parentId;
	var texValue="";
	var valoTex = this.options[this.selectedIndex];
	
	var name = "input" + this.parentId;
    var input = document.getElementById(name);
    
    if (valoTex.value != 0) {
    	texValue = valoTex.name + "&1&" + valoTex.value;
    	input.style.display = "none";
    }
    else {
		texValue = "Type hotel name if not listed&0&0";
		input.style.display = "block";
    }
    
    var placPosi = place.substring(0, place.length - 1);
    var posic = parseInt(place.substring(place.length, place.length - 1));
    if(texValue!=array_place[posic]){
		array_place[posic] = texValue;
	    f_cambiarCondi();
	    var tmpRcPlace=eleSegm[posic].split("&");
	    if(tmpRcPlace[16]=='p2'){
	    	var tmpRcHotel=infoHotel.split("&");
	    }
	    else{
	    	var tmpRcHotel=texValue.split("&");
	    }	
	    pos=posic;
	    OX.AJAST.call("http://www.interbusonline.com/htgt/asp/place/selectTimePlace.asp?Property=" + tmpRcHotel[0]+ "&Route=" +tmpRcPlace[0],'callbackTimePlace',post,500);
	}
}

function callbackTimePlace(data){
	horaPlace= data.split("|");
    if (horaPlace[0] == "0") {
        horasPlaces[pos]= horaPlace[1];
    }
    else {
        horasPlaces[pos]= false;
    }
}

function fMostrarAdd() {
    if (eleSegm.length <= 2) {
        document.getElementById("addService").style.display = "block";
    }
}

function f_cambiarCondi() {
    var tb = document.getElementById('tbAddSer');
    tb.style.display = 'none';
}

function fCambiarPlace() {
    for (var cont = 1; cont < array_place.length; cont++) {
        var nom = "ComboPlace" + cont;
        var comboPlace = document.getElementById(nom);
        if (array_place[cont] != "") {
            var tmp = array_place[cont].split("&");
            if (tmp[2] == "0") {
                var inputPlace = "inputPlace" + cont;
                var cbPlace = document.getElementById(inputPlace);
                cbPlace.value = tmp[0];
            }
            comboPlace.value = tmp[2];
            comboPlace.onchange();
        }
    }
}

function fRemove() {
	PosiSegment=1;
	tmpRem=true;
    vacioLabel();
    var tmpDel="";
    var tmpSeg="";
    var tmpFch="";
    var tmpPlc="";
    var pos = this.pos
    if(eleSegm.length!=2){
	    if(pos==1){
	    	tmpDel=resultsDisponibilidad[2];
	    	tmpSeg=eleSegm[2];
	    	tmpFch=FechaSelec[2];
	    	tmpPlc=array_place[2];
	    	psBor=2;
	    	
	    }
	    else{
	    	tmpDel=resultsDisponibilidad[1];
	    	tmpSeg=eleSegm[1];
	    	tmpFch=FechaSelec[1];
	    	tmpPlc=array_place[1];
	    	psBor=1;
	    }
	    resultsDisponibilidad = Array("","");
	    resultsDisponibilidad[1]=tmpDel;
	
	    eleSegm = new Array("0");
	    eleSegm[1]=tmpSeg;
	    
	    FechaSelec = Array();
	    FechaSelec[1] = tmpFch;
	    
		array_place = Array();
		array_place[1] = tmpPlc;
		table.tBodies[0].deleteRow(pos);
		if(pos==1){
			fModificarInfo(psBor);
		}
		
	}
	else{
		resultsDisponibilidad = Array("","");
		eleSegm = new Array("0");
		FechaSelec = Array();
		array_place = Array();
		table.tBodies[0].deleteRow(pos);
	}
	//TotalBook = 0;
	fMostrarAdd();
	fCargarTotal();
}

function fModificarInfo(psBor){
	var info = eleSegm[1].split("&");
	
	var fila = document.getElementById('tdServices' + (psBor));
	//SERVICIO
	celda = fila.getElementsByTagName('td')[0]
	celda.innerHTML = 'Service 1';

	//TARIFA
	var temp = document.getElementById('hrfaServ' + psBor);
	temp.innerHTML ='';
	temp.valor = eleSegm[1];
	var tmpRate = numFormat((parseFloat(info[5]) * parseInt(numPass[0])) + (parseFloat(info[6]) * parseInt(numPass[1])) + (parseFloat(info[7]) * parseInt(numPass[2])));
	temp.appendChild(document.createTextNode(numFormat(tmpRate)));
	temp.onclick = fInfoPas;
	temp.setAttribute('id', 'hrfaServ1');
	var divComboPlace = document.getElementById('divComboPlace' + (psBor));
	divComboPlace.setAttribute('id', 'divComboPlace1');
			
	var nbm='ComboPlace'+psBor;
	var ComboPlace= document.getElementById(nbm);
	
	ComboPlace.setAttribute('id', 'ComboPlace1');
	ComboPlace.setAttribute('parentId', 'Place1');
			
	var inputPlace= document.getElementById('inputPlace' + (psBor));
	inputPlace.setAttribute('id', 'inputPlace1');         
	
	var divFechafecha= document.getElementById('divFechafecha' + (psBor));
	divFechafecha.setAttribute('id', 'divFechafecha1');
		
	var tbFecha= document.getElementById('fecha' + (psBor));
	tbFecha.setAttribute('id', 'Fecha1');
			
	var ComboMesfecha= document.getElementById('ComboMesfecha' + (psBor));
	ComboMesfecha.setAttribute('id', 'ComboMesfecha1'); 
	ComboMesfecha.setAttribute('parentId', 'fecha1');
			
	var ComboDiafecha= document.getElementById('ComboDiafecha' + (psBor));
	ComboDiafecha.setAttribute('id', 'ComboDiafecha1'); 
	ComboDiafecha.setAttribute('parentId', 'fecha1');
			
	var ComboAniofecha= document.getElementById('ComboAniofecha' + (psBor));
	ComboAniofecha.setAttribute('id', 'ComboAniofecha1'); 
	ComboAniofecha.setAttribute('parentId', 'fecha1');	        

	var Btn= document.getElementById('Btn' + (psBor));
	Btn.setAttribute('id', 'Btn1');
	Btn.setAttribute('pos', '1');
			       
	fila.setAttribute('id', 'tdServices1');
}

function vacioLabel() {
    for (var i = 1; i < eleSegm.length; i++) {
        var inputPlace = "inputPlace" + i;
        var cbPlace = document.getElementById(inputPlace);
        if (cbPlace == null) {
            array_place[i] = "Type hotel name if not listed&0&0";
        }
        else {
            if (array_place[i] == "" || typeof (array_place[i]) == "undefined") {
                if (cbPlace.value == "Type hotel name if not listed") {
                    array_place[i] = "Type hotel name if not listed&0&0";
                }
                else {
                    array_place[i] = cbPlace.value + "&0&0";
                }
            }
            else {
                if (array_place[i] == "OTHER TYPE YOUR HOTEL") {
                    if (cbPlace.value == "Type hotel name if not listed") {
                        array_place[i] = "Type hotel name if not listed&0&0";
                    }
                    else {
                        array_place[i] = cbPlace.value + "&0&0";
                    }
                }
            }
        }
    }
}


function fCargarTotal() {
    cambiarTotal();
    var div = document.getElementById("divTotal");
    var tableTotal = document.getElementById('tableTotal');
    if (tableTotal != null) {
        var fila = document.getElementById("trTotal");
        fila.parentNode.removeChild(fila);
    }
    else {
        var table = document.createElement('table');
        table.setAttribute('id', 'tableTotal');
        var pos = 1;
    }

    var tableTotal = document.createElement('table');
    tableTotal.setAttribute('id', 'tableTotal');
    var rowTotal = document.getElementById('trTotal');
    if (rowTotal != null) {
        rowTotal.parentNode.removeChild(rowTotal);
    }

    var rowTotal = document.createElement("tr");
    rowTotal.setAttribute('id', 'trTotal');
    rowTotal.setAttribute(dclase, "detalleTableheader");

    var uno = document.createElement('label');
    uno.appendChild(document.createTextNode('Total USD  '));
    uno.setAttribute('id', 'uno');
    var dos = document.createElement('label');
    dos.appendChild(document.createTextNode('     for all travelers'));
    dos.setAttribute('id', 'dos');
    var hrfa = document.createElement('a');
    hrfa.setAttribute('id', 'hrfa');
    hrfa.setAttribute(dclase, 'hrfaTotal');
    hrfa.appendChild(document.createTextNode(numFormat(TotalBook)));
    hrfa.onclick = fInfoTotal;
    rowTotal.appendChild(uno);
    rowTotal.appendChild(hrfa);
    rowTotal.appendChild(dos);

    //TOTAL
    tableTotal.appendChild(rowTotal);
    div.appendChild(tableTotal);
}

function cambiarTotal() {
    campPassenger();
    var adultPass = parseInt(numPass[0]);
    var childPass = parseInt(numPass[1]);
    var extraPass = parseInt(numPass[2]);

    var valorTotal = 0;
    for (var cp = 1; cp < eleSegm.length; cp++) {
        var tmpEle = eleSegm[cp];
        tmpEle = tmpEle.split("&");
        var tAdult = tmpEle[5];
        var tChild = tmpEle[6];
        var tExtra = tmpEle[7];
        valorTotal = parseFloat(valorTotal) + (parseFloat(tAdult) * adultPass);
        valorTotal = parseFloat(valorTotal) + (parseFloat(tExtra) * extraPass);
        valorTotal = parseFloat(valorTotal) + (parseFloat(tChild) * childPass);
    }
    TotalBook = "";
    TotalBook = valorTotal;
}


function fInfoPas() {
    var ele = this.valor;
    var pos = this.id;
    ele = ele.split("&")
    pos = parseInt(pos.substring(8, pos.length));
    var totalpass = numFormat(ele[5]) * numFormat(numPass[0]) + numFormat(ele[6]) * numFormat(numPass[1]) + numFormat(ele[7]) * numFormat(numPass[2]);
    tmp = "<table>";
    tmp = tmp + "<tr><td style='width: 50px; height:30px' colspan='3' ><b>SERVICE " + pos + "</b></td></tr>";
    tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px'>" + numPass[0] + " (" + numFormat(ele[5]) + " per Adult)</td><td width= '150px' align='right'><p align='right'>" + numFormat(ele[5] * numPass[0]) + "</p></td></tr>";
    tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px'>" + numPass[1] + " (" + numFormat(ele[6]) + " per Child)</td><td width= '150px' aling='right'><p align='right'>" + numFormat(ele[6] * numPass[1]) + "</p></td></tr>";
    tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px'>" + numPass[2] + " (" + numFormat(ele[7]) + " per extra)</td><td width= '150px' aling='right'><p align='right'>" + numFormat(ele[7] * numPass[2]) + "</p></td></tr>";
    tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px' aling='right'><b><p align='right'>TOTAL</p></b></td><td width= '150px' aling='right'><b><p align='right'>" + numFormat(totalpass) + "</p></b></td></tr>";
    tmp = tmp + "</table>";
    createVtnHow("Information Passenger", tmp);
}
function fInfoTotal() {
    tmp = "<table>";
    for (var td = 1; td < eleSegm.length; td++) {
        var ele = eleSegm[td];
        ele = ele.split("&");
        var totalpass = numFormat(ele[5]) * numFormat(numPass[0]) + numFormat(ele[6]) * numFormat(numPass[1]) + numFormat(ele[7]) * numFormat(numPass[2]);
        tmp = tmp + "<tr><td style='width: 50px; height:30px' colspan='3' ><b>SERVICE " + td + "</b></td></tr>";
        tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px'>" + numPass[0] + " (" + numFormat(ele[5]) + " per Adult)</td><td width= '150px' align='right'><p align='right'>" + numFormat(ele[5] * numPass[0]) + "</p></td></tr>";
        tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px'>" + numPass[1] + " (" + numFormat(ele[6]) + " per Child)</td><td width= '150px' aling='right'><p align='right'>" + numFormat(ele[6] * numPass[1]) + "</p></td></tr>";
        tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px'>" + numPass[2] + " (" + numFormat(ele[7]) + " per extra)</td><td width= '150px' aling='right'><p align='right'>" + numFormat(ele[7] * numPass[2]) + "</p></td></tr>";
        tmp = tmp + "<tr><td style='width: 50px'></td><td width= '300px' aling='right'><b><p align='right'>TOTAL</p></b></td><td width= '150px' aling='right'><b><p align='right'>" + numFormat(totalpass) + "</p></b></td></tr>";
    }
    tmp = tmp + "</table>";
    createVtnHow("Information Passenger", tmp);
}

function obternerFec(ele) {
    var posic = parseInt(ele.substring(5, ele.length)) - 1;
    return FechaSelec[posic];
}

function cambiarFec(ele, fch) {
    var posic = parseInt(ele.substring(5, ele.length));
    FechaSelec[posic] = fch;
}

function contruirFech(ele, fch) {
    var posic = parseInt(ele.substring(5, ele.length));
    var fechaSig = fch;
    FechaSelec[posic] = fch;
    var name = "fecha" + (posic);
    FechaSelec[posic] = fechaSig;
    var elemento = document.getElementById(name);
    var padre = elemento.parentNode;
    var obj = new objFecha(name, fechaSig, elemento.fin, 'false');
    padre.replaceChild(obj.getDiv(), elemento);
    PosiSegment=posic;
    fCambiarPlacePickup()
}

function fCambiarPlacePickup() {
    var nom = "ComboPlace" + PosiSegment;
    var comboPlace = document.getElementById(nom);
    if (typeof(array_place[PosiSegment]) != "undefined") {
       if (array_place[PosiSegment] != "") {
	       var tmp = array_place[PosiSegment].split("&");
	       if (tmp[2] == "0") {
	          var inputPlace = "inputPlace" + PosiSegment;
	          var cbPlace = document.getElementById(inputPlace);
	          cbPlace.value = tmp[0];
	       }
	       comboPlace.value = tmp[2];
	       comboPlace.onchange();
       }
    }
    fObtenerDispo();  
}

function actionFunc(){
	if(sec < 8){
		wait.updateText('Loading' + (++sec) + '... Please Wait!');
		setTimeout(actionFunc, 1000);
	}else{
		wait.hide();
	}
}

function fObtenerDispo() {
	var tmpEle = eleSegm[PosiSegment].split("&");
	var tmpEle = eleSegm[PosiSegment].split("&");
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/segmento/segmentoHtgt.asp?cod=" + tmpEle[0] + "&fecha=" + FechaSelec[PosiSegment] + "&hora=" + tmpEle[3] + "&cantPass=" + numPass + "&tarifa=" + tmpEle[5] + "," + tmpEle[6] + "," + tmpEle[7],'callbackDisp',post,500); 
}

function callbackDisp(data){
	resultsServicio="";
	tmpConsulta=data;
	resultsServicio= tmpConsulta.split("|");
	aspDispo(PosiSegment)
}

function fCambiarPlacePax() {
	cambiarTotal();	
	fDisponibilidad();
	fCargarTotal();
}

function fDisponibilidad(){
	for(var i=1; i<resultsDisponibilidad.length; i++){
		var dis=resultsDisponibilidad[i].split("|");
		var dos=dis[1].split("&");
		dos[0]=parseInt(dos[0]);
		dos[1]=parseInt(dos[0])-(parseInt(numPass[0])+parseInt(numPass[1]));
		dos[2]=numFormat((parseFloat(dos[3]) * parseInt(numPass[0])) + (parseFloat(dos[4]) * parseInt(numPass[1])) + (parseFloat(dos[5]) * parseInt(numPass[2])));
		var tmp=dis[0]+"|"+dos[0]+"&"+dos[1]+"&"+dos[2]+"&"+dos[3]+"&"+dos[4]+"&"+dos[5];
		resultsDisponibilidad[i]=tmp;
		resultsServicio="";
		aspDispo(i);
	}	
}

function aspDispo(i){
	var info = eleSegm[i].split("&");
	if(resultsServicio!=""){
		resultsDisponibilidad[i]=tmpConsulta;
	}
	else{
		resultsServicio=resultsDisponibilidad[i].split("|");
	}
	if (resultsServicio[0] == "0") {
		var result = resultsServicio[1].split("&");
		if (result[1] < 0) {
			if (result[0] <= 0) {
				var fila = document.getElementById('tdServices' + (i));
    			for (var j = 0; celda = fila.getElementsByTagName('td')[j]; j++) {
					if (j == 0) {
    					celda.innerHTML = '**';
    					celda.setAttribute(dclase, 'segmentoError');
					}
					if (j == 1) {
      					celda.innerHTML = '';
          				var br = document.createElement('br');
				        var tmp = document.createElement('label');
				        tmp.innerHTML = info[1]+' '+ ' Imposible acquire this service for this time';
				        tmp.setAttribute(dclase, 'segmentoError');
				        celda.appendChild(br);
				        celda.appendChild(tmp);
			        }
			        else if (j == 2 || j == 3 || j == 4) {
			            celda.style.visibility='hidden'  
			        }
				}
			} //fin del if disponibilidad en menor e igual que cero
			else {
				fila = document.getElementById('tdServices' + (i));
				for (j = 0; celda = fila.getElementsByTagName('td')[j]; j++) {
					if (j == 0) {
						celda.innerHTML = '***';
						celda.setAttribute(dclase, 'segmentoError');
					}
					if (j == 1) {
						celda.innerHTML = '';
			            var br = document.createElement('br');
			            var tmp = document.createElement('label');
			            tmp.innerHTML = info[1]+' '+ result[0] + '-Available spaces';
			            tmp.setAttribute(dclase, 'segmentoError');
			            celda.appendChild(br);
			            celda.appendChild(tmp);
					}
					else if (j == 2 || j == 3 || j == 4) {
						celda.style.visibility='hidden'
						//celda.style.visibility = "collapse";  
					}
				}
			}
		} //fin del if resto es menor que cero
		else{
			var fila = document.getElementById('tdServices' + i );
			for (j = 0; celda = fila.getElementsByTagName('td')[j]; j++) {
				if(j==0){
					//SERVICIO
					celda.innerHTML = 'Service ' + i;
				}
				if(j==1){
					//NOMBRE SERVICIO
					celda.innerHTML = info[1];
				}
				if(j==3){
					celda.style.visibility = "visible";  
					//TARIFA
					var temp = document.getElementById('hrfaServ' + i);
					temp.innerHTML ='';
					temp.valor = eleSegm[i];
					var tmpRate = numFormat((parseFloat(info[5]) * parseInt(numPass[0])) + (parseFloat(info[6]) * parseInt(numPass[1])) + (parseFloat(info[7]) * parseInt(numPass[2])));
    
					temp.appendChild(document.createTextNode(numFormat(tmpRate)));
					temp.onclick = fInfoPas;
					celda.appendChild(temp);
				}
				if (j == 2 || j == 4|| j == 5|| j == 6) {
					celda.style.visibility = "visible";          
				}
			}
		}
	}
}

function desbloquear() {
	document.getElementById("bookServices").style.display = "block";
    
    document.getElementById("bookServices").style.display = "block";
    document.getElementById("btnaddService").style.display = "block";
    document.getElementById("addService").style.display = "block";
    document.getElementById("tbPassInfor").style.display = "block";
    document.getElementById("divTotal").style.display = "block";
    document.getElementById("contenido").style.display = "block";
    document.getElementById("Imp").style.display = "block";
	
    document.getElementById("tbAddSer").style.display = "none";
    document.getElementById("tablaTarg").style.display = "none";
    document.getElementById("confirmBook").style.display = "none";
    document.getElementById('dUserType1').style.display = 'none';
    document.getElementById('tableTerminos').style.display = 'none';

	document.getElementById("booking").style.visibility = 'visible';
    document.getElementById("booking").style.display = "block";
}

function bookContinue() {
    if (eleSegm.length == 1) {
        location.href = "default.htm";
    }
    else {
        document.getElementById("addService").style.display = "none";
        document.getElementById("tbAddSer").style.display = "block";
        var serSel = eleSegm[1].split("&");
        var tmp = serSel[2].split(" TO ");
        var arrayTmp = new Array();
        var pos = "";
        if (tmp[0] == "QUEPOS") {
            arrayTmp = p1;
            pos = "p1-";
        }
        else {
            arrayTmp = p2;
            pos = "p2-";
        }
        var sle = document.getElementById('sltService');
        if (sle.options) {//elimino las options del combo si ya tiene....
            for (var m = sle.options.length - 1; m > 0; m--)
                sle.options[m] = null;
        }
        for (var p = 0; p < arrayTmp.length; p++) {
            var results = arrayTmp[p].split("&");
            var ser = document.createElement('option');
            ser.text = results[2] + " ( " + results[1] + " )";
            ser.value = arrayTmp[p] + "&" + pos + "" + p;
            if (isIe) {
                sle.add(ser);
            }
            else {
                sle.appendChild(ser);
            }
        }
    }
}

function newService() {
    document.getElementById("tbAddSer").style.display = "none";
    var ComboSer = document.getElementById('sltService');
    var valorSel = ComboSer.options[ComboSer.selectedIndex].value;
    var pos = valorSel.split("&");
    book2(pos[17]);
}

function book2(seg) {
	PosiSegment=2;
    var pos = seg.split("-");
    var posi = parseInt(pos[1]);
    if (pos[0] == "p1") {
        segment = p1[posi];
    }
    else {
        segment = p2[posi];
    }
    var tmpSegm = segment.split("&");
    Segm = tmpSegm [2];
    eleSegm[2] = segment;

    Segm = "";
    var codOrigen = tmpSegm[14];
    var codOri = parseInt(codOrigen.substring(1, codOrigen.length));
	var codDestino = tmpSegm[15];
    var codDest = parseInt(codDestino.substring(1, codDestino.length));
    OX.AJAST.call("http://www.interbusonline.com/htgt/asp/place/llamarSelec.asp?PlaceOrigen=" + codOri+"&PlaceDestino="+codDest,'callbackPlace',post,500); 
}

function closeAll2() {
	eraseAllCookie(Session);
    document.getElementById("bookServices").style.display = "block";
    document.getElementById("booking").style.display = "block";
    document.getElementById("bookServices").style.display = "block";
    document.getElementById("btnaddService").style.display = "block";
    document.getElementById("addService").style.display = "block";
    document.getElementById("tbPassInfor").style.display = "block";
    document.getElementById("divTotal").style.display = "block";
    document.getElementById("contenido").style.display = "block";

    document.getElementById("tbAddSer").style.display = "none";
    document.getElementById("tablaTarg").style.display = "none";
    document.getElementById("confirmBook").style.display = "none";
    document.getElementById('dUserType1').style.display = 'none'; 
}

Ext.onReady(createIdSession);


///////////////////////////////////////////***********SEGUNDA PANTALLA***********//////////////////////////////////////
function PayOnline() {
    //verificar que halla servicios...
    if (eleSegm.length >= 2) {
        //validar que este todos los pickup y drop seleccionados...
        vacioLabel();
        var vacPl = validarPlace();
        if (vacPl == 0) {
            //verificar que exista la informacion del pasa...
            var fVal=fValidacion()
            if (fVal == true) {
                fguardarInfoPass();
                sec=0; 
				wait = Ext.Msg.wait('Loading... Please Wait!');
				setTimeout(actionFunc, 500);
                document.getElementById("tbPassInfor").style.display = "none";
                document.getElementById("tablaTarg").style.display = "block";
                document.getElementById("tableTerminos").style.display = "block";
                document.getElementById("Imp").style.display = "none";
                document.getElementById("btnaddService").style.display = "none";
			    var iCard = document.getElementById('dCardholder');
			    iCard.value = infoPass[1] + " " + infoPass[2];   
			    item = 2;
                fOcultarDesha();
   				cargarExpYear();
        		fConstruirOption();
        		fGuardarPrimerosDatos();
            }
        }
        else {
            Ext.Msg.alert('Error 0005!', vacPl);
        }
    }
    else {
        Ext.Msg.alert('Error!', "It must select a service to buy...");
    }
}
function fGuardarPrimerosDatos(){
	
	createCookie("infoContHotel", infoContHotel, Session);
	createCookie("numPass", numPass, Session);
	createCookie("horasPlaces", horasPlaces, Session);
	createCookie("FechaSelec", FechaSelec, Session);
	createCookie("infoPass", infoPass, Session);
	
	var tmpValue=CambiarString(infoHotel,"&",",");
	createCookie("infoHotel", tmpValue, Session);
	
	var arr_plc="";
	for(var i = 1; i < array_place.length; i++){
		var tmpValue=CambiarString(array_place[i],"&","..");
		arr_plc=arr_plc+tmpValue+"/";
	}
	createCookie("array_place", arr_plc, Session);
	
	var plc1="";
	for(var i = 1; i < pdcpOriDest.length; i++){
		var tmpValue=CambiarString(pdcpOriDest[i],"&","..");
		plc1=plc1+tmpValue+"/";
	}
	createCookie("pdcpOriDest", plc1, Session);
	
	var ele1="";
	for(var i = 1; i < eleSegm.length; i++){
		var tmpValue=CambiarString(eleSegm[i],"#","_SBNM_");
		tmpValue=CambiarString(tmpValue,"&","..");
		ele1=ele1+tmpValue+"|"
	}
	createCookie("eleSegm", ele1, Session);
}

function validarPlace() {
    for (var i = 1; i < array_place.length; i++) {
        var tmp = array_place[i].split("&");
        if (tmp[0] == "Type hotel name if not listed") {
            return "Your must be select the Pickup or DropOff of service " + i;
        }
    }
    return 0;
}

function fConfirPass() {
    var psw1 = document.getElementById('dPassword').value;
    var psw2 = document.getElementById('dPassword2').value;
    //Vacio
    if (psw1 == "" || psw2 == "") {
        Ext.Msg.alert('Error!', 'Password can not be empty.');
        return false;
    }
    if (psw1 != psw2) {
        Ext.Msg.alert('Error!', "You did not enter the same new password twice. Please re-enter your password.");
        return false;
    }
    return true;
}

function fFormatCorrec(campo) {
    var iCamp = document.getElementById(campo.id);
    if (IsString(iCamp.value) == false) {
        Ext.Msg.alert('Error!', "Invalid Name Format, it cannot be numerical");
        iCamp.focus();
        iCamp.select();
        return false;
    }
    return true;
}

function fLoginValidarEmail() {
    if (!/^(\w+)([\.-]?\w+)*@+(\w+)([\.-]?\w+)*[\.+](\w{2,3})$/.test(document.getElementById('dEmail').value)) {
        Ext.Msg.alert('Error!', "Invalid Email Format");
        document.getElementById('dEmail').focus();
        document.getElementById('dEmail').select();
        return false;
    }
    return true;
}

function fValidacion() {
    //verifica que los campos esten correctos
    var fir = document.getElementById('dFistName');
    var last = document.getElementById('dLastName');
    var mail = document.getElementById('dEmail');
    if (fir.value == "") {
        Ext.Msg.alert('Error!', 'Fist name can not be empty.');
        fir.focus();
        fir.select();
        return false;
    }
    if (last.value == "") {
        Ext.Msg.alert('Error!', 'Last name can not be empty.');
        last.focus();
        last.select();
        return false;
    }
    if (fFormatCorrec(fir) == false) {
        return false;
    }
    if (fFormatCorrec(last) == false) {
        return false;
    }
    if (mail.value == "") {
        Ext.Msg.alert('Error!', 'Email can not be empty.');
        mail.focus();
        mail.select();
        return false;
    }
    if (fLoginValidarEmail() == false) {
        return false;
    }
    if (fConfirPass() == false) {
        return false;
    }
    return true;
}

function fguardarInfoPass() {
    infoPass[0] = document.getElementById('dTitle').value;
    infoPass[1] = document.getElementById('dFistName').value;
    infoPass[2] = document.getElementById('dLastName').value;
    infoPass[4] = document.getElementById('dEmail').value;
    infoPass[5] = document.getElementById('dPassword').value;
}

function fOcultarDesha(){
	for(var i=1; i<=table.rows.length-1; i++){
		var nmPlc = 'ComboPlace'+i;
		var divPlc = document.getElementById(nmPlc);
		divPlc.disabled="disabled";
	
		var nmDivMes = 'ComboMesfecha'+i;
		var divMes = document.getElementById(nmDivMes);
		divMes.disabled="disabled"; 
		
		var nmDivDia = 'ComboDiafecha'+i;
		var divDia = document.getElementById(nmDivDia);
		divDia.disabled="disabled"; 
		
		var nmDivAn = 'ComboAniofecha'+i;
		var divAn = document.getElementById(nmDivAn);
		divAn.disabled="disabled"; 
		
		var nmBtn = 'Btn'+i;
		var divBtn = document.getElementById(nmBtn);
		divBtn.style.display = 'none';
	}
}

function cargarExpYear() {
    var fecha = new Date();
    dAnioinicio = fecha.getFullYear()
    //Determinar el inicio de los anios apartir del anio actual
    dAniofinal = dAnioinicio + 15;
    //construyo la tabla
    var sle = document.getElementById('ExpYear');
    for (var i = dAnioinicio; i <= dAniofinal; i++) {
        var Anio = document.createElement('option');
        Anio.text = i;
        Anio.value = i;
        //carga el select
        if (this.pAnio == i) {
            Anio.selected = true;
        }
        else {
            Anio.selected = false;
        }
        if (isIe) {
            sle.add(Anio);
        }
        else {
            sle.appendChild(Anio);
        }
    }
}

function callbackPais(data){
	var array_pais = Array();
    //construyo la tabla
    var sle = document.getElementById('dCountry');
    var tmpResults = data.split("|");
    if (tmpResults[0] == "0") {
        array_pais = tmpResults;
    }
    for (p = 0; p < array_pais.length - 1; p++) {
        var results = array_pais[p].split("#");
        var pais = document.createElement('option');
        if (results[0] == 0) {
            pais.text = "Select Country...";
            pais.value = "0";
        }
        else {
            pais.text = results[2];
            pais.value = results[1];
        }
        if (isIe) {
            sle.add(pais);
        }
        else {
            sle.appendChild(pais);
        }
    }
}

function fConstruirOption() {
    OX.AJAST.call("http://www.interbusonline.com/htgt/asp/Pais/pais.asp?id="+tmpId,'callbackPais',post,500);
}

///////////////////////////////////////////***********TERCERA PANTALLA***********//////////////////////////////////////
function BuyOnline() {
	/*sec=0; 
	wait = Ext.Msg.wait('Loading... Please Wait!');
	setTimeout(actionFunc, 1000);*/
    tmpConsulta="";
	var fullName= infoPass[1] +" "+infoPass[2];
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/itinerario/selectItinerario.asp?First=" + infoPass[1] + "&Last=" + infoPass[2] + "&by=" + fullName,'callbackSelec',post,500); 
}

function callbackSelec(data){
	var updateServicio = data.split("|");
    if (updateServicio[0] == "0") {
		if (confirm(exiIti + " It wants to execute the service?")) {
			cardInfo(); //guardo los objetos de la Card
	        if (CheckCardNumber(infoCard) == true) {//valida que todos los campos esten
	            if (fValCard() == true) {
	                fCargarCard();
	                generarItinerario();
				}
			}
		}
	}
	else {
		cardInfo(); //guardo los objetos de la Card
		var tmpCkCdN=CheckCardNumber(infoCard);
        if (tmpCkCdN == true) {//valida que todos los campos esten
            if (fValCard() == true) {
                fCargarCard();
                generarItinerario();
			}
		}
	}
}

function cardInfo() {
    infoCard[0] = document.getElementById('CardType');
    infoCard[1] = document.getElementById('CardNumber');
    infoCard[2] = document.getElementById('ExpMon');
    infoCard[3] = document.getElementById('ExpYear');
    infoCard[4] = document.getElementById('dCodeCard');
    infoCard[5] = document.getElementById('dAddressCard');
}

function fValCard() {
    //verifica que los campos esten correctos
    var acept = document.getElementById('dacept');
    if (infoCard[5].value == "") {
        Ext.Msg.alert('Error!', 'The biling Adrress can not be empty.');
        infoCard[5].focus();
        infoCard[5].select();
        return false;
    }
    if (acept.checked == false) {
        Ext.Msg.alert('Please!', 'To continue you need check the terms of accetpmet agrement');
        return false;
    }
    return true;
}

function fCargarCard() {
    infoCard[0] = document.getElementById('CardType').value;
    infoCard[1] = document.getElementById('CardNumber').value;
    infoCard[2] = document.getElementById('ExpMon').value;
    infoCard[3] = document.getElementById('ExpYear').value;
    infoCard[4] = document.getElementById('dCodeCard').value;
    infoCard[5] = document.getElementById('dAddressCard').value;
    createCookie("infoCard", infoCard, Session);
}

function generarItinerario() {
	tmpConsulta="";
    var tempResult = "";
    var values_Itinerario = Array();
    //1[Passenger_Name]
    values_Itinerario[0] = infoPass[1] + " " + infoPass[2];

    //2[Chargee_Type]
    values_Itinerario[1] = "PASSENGER";
    //3[Chargee]
    values_Itinerario[2] = values_Itinerario[0];
    //4[Chargee_Print_on_Invoice]
    values_Itinerario[3] = values_Itinerario[0];
    //5[Chargee_Accnt_Code]
    values_Itinerario[4] = "000523"
    //6[Payment_Method]
    values_Itinerario[5] = "CREDIT CARD";
    //7[Commission_Agent_Type]
    values_Itinerario[6] = infoContHotel[0];
    //8[Commission_Agent]
    values_Itinerario[7] = infoContHotel[1];
    //9[Commission_Agent_Print_on_Check]
    values_Itinerario[8] = infoContHotel[2];
    //10[Commission_Agent_Accnt_Code]
    values_Itinerario[9] = infoContHotel[3];
    //11[Commission_Percentage]
    values_Itinerario[10] = infoContHotel[4];
    //12[Commission_Remarks]
    values_Itinerario[11] = "INTERBUSONLINE.COM";
    //13[Requested_By]
    values_Itinerario[12] = "Interbusonline.com";
    //14[Created_By]
    values_Itinerario[13] = "Interbusonline.com";
    //17[Last_Modified_By]
    values_Itinerario[14] = "WEB";
    //18[Status]
    values_Itinerario[15] = "BOOKED";
    //19[Email]
    values_Itinerario[16] = infoPass[4];
    //20[Required_Payment]   
    values_Itinerario[17] = "1"; 

    //infoCard 21[Credit_Card]
    values_Itinerario[18] = "";
    //22[Date_Expiration]
    values_Itinerario[19] = "";
    //23[Credit_Number]
    values_Itinerario[20] = "";
    //24[CID]
    values_Itinerario[21] = "";
    //25[WebPassword]
    values_Itinerario[22] = infoPass[5];

    //Realizar Insert del itinerario.....
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/itinerario/re_ajax_AddItinerario.asp?itinerario=" + values_Itinerario,'fInsertarAsp',post,1000);
}

function fInsertarAsp(data){
	var insertItinerary = data.split("|");
    if (insertItinerary[0] == "0") {
        itinerario = insertItinerary[1];
        fInsertarServicios();        
    } //FIN DEL IF DE INSERT ITINERARIO
    else {
        Ext.Msg.alert('Error 0004!', 'THE RESERVE WAS NOT SUCCESSFUL, PLEASE CONTACT US AT SUPPORT@INTERBUSONLINE.COM');
    }
}

function fInsertarServicios() {
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/itinerario/re_ajax_AddServicio.asp?Session=" + Session + "&itinerario=" + itinerario,'fInsertSerAsp',post,1000);
}

function fInsertSerAsp(data){
	var insertServicio = data.split("|");
	respServi="";
    if (insertServicio[0] == "0") {
        respServi= true;
        IniciarCredo();
	} //FIN DEL IF DE INSERT ITINERARIO
    else {
        respServi= 'THE RESERVE WAS NOT SUCCESSFUL, PLEASE CONTACT US AT SUPPORT@INTERBUSONLINE.COM';
    }
}

function IniciarCredo() {
	if (respServi== true) {
		fCredomatic();
	}
	else {
    	Ext.Msg.alert('Error 0003!', respServi);
	}
}

function fCredomatic() {
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/credomatic/credomatic.asp?CardNumber=" + infoCard[1] + "&ExpMon=" + infoCard[2] + "&ExpYear=" + infoCard[3] + "&dTotalCargo=" + TotalBook + "&dItinerario=" + itinerario,'fCredocAsp',post,1000); 
}

function fCredocAsp(data){
	var resultadoCredo = data.split("|");
    if (resultadoCredo[0] == "0") {
        var datos = new Array("Interbusonline.com", infoCard[0], infoCard[2] + "/" + infoCard[3], infoCard[1], infoCard[4], itinerario);
		OX.AJAST.call("http://www.interbusonline.com/htgt/asp/itinerario/re_ajax_UpdateCardIti.asp?info=" + datos,'fUpdateSerAspCre',post,1000);
		item=3;
		sec=0; 
		wait = Ext.Msg.wait('Loading... Please Wait!');
		setTimeout(actionFunc, 500);
		window.parent.document.getElementById("Next").style.display = 'none';         
    } //FIN DEL IF DE INSERT ITINERARIO
    else {
    	var datos = new Array("VOID", "Interbusonline.com", itinerario);
	    OX.AJAST.call("http://www.interbusonline.com/htgt/asp/itinerario/re_ajax_UpdateStatus.asp?info=" + datos,'fUpdateSerAspCre',post,1000);
    }
}

function fUpdateSerAspCre(data){
	var tmpUpdate = data.split("|");
    if (tmpUpdate[0] == "0") {
        fEnviarCorreo();
    } //FIN DEL IF DE INSERT ITINERARIO
    else {
        Ext.Msg.alert('Error 0006!', 'INVALID CREDIT CARD OR NOT ENOUGH FUNDS. PLEASE CONTACT US AT support@interbusonline.com');
    }
}

function fEnviarCorreo() {
	OX.AJAST.call("http://www.interbusonline.com/htgt/asp/re_ajax_mail.asp?Card=" + infoCard + "&id=" + itinerario + "&Personal=" + infoPass,'fCorreoAsp',post,1000);
}

function fCorreoAsp(data){
	var resultadoCorreo = data.split("|");
    if (resultadoCorreo[0] != "0") {
        Ext.Msg.alert('Error 0007!', 'IF YOUR SESSION SUDDENLY ENDED OR YOU CLOSED THE PAGE, PLEASE CONTACT US AT SUPPORT@INTERBUSONLINE.COM TO VERIFY THE STATUS OF YOUR RESERVATION, SO WE MIGHT AVOID DOUBLE BOOKING AND DOUBLE CHARGING TO YOUR CREDIT CARD.');
    } //FIN DEL IF DE INSERT ITINERARIO
    confirmBuy();
}

//***************************PASO FINAL CONFIRMACIÓN.....
function confirmBuy() {
    var contenido = document.getElementById("contenido");
    contenido.style.display = "none";
    var bookServices = document.getElementById("bookServices");
    bookServices.style.display = "none";
    var confirm = document.getElementById("confirmBook");
    confirm.style.display = "block";
    fCmpNumber();
    fOcultarTr();
}

function fCmpNumber() {
    var tdNumber = document.getElementById('itNumber');
    tdNumber.innerHTML = 'Your Itinerary Number is  ' + itinerario;
}

function fOcultarTr() {
    var tdUserType1 = document.getElementById('dUserType1');
    tdUserType1.style.display = '';
}

function fPrintConfim() {
    window.open("http://www.interbusonline.com/htgt/asp/ItineraryPrintableVersion.asp?iItinerary=" + itinerario);
}

function closeAll() {
	eraseAllCookie(Session);
	eraseCookie("Session", Session);
    document.getElementById("bookServices").style.display = "block";
    document.getElementById("booking").style.display = "block";
    document.getElementById("bookServices").style.display = "block";
    document.getElementById("btnaddService").style.display = "block";
    document.getElementById("addService").style.display = "block";
    document.getElementById("tbPassInfor").style.display = "block";
    document.getElementById("divTotal").style.display = "block";
    document.getElementById("contenido").style.display = "block";

    document.getElementById("tbAddSer").style.display = "none";
    document.getElementById("tablaTarg").style.display = "none";
    document.getElementById("confirmBook").style.display = "none";
    document.getElementById('dUserType1').style.display = 'none';
    
    location.reload(true);
}

function post(){}



