﻿/// <changes>
/// 2008-07-04  IC      Added function ProcessError for handled ajax error
/// 2008-07-14  IC      Added logic for check chkfotos if the user has more than one pic or unchecked
/// 2008-07-16  IC      Added logic for show or hide message for pic upsells.
/// 2008-07-23  SB      Added logic for show error when price is lower 0
/// 2008-07-28  SS      Added logic to go back step 1
/// 2008-07-29  SS      Added logic to validate if users check the credit card if amount > 0
/// 2008-08-05  SS      BUG fixed when user select one pic
/// 2008-08-07  SB      Handle error in ProcessError
/// 2008-08-12  SS      Added validator for Estado
/// 2008-08-20  SS      Added support for safari browser moved to functiones.js
/// 2008-08-21  SS		Select default country and state
/// 2008-09-08  SS      Added logic to check the title and validate
/// 2008-09-12	SB		Added logic to unselect featured ads when select premium package
/// 2008-09-12  SS      Added confirm message 
/// 2008-09-17  SS		Changed Ampliar for target _blank and href to img url
/// 2008-09-26  SS		Added logic to add ivu tax and subtotal
/// 2008-09-24  SB		Add logic for manage AreaGeografica 
/// 2008-10-06  SS		Added logic user business don't have Premium Packages
/// 2008-10-21  SS		Added logic to virtual tour
/// 2008-10-22	SB		Added logic to manage credit card errors
/// 2008-10-23  SS      Allow user chek upsell pic without pic loaded.
/// 2008-10-24  SS      Added logic to check valid credit card number
/// 2008-10-26  SS      Show or Hide processing box to user
/// 2008-11-14	SS		Added validator to select CLiente
/// 2008-11-17	SS		Added  idCliente, only aplly to Agency user type
/// 2008-11-17	SS		Added  logic to select customer from ddl
/// 2008-11-17	SS		Added  idCliente to QS
/// 2008-11-27	SS		Added  bDestacado, only aplly to Business user type
///	2008-12-18	SS		Fix BUG: advertisement state 'expirado' or 'activo' couldn't edit bDestacado
///	2009-01-15	EF		Fix BUG: build attention getters list after validation (to ensure that a category
///                     has been selected).
/// 2009-01-23  EF      Fix BUG: Validate virtual tour data only if these data can be modified: it's not possible to
///                     modify Virtual Tour data when advertisement is active.
/// 2009-05-18  SS      Added validator for ciudad when is bienes raices
/// 2009-05-21  FF      Added function ArmarLinkLetrero()
/// </changes>

var idCategoria;
var C_cantImagenes = 11;
var arrArchivo = [];
// 2008-07-29   SS  Added logic to validate if users check the credit card if amount > 0
var totalForCreditCard = 0
var eTourVirtual; //virtual tour javascript object
//2008-07-21    AP  :Added
var registrado = false;

//referent to VT country states etc.
var IdTourVirtualPaisACargarEnc = "0";
var IdTourVirtualEstadoACargarEnc = "0";
var IdTourVirtualCiudadACargarEnc = "0";
var IdTourVirtualAreaGeograficaACargarEnc = "0";
// referent to advertise country states etc.
var IdEstadoACargarEnc = "0";
var IdCiudadACargarEnc = "0";
var IdAreaGeograficaACargarEnc= "0";
// 2008-08-21   SS      Select default country
var bSeleccionarPaisInicio;
// referent to credit card country states etc.	
var IdEstadoTarjetaACargarEnc = "0";
var IdCiudadTarjetaACargarEnc = "0";
var IdCodigoPostalTarjetaACargarEnc = "0";

//test bEditing
var bEditing = false;


function PautaAnuncioDatosIniciales() 
{
	
	if (!c_bRegisteredScreen)
	{
		
		if(UsuarioRegistrado())
		{
		   VirtualTourData();
		   DisplayPremiumPackage();
		   document.getElementById('ppassword').style.display = "inline";
		   CargarPaisesTourVirtual();
		   
		}else{
		
			document.getElementById('ppassword').style.display = "none";
			document.getElementById('chkAgregado'+chkVirtualTour).style.display = "none";
			document.getElementById('tdAgregado'+chkVirtualTour).style.display = "none";
		}
		
	}
	else
	{
		
		VirtualTourData();
	}
	
	if(Validar())
	{

	    ArmarAttetionGetters();

		//Get title and description
		var sTitulo = document.getElementById(txtTituloAviso).value;
		var sDescripcion = document.getElementById(txtDescripcionAviso).value;
		var valores = [].concat(document.getElementById("frmCampos").contentWindow.getFormValues());
		
//		if (!c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1.CrearCarrito(sTitulo, sDescripcion, valores, Pauta_callback); 
//		}
//		else 
//		{

//			PautaAnuncioPaso1Registrado.CrearCarrito(sTitulo, sDescripcion, valores, Pauta_callback); 
//		}
		PautaAnuncio.CrearCarrito(sTitulo, sDescripcion, valores, Pauta_callback); 

	}
}

//2008-07-21    AP  :This method verificate if the email corresponds to a register user.
function UsuarioRegistrado()
{

//	if (document.getElementById('txtEmail')!= null)
//	{
//		var sMail = document.getElementById('txtEmail').value;
//		registrado = PautaAnuncioPaso1.UsuarioRegistrado(sMail).value;
//	}
//	else
//	{
//		registrado  = false;
//	}
//	return registrado;


	if (document.getElementById('txtEmail')!= null)
	{
		var sMail = document.getElementById('txtEmail').value;
		registrado = PautaAnuncio.UsuarioRegistrado(sMail).value;
	}
	else
	{
		registrado  = false;
	}
	return registrado;
	
	
}
//2008-11-05	SS		Added logic to logged user (registered)
//function c_bRegisteredScreen
//{
////	try
////	{
////		registrado = PautaAnuncioPaso1Registrado.UsuarioRegistradoEnSession().value;
////		return registrado;
////	}
////	catch (e)
////	{
////		return false;
////	}
//		registrado = PautaAnuncio.UsuarioRegistradoEnSession().value;
//		return registrado;
//	

//}
// 2008-10-06  SS		Added logic user business don't have Premium Packages
function DisplayPremiumPackage()
{
//	if(PautaAnuncioPaso1.IsHouseHold().value)
//	{
//	   document.getElementById('idTrChkPremiumDesc').style.display = "";
//	   document.getElementById('idTrChkPremium').style.display = "";
//	}
//	else
//	{
//	   document.getElementById('idTrChkPremiumDesc').style.display = "none";
//	   document.getElementById('idTrChkPremium').style.display = "none"; 
//	}

	if(PautaAnuncio.IsHouseHold().value)
	{
	   document.getElementById('idTrChkPremiumDesc').style.display = "";
	   document.getElementById('idTrChkPremium').style.display = "";
	}
	else
	{
	   document.getElementById('idTrChkPremiumDesc').style.display = "none";
	   document.getElementById('idTrChkPremium').style.display = "none"; 
	}

}
function GuardarAviso()
{
//2008-07-21    AP  :If added to set visible or not txtPassword
	
	

	if(!c_bRegisteredScreen)
	{
		if(UsuarioRegistrado())
		{
		   document.getElementById('ppassword').style.display = "inline";
		}
		else
		{
			document.getElementById('ppassword').style.display = "none";
		}
	}

	if (Validar()){

		var sTitulo = document.getElementById(txtTituloAviso).value;
		var sDescripcion = document.getElementById(txtDescripcionAviso).value;
		var valores = [].concat(document.getElementById("frmCampos").contentWindow.getFormValues());
		var sPais = document.getElementById(ddlPais).value;
		var sEstado = document.getElementById(ddlEstado).value;
		var sMunicipio = document.getElementById(ddlCiudad).value;
		var sAreaGeografica = document.getElementById(ddlAreaGeografica).value;
		var sPrecio = document.getElementById(txtPrecio).value;
		var sDireccion1 = document.getElementById(txtDireccion1).value;
		var sDireccion2 = document.getElementById(txtDireccion2).value;
		// 2008-11-17	SS		Added  idCliente, only aplly to Agency user type
		var sIdCliente;
		// 2008-11-27	SS		Added  bDestacado, only aplly to Business user type
		var bDestacado = false;
		
		// 2009-04-30	SS		MAP location
		var sLatitud = ((document.getElementById('avisoLat')!= null && document.getElementById('avisoLat').value.length > 0) ? document.getElementById('avisoLat').value : "0");
		var sLongitud = ((document.getElementById('avisoLng') != null && document.getElementById('avisoLng').value.length > 0)? document.getElementById('avisoLng').value : "0");
		
		
		if (!c_bRegisteredScreen)
		{
			var sMail = document.getElementById('txtEmail').value;
			var sNombreEnTarjeta = document.getElementById('txtNombreEnTarjeta').value;
			var sApellidoEnTarjeta = document.getElementById('txtApellidoEnTarjeta').value;
			var sNumeroTarjeta = document.getElementById('txtNumeroTarjeta').value;
			var sCVV = document.getElementById('txtCVV').value;
			var sAnioExpiracion = document.getElementById('ddlAnioExpiracion').value;
			var sMesExpiracion = document.getElementById('ddlMesExpiracion').value;
			var sPaisTarjeta = document.getElementById(ddlPaisTarjeta).value;
			var sEstadoTarjeta = document.getElementById(ddlEstadoTarjeta).text;
			var sCiudadTarjeta = document.getElementById(ddlCiudadTarjeta).text;
			var sZipCode = document.getElementById(ddlCodigoPostalTarjeta).value;
			var sDireccionDeFacturacion = document.getElementById('txtDireccionDeFacturacion').value;
		
		
		}			
		else
		{
			sIdCliente = (document.getElementById('cmbCustomer') ? document.getElementById('cmbCustomer').value : null);
			var sFechaHasta = document.getElementById(txtFechaHasta)!= null ? document.getElementById(txtFechaHasta).value : "";
			bDestacado =  (document.getElementById(chkDestacado) ? document.getElementById(chkDestacado).checked : false);
		}
		
		var sAgregados="";
		var fAgregados = 0;
		var aAgregados = [];
		var oAgregado;
		for(var x in agregados)
		{
			if(agregados[x].Seleccionado)
			{
				if(agregados[x].Contar)
				{
					sAgregados += agregados[x].Nombre + ", ";
					fAgregados += parseFloat(agregados[x].Precio);
				}
				oAgregado = new Object();
				oAgregado.idAgregado = x;
				oAgregado.fPrecio = agregados[x].Precio;
				oAgregado.idPaquete = agregados[x].Paquete;
				oAgregado.idOpcionAgregado = agregados[x].Opcion;
				aAgregados[aAgregados.length] = oAgregado;
				//2008-10-21    SS      Added logic to virtual tour
				if (x == c_sIdTourVirtual)
				{
					CreateVirtualTour();
					fAgregados += parseFloat(eTourVirtual.CostoMillaje);
	                
				}
			}
		}

		
		if (!c_bRegisteredScreen)
		{
			if(fAgregados == 0 || ConfirmarPauta()) //&& !PautaAnuncioValidarDatosVirtualTour())
			{
				//  2008-10-21    SS      Added logic to virtual tour
				//  2008-10-23    EF      Add 30s timeout
				//  2008-10-26    SS      Show or Hide processing box to user
				ShowProcessingBox(null, "idProcessScreenPayPal", "Tiempo de espera agotado al pautar el aviso.");
				AjaxPro.timeoutPeriod = 30000;
				AjaxPro.onTimeout = HandleTimeout;
				PautaAnuncioPaso1.Insert(sTitulo, sDescripcion, idCategoria, sPais, sEstado, sMunicipio, sAreaGeografica, sMail, 
				    sPrecio, sDireccion1, sDireccion2, valores, arrArchivo, sAgregados, String(fAgregados), aAgregados, sNombreEnTarjeta, 
				    sApellidoEnTarjeta, sNumeroTarjeta, sCVV, sAnioExpiracion, sMesExpiracion, 
				    sPaisTarjeta, sEstadoTarjeta, sCiudadTarjeta, sZipCode, 
				    sDireccionDeFacturacion,  String(c_dIvu), eTourVirtual, sIdCliente,  sLatitud, sLongitud,GuardarAviso_callback);
			}
		}
		else if (ConfirmarPauta())
		{	
			ShowProcessingBox(null, "idProcessScreenPautaAnuncioRegistrado", "Tiempo de espera agotado al pautar el aviso.");
			if(bEditing)
			{
				PautaAnuncioPaso1Registrado.Update(idAviso, sTitulo, sDescripcion, idCategoria, sPais, sEstado, sMunicipio, sAreaGeografica, 
				    sPrecio, sDireccion1, sDireccion2, sFechaHasta, valores, arrArchivo, sAgregados, String(fAgregados), aAgregados, 
				    esHistorico, estadoAviso, sFechaHastaGuardada, String(c_dIvu), eTourVirtual, sIdCliente, bDestacado, sLatitud, sLongitud, UpdateAviso_callback);
			}
			else
			{
		 		PautaAnuncioPaso1Registrado.Insert(sTitulo, sDescripcion, idCategoria, sPais, sEstado, sMunicipio, sAreaGeografica, 
		 		    sPrecio, sDireccion1, sDireccion2, sFechaHasta, valores, arrArchivo, sAgregados, String(fAgregados), aAgregados, 
		 		    String(c_dIvu), eTourVirtual, sIdCliente, bDestacado, sLatitud, sLongitud,GuardarAviso_callback);
			}	
		}
		
	}
}

