function changeThisValue(cbox) {
    	if(cbox.checked) cbox.value = "1";
    	if(!cbox.checked) cbox.value = "0";
    }

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


MM_reloadPage(true);


function isObjectNull(object){
	if (object != null){
		return true;
	}else{
		return false;
	}
}


/*
TODO - Esta funcion tiene que ser DINAMICA, dependiendo de los ITEMS.
debe recibir cantidad items
el id de los divs deberia formarse por la cantidad/orden
*/


function cambiarImagen (url, indice) {

	if (document.getElementById('secundario_1') != null){
		document.getElementById ('secundario_1').className = 'secundario_1 borde_blanco pointer';
	}

	if (document.getElementById('secundario_2') != null){
		document.getElementById ('secundario_2').className = 'secundario_2 borde_blanco pointer';
	}

	if (document.getElementById('secundario_3') != null){
			document.getElementById ('secundario_3').className = 'secundario_3 borde_blanco pointer';
	}

	if (document.getElementById('secundario_4') != null){
			document.getElementById ('secundario_4').className = 'secundario_4 borde_blanco pointer';
	}

	if (document.getElementById('banner_principal') != null){
			document.getElementById ('banner_principal').style.background = 'url('+url+')';
	}

	if (document.getElementById('secundario_'+indice) != null){
			document.getElementById ('secundario_'+indice).className = 'secundario_'+indice+' borde_blanco secundario_filtro';
	}

}

/* usar para cambiar las imagenes del detalle de paquetes */
function cambiarImagenPaquetes (url, indice) {
  document.getElementById ('fotogrande_'+indice).src = url;
}
/* var GLOBAL - Se usa para saber que miniatura pasa a ser seleccionable*/
var ultimaImagen=null;

function cambiarEstiloMiniatura (indice) {

	document.getElementById ('secundario_'+indice).className = 'secundario_ borde_blanco secundario_filtro';
	if (ultimaImagen!=null && ultimaImagen!=indice)
	{
		document.getElementById ('secundario_'+ultimaImagen).className = 'secundario_ borde_blanco pointer';
	}
	ultimaImagen = indice;
}


function chat () {
  window.open ('chat.html', 'chat', 'width=475,height=520,status=no,toolbar=no,menubar=no,location=no');
}

/*
function cambiarDisplay (documento,id, valor) {

	if (valor) documento.getElementById (id).style.display = '';
	else documento.getElementById (id).style.display = 'none';

}
function cambiarDisplay (id, valor) {

  if (valor) document.getElementById (id).style.display = '';
  else document.getElementById (id).style.display = 'none';

}
 */

/*
	Se usa para cambiar los datos a mostrar en cada PROMOCION
	de la home
	id -> id del elemento a modificar
	valor -> valor nuevo del elemento id
*/
function cambiarTextosPromociones(id, valor)
{
	////alert(id +'  '+ valor);
	document.getElementById(id).innerHTML=valor;
}

function OcultarTodo(nivel)
{
		if (nivel == 1) {
			OcultarBloque("layerAvanzada");
		}
}

function MostrarBloque(strBloque, nivel)
{
	if (document.getElementById(strBloque).style.visibility=='visible'){
//			OcultarTodo();
		OcultarBloque(strBloque);
	} else {
		OcultarTodo(nivel);
		document.getElementById(strBloque).style.display='block';
		document.getElementById(strBloque).style.visibility='visible';
	}
}

function OcultarBloque(strBloque)
{
	document.getElementById(strBloque).style.display='none';
	document.getElementById(strBloque).style.visibility='hidden';
}

