﻿ua = navigator.userAgent.toLowerCase();
isIE7 = check(/msie 7/);
isIE8 = check(/msie 8/);
isIE6 = !isIE7 && !isIE8;

if (window.ActiveXObject) {
    var isIe = true;
	var dclase = "className";
	if (isIE8){
	    var dclase = "class";
	}
}
else {
    var isIe = false;
    var dclase = "class";
}
function check(r){
	return r.test(ua);
}

function direccionar(pagina) {
    window.location = pagina;
}

function numFormat(numero) {
    var original = parseFloat(numero);
    var result = original.toFixed(2);
    return result;
}

function IsNumeric(input) {
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return RE.test(input);
}

//valida string
function IsString(input) {
    var RE = /^[a-zA-Z\n\r\t\&\á\é\í\ó\ú\ñ\\Á\É\Í\Ó\Ú\Ñ ]+$/;
    return RE.test(input);
}

//funcion que retorna la hora o el minuto;
function fHourMin(campo, fhc) {
    var fch = new Date(fhc);
    if (campo == "h") {
        var hour = fch.getHours();
        if (hour <= 9) {
            hour = "0" + hour;
        }
        return hour;
    }
    if (campo == "m") {
        var minute = fch.getMinutes();
        if (minute <= 9) {
            minute = "0" + minute;
        }
        return minute;
    }
    if (campo == "s") {
        var second = fch.getSeconds();
        if (second <= 9) {
            second = "0" + second;
        }
        return second;
    }
}

function fechaActual() {
    var ahora = new Date();
    var Mes = ahora.getMonth() + 1;
    var Dia = ahora.getDate();
    var Anio = ahora.getFullYear();
    fecha = Mes + "/" + Dia + "/" + Anio;
    return fecha;
}

function getfecha(fch) {
    var ahora = new Date(fch);
    var mes = ahora.getMonth() + 1;
    var dia = ahora.getDate();
    var anio = ahora.getFullYear();
    var fch = mes + "/" + dia + "/" + anio;
    return fch;
}

var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function fechaDia(mes, anio) {
    return aFinMes[mes - 1] + (((mes == 2) && (anio % 4) == 0) ? 1 : 0);
}

function incFecha(fecha) {
    var ahora = new Date(fecha);
    var nDia = ahora.getDate();
    var nMes = ahora.getMonth() + 1;
    var nAnio = ahora.getFullYear();
    nDia += 1;
    if (nDia > fechaDia(nMes, nAnio)) {
        nDia = 1;
        nMes += 1;
        if (nMes == 13) {
            nMes = 1;
            nAnio += 1;
        }
    }
    fecha = nMes + "/" + nDia + "/" + nAnio;
    return fecha;
}
function cmbStatusWizard(status) {
	var url = getAppPath() + "/interfaz/asp/session/statusWizard.asp?status=" + status;
    var DatosSesion = new net.CargadorContenidos(url, nada, false);
    resultsSession = DatosSesion.req.responseText.split("|");
    fStatusWizard();
}

function fStatusWizard() {
	var status = getSession("wizard");
	if (status=="1"){
		document.getElementById("wizardStart").style.display = 'none';
	    document.getElementById("wizardStop").style.display = 'inline'; 
	    Ib.Offert();
	}
	if (status=="0"){
		var ventanaWizard=Ext.getCmp('ventanaWizard')
		if(typeof ventanaWizard!= 'undefined'){
		    	ventanaWizard.close();
		}
	    document.getElementById("wizardStart").style.display = 'inline';
	    document.getElementById("wizardStop").style.display = 'none'; 
	}
	if (status=='none'){
	    document.getElementById("wizardStart").style.display = 'none';
		document.getElementById("wizardStop").style.display = 'none'; 
	}
	
}