function GuardarAviso_callback(res)
{
	if (res.error != null)
	{
		ProcessError(res);
	}
	else
	{
		if (!c_bRegisteredScreen)
		{ 
			if(res.value.ErrorMessage.length == 0)
			{
				if(res.value.ReturnValue == 'MisAnuncios.aspx')
				{
					document.location.href = 'MisAnuncios.aspx';
				}
				else  
				{      
					Pauta_Checkout(res.value.ReturnValue);        
				}
				//  2008-10-26    SS      Show or Hide processing box to user
				HideProcessingBox(null,"idProcessScreenPayPal");
			}
			else
			{
				//  2008-10-26    SS      Show or Hide processing box to user
				HideProcessingBox(null,"idProcessScreenPayPal");
				alert(res.value.ErrorMessage);
			}
		}
		else
		{
			HideProcessingBox(null,"idProcessScreenPautaAnuncioRegistrado");
			// 2008-11-17	SS		Added  idCliente to QS
			window.location =	"PautaAnuncioPaso3Registrado.aspx?id=" + idCategoria + 
								"&ida=" + res.value.ReturnValueIdAviso + 
								"&idCliente=" + res.value.ReturnValueIdCliente;
		
		}
	 }
}
function UpdateAviso_callback(res)
{
    if (res.error != null)
    {
        ProcessError(res);
    }
    else
    {
        HideProcessingBox(null,"idProcessScreenPautaAnuncioRegistrado");
        if (mode =='canasta')
        {
            document.location.href='CanastaWebPaso1.aspx';
        }
        else
            document.location.href='MisAnuncios.aspx';
    }
        
}

function CargarDatosEdicion(sTituloAviso,sDescripcionAviso, sPrecio, sDireccion1, sDireccion2, sFechaHasta, sEstadoAviso, bDestacado) 
{
    bEditing = true;
    document.getElementById(txtTituloAviso).value = sTituloAviso;
    document.getElementById(txtDescripcionAviso).value = sDescripcionAviso;
    document.getElementById(txtPrecio).value = sPrecio;
    document.getElementById(txtDireccion1).value = sDireccion1;
    document.getElementById(txtDireccion2).value = sDireccion2;
    sFechaHastaGuardada = sFechaHasta;
    if (document.getElementById(txtFechaHasta)!=null)
    {
        document.getElementById(txtFechaHasta).value = sFechaHasta;
        
        if (sEstadoAviso == 1)  //  Activo
        {
            document.getElementById(txtFechaHasta).disabled = true;
            document.getElementById('spanCalendario').style.display = "none";
             
            
        }
    }
    
    //2008-12-18	SS		FIX BUG advertisement state 'activo' couldn't edit bDestacado
    if (document.getElementById(chkDestacado))
    {
		document.getElementById(chkDestacado).checked = bDestacado;
		
		if (sEstadoAviso == 1)
		{
			document.getElementById(chkDestacado).disabled = true;
		}

    }
}
function Pauta_callback(res)
{
	if(res.error!=null)
	{
		 ProcessError(res);
	}
	else if (c_bRegisteredScreen)
	{
		if (document.getElementById(hidIdAviso).value != '' && document.getElementById(hidIdAviso).value != undefined) 
		{
        
            if (mode=='canasta')
            {
                MostrarPaso(2);
            }    
            else 
            {
                    if(estadoAviso=='1')// aviso activo
                    {
                        MostrarPaso(3);
                    }
                    else  //if (!PautaAnuncioValidarDatosVirtualTour())
        
                    {
                        
                        MostrarPaso(2);
                    }
            }
        } 
        else 
        {
            MostrarPaso(2);
        }
	}
	else 
	{

		document.getElementById("divPautaAnuncioPaso1").style.display="none";
		document.getElementById("divPautaAnuncioPaso3").style.display="none";
		document.getElementById("divPautaAnuncioPaso2").style.display="block";
		CrearTablaImagenesPaso2();
	}
}

function Pauta_NuevoAnuncio() 
{
	document.location.href=sslpautapaso1; 
}

function Pauta_Checkout(aviso) 
{
	document.getElementById("divPautaAnuncioPaso1").style.display="none";
	document.getElementById("divPautaAnuncioPaso2").style.display="none";
	document.getElementById("divPautaAnuncioPaso3").style.display="block";
	CrearTablaPaso3(aviso);
	document.location.href = "#divTopPauta";
}


function Pauta_MostrarCarrito() 
{
	PautaAnuncioPaso1.MostrarCanasta(Pauta_MostrarCarrito_callback);    
}

function Pauta_MostrarCarrito_callback(res) 
{
	if(res.error!=null)
	{
		ProcessError(res);
	}
}

function setInnerHTML(oElemento, sHTML) 
{
	document.getElementById(oElemento).innerHTML = sHTML;
}

function ConfirmarPauta() 
{
	//Validar que haya completado los datos de la tarjeta de credito.
	var bErrores = false;

    //  2009-01-23  EF      Fix BUG: Validate virtual tour data only if these data can be modified: it's not possible to
    //                      modify Virtual Tour data when advertisement is active.
    if (typeof(estadoAviso) == 'undefined' || estadoAviso != '1')   // New Advertisement or a not Active one
    {
	    //  2008-10-21    SS  Added logic to virtual tour    
	    bErrores = PautaAnuncioValidarDatosVirtualTour(); 
    }
	
	if (!c_bRegisteredScreen)
	{
	    if (document.getElementById('txtNombreEnTarjeta').value=='') 
	    {
		    setInnerHTML('rfvtxtNombreEnTarjeta', 'Indique el nombre que figura en la tarjeta');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('rfvtxtNombreEnTarjeta', '');
	    }
	    if (document.getElementById('txtApellidoEnTarjeta').value=='') 
	    {
		    setInnerHTML('rfvtxtApellidoEnTarjeta', 'Indique el apellido que figura en la tarjeta');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('rfvtxtApellidoEnTarjeta', '');
	    }
	    if (document.getElementById('txtNumeroTarjeta').value=='') 
	    {
		    setInnerHTML('rfvtxtNumeroTarjeta', 'Indique el n&uacute;mero de la tarjeta');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('rfvtxtNumeroTarjeta', '');
	    }
	    if (document.getElementById('txtCVV').value=='') 
	    {
		    setInnerHTML('rfvtxtCVV', 'Indique el c&oacute;digo de verificaci&oacute;n');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('rfvtxtCVV', '');
	    }
	    if (document.getElementById(ddlPaisTarjeta).value=='0') 
	    {
		    setInnerHTML('RFV_ddlPaisTarjeta', 'Indique el pa&iacute;s');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('RFV_ddlPaisTarjeta', '');
	    }
	    if (document.getElementById(ddlEstadoTarjeta).value=='0') 
	    {
		    setInnerHTML('RFV_ddlEstadoTarjeta', 'Indique el estado');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('RFV_ddlEstadoTarjeta', '');
	    }
	    if (document.getElementById(ddlCiudadTarjeta).value=='0') 
	    {
		    setInnerHTML('RFV_ddlCiudadTarjeta', 'Indique la ciudad');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('RFV_ddlCiudadTarjeta', '');
	    }
	    if (document.getElementById(ddlCodigoPostalTarjeta).value=='0') 
	    {
		    setInnerHTML('RFV_txtZipCode', 'Indique el zip');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('RFV_txtZipCode', '');
	    }
	    if (document.getElementById('txtDireccionDeFacturacion').value=='') 
	    {
		    setInnerHTML('rfvtxtDireccionDeFacturacion', 'Indique el domicilio de facturaci&oacute;n');
		    bErrores = true;
	    }
	    else 
	    {
		    setInnerHTML('rfvtxtDireccionDeFacturacion', '');
	    }

	     // 2008-10-24   SS      Added logic to check valid credit card number
	    if (totalForCreditCard > 0) 
	    {
		    if (c_bCreditCardSelectedByAmount)
		    {
			    var sCreditCard = document.getElementById('txtNumeroTarjeta').value;
    	 
			    if (IsMasterCard(sCreditCard) && document.getElementById('optMastercard').checked)
			    {
					    setInnerHTML('rfvtxtNumeroTarjeta', '');  
			    }
			    else if (IsVisaCard(sCreditCard) && document.getElementById('optVisa').checked)
			    {
					    setInnerHTML('rfvtxtNumeroTarjeta', '');  
			    }
			    else if  (IsAmericanCard (sCreditCard) && document.getElementById('optAmEx').checked)
			    {
					    setInnerHTML('rfvtxtNumeroTarjeta', '');  
			    }
			    else
			    {
					    setInnerHTML('rfvtxtNumeroTarjeta', 'N&uacute;mero de tarjeta inválido');
					    bErrores = true;
			    }
    	     
		     }
		     else
		     {

			    setInnerHTML('rfvCreditCardSelected', 'Seleccione una tarjeta de cr&eacute;dito');
			    bErrores = true;
		    }
	    }
	    else 
	    {
		    setInnerHTML('rfvCreditCardSelected', '');
	    }
    }
    
	return !bErrores;
}