/*
	Mostrar / Ocultar-Restaurarvalores de
	los campos de telefono. Se permiten hasta 3.
*/
	var contadorTelefonos = 2;

	function Alternar(){
		var id = "telefono_" + contadorTelefonos;
			if (document.getElementById(id)!= null)
			{
			    if (document.getElementById(id).style.display=="none")
			    {
			    	document.getElementById(id).style.display="";
			    	contadorTelefonos++;
			    }
			}
	}

	function Ocultar(id){
		contadorTelefonos = 2;
		var idtelefono = "telefono_" + id;
		var vidTipoTelefono = "idTipoTelefono"+ id;
		var vprefTelefono = "prefTelefono"+ id;
		var vnroTelefono = "nroTelefono"+ id;
		document.getElementById(idtelefono).style.display="none";
		eval("document.forms[0]." + vidTipoTelefono + ".selectedIndex=0");
		eval("document.forms[0]." + vprefTelefono+ ".value=''");
		eval("document.forms[0]." + vnroTelefono + ".value=''");
	}

	/*
	function ocultarDestino(id) {

		var idFilaDestino = "destino_" + id;
		var idInputDestino = "destino" + id;
		document.getElementById(idFilaDestino).style.display="none";
		document.getElementById(idInputDestino).value='';
	}

	function agregarDestino () {

		for (var index = 2; index < 6; index++) {
			var idFilaDestino = "destino_" + index;
			if (document.getElementById(idFilaDestino).style.display=="none")
			{
				document.getElementById(id).style.display="";
				break;
			}
		}
	}*/

	

/*
		se utiliza para cambiar dinamicamente el estilo aplicado a los div de las etapas de la reserva.
		las etapas para hoteles son 3, asi que por ahora hago todo estatico.
		@param estiloPaso1
		@param estiloPaso2
		@param estiloPaso3
	*/
	function cambiarEtapaParent(estiloPaso1,estiloPaso2,estiloPaso3){
		var flacha = '<img src="../img/flecha_up.gif" alt="" height="4" width="8" />';
		if (estiloPaso1){
			window.parent.document.getElementById('tdpaso1').setAttribute('class','seleccionado'); // Failed
																									// on
																									// IE
			window.parent.document.getElementById('tdpaso1').className='seleccionado'; // Cross-browser
			window.parent.document.getElementById('divpaso1Flecha').innerHTML = flacha;
			// cambio los que no van
			window.parent.document.getElementById('tdpaso2').setAttribute('class',''); // Failed
																						// on
																						// IE
			window.parent.document.getElementById('tdpaso2').className=''; // Cross-browser
			window.parent.document.getElementById('divpaso2Flecha').innerHTML = '';
			window.parent.document.getElementById('tdpaso3').setAttribute('class',''); // Failed
																						// on
																						// IE
			window.parent.document.getElementById('tdpaso3').className=''; // Cross-browser
			window.parent.document.getElementById('divpaso3Flecha').innerHTML = '';
		}

		if (estiloPaso2){
			window.parent.document.getElementById('tdpaso2').setAttribute('class','seleccionado'); // Failed
																									// on
																									// IE
			window.parent.document.getElementById('tdpaso2').className='seleccionado'; // Cross-browser
			window.parent.document.getElementById('divpaso2Flecha').innerHTML = flacha;
			// cambio los que no van
			window.parent.document.getElementById('tdpaso1').setAttribute('class',''); // Failed
																						// on
																						// IE
			window.parent.document.getElementById('tdpaso1').className=''; // Cross-browser
			window.parent.document.getElementById('divpaso1Flecha').innerHTML = '';
			window.parent.document.getElementById('tdpaso3').setAttribute('class',''); // Failed
																						// on
																						// IE
			window.parent.document.getElementById('tdpaso3').className=''; // Cross-browser
			window.parent.document.getElementById('divpaso3Flecha').innerHTML = '';
		}

		if (estiloPaso3){
			window.parent.document.getElementById('tdpaso3').setAttribute('class','seleccionado'); // Failed
																									// on
																									// IE
			window.parent.document.getElementById('tdpaso3').className='seleccionado'; // Cross-browser
			window.parent.document.getElementById('divpaso3Flecha').innerHTML = flacha;
			// cambio los que no van
			window.parent.document.getElementById('tdpaso1').setAttribute('class',''); // Failed
																						// on
																						// IE
			window.parent.document.getElementById('tdpaso1').className=''; // Cross-browser
			window.parent.document.getElementById('divpaso1Flecha').innerHTML = '';
			window.parent.document.getElementById('tdpaso2').setAttribute('class',''); // Failed
																						// on
																						// IE
			window.parent.document.getElementById('tdpaso2').className=''; // Cross-browser
			window.parent.document.getElementById('divpaso2Flecha').innerHTML = '';

			//INI - compatibilidad vuelos-hoteoes
			parent.document.getElementById('step2RSS').setAttribute('class',''); // Failed on IE
			parent.document.getElementById('step2RSS').className=''; // Cross-browser
			//END - compatibilidad vuelos-hoteoes
		}

	}

