﻿// JavaScript Document
// Debug
function d(algo){
	alert('debug ->' + algo);
}

function hiddeMsg(divId){
	document.getElementById(divId).style.display="none";
	//alert('test' + divId);
}
//  Validacion  de campos en base de datos

function styles(Id, Propiedad, Valor){
	//alert('style');
	var idTextArr = new Array();
			idTextArr=Id.split("|");
			for(i=0;i<idTextArr.length;i++){
				//d('idTextArr ->' + idTextArr[i]);
				if(document.getElementById(idTextArr[i])!=undefined){
					document.getElementById(idTextArr[i]).style[Propiedad] = Valor;
				}
			}
	
	//alert('test' + divId);
}

function validOnTime(funcion, tiempo){ 
//alert('alert test ' + funcion);
setTimeout(funcion,tiempo);
       
}

function validaEmail(msgError, divId){
	var msgEmail = document.getElementById(divId);
	var btnEnviar = document.getElementById('btn_registrate1');
	var inputEmail = document.getElementById('email_propietario');
	if(document.registro.validemail!=undefined && inputEmail.disabled==false){
		if (document.registro.validemail.value=='no'){
			msgEmail.innerHTML=msgError;
			msgEmail.style.display="block";
			btnEnviar.style.display="none";
			return false; 
		}else if (document.registro.validemail.value=='si'){
			msgEmail.style.display="none";
			btnEnviar.style.display="block";
			return true;
		}	
	}else{
		//alert('hola cada 500 ms');
		validOnTime('validaEmail("'+msgError+'", "'+divId+'")',500);
		
	}
}

function validaCaptcha(msgError, divId){
	var btnEnviar = document.getElementById('btn_registrate01');
	var msgCaptcha = document.getElementById(divId);
	if(document.registro01.validcaptcha!=undefined){
		if (document.registro01.validcaptcha.value=='no'){
			msgCaptcha.innerHTML=msgError;
			msgCaptcha.style.display="block";
			btnEnviar.style.display="none";
			return 0; 
		}else if (document.registro01.validcaptcha.value=='si'){
			msgCaptcha.style.display="none";
			btnEnviar.style.display="block";
			return true;
		}
	}else{
		
		validOnTime('validaCaptcha("'+msgError+'", "'+divId+'")',500);
	}
}
//  Validacion  de campos en base de datos  END


//////////////////////////////////////////      Clicks en el document seguimiento

document.onmousedown = function (e) {
	e = e || event
	var target = e.target || e.srcElement
 
	//alert('Tipo de Objeto ->' + target + '| Nombre ->' + target.name + '| Valor ->' + target.value + '| Alt ->' + target.alt + '| Text ->' + target.text + '| ID ->' + target.id + '| Title ->' + target.title + '| Tag ->' + target.tags + '| Type ->' + target.type + '| Href ->' + target.href + '| Parent  ->' + target.parentNode + '| anchorTags  ->' + target.anchorTags + '| target.nodeName  ->' + target.nodeName + '| target.parentNode.nodeName  ->' + target.parentNode.nodeName + '| target.parentNode.nodeName  ->' + target.parentNode.nodeName);


	if(target.nodeName=='A' || target.parentNode.nodeName=='A'){

		var origen=location.href;
		
		if(target.nodeName=='A'){
			var destino=target.href;
			
			if(target.title!=undefined && target.title!=''){
				var title=target.title;
			}else{
				var title='Indefinido';
			}
		}else if(target.parentNode.nodeName=='A'){
			var destino=target.parentNode.href;
			
			if(target.parentNode.title!=undefined && target.parentNode.title!=''){
				var title=target.parentNode.title;
			}else{
				var title='Indefinido';
			}
			
			
		 }
		
		var data='href_origen='+ origen +'&href_destino=' + destino + '&title=' + title;
		//alert(data);
		// Guardamos en DB
		//alert(document.location);
		
		var loc = document.location.toString();
		//alert(loc.toString());
		//alert(parseInt(loc.indexOf("/love/")) + " - " + parseInt(loc.indexOf("/club/")) + " - " + parseInt(loc.indexOf("/shop/")) + " - " + parseInt(loc.indexOf("/unite/")));
		//alert(loc.indexOf("/love/"));
		if(parseInt(loc.indexOf("/love/"))!=-1 || 
			parseInt(loc.indexOf("/club/"))!=-1 ||
			parseInt(loc.indexOf("/shop/"))!=-1 ||
			parseInt(loc.indexOf("/unite/"))!=-1)
		//if(loc.indexOf("/love/")!=-1)
			nuevoEvento(data, 'onlySave', '../lib/clickSave.php');
		else nuevoEvento(data, 'onlySave', 'lib/clickSave.php');
		
		//return false;
		
	}
}