function fCambiarLog() {
    if (getSession("FullName") != "Interbusonline.com") {
        var usu = getSession("FullName");
        
        if (getSession("dUserType") != "1") {
            if (getSession("dUserType") == "3") {
	            usu = usu;
	        }
	        else{
	        	usu = usu + ", " + getSession("dChargee");
	        }
        }
        
        var elemento = document.getElementById("labelUser");

        var encabezadoUser = document.getElementById("encabezadoUser");
        encabezadoUser.style.display = 'inline';
        var labelUser = document.createElement("label");
        labelUser.setAttribute('id', 'labelUser');
        var txtUser = document.createTextNode(usu);
        labelUser.appendChild(txtUser);
        encabezadoUser.replaceChild(labelUser, elemento);
        
        //cambiar el log del menu
        document.getElementById("mLogIn").style.display = 'none';
        document.getElementById("mLogOut").style.display = 'inline'; 
    }
}

function fCambiarLog1() {
    if (getSession("FullName") != "Interbusonline.com") {
        var usu = getSession("FullName");
        
        if (getSession("dUserType") != "1") {
            if (getSession("dUserType") == "3") {
	            usu = usu;
	        }
	        else{
	        	usu = usu + ", " + getSession("dChargee");
	        }
        }
        
        var elemento = document.getElementById("labelUser");

        /*var encabezadoUser = document.getElementById("encabezadoUser");
        encabezadoUser.style.display = 'inline';
        var labelUser = document.createElement("label");
        labelUser.setAttribute('id', 'labelUser');
        var txtUser = document.createTextNode(usu);
        labelUser.appendChild(txtUser);
        encabezadoUser.replaceChild(labelUser, elemento);*/
        
        //cambiar el log del menu
        document.getElementById("mLogIn").style.display = 'none';
        document.getElementById("mLogOut").style.display = 'inline'; 
    }
}
function justificardocumento() {
    var lagoDocumento = document.getElementById("contenido").offsetHeight;
    if (lagoDocumento < 540) {
        document.getElementById("contenido").style.height = "70%";
    }
    else {
        document.getElementById("contenido").style.height = "";
    }
}

function getAppPath() {
    appPath = location.protocol + "//" + location.host;
    return appPath;
}

function getSession(name) {
    var url = getAppPath() + "/interfaz/asp/session/ajax_getSession.asp?session=" + name;
    var DatosSesion = new net.CargadorContenidos(url, nada, false);
    resultsSession = DatosSesion.req.responseText.split("|");
    return resultsSession[0];
}
function nada() { }
//********************************************************************************;
// Ventana del ext;
//********************************************************************************;
function createVentana(titlex, valor, w, h) {
    var ventanasEmergente = new Ext.Window({
        title: titlex,
        modal: true,
        width: w,
        height: h,
        html: valor,
        autoScroll: true,
        buttons: [
        	{ text: 'Close',
        	    listeners: {
        	        click: function() {
        	            ventanasEmergente.close();
        	        }
        	    }
        	}
            ],
        buttonAlign: 'center'
    });
    ventanasEmergente.show();
}

function msjChkPlace(chk) {
    var ele = "";
    var pos = "";
    var oriDes = "";
    if (paso == "Hotel") {
        pos = chk.split("-");
        pos = pos[1];
        pos = parseInt(pos.substring(5, pos.length));
        ele = eleSegm[pos];
        ele = ele.split("&");
        ele = ele[2];
        oriDes = " pick up or drop off or neither of them";
    }
    else {
        pos = chk.split("-");
        pos = pos[1];
        var obj = "";
        obj = pos.substring(0, 11);
        if (obj == "PlaceOrigen") {
            pos = parseInt(pos.substring(11, pos.length));
            oriDes = " pick up";
        }
        else {
            pos = parseInt(pos.substring(12, pos.length));
            oriDes = " drop off";
        }
        ele = eleSeg[pos];
        ele = ele.split("&");
        ele = ele[6];
    }
    msj = "<p style='margin:10px 10px 10px 10px'>You selected transportation from  <Strong>" + ele + "</Strong>. And you did not indicate a hotel for <Strong>" + oriDes + "</Strong>.";
    msj = msj + " Please remember to let us know with at least 72 hours prior to your travel which hotel you need to be picked up and dropped off,";
    msj = msj + " otherwise you might loose your reservation and no refund will be made. In order to modify your reservation:</p>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'>1. Go to www.interbusonline.com.</p>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'>2. At the menu bar click on LOG IN. Use the same email address and password used during reservation.</p>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'>3. Click on SERVICES and then choose MY ITINERARIES.</p>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'>4. Modify your itinerary following instruction and save it. You can also modify your reservation by email at";
    msj = msj + " support@interbusonline.com or by calling our customer service at (+506) 2283-5573 during office hours: Daily 07.00 – 20.00 Costa Rica time.</p>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'> As you did not indicate a hotel for <Strong>" + oriDes + "</Strong>, at the end of this reservation you will have ";
    msj = msj + " the possibility to choose among a list of hotels we selected for you at a great balance between quality and price. Check out www.costaricadeluxe.com.";
    msj = msj + " You can also contact us at support@interbusonline.com  or by phone (+506) 2283 5573 for more information regarding lodging.</br></br></p>";
    var w = 400;
    var h = 300;

    parent.createVentana('Confirm Need Hotel!', msj, w, h);
}

