function closePromoBanner(){
    $("#promo_banner").remove();
    markPromoBannerAsVisited();
}

function markPromoBannerAsVisited(){
    $.ajax({
       async: true,
       type: "GET",
       url:  "_ajax.php",
       data:  "opc=markPromoBannerAsVisited",
       success: function(data){
            
       }
    });
}

function isCaptchaCodeCorrect(code){
		var bool =true;
		$.ajax({
			   async: false,
			   type: "GET",
		   url:  "_ajax.php",
		   data:  "opc=getCaptcha&captcha="+code,
		   success: function(data){
				if(data==0){
					 bool=false;
				}
		   }
		});
	 return bool;
}

function updateCaptcha(layer){
	
	$.ajax({
	   async: false,
	   type: "GET",
	   url:  "_ajax.php",
	   data:  "opc=updateCaptcha",
	   success: function(data){
			$(layer).replaceWith(data);
	   }
	});
}

function changeStoreProvinces(code){
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=changeStoreProvinces&code="+code, 
		   success: function(data){
		       $('#cmbProvinces').html(data);
		   }
	 });	
}

function is_numeric(value){
	if(typeof(value)=='number'){
		return true;
	}else{
		return false;
	}
}
function changeStoreCities(code,province){
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=changeStoreCities&code="+code+"&province="+province, 
		   success: function(data){
		       $('#cmbCities').html(data);
		   }
	 });	
}

function showStores(code,province,city){
	
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=showStores&code="+code+"&province="+province+"&city="+city, 
		   success: function(data){
		       $('#showStores').html(data);
		   }
	 });
}

function mostrarLogin(){
	
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=mostrarLogin", 
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });	
}


function showRecoverPasswordForm(){

	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=showRecoverPasswordForm",
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });
}

function openSendWindow(idProducto){
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: 'opc=enviarProducto&idProducto='+idProducto,
			   success: function(data){
			    	MySimpleLightBox.loadHTML(data);
			   }
		 });
}
	
function sendEmail(fromName,toEmail,idProducto){
	var content = $(".lightbox");
	content.addAjaxLoader(true);
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=sendEmail&fromName="+fromName+"&toEmail="+toEmail+"&idProducto="+idProducto,
		   success: function(data){
		       content.html(data);
		       content.removeAjaxLoader();
		   }
	 });
}


function changeProductImage(id_container,el,pic,description_content,description){
   
    el.parents("ul").find("li").removeClass("active");
    el.parents("li:first").addClass("active");
    
	if($('#'+id_container+' img:first').attr("src")==pic)return;
	$('#'+id_container).prepend('<img style="position:absolute;top:0px;left:0px;z-index:2" src="'+pic+'"/>');
	
	$('#'+description_content).each(function(){
				$(this).css('visibility','hidden');
	});
	
	$('#'+id_container+' img:first').fadeTo(1,0.0);
	$('#'+id_container+' img:odd').fadeTo(1000,0.0,function(){
		$('#'+id_container+' img:odd').remove();
	});
	$('#'+id_container+' img:first').fadeTo(1000,1,function(){
		$('#'+description_content).each(function(){
				$(this).html(description);
				$('#'+description_content).each(function(){
					$(this).css('visibility','visible');
				});
		});
	});
}

function mostrarFormularioRegistro(perfil){
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=mostrarFormularioRegistro&perfil="+perfil,
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });
}
	
function mostrarRegistro(){

	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=mostrarRegistro",
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });
}

function mostrarSuscripcionNewsletter(){

	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=mostrarSuscripcionNewsletter",
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });
}

function login(username,password,lng){
	$("#frmLogin").addAjaxLoader(true);
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=login&username="+username+"&password="+password,
		   success: function(data){
		  		
		    	if(data == "1"){
		    		window.location.reload();
				}
		    	else{
					if(lng=='es'){
						alert("Nombre de usuario o contrasea incorrectos.")
					}
					else if(lng=='en'){
						alert("Wrong username or password.");
					}
					$("#frmLogin").removeAjaxLoader();
				}
		    		
		   }
	 });
}

function recoverPassword(){
    if(checkFormFields('recover_password_form',1,1,'#000','transparent')){
        $('#recover_password_form').addAjaxLoader();
        $.ajax({
           async: true,
           type: "POST",
           url: "_ajax.php",
           data: "opc=recoverPassword&email="+$("#recover_email").val(),
           success: function(data){
                $('#recover_password_form').removeAjaxLoader();
                MySimpleLightBox.close(true);
                if(parseInt(data) == 1){
                    showAlertMessage(txt_solicitud_recuperar_enviada, "info");
                }
                else{
                    showAlertMessage(txt_no_enviado, "error");
                }
           }
        });
    }
}

