/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function buscarEnArchivo_1(){
	field_q= document.getElementById("archivo-form-buscador-q");
	var taggear= taggearBuscador();
	if(taggearBuscador()==false){
		return false;
	}
	return true;
}

function limpiarCampo_1(){
	field_q_1= document.getElementById("archivo-form-buscador-q");
	if(field_q_1.value=="Buscar Noticias de Colombia y el Mundo") field_q_1.value="";
	$(document).ready(function() {
		BuscadorAutocomplete();
	});
}

function ponerCookieCiudad_1(aliasciudad){
	if(aliasciudad==1){
		return;
	}
	$('#pypCiudad1').load('/servicios/pico_placa/'+aliasciudad+'.html');
	if(aliasciudad!='bogota' && aliasciudad!='barranquilla' && aliasciudad!='cali' && aliasciudad!='medellin'){
		 aliasciudadclima = 'bogota';
	}
	else{
		 aliasciudadclima = aliasciudad;
	}
	$('#climaCiudad1').load('/servicios/clima/clima-'+aliasciudadclima+'.html');
	setCookie('eltiempociudad',aliasciudad,1323187445,'/','');
}

function setCookie_1(name, value, tiempo1, path, dominio, secure)
{
	var fecha = new Date();
	var tiempo = new Date(tiempo1);
	var validezCookie=7;	// Cookies con 7 días de vida
	var caducaCookie=new Date();
	caducaCookie.setTime(caducaCookie.getTime()+(validezCookie*24*60*60*1000));
	if(name != '')
		document.cookie = name + '=' + escape(value)
		+ (caducaCookie?'; EXPIRE='+caducaCookie.toGMTString():'EXPIRE=1')
		+ (path?'; PATH='+path:'')
		+ (dominio?'; DOMAIN='+dominio:'')
		+ (secure?'; SECURE':'');
}

function getCookie1_1(name)
{
	if(name == '')
	return('');
	name_index = document.cookie.indexOf(name + '=');
	if(name_index == -1)
		return('');
	cookie_value =  document.cookie.substr(name_index + name.length + 1,
	document.cookie.length);
	//All cookie name-value pairs end with a semi-colon, except the last one.
	end_of_cookie = cookie_value.indexOf(';');
	if(end_of_cookie != -1)
		 cookie_value = cookie_value.substr(0, end_of_cookie);
	//Restores all the blank spaces.
	space = cookie_value.indexOf('+');
	while(space != -1)
	{
		cookie_value = cookie_value.substr(0, space) + ' ' +
		cookie_value.substr(space + 1, cookie_value.length);
		space = cookie_value.indexOf('+');
	}
	return(cookie_value);
}

function clearCookie_1(name)
{
	expires = new Date();
	expires.setYear(expires.getYear() - 1);
	document.cookie = name + '=null' + '; expires=' + expires; 		
}

function clearCookies_1()
{
	Cookies = document.cookie;
	Cookie = Cookies;
	expires = new Date();
	expires.setYear(expires.getYear() - 1);
	while(Cookie.length > 0)
	{
		//All cookie name-value pairs end with a semi-colon, except the last one.
		Cookie = Cookies.substr(0, Cookies.indexOf(';'));
		Cookies = Cookies.substr(Cookies.indexOf(';') + 1, Cookies.length);
		if(Cookie != '')
			document.cookie = Cookie + '; expires=' + expires;
		else
			document.cookie = Cookies + '; expires=' + expires;			  			  	
	 }		 		
}

function abrirVentanaW_1(pagina) {
	window.name = "main";
	window.open(pagina,'window','width=646,height=431,scrollbars=no,resizable=yes');
}

function cambiarmouse_1(i,titulo){
	for(j=0; j<totart; j++){
		document.getElementById('m_destacado'+j).style.display="none";
		$('#tab'+j).removeClass("activo");
		document.getElementById('titulo_'+j).style.display = "block";
		document.getElementById('titulo2_'+j).style.display = "none";
		if(j==i){
			document.getElementById('m_destacado'+i).style.display="block";
			$('#tab'+j).addClass("activo");
			document.getElementById('titulo_'+j).style.display = "none";
			document.getElementById('titulo2_'+j).style.display = "block";
		}
	}
}

