// JavaScript Document
var hostt = server;
function cargarpag4(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='"+hostt+"imagenes/publicas/load.gif' /></div>");
        },
        success: function(rpta){		
			jQuery("#"+div).html(rpta);
        }
	});
}

function cargarpag5(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:0px 0px 0px 0px'><img src='"+hostt+"imagenes/publicas/load.gif' /></div>");
        },
        success: function(rpta){		
			jQuery("#"+div).html(rpta);
        }
	});
}

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='"+hostt+"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(hostt+'img/cartelera1.gif',hostt+'img/clientes2.gif',hostt+'img/home2.gif',hostt+'img/recomiendenos2.gif',hostt+'img/contacto2.gif',hostt+'img/operaciones2.gif',hostt+'img/servicios2.gif',hostt+'img/cartelera2.gif',hostt+'img/market2.gif',hostt+'/img/mundo2.gif',hostt+'img/consu2.gif',hostt+'img/sercorp2.gif',hostt+'img/comer2.gif',hostt+'img/serfin2.gif',hostt+'img/geren1.gif',hostt+'img/empresa2.gif',hostt+'img/geren2.gif',hostt+'img/op_edicom2.jpg',hostt+'img/op_proyex2.jpg',hostt+'img/op_inver2.jpg',hostt+'img/op_ofi2.jpg',hostt+'img/op_indus2.jpg',hostt+'img/op_retail2.jpg',hostt+'img/op_consul2.jpg',hostt+'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 !="")
	{
		//alert(hostt);
		jQuery.ajax({
						type: "POST",
						url: hostt+"pages/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=hostt+'pages/index.php';
									window.location.href=hostt+'pages/cuentausuario.php'
									
							}
							if(datos == "sinfoto")
							{
									jAlert('Te logueaste correctamente', 'Mensaje');
									window.location.href=hostt+'pages/cuenta_foto.php'
									
							}
							if(datos == "sinalbum")
							{
									jAlert('Te logueaste correctamente', 'Mensaje');
									window.location.href=hostt+'pages/cuenta_imagen.php'
									
							}
							if(datos == "Error")
							{
									jAlert('Te olvidaste tu contrase&ntilde;a', 'Mensaje');
							}
							if(datos == "cerrar")
							{
									window.location.href=hostt+'pages/cuentausuario.php'
							}
							
					  }
				});
		
	}
	else
	{
		jAlert('No has escrito tu email y password', 'Mensaje');	
	}

}//end login

