function load() {
	if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));

		map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(37.392400,-5.998867), 17);
						
		//marca puntual
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		var point = new GLatLng(southWest.lat() + latSpan/2  + 0.0005, southWest.lng() + lngSpan/2 );

		map.addOverlay(new GMarker(point));
		

    }
}

/* aqui funcion favoritos, a la espera de ubicacion final*/
/*
function bookmarksite(title, url)
	{
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}
*/
function bookmarksite(title, url){
  if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else
		alert("Press Crtl+D in order to add this site to your Bookmarks"); 
} 


function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Incorrect email format")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		alert("Incorrect email format")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Incorrect email format")
			return false
			}
		}
		return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Incorrect email format")
		return false;
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>4) {
		 alert("Incorrect email format")
	   return false
	}

	if (len<2) {
	   var errStr="Incorrect email format"
	   alert(errStr)
	   return false
	}
}

function valida_recomendar_web(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Intruduce your name");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<5){
		alert("Introduce your email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	if(document.getElementById("nombre_amigo").value.length<3){
		alert("Introduce your friends name");
		document.getElementById("nombre_amigo").focus();
		return false;
	}

	if(document.getElementById("email_amigo").value.length<5){
		alert("Introduce your friends email");
		document.getElementById("email_amigo").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email_amigo").value);
		if(resu ==false){
			 document.getElementById("email_amigo").focus();
			 return resu;
		}
	
	}

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduzca su mensaje")){
		alert("Introduce your message");
		document.getElementById("mensaje").focus();
		return false;
	}

	

	if(document.getElementById("pass").value.length<5){
		alert("Introduce the numbers shown in the image");
		document.getElementById("pass").focus();
		return false;
	}
}

function validar(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Introduce your name");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<1){
		alert("Introduce your email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	
	if(document.getElementById("asunto").value.length<3){
		alert("Introduce the subject");
		document.getElementById("asunto").focus();
		return false;
	}
	

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduce your message")){
		alert("Introduce your message");
		document.getElementById("mensaje").focus();
		return false;
	}
	
	if(document.getElementById("pass").value.length<5){
		alert("Introduce the numbers shown in the image");
		document.getElementById("pass").focus();
		return false;
	}
	
	return true;
}

function validar_myaccount(){
	if(document.getElementById("ellogin").value.length<3){
		alert("Introduce your user name");
		document.getElementById("ellogin").focus();
		return false;
	}

	if(document.getElementById("passw").value.length<3){
		alert("Introduce your password");
		document.getElementById("passw").focus();
		return false;
	}

	return true;
}

function validar_lostpassword(){
	if(document.getElementById("ellogin").value.length<3){
		alert("Introduce your user name");
		document.getElementById("ellogin").focus();
		return false;
	}

	return true;
}

function validar_modifydata(formulario){
	
	if(document.getElementById("foto").value.length>1){
		var n=document.getElementById("foto").value.lastIndexOf(".");
		var ext=document.getElementById("foto").value.substr(n+1);
		var ext=ext.toLowerCase();
		if((ext!='jpg')&&(ext!='jpeg')){
			alert("Extension photo error: its must be JPG or JPEG");
			return false;
		}
	}
	/*
	if(document.getElementById("nombre").value.length<3){
		alert("Introduce your name");
		document.getElementById("nombre").focus();
		return false;
	}

	if(document.getElementById("apellidos").value.length<3){
		alert("Introduce your last name");
		document.getElementById("apellidos").focus();
		return false;
	}



	if(document.getElementById("email").value.length<5){
		alert("Introduce your email");
		document.getElementById("email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email").value);
		if(resu ==false){
			 document.getElementById("email").focus();
			 return resu;
		}
	
	}
	*/
	
 if ((formulario.telefono.value.length < 9)&&(formulario.telefono.value.length > 1)) {

		alert("Introduce Telephone");
		formulario.telefono.focus();
		return (false);
  }
// if (formulario.movil.value.length < 9){
 if ((formulario.movil.value.length < 9)&&(formulario.movil.value.length > 1)) {

		alert("Introduce Mobile Number");
		formulario.movil.focus();
		return (false);
  }


	if(document.getElementById("password").value.length>0){
		if(document.getElementById("password2").value.length<3){
			alert("Confirm your password");
			document.getElementById("password").focus();
			return false;
		}else{
			if(document.getElementById("password").value!=document.getElementById("password2").value){
				alert("Passwords do not match");
				return false;
			}
	
		
		}

	}


	return true;
}