function buscarVuelos_1(){
 a = true;
	if((document.getElementById('radIdaVuelta').checked==false) && (document.getElementById('solo ida').checked==false)){
		alert('Elija ida o ida y vuelta');
		document.getElementById('radIdaVuelta').focus();
		a = false;
		return false;
	}
	else
	{
		if(document.getElementById('solo ida').checked==true){
			txtida='OW';
		}else{
			txtida='RT';
		}
	}
	if(document.getElementById('TO').value==0){
		alert('Elija un destino');
		a = false;
		return false;
	}
	txtFrom = document.getElementById('FROM').value;
	txtTo = document.getElementById('TO').value;
	if (txtFrom == txtTo){
		alert('Debe elegir una ciudad de destino diferente a la de origen');
		a = false;
	}
	txtAnoS = document.getElementById('anosalida').value;
	txtMesS = document.getElementById('messalida').value;
	txtDiaS = document.getElementById('diasalida').value;
	txtAnoR = document.getElementById('anoregreso').value;
	txtMesR = document.getElementById('mesregreso').value;
	txtDiaR = document.getElementById('diaregreso').value;
	var gNow = new Date();
	if (txtAnoS <= gNow.getFullYear())
	{
		if (txtMesS < (gNow.getMonth()+1)){
			//&& gNow.getDate() > diaini.value &&
			alert('La fecha de salida debe ser igual o superior a la fecha actual');
			a = false;
		}else if (txtMesS == (gNow.getMonth()+1)){
			if (txtDiaS < gNow.getDate()){
				alert('La fecha de salida debe ser igual o superior a la fecha actual');
				a = false;
			}
		}
	}
	if (document.getElementById('solo ida').checked==false)
	{
		if (txtAnoR <= gNow.getFullYear())
		{
			if (txtMesR < (gNow.getMonth()+1))
			{
				//&& gNow.getDate() > diaini.value &&
				alert('La fecha de regreso debe ser igual o superior a la fecha actual');
				a = false;
			}else if (txtMesR == (gNow.getMonth()+1))
			{
				if (txtDiaR < gNow.getDate()){
					alert('La fecha de regreso debe ser igual o superior a la fecha actual');
					a = false;
				}
			}
		}
		if (txtAnoR <= txtAnoS)
		{
			if (txtMesR < txtMesS)
			{
				//&& gNow.getDate() > diaini.value &&
				alert('La fecha de regreso debe ser igual o superior a la fecha de salida');
				a = false;
			}else if (txtMesR == txtMesS)
			{
				if (txtDiaR < txtDiaS)
				{
					alert('La fecha de regreso debe ser igual o superior a la fecha de salida');
					a = false;
				}
			}
		}
	}
		//txtFechas = document.getElementById('fechas').value;
	txtAdultos = document.getElementById('pasaxjeros').value;
	txtNinos = document.getElementById('pasajerosninos2').value;
	txtInfantes = document.getElementById('infantesPasajeros2').value;
	if((document.getElementById('fechas2').checked==false) && (document.getElementById('fechas3').checked==false)){
		alert('Elija las fechas');
		document.getElementById('fechas2').focus();
		a = false;
		return false;
	}else{
		if(document.getElementById('fechas2').checked==true){
			txtFechas='false';
		}else{
			txtFechas='true';
		}
	}
	if (a){
		/*CMCO_SendBooking(txtFrom,txtTo,txtDiaS,txtMesS,txtAnoS,txtDiaR,txtMesR,txtAnoR,txtFechas,txtida,txtAdultos,txtNinos,txtInfantes,txtVendedor, txtCabina);*/
		/*function CMCO_SendBooking(desde, hasta, diafechasalida, mesfechasalida, anofechasalida, diafecharegreso, mesfecharegreso, anofecharegreso, fechasflexibles, tipoviaje, qtyadultos, qtyninos, qtyinfantes){ */
		CMCO_SendBooking(txtFrom, txtTo, txtDiaS, txtMesS, txtAnoS, txtDiaR, txtMesR, txtAnoR, txtFechas, txtida, txtAdultos,txtNinos,txtInfantes)
	}
	/*URL DE CLICK*/
	if (!document.eplUC) { document.eplUC=[]; }
	var i = new Image(); i.src = "http://ads.eltiempo.com/call/clicpixel/5674666/[timestamp]?";
	document.eplUC.push(i);
	return true;
}