function registrarCliente(nombre,mail,numint,lng){
	
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarCliente&nombre="+nombre+"&mail="+mail+"&numint="+numint,
		   success: function(data){
	   			var content = $("#registroCliente");
				if(data=="1"){
					content.html($('#registroClienteRtaOk').html());
				}
				else if(data=="0"){
					content.html($('#registroClienteRtaError').html());
				}
				else if(data == "2"){
					if(lng=='es'){
						alert("Nombre de usuario o contrasea incorrectos.");
					}
					else if(lng=='en'){
						alert("Wrong username or password.");
					}
				}
				content.removeAjaxLoader();
				MySimpleLightBox.centerContent();
				MySimpleLightBox.updateHeight();
		   }
	 });
}

function registrarCapacitador(nombre,mail,password,lng){
	var content = $("#registroCapacitador").parents("form:first").parents("div:first");
	content.addAjaxLoader(true);
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarCapacitador&nombre="+nombre+"&mail="+mail+"&password="+password,
		   success: function(data){
				
		      	if(data=="1"){
					content.html($('#registroCapacitadorRtaOk').html());
				}
		      	if(data == "3"){
		      		if(lng == "es"){
						alert("Te registraste con éxito pero el sistema no pudo enviarte un mail con tus datos, por favor, contactate en contacto con un administrador.");
					}
		      		else if(lng == "en"){
						alert("You have been registred successfuly but the system could not send you the email with your personal information, please contact an administrator to get your password.");
					}
		      		content.html($('#registroCapacitadorRtaOk').html());
		      	}
				else if(data=="0"){
					content.html($('#registroCapacitadorRtaError').html());
				}
				else if(data == "2"){
					if(lng == "es"){
						alert("El email ingresado se encuentra registrado.");
					}
					else if(lng == "en"){
						alert("The entred e-mail is already registered!");
					}
				}
		      	content.removeAjaxLoader();
				MySimpleLightBox.centerContent();
				MySimpleLightBox.updateHeight();
		   }
	 });
}

function registrarTecnico(nombre,mail,numint,lng){
	var content = $("#registroTecnico").parents("form:first").parents("div:first");
	content.addAjaxLoader(true);
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarTecnico&nombre="+nombre+"&mail="+mail+"&numint="+numint,
		   success: function(data){
		   		
				if(data=="1"){
					content.html($("#registroTecnicoRtaOk").html());
				}
				else if(data=="0"){
					content.html($("#registroTecnicoRtaError").html());
				}
				else if(data == "2"){
					if(lng == "es"){
						alert("El email ingresado se encuentra registrado.");
					}
					else if(lng == "en"){
						alert("The entred e-mail is already registered!");
					}
				}
				content.removeAjaxLoader();
				MySimpleLightBox.centerContent();
				MySimpleLightBox.updateHeight();
		   }
	 });
}

function registrarDisenador(nombre,mail,numint,lng){
		var content = $("#registroDisenador");
		content.addAjaxLoader(true);
		$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarDisenador&nombre="+nombre+"&mail="+mail+"&numint="+numint,
		   success: function(data){
				
				
				if(data=="1"){
					content.html($('#registroDisenadorRtaOk').html());
				}
				else if(data=="0"){
					//Error
					content.html($('#registroDisenadorRtaError').html());
				}
				else if(data == "3"){
					if(lng == "es"){
						alert("Te registraste con éxito pero el sistema no pudo enviarte un mail con tus datos, por favor, contactate en contacto con un administrador.");
					}
					else if(lng == "en"){
						alert("You have been registred successfuly but the system could not send you the email with your personal information, please contact an administrator to get your password.");
					}
					content.html($(".registroArquitectoRtaOk").html());
				}
				else if(data == "2"){
					if(lng == "es"){
						alert("El email ingresado se encuentra registrado.");
					}
					else if(lng == "en"){
						alert("The entred e-mail is already registered!");
					}
					
				}
				content.removeAjaxLoader();
		   }
	 });
	
}

function registrarGasista(nombre,mail,numint,lng){
		var content = $("#registroGasista");
		content.addAjaxLoader(true);
		$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarGasista&nombre="+nombre+"&mail="+mail+"&numint="+numint,
		   success: function(data){


				if(data=="1"){
					content.html($('#registroGasistaRtaOk').html());
				}
				else if(data=="0"){
					//Error
					content.html($('#registroGasistaRtaError').html());
				}
				else if(data == "3"){
					if(lng == "es"){
						alert("Te registraste con éxito pero el sistema no pudo enviarte un mail con tus datos, por favor, contactate en contacto con un administrador.");
					}
					else if(lng == "en"){
						alert("You have been registred successfuly but the system could not send you the email with your personal information, please contact an administrator to get your password.");
					}
					content.html($(".registroArquitectoRtaOk").html());
				}
				else if(data == "2"){
					if(lng == "es"){
						alert("El email ingresado se encuentra registrado.");
					}
					else if(lng == "en"){
						alert("The entred e-mail is already registered!");
					}

				}
				content.removeAjaxLoader();
		   }
	 });

}