function chkAgregado_Click(idAgregado, check, contar)
{
	agregados[idAgregado].Seleccionado = check;
	agregados[idAgregado].Contar = contar;

	for(var i = 0; i < agregados[idAgregado].Componentes.length; i++)
	{
	//        if (agregados[agregados[idAgregado].Componentes[i]].IdAgregado!=7)
	//        {
			document.getElementById('chkAgregado' + agregados[idAgregado].Componentes[i]).disabled = check;
			document.getElementById('chkAgregado' + agregados[idAgregado].Componentes[i]).checked = check;
			chkAgregado_Click(agregados[idAgregado].Componentes[i], check, !check);
	//        }
		agregados[agregados[idAgregado].Componentes[i]].Paquete = check ? idAgregado : null;

	}

	if(idAgregado == chkFotos)
	{
		if(!check)
		{
			while(arrArchivo.length > 1)
			{
				arrArchivo.splice(1, 1);
	        }
	          
			parent.document.getElementById('chkAgregado' + chkFotos).checked = check;   
			parent.document.getElementById('chkAgregado' + chkFotos).disabled = false;
			//2008-7-16     IC      Added logic for hide message for upsells
			var divSpan = document.getElementById('divAlert'); 
			if (divSpan  != null )
			{
				   divSpan.style.display = 'none';
			}
	        if (UsuarioRegistrado())
	        {
				ActualizarTablaImagenes();
			}
			else
			{
				
			}
		}
		else 
		{     
			//2008-7-16     IC      Added logic for check pics upsells
			if (arrArchivo.length >1)
			{  
				parent.document.getElementById('chkAgregado' + chkFotos).disabled = true;
				parent.document.getElementById('chkAgregado' + chkFotos).checked = check;
	            
				//2008-7-16     IC      Added logic for show message for upsells
				var divSpan = document.getElementById('divAlert'); 
				if (divSpan  != null )
				{
					  divSpan.style.display = 'block';  
				}
			}
		}
	}

	//2008-10-21    SS        Added logic to virtula tour
	if (idAgregado == chkVirtualTour) 
	{
		if(check)
		{
			if (!c_bRegisteredScreen)
			{ 
				document.getElementById('ulVirtualTourData').style.display = 'block';
			}
			else
			{
				document.getElementById('divVirtualTourData').style.display = 'block';
			}
			CalculateTourVirtualCost();
		}
		else
		{
			if (!c_bRegisteredScreen)
			{ 
				document.getElementById('ulVirtualTourData').style.display = 'none';
			}
			else
			{
				document.getElementById('divVirtualTourData').style.display =  'none';
			}
		}
	}
}