function createVtnHow(titlex, valor) {
    var ventanasEmergente = new Ext.Window({
        title: titlex,
        modal: true,
        width: 400,
        height: 300,
        html: valor,
        autoScroll: true,
        buttons: [
        	{ text: 'Close',
        	    listeners: {
        	        click: function() {
        	            ventanasEmergente.close();
        	        }
        	    }
        	}
            ],
        buttonAlign: 'center'
    });
    ventanasEmergente.show();
}

function WindowsPopup(titlex) {
    var windowPopup = new Ext.Window({
        title: titlex,
        modal: true,
        width: 850,
        border: true,
        collapsible: true, 
        closeAction: 'hide',
        height: 500,
        autoScroll: true,
        contentEl: 'booking',
        buttons: [
        	{ text: 'Close',
        	    listeners: {
        	        click: function() {
        	            if (paso == "Hotel") {
        	                closeAll();
        	                windowPopup.hide();
        	            }

        	        }
        	    }
        	},
	        { text: 'Next',
	            listeners: {
	                click: function() {
	                    if (item == "1") {
	                        PayOnline();
	                    }
	                    else {
	                        var buy = BuyOnline();
	                        if (buy == true) {
	                            this.hide();
	                        }
	                        else {}
	                    }
	                }
	            }
	        }

            ],
        buttonAlign: 'right'

    });
    windowPopup.show();

    //fire when the user clicks the minimize button;  
    windowPopup.on('minimize', function(w) {
        w.modal = false;
        w.setPosition(25, 25);
        w.collapse();
    });
}

function msjPsw() {
    var msj = "<p style='margin:10px 10px 10px 10px'>Email and password used at this time will be needed in case you want to ";
    msj = msj + "modify your itinerary. Email is your username.</p>";
    createVentana("Information Password!", msj, 400, 300);
}  

function msjDiscount() {   
	var msj = "<p style='margin:10px 10px 10px 10px'>You need to book at least 3 transfers at the same time in order to get the discount.</p></BR>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'>This discount will be reflected at the time of credit card payment. For further information please contacts reservations@interbusonline.com</p>";
    createVentana("Information Discount!", msj, 400, 300);
}  

function msjCarbon() {
    var msj = "<p style='margin:10px 10px 10px 10px'><font color='green'><b>INTERBUS</b></font>, is proud to be a company			"
    msj = msj +"<img src='/../home/png/fondo/co2-offset.png'/>"
    msj = msj +"			<font color='red' size=5>100% carbon offset</font> certified by <b>FONAFIFO</b> (Fondo Nacional de Financiamiento Forestal) a Costa Rica`s governament organization dedicated to the reforestation of the terrotory. </p><p style='margin:10px 10px 10px 10px'>For more information please visit <font color='blue'> www.fonafifo.com</font></p>";
    createVentana("100% Carbon Offset!", msj, 400, 300);
} 

function msjRates() {
    var msj = "<p style='margin:10px 10px 10px 10px'>Rate per one adult (Children under 12 pasy 50% of adult rate)</p>";
    createVentana("Information Rate!", msj, 400, 300);
}

function msjDiasFeriados() {
    var msj = "<p style='margin:10px 10px 10px 10px'>May 1st</p>";
    msj = msj + "<p style='margin:10px 10px 10px 10px'>September 15th</p>";
	msj = msj + "<p style='margin:10px 10px 10px 10px'>October 12th</p>";
	msj = msj + "<p style='margin:10px 10px 10px 10px'>and from December 22nd through January 4th</p>";
    createVentana("Information Costa Rican Holidays!", msj, 400, 300);
}

