// JavaScript Document


function cargarpag3(pag,div){
	jQuery.ajax({
		async:true,
		url: pag,
		type: "GET",
		cache: false,
        dataType: "html",
		beforeSend: function(objeto){
          // document.getElementById("contenido").innerHTML="<div style='text-align:center'><img src='img/carga.gif' /></div>";
			jQuery("#"+div).html("<div style='width:100%; text-align:center; padding:120px 0px 120px 0px'><img src='../imagenes/publicas/carga.gif' /></div>");
        },
        success: function(rpta){		
			jQuery("#"+div).html(rpta);
        }
	});
}
function cargarpag2(pag,div){
	jQuery.ajax({
		async:true,
		url: pag,
		type: "GET",
		cache: false,
        dataType: "html",
		beforeSend: function(objeto){
          // document.getElementById("contenido").innerHTML="<div style='text-align:center'><img src='img/carga.gif' /></div>";
			jQuery("#"+div).html("<span style='font-size:16px;'><p>Cargando...</p></span>");
        },
        success: function(rpta){		
			jQuery("#"+div).html(rpta);
        }
	});
}
function cargarpag(pag,div){
	jQuery.ajax({
		async:true,
		url: pag,
		type: "GET",
		cache: false,
        dataType: "html",
        success: function(rpta){		
			jQuery("#"+div).html(rpta);
        }
	});
}
function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;

}


function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}