function subtractPx (firstOp,secondOp) {
		    var firstNumber = null;
		    var secondNumber = null;
		    var  posPx = -1;

		    posPx = firstOp.toString().indexOf('px');

		    if ( posPx > -1)
		                firstNumber =  parseInt  (firstOp.substring(0,posPx) ) ;

		    posPx = secondOp.toString().toLowerCase().indexOf('px');

		    if ( posPx > -1)
		                secondNumber = parseInt ( secondOp.substring(0,posPx) ) ;

		    return new String (firstNumber - secondNumber + "px" );
}

function PxToNumber (px) {
		var posPx = px.toString().indexOf('px');
		return parseInt (px.substring(0,posPx) ) ;
}

function recalcularFrameProductos () {
    	/* Obtención de elementos relevantes para el calculo */
    	var elements = getElementsByClassName ("oferta_hotel", document);
    	var titulo = document.getElementById ("tituloProductos");
    	var pie = document.getElementById ("pieProductos");
    	
		var alturaProd = 0;		
		if (elements.length > 0 ) {
			var producto = elements[0];		
			alturaProd = producto.clientHeight == 0 ? producto.offsetHeight : producto.clientHeight;
			
		}
			var counter = elements.length == 0 ? 2 : elements.length; 
		
		/* Calculo basado en Titulo + Div de cantidad de productos + Pie */
			var plus = isExplorer () ? 65 : 55;
		  	var multp =   Math.round (counter / 2 ) ;
		    var totalAltura = (multp * alturaProd ) + (multp * 10 ) + ( titulo.clientHeight )  + ( pie.clientHeight) + plus;

		    var iframe = parent.document.getElementById("frame_centro");
			var secc_prods = document.getElementById("secc_prods");
			var list_prods = document.getElementById("list_prods");
	
     	if (totalAltura < 442) {
                	iframe.style.height="442px";
                	if (list_prods != null) list_prods.style.height = "315px";
		        	if (secc_prods != null) secc_prods.style.height = "438px";
        }
     	else
        {
                   secc_prods.style.height =  totalAltura - 5  + 'px';
				   iframe.style.height= totalAltura +  'px';
        }
}

function recalcularFrameRegistroUsr() {
	var a1 = getHeight ('table_errors');
	var a2 = getHeight ('table_errors2');
	var a3 = getHeight ('scroll_registro');
	var altura = a1 + a2 + a3;
	cambiarComponente ('div_scroll', altura + 10 );
	cambiarComponente ('div_central', altura + 170 );
	cambiarFrameCentro( altura + 175 );
}


function cambiarFrameParaAlternativas() {
	var tablaDetalle = document.getElementById ('tablaDetalle');
	// alert ('clientH = ' + tablaDetalle.clientHeight );
	// alert ('offsetHeight= ' + tablaDetalle.offsetHeight );
	var tablaHeight = tablaDetalle.clientHeight == 0 ? tablaDetalle.offsetHeight : tablaDetalle.clientHeight;
	// alert ('tabla height = ' + tablaHeight);
	 
	var pie = document.getElementById ("pieProductos");
	var pieHeight = 0;
	if (pie != null) {
		pieHeight = pie.clientHeight == 0 ? pie.offsetHeight : pie.clientHeight;
	}
	// alert ('pie height = ' + pieHeight);
	 
	var totalHeight = tablaHeight + pieHeight
	 	
		if (totalHeight + 100 > 442) {
				cambiarFrameCentro (totalHeight + 100);
				cambiarComponente ('div_central',totalHeight + 55);
				cambiarComponente ('div_scroll', totalHeight + 20);
		}
		else
		{
			frameAlternativasMinimo ();
		}		
}

function frameAlternativasMinimo () {
//	alert('frameAlternativaMinimo');
	cambiarFrameCentro (442);
	//cambiarComponente ('div_central',438);
	//cambiarComponente ('div_scroll', 395);
	cambiarComponente ('div_central',400);
	cambiarComponente ('div_scroll', 380);
}

