function input_value (el,val) {
	
	if ($(el).value == val) $(el).value = '';
	else if ($(el).value == '') $(el).value = val;
}
function getRadioButtonSelectedValue(ctrl)
{
	for(i=0;i<ctrl.length;i++)
        	if(ctrl[i].checked) return ctrl[i].value;
	return false;
}

function validateEmail(v) { return (/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)); }

//Muestra captcha
function showRecaptcha(element) {
	if ($(element))
	{
		Recaptcha.destroy();
		Recaptcha.theme = "clean";
		Recaptcha.create("6LdX3ccSAAAAAGYOAKAZVh1JuIVjjAvYRHj8VRZz",element,{ 
			theme: "clean"
		});
	}
}



function showRecaptcha_custom(element) {
		
		Recaptcha.create("6LdX3ccSAAAAAGYOAKAZVh1JuIVjjAvYRHj8VRZz", element, {
			theme: "custom"
	
		});
}



function captcha (form_id,el,el1,msg,course) {
	
	$.ajax({
		async:true,
		type: "POST",
		dataType: "html",
		contentType: "application/x-www-form-urlencoded",
		url:"/include/captcha/check_captcha.php",
		data:"recaptcha_response_field="+$("#"+el).attr("value")+"&recaptcha_challenge_field="+$("#"+el1).attr("value")+"",
		success: function(objeto, exito) {
			
			if (objeto == "OK") {
				
				$('#'+msg).css("background-color","#D4E4D4");
				if(course>0 && $('#ctRegister:checked').length==1){
					newRegistration(course); // regitro
				}
				else if(course>0 && $('#ctQuestion:checked').length==1) {
					newsletter(course); //consulta
				}
				else if(course==0){
					contact();
				}
				
			} else {
				$.colorbox({
					html:"<div class='txtCenter copyTxt'>El codigo introducido es incorrecto, intentalo de nuevo.</div>",
					open:true,
					innerWidth:400,
					innerHeight:70,
					top:"10px",
					fixed:true
				});
				Recaptcha.reload();
				$('#'+msg).css("background-color","#FCBBBB");				
				//return false;
			}
		},
		beforeSend : function(){
			$.colorbox({
				html:"<div class='txtCenter copyTxt'>Enviando...</div>",
				open:true,
				innerWidth:300,
				innerHeight:50,
				top:"10px",
				fixed:true
			});
			
		},
		complete : function(){
			$.colorbox.close();
			Recaptcha.reload();
			//resetForm(form_id);

		},
		timeout:10000
		
	}); 
	
}

function newRegistration(course){
	
	var firstname = $("#ctName").val();
	var lastname = $("#ctLastname").val();
	var email = $("#ctEmail").val() ;
	var telph = $("#ctTelph").val();
	var comments = $("#ctComments").val();
	var recieve = $("#ctNewsletter:checked").length;

	$.ajax({
			type: "get",
			url: "/include/processAjax/registration.php",
			data: "course="+course+"&name="+firstname+"&lastname="+lastname+"&email="+email+"&telph="+telph+"&comments="+comments+"&newsletter="+recieve,
			beforeSend: function(){
				//$("#export_imgLoading").show();
			},
			success: function(msg){
				var response = jQuery.parseJSON(msg);
				if(response.status=="OK"){
  					window.location.href = "/"+response.url;
					$.colorbox.close();	
				}
				else{
					var error ="";
					
					if(response.status == "ERROR3")
						error = "<div class='txtCenter copyTxt'>No se ha podido env&iacute;ar el email, int&eacute;ntelo de nuevo mas tarde</div>";

					if(response.status == "ERROR2")
						error = "<div class='txtCenter copyTxt'>Ya estas inscrito en este curso</div>";

						if(response.status == "ERROR4")
						error = "<div class='txtCenter copyTxt'>Los cupos para el curso est&aacute;n agotados.</div>";
					
					
					$.colorbox({
							html:error,
							open:true,
							innerWidth:400,
							innerHeight:70,
							top:"10px",
							fixed:true
						});
				}
					
				
			},
			complete: function(){
				//$("#export_imgLoading").hide();
			}
		});
	

}