function ArmarTablaAgregados()
{


	var vacio = true;
	var total = 0;
	var sTemp = "";
	sTemp += "\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"OrderCost Clearfix\">";
	for(var x in agregados)
	{
		//2008-10-21    SS      Added logic to virtual tour
		if(x != c_sIdTourVirtual )
		{
			if(agregados[x].Seleccionado && agregados[x].Contar )
			{
				sTemp += "\n    <tr>";
				sTemp += "\n	    <td><em>" + agregados[x].Nombre + ":</em> <strong id=\""+ agregados[x].IdAgregado +"\">$ " + agregados[x].Precio + "</strong><span><!-- --></span></td>";
				sTemp += "\n    </tr>";
				//total += parseFloat(agregados[x].Precio);
				total += parseFloat((agregados[x].Precio).replace(",", "."));
				vacio = false;
			}
		 }
		 else
		 {
			if(agregados[x].Seleccionado && agregados[x].Contar )
			{
				var c_dTotalVt = c_dTotal > 0 ? formatCurrency(c_dTotal) : agregados[x].Precio;
				sTemp += "\n    <tr>";
				sTemp += "\n	    <td><em>" + agregados[x].Nombre + ":</em> <strong id=\""+ agregados[x].IdAgregado +"\">$ " + c_dTotalVt + "</strong><span><!-- --></span></td>";
				sTemp += "\n    </tr>";
				//total += parseFloat(agregados[x].Precio);
				total += parseFloat(c_dTotalVt);
				vacio = false;
			}
		 }
	}
	
	if(vacio)
	{
		sTemp += "\n    <tr>";
		sTemp += "\n	    <td><em>[Ninguno]</em> <strong>$ 0.00</strong><span><!-- --></span></td>";
		sTemp += "\n    </tr>";
	}
	else
	{   
		sTemp += "\n    <tr>";
		sTemp += "\n	    <td style=\"background: transparent; height: 12px; font-size:10%\">&nbsp;</td>";
		sTemp += "\n    </tr>";
	   /// 2008-09-26  SS		Added logic to subtotal
		sTemp += "\n    <tr>";
		sTemp += "\n	    <td><em>SubTotal</em> <strong>$ " + formatCurrency(total) + "</strong><span><!-- --></span></td>";
		sTemp += "\n    </tr>";
		sTemp += "\n    <tr>";
		/// 2008-09-26  SS		Added logic to add ivu tax
		sTemp += "\n	    <td><em>IVU("+ c_dIvu +"%)</em> <strong>$ " +  formatCurrency(total * c_dIvu / 100) + "</strong><span><!-- --></span></td>";
		sTemp += "\n    </tr>";
		sTemp += "\n    <tr>";
		/// 2008-09-26  SS		Added logic to add ivu tax
		total  = total + (total * c_dIvu / 100);
		sTemp += "\n	    <td><em  style=\"font-weight: bold;\">Total</em> <strong  style=\"font-weight: bold;\">$ " + formatCurrency(total) + "</strong><span><!-- --></span></td>";
		sTemp += "\n    </tr>";
		// 2008-07-29   SS  Added logic to validate if users check the credit card if amount > 0
	        
		totalForCreditCard = parseFloat(total);
	}
	 

	sTemp += "\n</table>";
	document.getElementById('divAgregadosLista').innerHTML = sTemp;
}
//2008-07-28    SS      Added logic to go back step 1
function MostrarPaso(nPaso)
{


//	if(nPaso == 1)
//    {
//        document.getElementById("divPautaAnuncioPaso2").style.display="none";
//        document.getElementById("divPautaAnuncioPaso3").style.display="none";
//        document.getElementById("divPautaAnuncioPaso1").style.display="block";
//    }
//    else if(nPaso == 2)
//    {
//        document.getElementById("divPautaAnuncioPaso1").style.display="none";
//        document.getElementById("divPautaAnuncioPaso3").style.display="none";
//        document.getElementById("divPautaAnuncioPaso2").style.display="block";
//        CargarPaisesTourVirtual();
//    }
//    else
//    {

//        if (!PautaAnuncioValidarDatosVirtualTour())
//        {
//            GuardarAviso();
//        }
////        document.getElementById("divPautaAnuncioPaso1").style.display="none";
////        document.getElementById("divPautaAnuncioPaso2").style.display="none";
////        document.getElementById("divPautaAnuncioPaso3").style.display="block";
//    }
	if (typeof(c_bRegisteredScreen) != 'undefined' && !c_bRegisteredScreen)
	{

		ActualizarTablaImagenes();
	}

	if(nPaso == 1)
	{
		document.getElementById("divPautaAnuncioPaso2").style.display="none";
		document.getElementById("divPautaAnuncioPaso1").style.display="block";
		if (document.getElementById("divPautaAnuncioPaso3") != null )
			document.getElementById("divPautaAnuncioPaso3").style.display="none";
	}
	else if(nPaso == 2)
	{
		document.getElementById("divPautaAnuncioPaso1").style.display="none";
		document.getElementById("divPautaAnuncioPaso2").style.display="block";
		if (document.getElementById("divPautaAnuncioPaso3") != null )
			document.getElementById("divPautaAnuncioPaso3").style.display="none";
	}
	else
	{
//		alert("PASO 3");
//		if (!c_bRegisteredScreen || !PautaAnuncioValidarDatosVirtualTour())
//		{
			GuardarAviso();
//		}
		
	}
	
}

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num))
	{
		num = "0";
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
	{
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	
	return (((sign)?'':'-') + num + '.' + cents);
}
//2008-11-04	SS		Added original file name
function EArchivo(path, orden, idImagen, stPathHiRes, sNombre){
    this.path       = path;
    this.orden      = orden;
    this.idImagen   = idImagen;
    this.stPathHiRes   = stPathHiRes;
    this.sNombre = sNombre;
}

//2008-11-04	SS		Added original file name
function AgregarImagen(sNombreArchivo, sNombreArchivoOriginal, idImagen, stPathHiRes)
{

	var pos = 0;
	if (arrArchivo.length <= C_cantImagenes )
	{
		pos = arrArchivo.length;    
	}
//	arrArchivo.splice(pos + 1,1,new EArchivo(sNombreArchivo, pos));
	//2008-11-04	SS		Added original file name
	arrArchivo.splice(pos + 1,1,new EArchivo(sNombreArchivo, pos, idImagen, stPathHiRes, sNombreArchivoOriginal));

	var checkFotos = document.getElementById('chkAgregado' + chkFotos );

	if (!checkFotos.checked)
	{
		chkAgregado_Click(chkFotos, (arrArchivo.length > 1), ((pos > 0)? true : false));
	}


//	var pos = 0;
//    //if (arrArchivo.length <= C_cantImagenes && agregados[chkFotos].Seleccionado)
//    if (arrArchivo.length <= C_cantImagenes)
//        pos = arrArchivo.length;    
//  
////    arrArchivo[pos] = new EArchivo(sNombreArchivo, pos);
//    arrArchivo.splice(pos + 1,1,new EArchivo(sNombreArchivo, pos, idImagen, stPathHiRes));
//    
////    chkAgregado_Click(chkFotos, true, 0)
//    var checkFotos = document.getElementById('chkAgregado' + chkFotos );
//    if (!checkFotos.checked)
//    {
////        chkAgregado_Click(chkFotos, true, ((pos > 1)? true : false));
//        chkAgregado_Click(chkFotos, (arrArchivo.length > 1), ((pos > 0)? true : false));
//    }
//    

	
	if (!c_bRegisteredScreen)
	{ 
		ActualizarTablaImagenes();
		ArmarTablaAgregados();
	}
	else
	{

		CrearTablaImagenesPaso2();
	}
}

function EliminarImagen(pos)
{
	//2008-09-12       SS Added confirm message 
	if (confirm('¿Desea eliminar la imagen seleccionada?'))
	{
		arrArchivo.splice(pos,1);
		 if (arrArchivo.length == 1)
		{
			//2008-7-16     IC      Added logic for check pics upsells
		   chkAgregado_Click(chkFotos, false, 0)
		   //2008-7-16     IC      Added logic for hide message for upsells
			var divSpan = document.getElementById('divAlert'); 
			if (divSpan  != null )
			{
				  divSpan.style.display = 'none';
			}
		}
		ActualizarTablaImagenes();
		//new
		if (!c_bRegisteredScreen)
		{ 
			ArmarTablaAgregados();
		}
	}
}

function SubirFoto(pos)
{
	var ordenSeleccionado = arrArchivo[pos].orden;
	arrArchivo[pos].orden = arrArchivo[pos-1].orden;
	arrArchivo[pos-1].orden = ordenSeleccionado;
	arrArchivo.sort(OrdenarArray);
	ActualizarTablaImagenes();
}
function OrdenarArray (a,b)
{
	if ( a.orden < b.orden) return -1;
	if ( a.orden > b.orden) return 1;
	return 0;
}

function ActualizarTablaImagenes()
{

	if (document.getElementById("divPautaAnuncioPaso2").style.display=="block")
	{
		CrearTablaImagenesPaso2();
	}
	else
	{
		CrearTablaImagenesPaso1();
	}
}

function CrearTablaImagenesPaso1()
{
	var sTable =
	"<table width=\"410\" cellspacing=\"0\" class=\"PicturesGrid Clearfix\">" +
	  "<tr bgcolor=\"#FFFFFF\">" +
		"<th width=\"18%\"><span>FOTO</span></th>" +
		"<th>&nbsp;</th>" +
		"<th width=\"15%\" class=\"center\">AMPLIAR</th>" +
		"<th width=\"15%\" class=\"center\">BORRAR</th>" +
	  "</tr>";
	for (var n=0; n < arrArchivo.length; n++)
	{
	  sTable += "<tr class=\"ColorRow\">" +
		 // 2008-09-17   SS       Changed Ampliar for target _blank and href to img url
	//        "<td><a href=\"#\"><img src=\""+ arrArchivo[n].path +"\" alt=\"\" width=\"48\" height=\"38\" class=\"Thumb\" /></a></td>" +
		"<td><a href=\"" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "\" target=\"_blank\"><img src=\""+ arrArchivo[n].path +"\" alt=\"\" width=\"48\" height=\"38\" class=\"Thumb\" /></a></td>" +
		"<td>&nbsp;</td>" +
		 // 2008-09-17   SS       Changed Ampliar for target _blank and href to img url
	//        "<td class=\"center\"><a href=\"#\" onclick=\"Ampliar('" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "'); return false;\"><img src=\"App_Images/usuarios/icon_ampliar.gif\" alt=\"Ampliar\" width=\"27\" height=\"27\" /></a></td>" +
		"<td class=\"center\"><a href=\"" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "\" target=\"_blank\"><img src=\"App_Images/usuarios/icon_ampliar.gif\" alt=\"Ampliar\" width=\"27\" height=\"27\" /></a></td>" +
		"<td class=\"center\"><a href=\"javascript:EliminarImagen("+ n + ");\"><img src=\"App_Images/usuarios/icon_delete.gif\" alt=\"Borrar\" width=\"27\" height=\"27\" /></a></td>" +
	  "</tr>";
	}
	sTable +="</table>";
	
	//SS TEST
	if (document.getElementById('divImagenPaso1'))
		document.getElementById('divImagenPaso1').innerHTML = sTable;
	
	if (document.getElementById('btnPautarAhora'))
	{
		if (arrArchivo.length > 1)
		{
			document.getElementById('btnPautarAhora').disabled = true;
		}
		else
		{
			document.getElementById('btnPautarAhora').disabled = false;
		}
	}
	
}

function CrearTablaImagenesPaso2()
{
	var tableWidth = (!c_bRegisteredScreen ? 410 : 600 );
	var sTable ="";
	
	if (arrArchivo.length > 0 && c_bRegisteredScreen) //WEB REGISTRADO
	{
	
		sTable = "<table width=\"" + tableWidth  + "\" cellspacing=\"0\" class=\"PicturesGrid Clearfix\">" +
					"<tr bgcolor=\"#FFFFFF\">" +
						"<th width=\"5%\" class=\"PDL12\">#</th>"+
						"<th width=\"18%\"><span>FOTO</span></th>"+
						"<th>&nbsp;</th>"+
						"<th width=\"15%\" class=\"center\">PRINCIPAL</th>"+
						"<th width=\"15%\" class=\"center\">AMPLIAR</th>"+
						"<th width=\"15%\" class=\"center\">BORRAR</th>"+
				"</tr>";
	}
	else //WEB GRATIS
	{
		sTable = "<table width=\"" + tableWidth  + "\" cellspacing=\"0\" class=\"PicturesGrid Clearfix\">" +
					"<tr bgcolor=\"#FFFFFF\">" +
						"<th width=\"5%\" class=\"PDL12\">#</th>"+
						"<th width=\"18%\"><span>FOTO</span></th>"+
						"<th>&nbsp;</th>"+
						"<th width=\"15%\" class=\"center\">PRINCIPAL</th>"+
						"<th width=\"15%\" class=\"center\">AMPLIAR</th>"+
						"<th width=\"15%\" class=\"center\">BORRAR</th>"+
				"</tr>";
	}
		for (var n=0; n < arrArchivo.length; n++){
			if (n < 1){ // Si es la imagen gratis
				sTable += "<tr class=\"Selected\">" +
					"<td class=\"PDL12 SltL\"><strong>" + (n+1) + "</strong></td>" +
					// 2008-09-17   SS       Changed Ampliar for target _blank and href to img url
	//	                "<td><a href=\"#\" onclick=\"Ampliar('" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "'); return false;\"><img src=\"" + arrArchivo[n].path + "\" width=\"48\" height=\"38\" class=\"Thumb\" /></a></td>" +
					"<td><a href=\"" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "\" target=\"_blank\"><img src=\"" + arrArchivo[n].path + "\" width=\"48\" height=\"38\" class=\"Thumb\" /></a></td>" +
					"<td><span>Imagen Principal<br /><em class=\"Gratis\">(GRATIS)</em></span></td>" +
					"<td class=\"center\"><img src=\"App_Images/usuarios/icon_flechaup-off.gif\" alt=\"\" width=\"27\" height=\"27\" /></td>" +
					// 2008-09-17   SS       Changed Ampliar for target _blank and href to img url
	//	                "<td class=\"center\"><a href=\"#\" onclick=\"Ampliar('" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "'); return false;\"><img src=\"App_Images/usuarios/icon_ampliar.gif\" alt=\"Ampliar\" width=\"27\" height=\"27\" /></a></td>" +
					"<td class=\"center\"><a href=\"" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "\" target=\"_blank\"><img src=\"App_Images/usuarios/icon_ampliar.gif\" alt=\"Ampliar\" width=\"27\" height=\"27\" /></a></td>" +
					"<td class=\"center SltR\"><a href=\"javascript:EliminarImagen("+ n + ");\"><img src=\"App_Images/usuarios/icon_delete.gif\" alt=\"Borrar\" width=\"27\" height=\"27\" /></a></td>";
			}else{
				sTable += "<tr class=\"ColorRow\">" +
					"<td class=\"PDL12\">" + (n+1) + "</td>" +
					// 2008-09-17   SS       Changed Ampliar for target _blank and href to img url
	//	                "<td><a href=\"#\" onclick=\"Ampliar('" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "'); return false;\"><img src=\""+ arrArchivo[n].path +"\" alt=\"\" width=\"48\" height=\"38\" class=\"Thumb\" /></a></td>" +
					"<td><a href=\"" +arrArchivo[n].path.replace(/\\/g, "\\\\") + "\" target=\"_blank\"><img src=\""+ arrArchivo[n].path +"\" alt=\"\" width=\"48\" height=\"38\" class=\"Thumb\" /></a></td>" +
					"<td>&nbsp;</td>" +
					"<td class=\"center\"><a href=\"javascript:SubirFoto(" + n + ");\"><img src=\"App_Images/usuarios/icon_flechaup.gif\" alt=\"\" width=\"27\" height=\"27\" /></a></td>" +
					// 2008-09-17   SS       Changed Ampliar for target _blank and href to img url
	//	                "<td class=\"center\"><a href=\"#\" onclick=\"Ampliar('" + arrArchivo[n].path.replace(/\\/g, "\\\\") + "'); return false;\"><img src=\"App_Images/usuarios/icon_ampliar.gif\" alt=\"Ampliar\" width=\"27\" height=\"27\" /></a></td>" +
					"<td class=\"center\"><a href=\"" +arrArchivo[n].path.replace(/\\/g, "\\\\") + "\" target=\"_blank\"><img src=\"App_Images/usuarios/icon_ampliar.gif\" alt=\"Ampliar\" width=\"27\" height=\"27\" /></a></td>" +
					"<td class=\"center\"><a href=\"javascript:EliminarImagen("+ n + ");\"><img src=\"App_Images/usuarios/icon_delete.gif\" alt=\"Borrar\" width=\"27\" height=\"27\" /></a></td>";
			}
		}	
		sTable += "</tr></table>";
	
	document.getElementById(divImagen).innerHTML = sTable;
	
}

function CrearTablaPaso3(sTable)
{


	document.getElementById('divPautaAnuncioPaso3').innerHTML = sTable;
}
function Validar()
{
	var bErrores = false;

	if (!ultimoSeleccionado) 
	{
		setInnerHTML('RFV_LoopDinamico1', 'Debe seleccionar una categor&iacute;a final');
		bErrores = true;
	}
	else
	{
		setInnerHTML('RFV_LoopDinamico1', '');
	}
	//	2008-11-14	SS		Added validator to select CLiente
	if (document.getElementById("cmbCustomer"))
	{
		if (document.getElementById("cmbCustomer").value=="0") 
		{
			setInnerHTML('RFV_CmbCustomers', 'Debe seleccionar el cliente');
			bErrores = true;
		}
		else 
		{
			setInnerHTML('RFV_CmbCustomers', '');
		}
	}
	
	
	if (document.getElementById(txtTituloAviso).value=="") {
		setInnerHTML('rfvtxtTituloAviso', 'Debe indicar el t&iacute;tulo del anuncio');
		bErrores = true;
	//    } else {
	//        setInnerHTML('rfvtxtTituloAviso', '');
	//    }
	// 2008-09-08  SS     Added logic to check the title and validate
	} 
	else if (!/^[a-zA-Z0-9ñÑáÁéÉíÍóÓúÚàÀèÈìÌòÒùÙäÄëËïÏöÖüÜ¿?!¡"-'\s]{1,250}$/.test(document.getElementById(txtTituloAviso).value))
	{
		setInnerHTML('rfvtxtTituloAviso', 'Caracteres inv&aacute;lidos');
		bErrores = true;
	}
	else
	{
		   setInnerHTML('rfvtxtTituloAviso', '');
	}

	if (document.getElementById(txtDescripcionAviso).value=="") 
	{
		setInnerHTML('rfvtxtDescripcionAviso', 'Debe indicar el texto del anuncio');
		bErrores = true;
	}
	else
	{
		setInnerHTML('rfvtxtDescripcionAviso', '');
	}
	if (document.getElementById(txtPrecio).value=="") 
	{
		setInnerHTML('RFV_txtPrecio', 'Debe indicar el precio');
		bErrores = true;
	} 
	else if (isNaN(document.getElementById(txtPrecio).value)) 
	{
		setInnerHTML('RFV_txtPrecio', 'El precio debe ser num&eacute;rico');
		bErrores = true;
	}
	else if (parseFloat(document.getElementById(txtPrecio).value)<0) 
	{
		setInnerHTML('RFV_txtPrecio', 'El precio debe ser mayor igual a cero');
		bErrores = true;
	}
	else 
	{
		setInnerHTML('RFV_txtPrecio', '');
	}
	if (document.getElementById(ddlPais).value=="0") 
	{
		setInnerHTML('RFV_ddlPais', 'Debe indicar el pa&iacute;s');
		bErrores = true;
	}
	else 
	{
		setInnerHTML('RFV_ddlPais', '');
	}
	//2008-08-12    SS      Added validator for Estado
	if (document.getElementById(ddlEstado).value=="0") {
		setInnerHTML('RFV_ddlEstado', 'Debe indicar el estado');
		bErrores = true;
	}
	else
	{
		setInnerHTML('RFV_ddlEstado', '');
	}

		//2009-05-18    SS      Added validator for ciudad when is bienes raices
	if (document.getElementById(ddlCiudad).value=="0" && bIsBienesRaices) {
		setInnerHTML('RFV_ddlCiudad', 'Debe indicar la ciudad');
		bErrores = true;
	}
	else
	{
		setInnerHTML('RFV_ddlCiudad', '');
	}
	


	if (document.getElementById('txtEmail') != null)
	{
		if (document.getElementById('txtEmail').value=="") 
		{
			setInnerHTML('rfvtxtEmail', 'Debe indicar su e-Mail');
			bErrores = true;
		}
		else if (!/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(document.getElementById('txtEmail').value)) 
		{
			setInnerHTML('rfvtxtEmail', 'e-Mail inv&aacute;lido');
			bErrores = true;
		}
		else
		{
			setInnerHTML('rfvtxtEmail', '');
		}
	}
	//2008-07-21    AP  :Code descommented, this code is to validate the password of user.
//	if(registrado)
	if (UsuarioRegistrado())
	{
		if (document.getElementById('txtPassword') != null )
		{
			if (document.getElementById('txtPassword').value=="") 
			{
				setInnerHTML('rfvtxtPassword', 'Debe indicar su Password');
				bErrores = true;
			}
			else
			{
				if (document.getElementById('txtEmail').value!="" && !PautaAnuncioPaso1.VerificarUsuario(document.getElementById('txtEmail').value, document.getElementById('txtPassword').value).value)
				{
					setInnerHTML('rfvtxtPassword', 'Password incorrecta');
					bErrores = true;
				}
				else
				{
					setInnerHTML('rfvtxtPassword', '');
				}
			}
		}
	}
	return (typeof(document.getElementById("frmCampos").contentWindow.validateFormFields) == "function" && document.getElementById("frmCampos").contentWindow.validateFormFields() && !bErrores);
}

setTimeout(CrearTablaImagenesPaso1,1000);


function CreateOption(text, value)
{
	var opt = document.createElement('option');
	opt.text = text;
	opt.value = value;
	return opt;
}
// 2008-11-17	SS		Added  logic to select customer from ddl
function SeleccionarCliente(idCliente)
{
	if (document.getElementById('cmbCustomer') && idCliente != null && idCliente.length > 1)
	{ 
		
		if (document.getElementById('cmbCustomer').options.length >1)
		{
			
			document.getElementById('cmbCustomer').value = idCliente;
		}
		else
		{
			document.getElementById('cmbCustomer').options[0].selected = true;
		}
	}
}

// 2008-08-21   SS      Select default country
function SeleccionarPais()
{
	if (document.getElementById(ddlPais).options.length >1)
	{      
		var nSeleccionarPaisInicio;

		document.getElementById(ddlPais).options[1].selected = true;
		nSeleccionarPaisInicio  = document.getElementById(ddlPais).options[1].value;
	//         IdTourVirtualPaisACargarEnc = nSeleccionarPaisInicio;
		CargarEstados(nSeleccionarPaisInicio);
		bSeleccionarPaisInicio = true;
	}
}

function LimpiarEstados()
{
	while (document.getElementById(ddlEstado).options.length > 0)
	{
		document.getElementById(ddlEstado).options[0] = null;
	}
	document.getElementById(ddlEstado).options[0] = CreateOption(initialValue, "0");
	LimpiarCiudades();
}

function CargarEstados(IdPaisEnc)
{
	LimpiarEstados();
	//2008-10-21    SS      Added logic to virtual tour
	
	if(IdPaisEnc!="0")
	{   
		CargarEstadosVirtualTour(IdPaisEnc);
//		if (!c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1.CargarEstados(IdPaisEnc, CargarEstados_callback);
//		}
//		else if (c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1Registrado.CargarEstados(IdPaisEnc, CargarEstados_callback);
//		}
		PautaAnuncio.CargarEstados(IdPaisEnc, CargarEstados_callback);
	}

}

function CargarEstados_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
		{
			document.getElementById(ddlEstado).options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idEstado"]);
		}
		document.getElementById(ddlEstado).value = IdEstadoACargarEnc;
		IdEstadoACargarEnc = "0";
	}

	// 2008-08-21   SS      Select default state if country exist
	if (typeof(bSeleccionarPaisInicio) != "undefined" && bSeleccionarPaisInicio &&  document.getElementById(ddlEstado).options.length > 0)
	{
		document.getElementById(ddlEstado).options[1].selected = bSeleccionarPaisInicio;
		CargarCiudades(document.getElementById(ddlEstado).options[1].value); 
		bSeleccionarPaisInicio = false; 
	}     

}

function LimpiarCiudades()
{
	while (document.getElementById(ddlCiudad).options.length > 0)
	{
		document.getElementById(ddlCiudad).options[0] = null;
	}
	document.getElementById(ddlCiudad).options[0] = CreateOption(initialValue, "0");
}

function CargarCiudades(IdEstadoEnc)
{
	IdTourVirtualEstadoACargarEnc = IdEstadoEnc;
	LimpiarCiudades();

	if(IdEstadoEnc!="0")
	{
		CargarCiudadesVirtualTour(IdEstadoEnc); 
		
//		if (!c_bRegisteredScreen)
//		{ 
//			PautaAnuncioPaso1.CargarCiudades(IdEstadoEnc, CargarCiudades_callback);
//		}
//		else
//		{
//			PautaAnuncioPaso1Registrado.CargarCiudades(IdEstadoEnc, CargarCiudades_callback);
//		}
	
		PautaAnuncio.CargarCiudades(IdEstadoEnc, CargarCiudades_callback);
	}
}

function CargarCiudades_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
		{
			document.getElementById(ddlCiudad).options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idCiudad"]);
		}
		document.getElementById(ddlCiudad).value = IdCiudadACargarEnc;
		IdCiudadACargarEnc = "0";
	}
}