function validar_formpayments(){
	if(document.getElementById("amount").value.length<1){
		alert("Introduce the amount to have pay");
		document.getElementById("amount").focus();
		return false;
	}else if(!numerico(document.getElementById("amount"))){
		alert("The amount must be a numeric value");
		document.getElementById("amount").focus();
		return false;
	
	}

	if(!numerico(document.getElementById("amount2"))){
		alert("The amount must be a numeric value");
		document.getElementById("amount2").focus();
		return false;
	
	}


	return true;
}

function numerico(variable){
	var vari=variable.value;
	vari=vari.replace(/\,/g, "");
	if(isNaN(vari)){
		return false;
	}else{
		if(vari.indexOf(".",0)!=-1){
			return false;
		}
	}
	return true;
}


function detalles_payments(solicitud)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_detalles_" + solicitud;
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/detalles_payments.php" ;
	url=url+"?id=" + solicitud;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}


function Comma(SS) { 
  var T='', S=String(SS),  C, j, S1, L
	  S1=S.replace(/\,/g, "")
	  S1=S1.replace(/\./g, "")
	  L=S1.length-1
  for (j=0; j<=L; j++) {
    T+=C=S1.charAt(j)
    if ((j < L) && ((L-j)%3 == 0) && (C != '-')) T+=',' }
  return T }



 function validar_myprogram(){
	if(document.getElementById("pass").value.length<2){
		alert("Introduce your password");
		document.getElementById("pass").focus();
		return false;
	}

	
	return true;
}



function show_field(valor,ok1,ok2,ok3,ok4,field){
	if((valor==ok1)||(valor==ok2)||(valor==ok3)||(valor==ok4)) {
		document.getElementById(field).style.display="block"; 
	}else {
		document.getElementById(field).style.display="none";
	}
}

function hide_field(valor,ok1,ok2,field){
	if((valor==ok1)||(valor==ok2)) {
		document.getElementById(field).style.display="none"; 
	}else  {
		document.getElementById(field).style.display="block";
	}
}