function cambiarTelRosa_1(id,arts){
	if(id==(arts)||id==0){
		id=0;
	}
	if(id<0){
		id=arts-1;
	}
	for(i=0;i<arts;i++){
		$('#telrosa_' + i).hide();
	}
	$('#telrosa_' + id).show();
}



function numerosaleatorios_1(){
	var aleatorios = new Array();
	while(poss<numaleatorios){
		var aleatorio = Math.floor(Math.random()*(rango_superior-(rango_inferior-1))) + rango_inferior;
		if(poss==0){
			aleatorios[poss] = aleatorio;
			poss++;
		}else{
			cont_rep=0;
			for(y=0;y<=aleatorios.length;y++){
				if(aleatorios[y] == aleatorio){
					cont_rep++;
				}
			}
			if(cont_rep==0){
				aleatorios[poss] = aleatorio;
				poss++;
			}else{
			}
		}
	}
	return aleatorios;
}

function array_rand_1( input, num_req ) {
	// Realiza la misma funcion de array_rand de php
	var indexes = [];
	var ticks = num_req || 1;	var checkDuplicate = function ( input, value ) {
	var exist = false, index = 0;
	while ( index < input.length ) {
		if ( input [ index ] === value ) {
			exist = true;				break;
		}
		index++;
	}
	return exist;	};
	if ( input instanceof Array && ticks <= input.length ) {
		while ( true ) {
			var rand = Math.floor( ( Math.random( ) * input.length ) );			if ( indexes.length === ticks ) { break; }
			if ( !checkDuplite( indexes, rand ) ) { indexes.push( rand ); }
		}
	} else {
		indexes = null;
	}
	return ( ( ticks == 1 ) ? indexes.join( ) : indexes );
}

function carrusel_galerias_destacadas(){
	$("#Carrusel_img").jCarouselLite({
		btnNext: "#next_img",
		btnPrev: "#prev_img",
		speed: 500,
		visible:2,
		circular:true
	});
}

function carrusel_fotos_noticias_home(){
	$("#CarruselMasNoticias").jCarouselLite({
		btnNext: "#next_nh",
		btnPrev: "#prev_nh",
		speed: 500,
		visible:3,
		circular:true
	});
}

function carrusel_fotos_noticias_home_fin_anio(){
	$("#CarruselMasNoticias").jCarouselLite({
		btnNext: "#next_nh",
		btnPrev: "#prev_nh",
		speed: 500,
		visible:7,
		start:-1,
		circular:true
	});
}

function pageviews(){
	s_events='event1';
	s_linkTrackVars='events';
	s_linkTrackEvents='event1';
	try
	{
		var s_code=s.t();if(s_code)document.write(s_code);
	}
	catch(err){}
}
function BuscadorAutocomplete(){
	(function($) {
		$('#archivo-form-buscador-q').autocomplete({
			source: function(request,response) {
				$.ajax({
					url: "http://www.eltiempo.com/archivo/a",
					success: function(data) {
						var suggestions = data.spellcheck.suggestions;
						var s = (function() {
							if (suggestions.length > 1)
								return suggestions[1].suggestion;
							return [];
						})();
						response(s);
					},
					type: "GET",
					data: 'q='+ request.term,
					dataType: 'jsonp',
					jsonp: 'json.wrf'
				});
			}
		});
	})(jQuery);
}
