//var base_cosmic = 'http://localhost/cosmictravelnetwork/';
var base_cosmic = 'http://cosmictravel.net/';
function attach_file( p_script_url ) 
{
	script = document.createElement( 'script' );
	script.src = p_script_url;
	document.getElementsByTagName( 'head' )[0].appendChild( script );
}
function mailValido(elemento)
{
	return /^[(a-z)][\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}$/i.test (elemento.toLowerCase());
}

function fechaValida(dia, mes, anio)
{
	mes = mes-1;
	var fecha = new Date(anio, mes, dia);
	return correcto = anio == fecha.getFullYear() && mes == fecha.getMonth() && dia == fecha.getDate();
}
function validarFecha(nro)
{
	var anio, mes, dia, msj;
	if (1==nro)
	{
		anio = document.getElementById('ciAnio').value*1;
		mes = document.getElementById('ciMes').value*1;
		dia = document.getElementById('ciDia').value*1;
		msj = 'in';
	}
	else
	{
		anio = document.getElementById('coAnio').value*1;
		mes = document.getElementById('coMes').value*1;
		dia = document.getElementById('coDia').value*1;
		msj = 'out';
	}
	if (!fechaValida(dia, mes, anio))
	{
		alert('Wrong check-'+msj+' date');
	}
}
function enviarFormulario()
{
    var anio, mes, dia;
	anio = document.getElementById('ciAnio').value;
	mes = document.getElementById('ciMes').value;
	dia = document.getElementById('ciDia').value;
	if (!fechaValida(dia, mes, anio))
	{
		alert('Wrong Check-in date');
		return;
	}
	var fecha1 = new Date(anio, mes-1, dia);
	
	anio = document.getElementById('coAnio').value;
	mes = document.getElementById('coMes').value;
	dia = document.getElementById('coDia').value;

	if (!fechaValida(dia, mes, anio))
	{
		alert('Wrong Check-out date');
		return;
	}
	var fecha2 = new Date(anio, mes-1, dia);
	mes = mes+1;
	
    if (fecha2<=fecha1)
    { 
        alert('Check out can\'t be less than the Check In');
        return;
    }
	
	document.frmAvailability.submit();
}
//-- para mostrar paquetes
function s2_verpaquete_mostrarSeccion(seccion)
{
	var pan;
	for(i=0;i<7;i++)
	{
		pan = document.getElementById("paq0"+i);
		pan.style.display = (seccion==i)? "":"none";

		pan= document.getElementById("tit0"+i);
		pan.style.color = (seccion==i)? "#C12F00":"#0e0e0e";

		pan= document.getElementById("tis0"+i);
		pan.style.color = (seccion==i)? "#C12F00":"#333333";
	}
}
  function s2_comentar()
  {
	var pan = document.getElementById("txbNombreComment").value;
	var msg = '';
	var url = document.getElementById('base_url').value+'ajax/comentar.php';
	pan = pan.replace(' ','');
	if(0==pan.length)
	{
		alert('Name');
		return false;
	}
	url +='?name='+pan;
	
	msg = 'Dear: '+pan+'\n';
	pan = document.getElementById("txbEmailComment").value;
	if (!mailValido(pan))
	{
		alert('E MAIL');
		return false;
	}
	
	url += '&mail='+pan;
	url += '&rate='+document.getElementById('cbbValoracionComment').value;

	if (document.getElementById('chkNewsComment').checked)
		url += '&news=1';
	else
		url += '&news=0';
	
	pan = document.getElementById("txbComentarioComment").value;

	if (pan.length < 10)
	{
		alert('The comment is short .... More than 10 characters');
		return false;
	}
	
	url +='&comment=' +pan;
	url +='&contenido=' + document.getElementById("idComment").value;
	url +='&tipo=' + document.getElementById("tipoComment").value;
	url +='&dominio=' + document.getElementById("dominioComment").value;
	
        var a =Math.floor(Math.random()*11);
        var b =Math.floor(Math.random()*11);
		
        var nombre = prompt('We STOP the spams, sorry for the inconvenience please solve the following problem:\n '+a+' + '+b+' = ?');
		
		if (nombre != a+b)
		{
			alert('Wrong result');
			return;
		}

	document.getElementById('esperarComment').style.display = '';
	document.getElementById('tbCuadroComentar').style.display = 'none';
	attach_file(url);
  }
function validarFormNews()
{
//formindex newsIndName newsIndMail 
	var pan;
	var url = base_cosmic+'ajax/newsletters.php';
	
	pan  = document.getElementById("newsIndName").value;	
	pan = pan.replace(/ /g,'');
	if(0==pan.length)
	{
		alert('Name');
		return false;
	}
	url +='?name='+pan;
	
	pan = document.getElementById("newsIndMail").value;
	if (!mailValido(pan))
	{
		alert('E MAIL');
		return false;
	}
	url +='&mail='+pan;       
        var a =Math.floor(Math.random()*11);
        var b =Math.floor(Math.random()*11);
        var nombre = prompt('We STOP the spams, sorry for the inconvenience please solve the following problem:\n '+a+' + '+b+' = ?');
		
        if (nombre != a+b)
        {
                alert('Wrong');
                return;
        }
        
	document.getElementById('newsContent').style.display = 'none';
	document.getElementById('newsIco').style.display = '';
	attach_file(url);		
}
function verformnews()
{
	document.getElementById('newsContent').style.display = '';
	document.getElementById('newsIco').style.display = 'none';	
	document.getElementById('newsMsj').style.display = 'none';	
	document.getElementById('newsMsj').innerHTML = '';		
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