function LimpiarAreasGeograficas()
{
	while (document.getElementById(ddlAreaGeografica).options.length > 0)
	{
		document.getElementById(ddlAreaGeografica).options[0] = null;
	}
	document.getElementById(ddlAreaGeografica).options[0] = CreateOption(initialValueAreasGeograficas, "0");
}

function CargarAreasGeograficas(IdCiudadEnc)
{
	LimpiarAreasGeograficas();
	if(IdCiudadEnc!="0")
	{
		CargarAreasGeograficasVirtualTour(IdCiudadEnc);
//		if (UsuarioRegistrado())
//		{ 
//			PautaAnuncioPaso1.CargarAreasGeograficas(IdCiudadEnc, CargarAreasGeograficas_callback);
//		}
//		else if (c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1Registrado.CargarAreasGeograficas(IdCiudadEnc, CargarAreasGeograficas_callback);
//		}

		PautaAnuncio.CargarAreasGeograficas(IdCiudadEnc, CargarAreasGeograficas_callback);
	}
}

function CargarAreasGeograficas_callback(res)
{
	if (res.error != null)
	{
		ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
		{
			document.getElementById(ddlAreaGeografica).options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idAreaGeografica"]);
		}
		document.getElementById(ddlAreaGeografica).value = IdAreaGeograficaACargarEnc;
	//        IdTourVirtualAreaGeograficaACargarEnc = IdAreaGeograficaACargarEnc;
		IdAreaGeograficaACargarEnc = "0";
	}
}