function newsletter(course){
	
	var firstname = $("#ctName").val();
	var lastname = $("#ctLastname").val();
	var email = $("#ctEmail").val() ;
	var telph = $("#ctTelph").val();
	var comments = $("#ctComments").val();
	var recieve = $("#ctNewsletter:checked").length;
	
	$.ajax({
			type: "get",
			url: "/include/processAjax/newsletter.php",
			data: "name="+firstname+"&lastname="+lastname+"&email="+email+"&newsletter="+recieve+"&telph="+telph+"&comments="+comments+"&course="+course,

			beforeSend: function(){
				//$("#export_imgLoading").show();
			},
			success: function(msg){
				var response = jQuery.parseJSON(msg);
				if(response.status="OK"){
					window.location.href = "/"+response.url;
				}
				else{
					$.colorbox({
						html:"<div class='txtCenter copyTxt'>No se ha podido env&iacute;ar el email, int&eacute;ntelo de nuevo mas tarde</div>",
						open:true,
						innerWidth:400,
						innerHeight:100,
						top:"10px",
						fixed:true
					});
				
				}
			},
			complete: function(){
				//$("#export_imgLoading").hide();
			}
		});
}


function contact(){
	var firstname = $("#ctName").val();
	var lastname = $("#ctLastname").val();
	var email = $("#ctEmail").val() ;
	var recieve = $("#ctNewsletter:checked").length;
	var telph = $("#ctTelph").val();
	var company = $("#ctCompany").val();
	var comments = $("#ctComments").val();
	
	$.ajax({
			type: "get",
			url: "/include/processAjax/send.php",
			data: "name="+firstname+"&lastname="+lastname+"&email="+email+"&newsletter="+recieve+"&telph="+telph+"&comments="+comments+"&company="+company,
			beforeSend: function(){
				//$("#export_imgLoading").show();
			},
			success: function(msg){
				var response = jQuery.parseJSON(msg);
				
				if(response.status="OK")
					window.location.href = "/"+response.url;
				else{
					$.colorbox({
						html:"<div class='txtCenter copyTxt'>No se ha podido env&iacute;ar el email, int&eacute;ntelo de nuevo mas tarde</div>",
						open:true,
						innerWidth:400,
						innerHeight:100,
						top:"10px",
						fixed:true
					});
				
				}
				
			},
			complete: function(){
				//$("#export_imgLoading").hide();
			}
		}); 

}
function change_font_size (o)	{
	var _min = 10;
	var _max = 40;
	var op = o; //op es la la operacion, si es 0 resto (achico) si es 1 sumo (agrando)
	
	var els = new Array();

	
	els[0] = 'div.right_col *';
		
	
	
	for(i=0;i<els.length;i++) {
	
	$$(els[i]).each(function(s) {
				
		//valor actual del font-size ej: 13px
		var font =	s.getStyle('font-size');
		//le saco el 'px' ej:13
		var new_font = parseInt(font.substring(0,font.length-2));
		if (op == 0 && (new_font < _min)) //si quiero seguir achicando y el tama�o de la letra es menor al minimo, termino.
			return;
		if (op == 1 && (new_font > _max)) //si quiero seguir agrandando y el tama�o de la letra es mayor al max, termino.
			return;
		//sumo 2
		if (op == 0)
			new_font = new_font - 2;
		else
			new_font = new_font + 2;
		//agrego 'px'
		new_font = new_font +'px';
		//valor actual del line-height ej: 13px
		var line =	s.getStyle('line-height');
		//le saco el 'px' ej:13
		var new_line = parseInt(line.substring(0,line.length-2));
		//sumo 2
		if (op == 0)
			new_line = new_line - 2;
		else
			new_line = new_line + 2;
		//agrego 'px'
		new_line = new_line +'px';
		
		if (new_font == 'NaNpx')
			new_font = '13px';
		if (new_line == 'NaNpx')
			new_line = '21px';
		
		
		s.setStyle({
  			fontSize: new_font,
			lineHeight: new_line
			});
		
		
		
		});
	}
}



jQuery.fn.reset = function () {
	$(this).each (function() { this.reset(); });
}
	
function outs(val,field) {
	//alert("fuera");
	if($("#"+field).attr("value")==""){
		$("#"+field).attr("value",val);
	}
}

function tops(val,field) {
	
	if(($("#"+field).attr("value")==val)||($("#"+field).attr("value")==idioma[idioma_sitio]['required-field'])) {
		$("#"+field).attr("value","");
	}
}


function tops_id() {
	if($(this).attr("value")=="ID...") {
		$(this).attr("value","");
	}
}

function outs_id() {
	if($(this).attr("value")=="") {
		$(this).attr("value","ID...");
	}
}


