
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 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 = $("#frmAjax").parents("div:first");
	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);
		       MySimpleLightBox.centerContent();
		       MySimpleLightBox.updateHeight();
		       content.removeAjaxLoader();
		   }
	 });
}


function changeProductImage(id_container,id_picture,pic,description_content,description){
	if($('#'+id_container+' img:first').attr("src")==pic)return;
	$('#'+id_container).prepend('<img style="position:absolute;top:0px;left:0px;z-index:997" 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 login(username,password,lng){
	$("#frmLogin").addAjaxLoader(true);
	$.ajax({
		   async: false,
		   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 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").parents("form:first").parents("div:first");
		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();
				MySimpleLightBox.centerContent();
				MySimpleLightBox.updateHeight();
		   }
	 });
	
}

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").parents("form:first").parents("div:first");
	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();
				MySimpleLightBox.centerContent();
				MySimpleLightBox.updateHeight();
		   }
	 });
}
	
function open_window( name, page, params ) {
	window.open( page, 'window_' + name, params );
}