function CargaAutomatica(IdPaisEnc, IdEstadoEnc, IdCiudadEnc, IdAreaGeograficaEnc, IdClienteEnc)
{
	CargarEstados(IdPaisEnc);
	IdEstadoACargarEnc = IdEstadoEnc;
	CargarCiudades(IdEstadoEnc);
	IdCiudadACargarEnc = IdCiudadEnc; 
	CargarAreasGeograficas(IdCiudadEnc);
	IdAreaGeograficaACargarEnc = IdAreaGeograficaEnc;
	// 2008-11-17	SS		Added  logic to select customer from ddl
	if (typeof(IdClienteEnc)!= 'undefined')
	{
		SeleccionarCliente(IdClienteEnc)
	}

}

//2008-10-15    SS      Added logic to virtual tour
//function SeleccionAutomaticaVirtualTour(IdPaisEnc, IdEstadoEnc, IdCiudadEnc, IdAreaGeograficaEnc)
//{

//   
//	CargarPaisesTourVirtual();
//	IdTourVirtualPaisACargarEnc = IdPaisEnc; 

//	CargarEstadosVirtualTour (IdPaisEnc);
//	IdTourVirtualEstadoACargarEnc = IdEstadoEnc;



//	CargarCiudadesVirtualTour(IdEstadoEnc);
//	IdTourVirtualCiudadACargarEnc = IdCiudadEnc ;

//	CargarAreasGeograficasVirtualTour(IdCiudadEnc);
//	IdTourVirtualAreaGeograficaACargarEnc = IdAreaGeograficaEnc; 

//	document.getElementById('ddlVirtualTourPais').value = IdPaisEnc;

//	document.getElementById('ddlVirtualTourEstado').value = IdEstadoEnc;

//	if (IdCiudadEnc == "0")
//	{
//	document.getElementById('ddlVirtualTourCiudad').value = "0";
//	}
//	else
//	{
//	document.getElementById('ddlVirtualTourCiudad').value = IdCiudadEnc;
//	}
//	if ( IdAreaGeograficaEnc == "0" )
//	{
//	document.getElementById('ddlVirtualTourAreaGeografica').value = "0";
//	}
//	else
//	{
//	document.getElementById('ddlVirtualTourAreaGeografica').value = IdAreaGeograficaEnc;
//	}
//   
//    if (bEditing)
//        CalculateTourVirtualCost(); 

//}


function LimpiarEstadosTarjeta()
{
	while (document.getElementById(ddlEstadoTarjeta).options.length > 0)
	{
		document.getElementById(ddlEstadoTarjeta).options[0] = null;
	}
	document.getElementById(ddlEstadoTarjeta).options[0] = CreateOption(initialValue, "0");
	LimpiarCiudadesTarjeta();
}

function CargarEstadosTarjeta(IdPaisEnc)
{
	LimpiarEstadosTarjeta();
	if(IdPaisEnc!="0")
	{
//		PautaAnuncioPaso1.CargarEstados(IdPaisEnc, CargarEstadosTarjeta_callback);
		PautaAnuncio.CargarEstados(IdPaisEnc, CargarEstadosTarjeta_callback);
	}
}

function CargarEstadosTarjeta_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
			document.getElementById(ddlEstadoTarjeta).options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idEstado"]);
		document.getElementById(ddlEstadoTarjeta).value = IdEstadoTarjetaACargarEnc;
		IdEstadoTarjetaACargarEnc = "0";
	}
}

function LimpiarCiudadesTarjeta()
{
	while (document.getElementById(ddlCiudadTarjeta).options.length > 0)
	{
		document.getElementById(ddlCiudadTarjeta).options[0] = null;
	}
	
	document.getElementById(ddlCiudadTarjeta).options[0] = CreateOption(initialValue, "0");
	LimpiarCodigosPostalesTarjeta();
}

function CargarCiudadesTarjeta(IdEstadoEnc)
{
	LimpiarCiudadesTarjeta();
	if(IdEstadoEnc!="0")
	{
//		PautaAnuncioPaso1.CargarCiudades(IdEstadoEnc, CargarCiudadesTarjeta_callback);
				PautaAnuncio.CargarCiudades(IdEstadoEnc, CargarCiudadesTarjeta_callback);
	}
}

function CargarCiudadesTarjeta_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
			document.getElementById(ddlCiudadTarjeta).options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idCiudad"]);
		document.getElementById(ddlCiudadTarjeta).value = IdCiudadTarjetaACargarEnc;
		IdCiudadTarjetaACargarEnc = "0";
	}
}


//	2008-12-23	SS		Added logic to ZIP

function CargarCodigosPostalesTarjeta(IdCiudadEnc)
{
	LimpiarCodigosPostalesTarjeta();
	if(IdCiudadEnc!="0")
	{
				PautaAnuncio.CargarCodigosPostales(IdCiudadEnc, CargarCodigosPostalesTarjeta_callback);
	}
}

function CargarCodigosPostalesTarjeta_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
			document.getElementById(ddlCodigoPostalTarjeta).options[i+1] = CreateOption(dt.Rows[i]["CodigoPostal"], dt.Rows[i]["CodigoPostal"]);
		document.getElementById(ddlCodigoPostalTarjeta).value = IdCodigoPostalTarjetaACargarEnc;
		IdCodigoPostalTarjetaACargarEnc = "0";
	}
}

function LimpiarCodigosPostalesTarjeta()
{
	while (document.getElementById(ddlCodigoPostalTarjeta).options.length > 0)
	{
		document.getElementById(ddlCodigoPostalTarjeta).options[0] = null;
	}
	
	document.getElementById(ddlCodigoPostalTarjeta).options[0] = CreateOption(initialValue, "0");
}



function CargaAutomaticaTarjeta(IdPaisEnc, IdEstadoEnc, IdCiudadEnc, IdCodigoPostalEnc)
{
	CargarEstadosTarjeta(IdPaisEnc);
	IdEstadoTarjetaACargarEnc = IdEstadoEnc;
	CargarCiudadesTarjeta(IdEstadoEnc);
	IdCiudadTarjetaACargarEnc = IdCiudadEnc;
	CargarCodigosPostalesTarjeta(IdCiudadEnc);
	IdCodigoPostalTarjetaACargarEnc =IdCodigoPostalEnc;
}

function Ampliar(path)
{
	window.open(path, '', '');
}
	
//2008-10-21    SS      Added logic for virtual tours
function CargarPaisesTourVirtual()
{
	 LimpiarPaisesTourVirtual();
	 
	 var optPaises =  document.getElementById(ddlPais).options;
	 
	 for(i=1; i<optPaises.length; i++)
	 {
		document.getElementById('ddlVirtualTourPais').options[i] =  CreateOption(optPaises[i].text, optPaises[i].value);
	 }
	 document.getElementById('ddlVirtualTourPais').value =   IdTourVirtualPaisACargarEnc;

}

//2008-10-21    SS      Added logic for virtual tours
function LimpiarPaisesTourVirtual()
{
	while (document.getElementById('ddlVirtualTourPais').options.length > 0)
	{
		document.getElementById('ddlVirtualTourPais').options[0] = null;
	}
	document.getElementById('ddlVirtualTourPais').options[0] = CreateOption(initialValue, "0");
}
	
//2008-10-21    SS      Added logic to virtual tour
function CargarEstadosVirtualTour(IdPaisEnc)
{
	LimpiarEstadosVirtualTour();
	if(IdPaisEnc!="0")
	{
//		if (UsuarioRegistrado())
//		{
//			PautaAnuncioPaso1.CargarEstadosVirtualTour(IdPaisEnc, CargarEstadosVirtualTour_callback);
//		}
//		else if (c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1Registrado.CargarEstadosVirtualTour(IdPaisEnc, CargarEstadosVirtualTour_callback);
//		}
		PautaAnuncio.CargarEstadosVirtualTour(IdPaisEnc, CargarEstadosVirtualTour_callback);
	}
}

//2008-10-21    SS      Added logic to virtual tour
function CargarEstadosVirtualTour_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
		{
			document.getElementById('ddlVirtualTourEstado').options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idEstado"]);
		}
		document.getElementById('ddlVirtualTourEstado').value = IdTourVirtualEstadoACargarEnc;
		if (!bEditing)
		{
			IdTourVirtualEstadoACargarEnc = "0";
		}
	}
}

//2008-10-21    SS      Added logic to virtual tour
function LimpiarEstadosVirtualTour()
{
	while (document.getElementById('ddlVirtualTourEstado').options.length > 0)
	{
		document.getElementById('ddlVirtualTourEstado').options[0] = null;
	}
	document.getElementById('ddlVirtualTourEstado').options[0] = CreateOption(initialValue, "0");
	LimpiarCiudadesVirtualTour();
}

//2008-10-21    SS      Added logic to virtual tour
function CargarCiudadesVirtualTour(IdEstadoEnc)
{   

	LimpiarCiudadesVirtualTour();
	if(IdEstadoEnc!="0")
	{
//		if (UsuarioRegistrado())
//		{
//			PautaAnuncioPaso1.CargarCiudadesVirtualTour(IdEstadoEnc, CargarCiudadesVirtualTour_callback);
//		}
//		else if (c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1Registrado.CargarCiudadesVirtualTour(IdEstadoEnc, CargarCiudadesVirtualTour_callback);
//		}
		PautaAnuncio.CargarCiudadesVirtualTour(IdEstadoEnc, CargarCiudadesVirtualTour_callback);		
	}
}