function registrarNewsletter(nombre,mail,dom,loc,prov,tel,lng){
		var content = $("#registroNewsletter").parents("form:first").parents("div:first");
		content.addAjaxLoader(true);
		$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarNewsletter&nom="+nombre+"&mail="+mail+"&dom="+dom+"&loc="+loc+"&prov="+prov+"&tel="+tel,
		   success: function(data){
				
				if(data=="1"){
					content.html($("#registroNewsletterRtaOk").html());
				}
				if(data=="0"){
					content.html($("#registroNewsletterRtaError").html());
				}
				if(data == "2"){
					if(lng == "es"){
						alert("El email ingresado se encuentra registrado.");
					}
					else if(lng == "en"){
						alert("The entred e-mail is already registered!");
					}
				}
				content.removeAjaxLoader();
				MySimpleLightBox.centerContent();
				MySimpleLightBox.updateHeight();
		   }
	 });
	
	
}

function registrarArquitecto(nom,razon,dom,loc,prov,tel,mail,lng){
	var content = $("#registroArquitecto");
	content.addAjaxLoader();
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=registrarArquitecto&nom="+nom+"&razon="+razon+"&dom="+dom+"&loc="+loc+"&prov="+prov+"&tel="+tel+"&mail="+mail,
		   success: function(data){
		        
				
		        if(data=="1"){
		        	content.html($("#registroArquitectoRtaOk").html());
				}
				if(data == "3"){
					if(lng == "es"){
						alert("Te registraste con éxito pero el sistema no pudo enviarte un mail con tus datos, por favor, contactate en contacto con un administrador.");
					}else if(lng == "en"){
						alert("You have been registred successfuly but the system could not send you the email with your personal information, please contact an administrator to get your password.");
					}
		        	content.html($("#registroArquitectoRtaOk").html());
				}
				if(data=="0"){
					//Error
		        	content.html($("#registroArquitectoRtaError").html());
				}
				if(data == "2"){
					if(lng == "es"){
						alert("El email ingresado se encuentra registrado.");
					}else if(lng == "en"){
						alert("The entred e-mail is already registered!");
					}
				}
				content.removeAjaxLoader();
		   }
	 });
}

function suscribirNewsletter(nom,dom,loc,prov,tel,mail,lng){
	var content = $("#suscripcionNewsletter");
	content.addAjaxLoader();
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=suscribirNewsletter&nombre="+nom+"&domicilio="+dom+"&localidad="+loc+"&provincia="+prov+"&telefono="+tel+"&email="+mail,
		   success: function(data){    
		        if(data=="1"){
		        	content.html($("#registroNewsOk").html());
				}
				if(data=="0"){
					//Error
		        	content.html($("#registroNewsError").html());
				}
				if(data=="mailExist"){
					content.html($("#mailRegistrado").html());
				}
				content.removeAjaxLoader();
		   }
	 });
}


function sendFormService(form_id,callback){
	callback = callback==undefined?false:callback;
	$("#"+form_id).addAjaxLoader();
	var vars = 'opc=sendFormService&'+$("#"+form_id).serializeForm()+'&'+$("#"+form_id).serializeFormDescriptions();
	$.ajax({
	   async: true,
	   type: "POST",
	   url: "_ajax.php",
	   data: vars,
	   success: function(data){
			$.ajax({
			   async: true,
			   type: "POST",
			   url: "_ajax.php",
			   data: "opc=translate&word="+(parseInt(data)==1?"message_sent":"message_not_sent"),
			   success: function(translate){
					MySimpleLightBox.close();
					showAlertMessage(translate,(data==1?"info":"error"));
					$("#"+form_id).removeAjaxLoader();
					if(callback){
						callback.apply(this,[]);
					}
			   }
			 });
			
	   }
	 });
}

function open_window( name, page, params ) {
	window.open( page, 'window_' + name, params );
}

function  closeBanner(){
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=cerrarBanner",
		   success: function(){
			document.getElementById('banner_concurso').style.display = 'none';
		   }
	 });
}

function sendConcursoForm() {
	if(checkFormFields('frmConcurso',1,1,'#000','transparent') &&(document.getElementById('acepta-bases').checked)){
		document.getElementById('frmConcurso').submit();
	} else if (checkFormFields('frmConcurso',1,1,'#000','transparent')){
		mostrarAdvertenciaConcurso();
	}
}

function mostrarAdvertenciaConcurso() {
	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=mostrarAdvertenciaConcurso",
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });
}

function showDescription(id){
	$(".description").css("display","none");

	$("#"+id).css("display","block");
	$("#btn_seguir").css("display","block");

}

function mostrarFormularioService(){
	MySimpleLightBox.loadFile('includes/formularios/_service.php');
}


function changeInputValue(id){
	var actualValue=$('#'+id).val();
	if(actualValue=='no'){
		$('#'+id).val('si');
	}else{
		$('#'+id).val('no');
	}
}

function changeRadioValue(radioValue){
	$('#tiene_garantia').val(radioValue);
}

function gotoNextStep(step){
	$('#container').addAjaxLoader(true);
	$('#container').load(step, function() {
	$('#container').removeAjaxLoader();
});
}


function mostrarRegistroProf(){

	$.ajax({
		   async: true,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=mostrarRegistroProf",
		   success: function(data){
		       MySimpleLightBox.loadHTML(data);
		   }
	 });
}