function cerrar()
{
		
		jQuery.ajax({
				type: "POST",
				url: hostt+"pages/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=hostt+'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: hostt+"pages/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: hostt+"pages/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: hostt+"pages/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'){	
	$('#c1').hide();jQuery('#c2').show();jQuery('#c3').hide();
	
	$.ajax({
		type: "POST",
		url: hostt+"abc/pages/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: hostt+"pages/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');	
}

}

function quehaces(){

	var txt_quehaces = jQuery('#txt_quehaces').val();
	//txt_quehaces
	
	if(txt_quehaces !=''){
		$('#link_haciendo').hide();
		$('#save_cargar').show().html('Enviando datos...');

		//$('#msg_quehaces').html('Enviando datos...');
		$.post('proc_user_msg.php', { op:'hacer', txt_quehaces:txt_quehaces },
		function(data){
			$('#quehaciendo').html(txt_quehaces);
			$('#txt_quehaces').val('');
			$('#hacecuanto').html('Hace un momento');
			$('#save_cargar').hide();
			$('#link_haciendo').show();
			$('.span_add_com:last').after(data);
			$(".row_msg_red:first").fadeIn();
		});
	}else{
		jAlert("No Ingreso ningun comentario");
	}

}
function quehaces2(id_amigo){

		var txt_quehaces = jQuery('#txt_quehaces').val();
		if(txt_quehaces !=''){
			$('#link_haciendo').hide();
			$('#save_cargar').show().html('Enviando datos...');
	
			$.post('proc_user_msg.php', { op: 'hacer2', txt_quehaces:txt_quehaces, id_amigo:id_amigo },
			function(data){
				//$('#quehaciendo').html(txt_quehaces);
				$('#txt_quehaces').val('');
				//$('#hacecuanto').html('Hace un momento');
				$('#save_cargar').hide();
				$('#link_haciendo').show();
				$('.span_add_com:last').after(data);
				$(".row_msg_red:first").fadeIn();
				/*
				$('#msg_publicar').html('Datos enviados');	
				window.location.reload();
				*/
			});
		}
		else{
			jAlert("No Ingreso ningun comentario")	;
		}
		
			
}
function agregar_comentario(id_tblupdate){
	var comentario = jQuery('#txt_comentario').val();		
	if($.trim(comentario)!=''){	
		$.post('proc_ajax_comentario.php', { op:'agregar_comentario', id_tblupdate:id_tblupdate, comentario:comentario },
		function(data){
			window.location.reload();
		});
	}else{
		jAlert('No lleno el mensaje.');	
	}
}

function comentar_serv_tecnico(){
	var title = $('#txt_title').val();
	var com = $('#txt_com').val();

	if($.trim(title)!='' && $.trim(com)!=''){
		$('#btns').html('Enviando informaci&oacute;n');
		$.post('proc_ajax_comentario.php', { op:'add_com_tec', title:title, com:com},
		function(data){
			$('#btns').html('Su consulta ha sido enviada');
			setTimeout("window.location.reload()",1000);
		});
	}else{
		jAlert('Datos incompletos');	
	}

}
function responder_serv_tecnico(){

	var idconsulta = $('#txt_idconsulta').val();
	var resp = $('#txt_resp').val();
	
	if($.trim(resp)!=''){
		$('#btns').html('Enviando informaci&oacute;n');
		$.post('proc_ajax_comentario.php', { op:'resp_com_tec', resp:resp, idconsulta:idconsulta},
		function(data){
			//alert(data);
			$('#btns').html('Respuesta Enviada');
			setTimeout("window.location.reload()",1000);
		});
	}else{
		jAlert('Datos incompletos');	
	}
}
/*	FUNCION PARA COMENTARIOS QUE HACEN A LAS ACTUALIZACIONES*/

function add_resp_com(idrow,id_user){ //idrow=id tabla actualizaciones, idus
	//idrow = id de la tabla actualizacion
	var message = $('#data_msg'+idrow).find('textarea').val();
	$('#data_msg'+idrow).find('textarea').val('');
	if($.trim(message)!=''){
		//$('#data_msg'+idrow).find('.link_ok').replaceWith("<span class='link_change'>Enviando...</span>");
		$('#data_msg'+idrow).find('.link_ok').replaceWith("<span class='link_change'>Enviando...</span>");
		$('#data_msg'+idrow).find('.link_cancel').hide();
		$.post('proc_user_msg.php', { op:'resp_com', message:message, idrow:idrow, id_user:id_user},
		function(data){
			$('#data_msg'+idrow).before(data);
			$('#data_msg'+idrow).hide();
			$('#data_msg'+idrow).find('.link_change').replaceWith("<span onclick='add_resp_com("+idrow+","+id_user+")' class='link_ok'>Aceptar</span>");
			$('#addcom'+idrow).show();
			$('#data_msg'+idrow).find('.link_cancel').show();
			//<span onclick='add_resp_com(<?=$row->id?>)' class='link_ok'>Aceptar</span>
			//<span onclick='add_resp_com(<?=$row->id?>)' class='link_ok'>Aceptar</span>
			//window.location.reload();
		});
	}else{
		jAlert('Llene el mensaje.');
	}
}

/* YOUTUBE	*/

function listar_videos_yt(){
	
	var criterio = $('#txt_criterio').val();
	
	//if($.trim(criterio)!=''){
		$('#btn_listar_yt').attr('disabled',true).val('Buscando...');
		$.post('rpacoc_youtube/index.php', { op:'agregar_comentario', query:criterio },
		function(data){
			$('#btn_listar_yt').attr('disabled',false).val('Buscar');
			$('#listado_media_yt').html(data);
		});
	/*}else{
		jAlert('Ingresa un titulo');
		$('#txt_criterio').focus().select();
	}*/
		
}
function media_view_yt(codigo){
	var cad = "<object width='218' height='180'><param name='movie' value='http://www.youtube.com/v/"+codigo+"&hl=es_ES&fs=1&'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/"+codigo+"&hl=es_ES&fs=1&' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='218' height='180'></embed></object>";	
	$('#reprod_youtube').html(cad);
	$('#listado_media_yt').hide();
	$('#frm_media_yt').show();
	$('#txt_codigo_yt').val(codigo);
	$('#btn_listar_yt').hide();
}
function create_video_yt(){

	var codigo = $('#txt_codigo_yt').val();
	var titleyt = $('#txt_'+codigo+'_title').val();
	var descyt = $('#txt_'+codigo+'_desc').val();
	var titulo = $('#txt_titulo_yt').val();
	var autor = $('#txt_autor_yt').val();

	if($.trim(titulo)!=''){
		$('#btn_create_yt').attr('disabled',true).val('Guardando...');
		//alert(codigo+' / '+ titleyt+' / '+descyt);
		$.post('proc_ajax_perfil_edit.php', { op:'guardar_musica',titulo:titulo, autor:autor, valor:codigo, title:titleyt, desc:descyt},
		function(data){
			$('#btn_create_yt').val('Guardado');
			window.location.reload();
		});
	}else{
		jAlert('Datos incompletos');
		$('#txt_titulo_yt').focus().select();
	}

}


/* FIN YOUTUBE	*/