//2008-10-21    SS      Added logic to virtual tour
function CargarCiudadesVirtualTour_callback(res)
{
	if (res.error != null)
	{
		 ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
		{
				document.getElementById('ddlVirtualTourCiudad').options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idCiudad"]);
		}
		document.getElementById('ddlVirtualTourCiudad').value = IdTourVirtualCiudadACargarEnc;
		if (!bEditing)
		{
			IdTourVirtualCiudadACargarEnc = "0";
		}
	}
}

//2008-10-21    SS      Added logic to virtual tour
function LimpiarCiudadesVirtualTour()
{
	while (document.getElementById('ddlVirtualTourCiudad').options.length > 0)
	{
		document.getElementById('ddlVirtualTourCiudad').options[0] = null;
	}
	document.getElementById('ddlVirtualTourCiudad').options[0] = CreateOption(initialValue, "0");
}

//2008-10-21    SS      Added logic to virtual tour
function CargarAreasGeograficasVirtualTour(IdCiudadEnc)
{

	LimpiarAreasGeograficasVirtualTour();
	if(IdCiudadEnc!="0")
	{
//		if (UsuarioRegistrado())
//		{
//			PautaAnuncioPaso1.CargarAreasGeograficasVirtualTour(IdCiudadEnc, CargarAreasGeograficasVirtualTour_callback);
//		}
//		else if (c_bRegisteredScreen)
//		{
//			PautaAnuncioPaso1Registrado.CargarAreasGeograficasVirtualTour(IdCiudadEnc, CargarAreasGeograficasVirtualTour_callback);
//		}
	
		PautaAnuncio.CargarAreasGeograficasVirtualTour(IdCiudadEnc, CargarAreasGeograficasVirtualTour_callback);

	}
}
	//2008-10-21    SS      Added logic to virtual tour
function CargarAreasGeograficasVirtualTour_callback(res)
{
	if (res.error != null)
	{
		ProcessError(res);
	}
	else
	{
		dt = res.value;
		for(i=0; i<dt.Rows.length; i++)
		{
			document.getElementById('ddlVirtualTourAreaGeografica').options[i+1] = CreateOption(dt.Rows[i]["sNombre"], dt.Rows[i]["idAreaGeografica"]);
		}
	    
		document.getElementById('ddlVirtualTourAreaGeografica').value = IdTourVirtualAreaGeograficaACargarEnc;
		if (!bEditing)
		{	    
			IdTourVirtualAreaGeograficaACargarEnc = "0";
		}

	}
}
//2008-10-21    SS      Added logic to virtual tour
function LimpiarAreasGeograficasVirtualTour()
{
	while (document.getElementById('ddlVirtualTourAreaGeografica').options.length > 0)
	{
		document.getElementById('ddlVirtualTourAreaGeografica').options[0] = null;
	}

	document.getElementById('ddlVirtualTourAreaGeografica').options[0] = CreateOption(initialValueAreasGeograficas, "0");
}

//  Check virtual tour data
function PautaAnuncioValidarDatosVirtualTour()
{

	var bErrores = false;


	if (document.getElementById('chkAgregado'+chkVirtualTour).checked)
	{         
	    
		if (!document.getElementById('optTelefono').checked && !document.getElementById('optEmail').checked)
		{
			setInnerHTML('RFV_txtVirtualTourContacto', 'Debe seleccionar una opci&oacute;n');
			bErrores = true;
		}
		else
		{
			setInnerHTML('RFV_txtVirtualTourContacto', '');
		}
	    
		if (document.getElementById('txtTelefono').value=="")
		{
	        
			setInnerHTML('RFV_txtTelefonoVirtualTour', 'Indique el tel&eacute;fono de contacto');
			bErrores = true;
		} 
		else if (!(/^[0-9\+\-\s]{1,250}$/.test(document.getElementById('txtTelefono').value)))
		{
			setInnerHTML('RFV_txtTelefonoVirtualTour', 'Caracteres inv&aacute;lidos');
			bErrores = true;
		}
		else 
		{
			setInnerHTML('RFV_txtTelefonoVirtualTour', '');
		}

	   if (document.getElementById('txtEmailVirtualTour').value=="")
	   {
	        
			setInnerHTML('RFV_txtEmailVirtualTour', 'Indique el Email de contacto');
			bErrores = true;
		}
		else if (!(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(document.getElementById('txtEmailVirtualTour').value)))
		{
	        
			setInnerHTML('RFV_txtEmailVirtualTour', 'Caracteres inv&aacute;lidos');
			bErrores = true;
		}
		else 
		{
			setInnerHTML('RFV_txtEmailVirtualTour', '');
		}

	 
		if (document.getElementById('ddlVirtualTourPais').value=="0") {
			setInnerHTML('RFV_ddlVirtualTourPais', 'Indique el pa&iacute;s');
			bErrores = true;
		} 
		else 
		{
			setInnerHTML('RFV_ddlVirtualTourPais', '');
		}

		if (document.getElementById('ddlVirtualTourEstado').value=="0") {
			setInnerHTML('RFV_ddlVirtualTourEstado', 'Indique el estado');
			bErrores = true;
		} 
		else 
		{
			setInnerHTML('RFV_ddlVirtualTourEstado', '');
		}

		if (document.getElementById('ddlVirtualTourCiudad').value=="0") {
			setInnerHTML('RFV_ddlVirtualTourCiudad', 'Indique la ciudad');
			bErrores = true;
		}
		else 
		{
			setInnerHTML('RFV_ddlVirtualTourCiudad', '');
		}

		if (document.getElementById('txtFechaVirtualTour').value!="")
		{
				var desde = new Date(dFechaDesde);
				var hasta = new Date(dFechaHasta);
				var fechaIngresada = new Date(document.getElementById('txtFechaVirtualTour').value);
			   if ((fechaIngresada<desde)||(fechaIngresada>hasta))
			   {
				setInnerHTML('RFV_txtFechaVirtualTour', 'Fecha Inv&aacute;lida');
				bErrores = true;
				}
				else 
				{
				setInnerHTML('RFV_txtFechaVirtualTour', '');
				}
		} 
		else 
		{
			setInnerHTML('RFV_txtFechaVirtualTour', 'Debe ingresar una fecha v&aacute;lida');
			bErrores = true;
		}
	    
		if (document.getElementById('txtVirtualTourDescripcion').value=="") 
		{
			setInnerHTML('RFV_txtVirtualTourDescripcion', 'Indique la descripci&oacute;n');
			bErrores = true;
		}
		else
		{
			setInnerHTML('RFV_txtVirtualTourDescripcion', '');
		} 
		
		if (c_dTotal < 0) 
		{
			bErrores = true;
		}
	    
	}
	return bErrores;
}


function CalculateTourVirtualCost()
{
	c_dDate = document.getElementById('txtFechaVirtualTour').value;
	GetPrecioMillaje(c_dDate,IdTourVirtualCiudadACargarEnc) ;

	if (!bEditing)
	{
		SeleccionAutomaticaVirtualTour ( IdTourVirtualPaisACargarEnc, IdTourVirtualEstadoACargarEnc , IdTourVirtualCiudadACargarEnc, IdTourVirtualAreaGeograficaACargarEnc);
	}
}

//2008-10-15    SS      Added logic to virtual tour
function SeleccionAutomaticaVirtualTour(IdPaisEnc, IdEstadoEnc, IdCiudadEnc, IdAreaGeograficaEnc)
{
//	alert("IdEstadoEnc " +IdEstadoEnc);
	CargarPaisesTourVirtual();
	IdTourVirtualPaisACargarEnc = IdPaisEnc; 

	CargarEstadosVirtualTour (IdPaisEnc);
	IdTourVirtualEstadoACargarEnc = IdEstadoEnc;

	CargarCiudadesVirtualTour(IdEstadoEnc);
	IdTourVirtualCiudadACargarEnc = IdCiudadEnc ;

	CargarAreasGeograficasVirtualTour(IdCiudadEnc);
	IdTourVirtualAreaGeograficaACargarEnc = IdAreaGeograficaEnc; 

	document.getElementById('ddlVirtualTourPais').value = IdPaisEnc;

	document.getElementById('ddlVirtualTourEstado').value = IdEstadoEnc;

	if (IdCiudadEnc == "0")
	{
		document.getElementById('ddlVirtualTourCiudad').value = "0";
	}
	else
	{
		document.getElementById('ddlVirtualTourCiudad').value = IdCiudadEnc;
	}
	if ( IdAreaGeograficaEnc == "0" )
	{
		document.getElementById('ddlVirtualTourAreaGeografica').value = "0";
	}
	else
	{
		document.getElementById('ddlVirtualTourAreaGeografica').value = IdAreaGeograficaEnc;
	}

	 
    if (bEditing)
        CalculateTourVirtualCost(); 
}

function VirtualTourData() 
{

	 if (IdTourVirtualAreaGeograficaACargarEnc == "0")
	{
		document.getElementById('ddlVirtualTourAreaGeografica').value = document.getElementById('ddlVirtualTourAreaGeografica').options[0] = CreateOption(initialValueAreasGeograficas, "0");
		document.getElementById('ddlVirtualTourAreaGeografica').value = "0";
	}
	else    
	{
		document.getElementById('ddlVirtualTourAreaGeografica').value = IdTourVirtualAreaGeograficaACargarEnc;
	}

	if ( document.getElementById('ddlVirtualTourCiudad').value == "0" && document.getElementById(ddlCiudad).value == "0")
	{
		document.getElementById('ddlVirtualTourCiudad').value = document.getElementById('ddlVirtualTourCiudad').options[0] = CreateOption(initialValue, "0");
		document.getElementById('ddlVirtualTourCiudad').value = "0";
		setInnerHTML('RFV_ddlVirtualTourCiudad', 'Indique la ciudad');
	}
	else if( document.getElementById('ddlVirtualTourCiudad').value == "0")
	{
		 IdTourVirtualCiudadACargarEnc = document.getElementById(ddlCiudad).value;   
		 document.getElementById('ddlVirtualTourCiudad').value = document.getElementById(ddlCiudad).value;
		 setInnerHTML('RFV_ddlVirtualTourCiudad', '');
	}
	        
	if ( document.getElementById('ddlVirtualTourPais').value == "0" )
	{
		document.getElementById('ddlVirtualTourPais').value =  document.getElementById(ddlPais).value;
	}
	else
	{ 
		// si no esta cargado ya, caso de boton atras y luego continuar
		if (IdTourVirtualPaisACargarEnc != "0")
		{
			IdTourVirtualPaisACargarEnc = document.getElementById('ddlVirtualTourPais').value;
		}
		else
		{
			if (IdTourVirtualPaisACargarEnc == "0" ) 
			{
				IdTourVirtualPaisACargarEnc = document.getElementById(ddlPais).value;
			}
		}
	}
}

	//2008-10-14    SS      Added logic to virtual tours calculate mileage