function msjContact() {
	//var msj = "<br/><p style='margin:10px 10px 10px 10px' align='center' >"
	//msj = msj +"<strong>Interbus San José</strong><br/>De la Fuente de la Hispanidad, 100 E y 25 N,<br/>San Pedro, Montes de Oca<br/>"
	//msj = msj +"<strong>Phone</strong> (+506) 2283-5573<br/><strong>Fax</strong> (+506) 2283-7655<br/>"	
	//msj = msj +"<strong>Email:</strong>  <a href='mailto:reservations@interbusonline.com'>reservations@interbusonline.com</a></p>"			
	//msj = msj +"<p style='margin:10px 10px 10px 10px'>*If you are dialing from the USA or Canada please dial 011 first. From other countries, dial the overseas code and then the above numbers. If you are in Costa Rica just dial the last 8 digits.</p>"			
    //createVentana("Contact us!", msj, 400, 300);
	var msj = "<br/><p style='margin:10px 10px 10px 10px' align='center' >"
	msj = msj +"<b>Interbus San José</b><br/>De la Fuente de la Hispanidad, 100 E y 25 N,<br/>San Pedro, Montes de Oca<br/></p>"
	msj = msj +"<p style='margin:10px 10px 10px 10px'><b>Reservations</b><br/><strong>&nbsp;&nbsp;&nbsp;Phone:</strong> (+506) 2283-5573<br/><strong>&nbsp;&nbsp;&nbsp;Fax:</strong> (+506) 2283-7655<br/>"	
	msj = msj +"<strong>&nbsp;&nbsp;&nbsp;Email:</strong>  <a href='mailto:reservations@interbusonline.com'>reservations@interbusonline.com</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='mailto:info@interbusonline.com'>info@interbusonline.com</a>"
	msj = msj +"<br/><br/><b>Accounting - Treasury</b><br/><strong>&nbsp;&nbsp;&nbsp;Phone:</strong> (+506) 2524-2249<br/><strong>&nbsp;&nbsp;&nbsp;Fax:</strong> (+506) 2280-6436"
	//msj = msj +"<strong>&nbsp;&nbsp;&nbsp;Email:</strong>  <a href='mailto:reservations@interbusonline.com'>@interbusonline.com</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='mailto:@interbusonline.com'>info@interbusonline.com</a>"
	msj = msj +"<br/><br/><b>Operations</b><br/><strong>&nbsp;&nbsp;&nbsp;Phone / Fax:</strong> (+506) 2524-2252<br/></p>"	
	//msj = msj +"<strong>&nbsp;&nbsp;&nbsp;Email:</strong>  <a href='mailto:reservations@interbusonline.com'>@interbusonline.com</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='mailto:info@interbusonline.com'>@interbusonline.com</a></p>"
	msj = msj +"<p style='margin:10px 10px 10px 10px'>*If you are dialing from the USA or Canada please dial 011 first. From other countries, dial the overseas code and then the above numbers. If you are in Costa Rica just dial the last 8 digits.</p>"			
    createVentana("Contact us!", msj, 400, 500);
} 