function cambiarFrameParaFaq () {
	var altura = getHeight ('faq_table');
	//alert (altura);	
	if (parseInt (altura) + 55 > 442) {
		cambiarComponente ('div_central',altura+50);
		cambiarComponente ('div_scroll',altura+10);
		cambiarFrameCentro(altura+55);
	}
}

function resizeFrameCentral(padre) {
		var iframe = padre.getElementById("frame_centro");
		iframe.style.height="442px";
		// iframe.style.width="250px";
}

function resizeFrameCentral() {
	var iframe = parent.document.getElementById("frame_centro");
	iframe.style.height="442px";
}

function cambiarFrameCentro(h) {
	//alert ('cambiarFrameCentro -> ' + h);
	if(parent.document.getElementById('frame_centro') != null){
		var iframe = parent.document.getElementById("frame_centro");
		iframe.style.height=h+"px";		
	}
	
}

function cambiarComponente(id, h) {
	//alert ('in ' +  id + ' put ' + h);
	if(document.getElementById(id) != null){
		var iframe = document.getElementById(id);
		iframe.style.height=h+"px";
	}
	else
	{
		//alert (id + ' doesnt exist');	
	}
}

function reiniciarTramaIzquierda () { 
	
	if(document.title=="RegistroUsuario"){
		//alert("estamos en reiniciarTramaIzquierda()");
	}else{
		var box = parent.document.getElementById('trama_box');
		if(box != null) {		
			box.style.height = 0 + 'px';
			box.style.visibility = 'hidden';		
		}
	}
}

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];	
	var a = [];	
	var re = new RegExp('\\b' + classname + '\\b');	
	var els = node.getElementsByTagName("*");	
	for(var i=0,j=els.length; i<j; i++)	
	if(re.test(els[i].className))a.push(els[i]);	
		return a;
}

function getHeight (component) {
	var object = document.getElementById (component);
	if (object != null) {
		return object.clientHeight;
	}
	else
	{
		return 0;
	}
}

function CheckMaxLength( txt, size) {
    if(txt.value.length > size){
    	textarea = document.getElementById('comentarios_txt')
   		textarea.value = txt.value.substr( 0, size);

   		var msg = document.getElementById('mensajeValidacion');
   		msg.style.display='block';
    }
}

function limpiarFormulario() {
	  var frm = document.forms[0];
	  
	  var tableErr = document.getElementById("table_errors");
	     if (tableErr != null) {
	       var childs = tableErr.childNodes;
	   		if (childs != null)
	   			tableErr.removeChild (childs[0]);
	 	  }

	     tableErr = document.getElementById("table_errors2");
	     if (tableErr != null) {
	       var childs = tableErr.childNodes;
	   		if (childs != null)
	   			tableErr.removeChild (childs[0]);
	 	  }
	     
	   for (var i=0; i<frm.elements.length; i++) {
		 //if ( ($(frm.elements[i]).attr('readonly') != '') || ( $(frm.elements[i]).attr('disabled') != ''  ) ) {
           if (frm.elements[i].type == 'text' || frm.elements[i].type == 'textarea' || frm.elements[i].type == 'password') {
	                 frm.elements[i].value = '';
	         } else if (frm.elements[i].type == 'radio' || frm.elements[i].type == 'checkbox') {
	               for (var k=0; k<frm.elements[i].length; k++) {
	                     frm.elements[i][k].checked = false;
	               }
	         } else if (frm.elements[i].type == 'select-one') {
	               frm.elements[i].selectedIndex = 0;
	         }
		 //}
	}

	var el = document.getElementById('tipoContactoTel');
	if ( el != null) el.checked = false;
 	el = document.getElementById('tipoContactoMail').checked = false;
 	if ( el != null) el.checked = false;
}

function checkMaxLength( txt, size)
{
    if(txt.value.length > size){
   		txt.value = txt.value.substr( 0, size);
    }
}
function oneIfNull(field) {
	if(field.value==null || field.value.length==0)
		return 1;
	return 0;
}


function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3,4})+$/.test(valor)){
		return true;
	} else {
		return false;
	}
}