function GetPrecioMillaje(nYear, idCiudad)
{   
//	if (!c_bRegisteredScreen)
//	{ 
//		PautaAnuncioPaso1.GetPrecioMillaje(nYear, idCiudad, GetPrecioMillaje_callback);
//	}
//	else
//	{

//		PautaAnuncioPaso1Registrado.GetPrecioMillaje(nYear, idCiudad, GetPrecioMillaje_callback);
//	}

	PautaAnuncio.GetPrecioMillaje(nYear, idCiudad, GetPrecioMillaje_callback);
}

function GetPrecioMillaje_callback(res)
{
	if (res.error != null)
		 ProcessError(res);
	else
	{
		c_dMiles = res.value;
	  
		var sMillaje;
		var sTotal;
	    
			 c_dTotal = c_dPrecioAgregado + c_dMiles;
	       
		if (c_dMiles > 0)
		{
			sMillaje = "\n						<em style=\"background-color: rgb(240,241,244);\">Costo millaje</em>";
			sMillaje +="\n						<strong style=\"background-color: rgb(240,241,244);\">$ " + formatCurrency(c_dMiles) +"</strong>";
			sMillaje +="\n						<span></span>";
	        
			setInnerHTML('idMiles', sMillaje);
	        
			sTotal = "\n						<em style=\"font-weight: bold; background-color: rgb(240,241,244);\">Total</em>";
			sTotal +="\n						<strong style=\"font-weight: bold; background-color: rgb(240,241,244);\">$" + formatCurrency(c_dTotal) +"</strong>";
			sTotal +="\n						<span></span>"; 
	        
		}
		else
		{
			sTotal  = "\n						<em style=\"background-color: rgb(240,241,244);\">Costo millaje</em>";
			sTotal  +="\n						<strong style=\"background-color: rgb(240,241,244);\">"; 
			sTotal  +="\n						<strong style=\"background-color: rgb(240,241,244);\"><span style=\"color:#FF0000;font-size:11px; background-color: rgb(240,241,244); font-weight:bold;\">No se dispone de costo de transporte para esa ciudad.</span></strong>";
	        
			setInnerHTML('idMiles',"&nbsp;");

		}
		//recalculate total and ivu
		if (!c_bRegisteredScreen)
		{ 
			ArmarTablaAgregados();
		}
		setInnerHTML('idTotal',sTotal);
	}
}

//2008-10-15    SS      Added logic to virtual tour  
function ETourVirtual(IdSolicitudTourVirtual, IdPais,IdEstado,IdCiudad, IdAreaGeografica,FormaContacto,FechaFotos,EmailAlternativo,DescripcionTourVirtual,CostoTotal, CostoMillaje, ProductoOrdenado, Telefono)
{
	this.IdSolicitudTourVirtual = IdSolicitudTourVirtual;
	this.IdPais         = IdPais;
	this.IdEstado       = IdEstado;
	this.IdCiudad       = IdCiudad;
	this.IdAreaGeografica   = IdAreaGeografica;
	this.FormaContacto       = FormaContacto;
	this.FechaFotos      = FechaFotos;
	this.EmailAlternativo   = EmailAlternativo;
	this.DescripcionTourVirtual   = DescripcionTourVirtual;
	this.CostoTotal      = CostoTotal;
	this.CostoMillaje   = CostoMillaje;
	this.ProductoOrdenado   = ProductoOrdenado;
	this.Telefono   = Telefono;
}

//2008-10-15    SS      Added logic to virtual tour
function CreateVirtualTour()
{

	var IdSolicitudTourVirtual = idTour;
	var IdPais = document.getElementById('ddlVirtualTourPais').value;
	var IdEstado = document.getElementById('ddlVirtualTourEstado').value;
	var IdCiudad = document.getElementById('ddlVirtualTourCiudad').value;
	var IdAreaGeografica = document.getElementById('ddlVirtualTourAreaGeografica').value;
	var FormaContacto;
	var EmailAlternativo = document.getElementById('txtEmailVirtualTour').value;
	var Telefono = document.getElementById('txtTelefono').value;
	if (document.getElementById('optTelefono').checked)
	{
		FormaContacto = c_FormaContactoTelefono;
	}
	else if (document.getElementById('optEmail').checked)
	{
		FormaContacto = c_FormaContactoEmail;
	}


	var FechaFotos = document.getElementById('txtFechaVirtualTour').value;
	var DescripcionTourVirtual = document.getElementById('txtVirtualTourDescripcion').value;

	var CostoTotal = formatCurrency(c_dPrecioAgregado + c_dMiles);
	var CostoMillaje = c_dMiles;
	var ProductoOrdenado = document.getElementById('txtVirtualTourProductoOrdenado').value;

	agregados[chkVirtualTour].Precio = String(formatCurrency(c_dPrecioAgregado + c_dMiles));
	eTourVirtual = new ETourVirtual(IdSolicitudTourVirtual, IdPais,IdEstado,IdCiudad, IdAreaGeografica,FormaContacto,FechaFotos,EmailAlternativo,DescripcionTourVirtual,CostoTotal,CostoMillaje,ProductoOrdenado, Telefono);
}

function ArmarAttetionGetters()
{
	
	if (!c_bRegisteredScreen)
	{
	
		PautaAnuncioPaso1.GetUpsellsOptionsByCategory(c_nIdTipoUsuario, idCategoria, GetUpsellsOptionsByCategory_callback);
	}
	else
	{
		PautaAnuncioPaso1Registrado.GetUpsellsOptionsByCategory(c_nIdTipoUsuario, idCategoria, GetUpsellsOptionsByCategory_callback);
	}
//	if (!c_bRegisteredScreen)
//	{
//	
//		PautaAnuncioPaso1.armaTablaAgregados(c_nIdTipoUsuario, idCategoria, ArmarAttetionGetters_callback);
//	}
//	else
//	{
//		
//		if (bEditing)
//		{
////			alert('esHistorico, mode ' + esHistorico + ' ' + mode);
//			PautaAnuncioPaso1Registrado.armaTablaAgregados2(c_nIdTipoUsuario, idCategoria, parseInt(idAviso), esHistorico, ArmarAttetionGetters_callback);		
//		}
//		else
//		{
//			PautaAnuncioPaso1Registrado.armaTablaAgregados(c_nIdTipoUsuario, idCategoria, ArmarAttetionGetters_callback);		
//		}
//			
//	
//	}
	
	

}

function GetUpsellsOptionsByCategory_callback(res)
{
	if (res.error != null)
	{
		ProcessError(res);
	}
	else
	{
	    //  Set all to invisible
	    for(var x in opcionesAgregados)
	    {
            if (document.getElementById(opcionesAgregados[x].Control) != null)
            {
	            opcionesAgregados[x].Visible = false;
	        }
	    }
		
	    //  Mark those visible for the category
		for(var i = 0; i < res.value.length; i++)
		{
		    
	        var idOpcionAgregadoEnc = res.value[i];
	        
		    opcionesAgregados[idOpcionAgregadoEnc].Visible = true;
		}

        //  Hide or show upsell options
        var selectedOptionHasBeenHidden = false;
        var firstVisibleOption = null;
        for(var x in opcionesAgregados)
        {
            var opcionAgregadoContainerControl = document.getElementById(opcionesAgregados[x].Control);
            
            if (opcionAgregadoContainerControl != null)
            {
//     		    alert('Control=' + opcionAgregado.Control + ", diplay=" + opcionAgregadoContainerControl.style.display);
     		    
     		    if (opcionesAgregados[x].Visible)
     		    {
                    opcionAgregadoContainerControl.style.display = "";
                    
                    firstVisibleOption = opcionesAgregados[x];
                }
                else
     		    {
                    opcionAgregadoContainerControl.style.display = "none";
                    
                    if (agregados[opcionesAgregados[x].IdAgregadoCrypted].Opcion == opcionesAgregados[x].IdOpcionAgregadoCrypted)
                    {
                        selectedOptionHasBeenHidden = true;
                        
                        //  Uncheck option
                        agregados[opcionesAgregados[x].IdAgregadoCrypted].Opcion = '';
                        
                        var radioControl = document.getElementById(opcionesAgregados[x].Radio);
                        
                        if (radioControl != null)
                        {
                            radioControl.checked = false;
                        }
                    }
                }
            }
        }
        
        if (selectedOptionHasBeenHidden && firstVisibleOption != null)
        {
            //  Check option
            agregados[firstVisibleOption.IdAgregadoCrypted].Opcion = firstVisibleOption.IdOpcionAgregadoCrypted;
            
            var radioControl = document.getElementById(firstVisibleOption.Radio);
            
            if (radioControl != null)
            {
                radioControl.checked = true;
            }
        }
	}

}

function ArmarAttetionGetters_callback(res)
{
	if (res.error != null)
	{
		ProcessError(res);
	}
	else
	{
		setInnerHTML(divAdicionales, res.value); 
		
	}

}

function ArmarLinkLetrero()
{
    var avisoLetrero = document.getElementById('hidAvisoLetrero');
    var nroOrdenLetrero = document.getElementById('hidNroOrdenLetrero');
    var sAgregadosLetrero = document.getElementById('hidSAgregadosLetrero');
    var fAgregadosLetrero = document.getElementById('hidFAgregadosLetrero');
    
    document.location.href = 'LetreroNoRegistrado.aspx?idAviso=' + avisoLetrero.value + '&sag=' + sAgregadosLetrero.value + '&fag=' + fAgregadosLetrero.value + '&ord=' + nroOrdenLetrero.value;
}