function msjHotels2(codHotel,locali) {
	var camposForm = "[Product],[DescriptionA],[DescriptionB],[Picture]";
	var tableForm = 'Product';
	var Indice='iProduct';
	
	var objForm= Ext.Ajax.request({
		url : '/interfaz/asp/hoteles/hotelesOffert.asp',
		params:{table:tableForm,indice:Indice,fields:camposForm,registro:codHotel}
	});
	var obj1 = objForm.conn.responseText;
	var bj2 = obj1.split(',');

	var infoEstat="<b>BOOK ONE OR MORE EXTRA NIGHTS FOR ONLY</b><br/>"
	infoEstat=infoEstat+"<b>SGL:</b> USD 75.00<br/>"
	infoEstat=infoEstat+"<b>DBL:</b> USD 38.00<br/>"
	infoEstat=infoEstat+"<b>TPL:</b> USD 34.00<br/>"
	infoEstat=infoEstat+"<b><a  href='#' onclick='msjChild2()'>CHILD</a>:</b> USD 20.00<br/><br/>"
	infoEstat=infoEstat+"Rates per/person with taxes and breakfast (when applicable) included<br/>"
	infoEstat=infoEstat+"Write us at <a href='mailto:reservations@interbusonline.com'>reservations@interbusonline.com</a> "
	infoEstat=infoEstat+"with your itinerary in order to book more nights"
	
	if (bj2[0]=="true"){	
		var html="<p style='margin:10px 10px 10px 10px'><b>"+bj2[1]+", "+locali+"</b><br/><br/>"+bj2[2]+"<br/><br/>"+bj2[3]+"<br/><br/>"+infoEstat+"</p>"
		var ventanasEmergente = new Ext.Window({
	        title: bj2[1],
	        modal: true,
	        width: 500,
	        height: 400,
	        html: html,
	        autoScroll: true,
	        buttons: [{ text: 'Close',
        	    listeners: {
        	        click: function() {
        	            ventanasEmergente.close();
        	        }
        	    }
        	}],
	        buttonAlign: 'center'
	    });
	    ventanasEmergente.show();
	}
} 

function msjHotels(codHotel,locali) {
	var objForm= Ext.Ajax.request({
		url : '/interfaz/asp/hoteles/hotelesOffert--.asp',
		params:{registro:codHotel}
	});
	var obj1 = objForm.conn.responseText;
	var bj2 = obj1.split(',');

	var infoEstat="<b>BOOK ONE OR MORE EXTRA NIGHTS FOR ONLY</b><br/>"
	infoEstat=infoEstat+"<b>SGL:</b> USD 75.00<br/>"
	infoEstat=infoEstat+"<b>DBL:</b> USD 38.00<br/>"
	infoEstat=infoEstat+"<b>TPL:</b> USD 34.00<br/>"
	infoEstat=infoEstat+"<b><a  href='#' onclick='msjChild2()'>CHILD</a>:</b> USD 20.00<br/><br/>"
	infoEstat=infoEstat+"Rates per/person with taxes and breakfast (when applicable) included<br/>"
	infoEstat=infoEstat+"Write us at <a href='mailto:reservations@interbusonline.com'>reservations@interbusonline.com</a> "
	infoEstat=infoEstat+"with your itinerary in order to book more nights"
	
	if (bj2[0]=="true"){	
		var html="<p style='margin:10px 10px 10px 10px'><b>"+bj2[1]+", "+locali+"</b><br/>"+bj2[3]+"<br/><br/>"+bj2[2]+"<br/><br/>"+infoEstat+"</p>"
		var ventanasEmergente = new Ext.Window({
	        title: bj2[1],
	        modal: true,
	        width: 500,
	        height: 400,
	        html: html,
	        autoScroll: true,
	        buttons: [{ text: 'Close',
        	    listeners: {
        	        click: function() {
        	            ventanasEmergente.close();
        	        }
        	    }
        	}],
	        buttonAlign: 'center'
	    });
	    ventanasEmergente.show();
	}
}

function msjChild2() {
	Ext.Msg.alert('Information Child!', 'Child under 12 years old.');
}





function fCrearVisitado(texto1,texto2){
	var Visitado = new objVisitado(texto1,texto2);
}

function objVisitado(texto1,texto2){
	this.setVisitado(texto1,texto2);
}

objVisitado.prototype = {
    setVisitado: function(texto1, texto2) {
        //crear div de pagina Visitado;
        var divVisitado = document.createElement('div');
        divVisitado.id = "divVisitado";
        document.body.appendChild(divVisitado);
        //crear div de texto;
        var steptext = document.createElement('div');
        steptext.id = "steptext";
        var labelTextStep = document.createTextNode(texto1);

        steptext.appendChild(labelTextStep);
        var steptext2 = document.createElement('div');
        steptext2.id = "steptext2";
        var labelTextStep2 = document.createTextNode(texto2);
        steptext2.appendChild(labelTextStep2);
        divVisitado.appendChild(steptext);
        divVisitado.appendChild(steptext2);
        //leer menu ;
        var menu = document.getElementById("menu");
        //appendafter;
        document.body.insertBefore(divVisitado, menu);
    }
}