function flashes(){

  
    var obj_swf = new FlashObject("banner_home2.swf", "HOME", "564", "119", "8");
	obj_swf.addParam("quality", "high");
	obj_swf.addParam("menu", "false");
	obj_swf.addParam("scale", "noborder");
	obj_swf.addParam("wmode", "transparent");
	obj_swf.write("flash");


  //var params = {menu: "false",wmode :"transparent"};
  //swfobject.embedSWF("banner_home.swf", "flash", "564","119", "9.0.0","","",params);
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function iniciar()
{
	flashes();
	MM_preloadImages('../img/cartelera1.gif','../img/clientes2.gif','../img/home2.gif','../img/recomiendenos2.gif','../img/contacto2.gif','../img/operaciones2.gif','../img/servicios2.gif','../img/cartelera2.gif','../img/market2.gif','../img/mundo2.gif','../img/consu2.gif','../img/sercorp2.gif','../img/comer2.gif','../img/serfin2.gif','../img/geren1.gif','../img/empresa2.gif','../img/geren2.gif','../img/op_edicom2.jpg','../img/op_proyex2.jpg','../img/op_inver2.jpg','../img/op_ofi2.jpg','../img/op_indus2.jpg','../img/op_retail2.jpg','../img/op_consul2.jpg','../img/op_resid2.jpg')
}


function ir_oficina()
{
	var localizacion = jQuery("#oficina").attr("value");
	if(localizacion)
	{
	location.href = "http://www.colliers.com/"+localizacion;
	}
}


function login()
{
	var txt_email = jQuery("#txt_email").attr("value");
	var txt_pass = jQuery("#txt_pass").attr("value");
	var check_datos = jQuery('#check_datos').attr('checked');
	if(check_datos == true){
		var estado = "si";	
	}else{
		var estado = "no";	
	}
	//alert(estado);
	
	if( txt_email !="" && txt_pass !="")
	{
		
		jQuery.ajax({
						type: "POST",
						url: "proc_tbl_usuario.php",
						data: "op=login&txt_email="+txt_email+"&txt_pass="+txt_pass+"&estado="+estado,
						//data: "op=login&txt_email="+txt_email+"&txt_pass="+txt_pass,
						success: function(datos){
						 
							if(datos == "Logeado")
							{
									jAlert('Te logueaste correctamente', 'Mensaje');
									location.href='../pages/index.php';
									//window.location('../pages/index2.php');
									window.location.href='../pages/cuentausuario.php'
									//setTimeout( 'recargar_pagina()' , 1500);
									
							}
							if(datos == "Error")
							{
									jAlert('Te olvidaste tu contrase&ntilde;a', 'Mensaje');
							}
							if(datos == "cerrar")
							{
									//jAlert('Te logueaste correctamente', 'Mensaje');
								//setTimeout( 'recargar_pagina()' , 1500);
									window.location.href='../pages/cuentausuario.php'
							}
							
						
						
					  }
				});
		
	}
	else
	{
		jAlert('No has escrito tu email y password', 'Mensaje');	
	}

}//end login

function cerrar()
{
		
		jQuery.ajax({
				type: "POST",
				url: "proc_tbl_usuario.php",
				data: "op=cerrar",
				//data: "op=login&txt_email="+txt_email+"&txt_pass="+txt_pass,
				success: function(datos){
						 
					if(datos == "cerrar")
					{
						//jAlert('Te logueaste correctamente', 'Mensaje');
						//setTimeout( 'recargar_pagina()' , 1);
						window.location.href='../pages/index.php'			
					}else{
						jAlert('No se pudo cerrar sesion cierra esta ventana', 'Mensaje');
					}
						
						
				 }
			});

}

function olvidarclave()
{
	var email = jQuery('#email').attr('value');
		jQuery.ajax({
				type: "POST",
				url: "proc_tbl_usuario.php",
				data: "op=clave&email="+email,
				//data: "op=login&txt_email="+txt_email+"&txt_pass="+txt_pass,
				success: function(datos){
						 
					if(datos == "clave")
					{
						jAlert('Tu clave se envio a tu email', 'Mensaje');
						setTimeout( 'recargar_pagina()' , 1500);
									
					}
					if(datos == "sinclave"){
						jAlert('Usted no esta registrado', 'Mensaje');
						
					}
				
				//alert(datos);
				 }
			});

}

function olvidastes(){
	$('#frm_login').hide();	
	$('#frm_olvidar_login').show();	
}
function cancelar(){
	jQuery('#frm_olvidar_login').hide();
	jQuery('#frm_login').show();	
	
	
}


function login_empresa()
{
	var txt_email = jQuery("#txt_email").attr("value");
	var txt_pass = jQuery("#txt_pass").attr("value");
	
	if( txt_email && txt_pass)
	{
		
		jQuery.ajax({
						type: "POST",
						url: "proc_tbl_empresa.php",
						data: "op=login&txt_email="+txt_email+"&txt_pass="+txt_pass,
						success: function(datos){
						 
							if(datos == "Logeado")
							{
									jAlert('Te logueaste correctamente', 'Mensaje');
									setTimeout( 'recargar_pagina()' , 1500);
									
							}
							if(datos == "Error")
							{
									jAlert('Te olvidaste tu contrase&ntilde;a', 'Mensaje');
							}
							
						
						
					  }
				});
		
	}
	else
	{
		jAlert('No has escrito tu email y password', 'Mensaje');	
	}
	
}//end login


function recargar_pagina()
{
		window.location.reload();	
}


function borrar_escribir_email()
{
	jQuery("#txt_email").attr("value","");			
}
function escribir_email(){
	if(jQuery("#txt_email").attr("value") == ""){
		var copi = jQuery("#copiaemail").attr("value");
		jQuery("#txt_email").attr("value",copi);	
	}
	
}

var borrar_pass = true;
function borrar_escribir_pass()
{
		if(borrar_pass)
		{
			//jQuery("#txt_pass").attr("value","");	
			borrar_pass= false;
			jQuery("#txt_pass_finta").hide();
			jQuery("#txt_pass").show();
			
			setTimeout( 'ayuda_borrar_escribir_pass()' , 300 );
			
			
		}else{
			borrar_pass= true;
			jQuery("#txt_pass_finta").show();
			jQuery("#txt_pass").hide();
				
		}
}

function ayuda_borrar_escribir_pass()
{
	jQuery("#txt_pass").focus();	
}



function abrir_select_celeste()
{
	ubicar('div_capa_emergente_select_celeste','div_simular_select_celeste',0,-20);
	
	var expandido = jQuery("#div_capa_emergente_select_celeste").hasClass("expandido");
	var expandido = jQuery("#div_capa_emergente_select_celeste").hasClass("expandido");
	var expandido = jQuery("#div_capa_emergente_select_celeste").hasClass("expandido");
	var expandido = jQuery("#div_capa_emergente_select_celeste").hasClass("expandido");
	var expandido = jQuery("#div_capa_emergente_select_celeste").hasClass("expandido");
	
	if(expandido)
	{
		jQuery("#div_capa_emergente_select_celeste").removeClass("expandido");
		jQuery("#div_capa_emergente_select_celeste").hide();	
	}
	else
	{
		jQuery("#div_capa_emergente_select_celeste").addClass("expandido");	
		jQuery("#div_capa_emergente_select_celeste").show();	
	}
	
	
	
	
	
}


function ubicar(divmover , divrelativo,  numx , numy)
{
	var div = document.getElementById(divmover);
	
	div.style.display='block';
	
	
	var obj = document.getElementById(divrelativo);
	
	var posx = findPosX(obj);
	var posy = findPosY(obj);

	//alert("POS x "+posx +" Pos y: "+ posy);

	posy = posy - numy -1; 
	posx = posx + numx;
	

	div.style.top =posy+"px";
	div.style.left =posx+"px";
	
	jQuery('#'+divmover).show();
	
	
}


function seleccionar_combo_celeste(texto)
{
	if(texto)
	{
		jQuery("#div_reload_select_celeste_seleccionado").html(texto);	
		jQuery("#div_capa_emergente_select_celeste").removeClass("expandido");
		jQuery("#div_capa_emergente_select_celeste").hide();	
		
	}
}//end function seleccionar_combo_celeste


function cambiar_categoria(idarticulo)
{
		if(idarticulo)
		{
				
				var nueva_categoria = jQuery("#nueva_categoria"+idarticulo).attr("value");
				
				jConfirm('Desea Cambiar la categoria de este articulo?', 'Confirmaci&oacute;n', function(rpta) {
						
						if(rpta)
						{
								
								
								jQuery.ajax({
								type: "POST",
								url: "proc_tbl_articulos_blog.php",
								data: "op=cambiar_categoria&idarticulo="+idarticulo+"&nueva_categoria="+nueva_categoria,
								success: function(datos){
										
										window.location.reload();
								}
								});
								
								
						}//end rpta
						
						
			});
				
		}//edn validar articulo
		
}//end cambiar categoria
// guardar datos de cookie en el servidor
function enviar_contacto(){
	
	var nom = jQuery('#nombrec').val();
	var ema = jQuery('#emailc').val();
	var tel = jQuery('#telefonoc').val();
	var cel = jQuery('#celularc').val();
	var conocerc = jQuery('#conocerc').attr('value');
	
	var valpais = jQuery('#paisc').attr('checked');
	if(valpais == true) var pais = 'peru';
	else var pais = jQuery('#nompaisc').val();
	var com = jQuery('#comentariosc').val();
if(nom != '' && ema != '' && tel != '' && com != '' && conocerc != '-1'){	
	jQuery('#c1').hide();jQuery('#c2').show();jQuery('#c3').hide();
	
	jQuery.ajax({
		type: "POST",
		url: "proc_ajax_contacto.php",
		data: "op=contactar&nom="+nom+"&ema="+ema+"&tel="+tel+"&cel="+cel+"&pais="+pais+"&com="+com+"&conocerc="+conocerc,
		success: function(datos){
			jQuery('#c1').hide();jQuery('#c2').hide();jQuery('#c3').show();
			//setInterval(jQuery('#c1').show();jQuery('#c2').hide();jQuery('#c3').hide();,5000);
		    setTimeout("jQuery('#c1').show();jQuery('#c2').hide();jQuery('#c3').hide();",3000);
		   	jQuery('#nombrec').attr('value','');
			jQuery('#emailc').attr('value','');
			jQuery('#telefonoc').attr('value','');
			jQuery('#celularc').attr('value','');
			jQuery('#comentariosc').attr('value','');
		}
	});
	
}else{
	alert('Datos incompletos');
}
}

function enviar_recomendar(){
	
	var nombrer = jQuery('#nombrer').val();
	var emailr = jQuery('#emailr').val();
	var amigo1r = jQuery('#amigo1r').val();
	var email1r = jQuery('#email1r').val();
	var amigo2r = jQuery('#amigo2r').val();
	var email2r = jQuery('#email2r').val();
	var mensajer = jQuery('#mensajer').val();
if(nombrer != '' && emailr != '' && amigo1r != '' && email1r != ''){			
	jQuery('#c1').hide();jQuery('#c2').show();jQuery('#c3').hide();
	
	jQuery.ajax({
		type: "POST",
		url: "proc_ajax_recomendar.php",
		data: "op=recomendar&nombrer="+nombrer+"&emailr="+emailr+"&amigo1r="+amigo1r+"&email1r="+email1r+"&amigo2r="+amigo2r+"&email2r="+email2r+"&mensajer="+mensajer,
		success: function(datos){
			jQuery('#c1').hide();jQuery('#c2').hide();jQuery('#c3').show();
		    setTimeout("jQuery('#c1').show();jQuery('#c2').hide();jQuery('#c3').hide();",3000);
		   	jQuery('#nombrer').attr('value','');
			jQuery('#emailr').attr('value','');
			jQuery('#amigo1r').attr('value','');
			jQuery('#email1r').attr('value','');
			jQuery('#amigo2r').attr('value','');
			jQuery('#email2r').attr('value','');
			jQuery('#mensajer').attr('value','');
			//alert(datos);
		}
	});
}else{
	alert('Datos incompletos');	
}

}