//////////////////////////////////////////      Clicks en el document seguimiento   END


function validaEdicionPerfil(){
	//alert('test');
	
	if(document.registro.mail_original.value==document.registro.email_propietario.value){
		document.registro.mailChanged.value=0;
	}else{
		document.registro.mailChanged.value=1;
	}
	
	if(document.getElementById('sexoM').checked==true){
		document.registro.sexook.value='M';
	}else if(document.getElementById('sexoF').checked==true){
		document.registro.sexook.value='F';
	}
	
	var opcionales='';
	
	
	if(document.registro.passChPass != undefined){
		opcionales  +='|passChPass';
	}
	
	nuevoEvento('nombre_propietario|apellido_propietario|email_propietario|password|birthday_year|birthday_month|birthday_day|sexook|pais|usr_id|mailChanged|estado' + opcionales, 'responseUpdt', 'lib/edicionPerfil.php');


}

function validaPassEdicion(){
	
	if(document.registro.password.value!='' || document.registro.mail_original.value!=document.registro.email_propietario.value){
		if(document.registro.password.value!=''){
			document.registro.password.className='required validate-password';
			document.registro.password_confirm.className='required validate-password-confirm';
		}
		document.registro.pinta.value=1;
		nuevoEvento('pinta', 'msgPassActual', 'lib/pintaInputPass.php');

	}else{
		document.registro.pinta.value=0;
		nuevoEvento('pinta', 'msgPassActual', 'lib/pintaInputPass.php');
		// retiramos classes para que no valide
		document.registro.password.className='';
		document.registro.password_confirm.className='';
		
		// quitamos el password confirm
		document.registro.password_confirm.value='';
		
		
		// Retiramos los mensajes de errores  Si existen
		if(document.getElementById('advice-required-password_confirm')!=undefined){
			document.getElementById('advice-required-password_confirm').style.display='none';	
		}
		if(document.getElementById('advice-validate-password-password')!=undefined){
			document.getElementById('advice-validate-password-password').style.display='none';
		}
		if(document.getElementById('advice-validate-password-confirm-password_confirm')!=undefined){
			document.getElementById('advice-validate-password-confirm-password_confirm').style.display='none';
		}
	}

	
}

function validaEdicionPerfilPerro(){
	
	if(document.getElementById('sexoM').checked==true){
		document.registro02.sexook.value='M';
	}else if(document.getElementById('sexoF').checked==true){
		document.registro02.sexook.value='F';
	}
	
	if(document.getElementById('perro_pedegree_si').checked==true){
		document.registro02.perro_pedegree_ok.value='1';
	}else if(document.getElementById('perro_pedegree_no').checked==true){
		document.registro02.perro_pedegree_ok.value='0';
	}
	
	if(document.getElementById('perro_registrado_si').checked==true){
		document.registro02.perro_registrado_ok.value='1';
	}else if(document.getElementById('perro_registrado_no').checked==true){
		document.registro02.perro_registrado_ok.value='0';
	}
	
	if(document.getElementById('perro_chip_si').checked==true){
		document.registro02.perro_chip_ok.value='1';
	}else if(document.getElementById('perro_chip_no').checked==true){
		document.registro02.perro_chip_ok.value='0';
	}
	
	if(document.getElementById('perro_cruza').checked==true){
		document.registro02.perro_cruza_ok.value='1';
	}else{
		document.registro02.perro_cruza_ok.value='0';
	}
	
	if(document.getElementById('perro_esterilizado').checked==true){
		document.registro02.perro_esterilizado_ok.value='1';
	}else{
		document.registro02.perro_esterilizado_ok.value='0';
	}
	
	nuevoEvento('perro_nombre|birthday_year|birthday_month|birthday_day|sexook|raza|perro_peso|perro_pedegree_ok|perro_registrado_ok|perro_chip_ok|usr_id|perro_id|perro_esterilizado_ok|perro_cruza_ok', 'responseUpdt', 'lib/edicionPerfilPerro.php');
}