function validar_form_course(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Introduce your name");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<1){
		alert("Introduce your email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	
	if(document.getElementById("for_c_duration").value=='no'){
		alert("Select duration of the program");
		document.getElementById("for_c_duration").focus();
		return false;
	}

	if(document.getElementById("for_c_number_par").value=='no'){
		alert("Select number of participants");
		document.getElementById("for_c_number_par").focus();
		return false;
	}

	if(document.getElementById("for_c_housing_option").value=='no'){
		alert("Select desired housing");
		document.getElementById("for_c_housing_option").focus();
		return false;
	}else if(document.getElementById("for_c_housing_option").value=='4'){
		if(document.getElementById("for_c_specify").value.length<3){
			alert("Specify desired housing");
			document.getElementById("for_c_specify").focus();
			return false;
		}
	}
	
	if(document.getElementById("for_c_housing_option").value!=5){
		if(document.getElementById("for_c_room").value=='no'){
			alert("Select desired room");
			document.getElementById("for_c_room").focus();
			return false;
		}else if(document.getElementById("for_c_room").value=='3'){
				if(document.getElementById("for_c_specify2").value.length<3){
					alert("Specify desired room");
					document.getElementById("for_c_specify2").focus();
					return false;
				}
		}
		
		if((document.getElementById("for_c_housing_option").value==3)||(document.getElementById("for_c_housing_option").value==4)){
			if(document.getElementById("for_c_board").value=='no'){
				alert("Select desired board");
				document.getElementById("for_c_board").focus();
				return false;
			}else if(document.getElementById("for_c_board").value=='4'){
				if(document.getElementById("for_c_specify3").value.length<3){
					alert("Specify desired board");
					document.getElementById("for_c_specify3").focus();
					return false;
				}
			}
		
		
		}

	}


	if(document.getElementById("for_c_how_did_you").value=='no'){
		alert("Select how did you find out about YES");
		document.getElementById("for_c_how_did_you").focus();
		return false;
	}else if(document.getElementById("for_c_how_did_you").value=='5'){
		if(document.getElementById("for_c_specify4").value.length<3){
			alert("Specify how did you find about YES");
			document.getElementById("for_c_specify4").focus();
			return false;
		}
	}




	if(document.getElementById("pass").value.length<5){
		alert("Introduce the numbers shown in the image");
		document.getElementById("pass").focus();
		return false;
	}
	
	return true;
}


function validar_form_intership(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Introduce your name");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<1){
		alert("Introduce your email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	
	if(document.getElementById("for_i_duration").value=='no'){
		alert("Select duration of the program");
		document.getElementById("for_i_duration").focus();
		return false;
	}

	if(document.getElementById("for_i_number_par").value=='no'){
		alert("Select number of participants");
		document.getElementById("for_i_number_par").focus();
		return false;
	}

	if(document.getElementById("for_i_housing_option").value=='no'){
		alert("Select desired housing");
		document.getElementById("for_i_housing_option").focus();
		return false;
	}else if(document.getElementById("for_i_housing_option").value=='4'){
		if(document.getElementById("for_i_specify").value.length<3){
			alert("Specify desired housing");
			document.getElementById("for_i_specify").focus();
			return false;
		}
	}
	
	if(document.getElementById("for_i_housing_option").value!=5){
		if(document.getElementById("for_i_room").value=='no'){
			alert("Select desired room");
			document.getElementById("for_i_room").focus();
			return false;
		}else if(document.getElementById("for_i_room").value=='3'){
				if(document.getElementById("for_i_specify2").value.length<3){
					alert("Specify desired room");
					document.getElementById("for_i_specify2").focus();
					return false;
				}
		}
		
		if((document.getElementById("for_i_housing_option").value==3)||(document.getElementById("for_i_housing_option").value==4)){
			if(document.getElementById("for_i_board").value=='no'){
				alert("Select desired board");
				document.getElementById("for_i_board").focus();
				return false;
			}else if(document.getElementById("for_i_board").value=='4'){
				if(document.getElementById("for_i_specify3").value.length<3){
					alert("Specify desired board");
					document.getElementById("for_i_specify3").focus();
					return false;
				}
			}
		
		
		}

	}


	if(document.getElementById("for_i_how_did_you").value=='no'){
		alert("Select how did you find out about YES");
		document.getElementById("for_i_how_did_you").focus();
		return false;
	}else if(document.getElementById("for_i_how_did_you").value=='5'){
		if(document.getElementById("for_i_specify4").value.length<3){
			alert("Specify how did you find about YES");
			document.getElementById("for_i_specify4").focus();
			return false;
		}
	}

	if(document.getElementById("num_sectores").value<1){
		alert("Select which sectors are you insterested in");
		return false;
	}
	
		

	if(document.getElementById("pass").value.length<5){
		alert("Introduce the numbers shown in the image");
		document.getElementById("pass").focus();
		return false;
	}
	
	return true;
}

function validar_form_course_intership(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Introduce your name");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<1){
		alert("Introduce your email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	


	if(document.getElementById("for_ci_duration").value=='no'){
		alert("Select duration of the program");
		document.getElementById("for_ci_duration").focus();
		return false;
	}

	if(document.getElementById("for_ci_number_par").value=='no'){
		alert("Select number of participants");
		document.getElementById("for_ci_number_par").focus();
		return false;
	}

	if(document.getElementById("for_ci_housing_option").value=='no'){
		alert("Select desired housing");
		document.getElementById("for_ci_housing_option").focus();
		return false;
	}else if(document.getElementById("for_ci_housing_option").value=='4'){
		if(document.getElementById("for_ci_specify").value.length<3){
			alert("Specify desired housing");
			document.getElementById("for_ci_specify").focus();
			return false;
		}
	}
	
	if(document.getElementById("for_ci_housing_option").value!=5){
		if(document.getElementById("for_ci_room").value=='no'){
			alert("Select desired room");
			document.getElementById("for_ci_room").focus();
			return false;
		}else if(document.getElementById("for_ci_room").value=='3'){
				if(document.getElementById("for_ci_specify2").value.length<3){
					alert("Specify desired room");
					document.getElementById("for_ci_specify2").focus();
					return false;
				}
		}
		
		if((document.getElementById("for_ci_housing_option").value==3)||(document.getElementById("for_ci_housing_option").value==4)){
			if(document.getElementById("for_ci_board").value=='no'){
				alert("Select desired board");
				document.getElementById("for_ci_board").focus();
				return false;
			}else if(document.getElementById("for_ci_board").value=='4'){
				if(document.getElementById("for_ci_specify3").value.length<3){
					alert("Specify desired board");
					document.getElementById("for_ci_specify3").focus();
					return false;
				}
			}
		
		
		}

	}


	if(document.getElementById("for_ci_how_did_you").value=='no'){
		alert("Select how did you find out about YES");
		document.getElementById("for_ci_how_did_you").focus();
		return false;
	}else if(document.getElementById("for_ci_how_did_you").value=='5'){
		if(document.getElementById("for_ci_specify4").value.length<3){
			alert("Specify how did you find about YES");
			document.getElementById("for_ci_specify4").focus();
			return false;
		}
	}

	if(document.getElementById("num_sectores").value<1){
		alert("Select which sectors are you insterested in");
		return false;
	}
		
	if(document.getElementById("pass").value.length<5){
		alert("Introduce the numbers shown in the image");
		document.getElementById("pass").focus();
		return false;
	}
	
	return true;
}


function load_forms(formu)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="capa_cursos";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/load_forms.php" ;
	url=url+"?id=" + formu;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}




function validar_register_course(formulario) {

	if(document.getElementById("foto").value.length>1){
		var n=document.getElementById("foto").value.lastIndexOf(".");
		var ext=document.getElementById("foto").value.substr(n+1);
		var ext=ext.toLowerCase();
		if((ext!='jpg')&&(ext!='jpeg')){
			alert("Extension photo error: its must be JPG or JPEG");
			return false;
		}
	}


	if(document.getElementById("dni_alumno").value.length<8){
		alert("Introduce your Identification Number");
		document.getElementById("dni_alumno").focus();
		return false;
	}


	var exp_fechas= /^[0-9]{2}-{1}[0-9]{2}-{1}[0-9]{4}$/; //exp. para fecha  mm-dd-aaaa
	var ho=new Date();//hoy
	var hoy=new Date(ho.getFullYear(),ho.getMonth(),ho.getDate());
	var h=hoy.getTime();//hoy 

  if (formulario.apellidos.value.length < 1) {
    alert("Introduce Last Name");
    formulario.apellidos.focus();
    return (false);
  }

  if (formulario.nombre.value.length < 2) {
    alert("Introduce Name");
    formulario.nombre.focus();
    return (false);
  }
  

if (document.getElementById("fecha_nac").value!='mm-dd-aaaa'){//NO Obligatorio

	if ((document.getElementById("fecha_nac").value.length < 10)||(document.getElementById("fecha_nac").value=='mm-dd-aaaa')) {
		alert("Introduce Birth Date");
		document.getElementById("fecha_nac").focus();
		return (false);
	}else{
		if (!exp_fechas.test(document.getElementById("fecha_nac").value)) {
			alert("Introduce Birth Date - Incorrect format (mm-dd-aaaa)");
			document.getElementById("fecha_nac").focus();
			return (false);
		}else{
			var fec="fecha_nac";
			var fe=document.getElementById(fec).value.split( "-" );
			var mes=(fe[0]*1)-1;
			var fecha=new Date(fe[2],mes,fe[1]);
			var f=fecha.getTime();//fecha fin
			
			if(f>=h){//fecha posterior a hoy
				alert("The Birth Date is after today");
				document.getElementById(fec).select();
				return (false);
			}
		
		
		}
	}
}

	if(document.getElementById("nacionalidad").value.length<5){
		alert("Introduce nacionality");
		document.getElementById("nacionalidad").focus();
		return false;
	}
	
	/*
	if(document.getElementById("lugar_nac").value.length<5){
		alert("Introduce Birth Place");
		document.getElementById("lugar_nac").focus();
		return false;
	}
	*/
	/*
	if(document.getElementById("direccion").value.length<3){
		alert("Introduce Address");
		document.getElementById("direccion").focus();
		return false;
	}
	if(document.getElementById("cp").value.length<5){
		alert("Introduce Zip Code");
		document.getElementById("cp").focus();
		return false;
	}
	if(document.getElementById("localidad").value.length<5){
		alert("Introduce City");
		document.getElementById("localidad").focus();
		return false;
	}
	if(document.getElementById("provincia").value.length<3){
		alert("Introduce Province/State");
		document.getElementById("provincia").focus();
		return false;
	}
	*/

 //if (formulario.telefono.value.length < 9){
 if ((formulario.telefono.value.length < 9)&&(formulario.telefono.value.length > 1)) {

		alert("Introduce Telephone");
		formulario.telefono.focus();
		return (false);
  }
// if (formulario.movil.value.length < 9){
 if ((formulario.movil.value.length < 9)&&(formulario.movil.value.length > 1)) {

		alert("Introduce Mobile Number");
		formulario.movil.focus();
		return (false);
  }


	if(document.getElementById("email").value.length<5){
		alert("Introduce E-mail");
		document.getElementById("email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email").value);
		if(resu ==false){
			 document.getElementById("email").focus();
			 return resu;
		}
	}

	 if ((formulario.password.value.length < 6)) {

			alert("Introduce Password (6-15 caracters)");
			formulario.password.focus();
			return (false);
	  }

	 if ((formulario.password2.value.length < 6)) {

			alert("Repeat password (6-15 caracters)");
			formulario.password2.focus();
			return (false);
	  }



	 if(formulario.password.value!=formulario.password2.value){
		alert("The passwords entered do not match");
		return false;
	}

	if(document.getElementById("pass").value.length<5){
		alert("Introduce the numbers shown in the image");
		document.getElementById("pass").focus();
		return false;
	}


    return (true); 

}


function validar_agente(){
	if(document.getElementById("user").value.length<2){
		alert("Introduce your user");
		document.getElementById("user").focus();
		return false;
	}
	if(document.getElementById("pass").value.length<2){
		alert("Introduce your password");
		document.getElementById("pass").focus();
		return false;
	}

	
	return true;
}