function busquedaOver(){
	buscadorinput = document.getElementById("bt");
	if(buscadorinput.value=="BUSCAR EN NUUGI.COM") buscadorinput.value="";
}

function busquedaOut(){
	buscadorinput = document.getElementById("bt");
	if(buscadorinput.value=="") buscadorinput.value="BUSCAR EN NUUGI.COM";
}

function busquedaShopOver(){
	buscadorinput = document.getElementById("search_query");
	if(buscadorinput.value=="Buscar en Nuugi Shop") buscadorinput.value="";
	
}

function busquedaShopOut(){
	buscadorinput = document.getElementById("search_query");
	if(buscadorinput.value=="") buscadorinput.value="Buscar en Nuugi Shop";
}


function newsletterSubscribeOver(){
	buscadorinput = document.getElementById("newslt_email");
	if(buscadorinput.value=="Correo electrónico"){
		buscadorinput.value="";
		//d('Correo electrónico == ' + buscadorinput.value);
	}else{
		//d('Correo electrónico != ' + buscadorinput.value);
	}
	
}

function newsletterSubscribeOut(){
	buscadorinput = document.getElementById("newslt_email");
	if(buscadorinput.value=="") buscadorinput.value="Correo electrónico";
	//d('out buscadorinput.value ->' + buscadorinput.value);
}

function inputTextFocus(input, origtxt){
	//alert(input.value==origtxt);
	if(input.value==origtxt) input.value = "";
}

function inputTextBlur(input, blurtxt){
	//alert(input.value + " - " + blurtxt);
	if(input.value=="") input.value = blurtxt;
}

function displayLogin(){
	if(document.getElementById('login') != undefined){
		//alert('NO esta logueado');
		//jQuery(document).ready(function() {
    		j("#login").trigger('click');
		//});
	}else{
		//alert('YA esta logueado');
	}
}

function doClick(id){
	if(document.getElementById(id) != undefined){
		//d('existe el id ->' + id);
    		j("#" + id).trigger('click');
	}else{
		//d('no existe el id ->' + id);
	}
}

function openWindow(){
	window.open("http://www.javascript-coder.com","mywindow","menubar=1,resizable=1,width=350,height=250");

}
/*									ADMIN								*/

function wysiwyg(){
	d('wysiwyg');
	/*
	j(document).live('ready', function() {
			j("#raza_sintesis").cleditor();
	});
	*/
}


function inputFocus(id, valueDefault){
	var input = document.getElementById(id);
	var valueinput = input.value;
	//d('valueDefault->' + valueDefault + 'valueinput->' + valueinput);
	if(valueinput==valueDefault){
		input.value='';
	}
	
}

function inputBlur(id, valueDefault){
	var input = document.getElementById(id);
	var valueinput = input.value;
	//d('valueDefault->' + valueDefault + 'valueinput->' + valueinput);
	if(valueinput==''){
		input.value=valueDefault;
	}
}

function load(divId, file){
	j("#" + divId).load(file, {limit: 25}, function(){
		j("#" + divId).fadeIn("slow");
		//d("The last 25 entries in the feed have been loaded");
	});
}

