// JavaScript Document

/*gear comments*********************************************************************************/

function gcomments_getTTDR(id){

	if(isDefined(document.getElementById(id))){

		if(!isDefined($(id).prototip)){

			new Tip($(id), 'Responder al usuario',{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: {tip: 'bottomMiddle', mouse: false},

				offset: { x: 50, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideAfter:1,

				hideOn: false,

				width:138

			});

		}

   }

}

function gcomments_getTTDOk(id){

	if(isDefined(document.getElementById(id))){

		if(!isDefined($(id).prototip)){

			new Tip($(id), 'Votar a favor',{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: {tip: 'bottomMiddle', mouse: false},

				offset: { x: 12, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideAfter:1,

				hideOn: false,

				width:85

			});

		}

	}

}

function gcomments_getTTDKo(id){

	if(isDefined(document.getElementById(id))){

		if(!isDefined($(id).prototip)){

			new Tip($(id), 'Votar en contra',{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: {tip: 'bottomMiddle', mouse: false},

				offset: { x: 12, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideAfter:1,

				hideOn: false,

				width:98

			});

		}

	}

}

function gcomments_getOptionsReport(id, gear, id_gear){

	if(isDefined(document.getElementById('linkReport'+id))){

		if(!isDefined($('linkReport'+id).prototip)){

			content = "<a href=\"#\" onclick=\"gcomments_reportComment('" + id +"',0,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Spam</a><a href=\"#\" onclick=\"gcomments_reportComment('" + id +"',1,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Inapropiado</a><a href=\"#\" onclick=\"gcomments_reportComment('" + id + "',2,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Ofensivo</a>";

			new Tip($('linkReport'+id), content,{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: {tip: 'bottomMiddle', mouse: false},

				offset: { x: 12, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideAfter:1,

				hideOn: false,

				width:175

			});

		}

	}

}



function gcomments_getAvatar(id,content){

	if(isDefined(document.getElementById('avatar'+id))){

		if(!isDefined($('avatar'+id).prototip)){

			new Tip($('avatar'+id), content,{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: { tip: 'bottomMiddle', mouse: false },

				offset: { x: 35, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideOn: false,

				width: 100,

				hideAfter:1

			});

		}

	}

}



function gcomments_getOptionsReportGood(id, gear, id_gear){

	if(isDefined(document.getElementById('linkReportGood'+id))){

		if(!isDefined($('linkReportGood'+id).prototip)){

			content = "<a href=\"#\" onclick=\"gcomments_reportComment('" + id +"',3,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Interesante</a><a href=\"#\" onclick=\"gcomments_reportComment('" + id +"',4,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Brillante</a>";

			new Tip($('linkReportGood'+id), content,{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: { tip: 'bottomMiddle', mouse: false },

				offset: { x: 13, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideOn: false,

				width: 130,

				hideAfter:1

			});

		}

	}

}



function gcomments_tooltipsBackActions(id, gear, id_gear){

	if(isDefined(document.getElementById('backActions_'+id))){

		if(!isDefined($('backActions_'+id).prototip)){

			content = "<a href=\"#\" onclick=\"gcomments_reportComment('" + id +"',3,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Interesante</a><a href=\"#\" onclick=\"gcomments_reportComment('" + id +"',4,'" + gear +"','" + id_gear +"');return false;\" class=\"linkWhite\">Brillante</a>";

			new Tip($('backActions_'+id), content,{

				style: 'darkgrey',

				stem: 'bottomMiddle',

				hook: { tip: 'bottomMiddle', mouse: false },

				offset: { x: 35, y: 0},

				closeButton: false,

				showOn: 'mousemove',

				hideOthers: true,

				radius:5,

				border:5,

				hideOn: false,

				width: 130,

				hideAfter:1

			});

		}

	}

}



function gcomments_crearTooltipsResponse(id, gear, id_gear){

	gcomments_getOptionsReport(id, gear, id_gear);

	gcomments_getOptionsReportGood(id, gear, id_gear);

}



function gcomments_crearTooltips(id, gear, id_gear){

	gcomments_getTTDR('linkResponse'+id);

	gcomments_getTTDOk('rateY'+id);

	gcomments_getTTDKo('rateN'+id);

	gcomments_getOptionsReport(id, gear, id_gear);

	gcomments_getOptionsReportGood(id, gear, id_gear);

}



function gcomments_enviarComments(gear,id_gear){

	Tips.hideAll();	

	

	if(document.getElementById('comment').value != ""){

		document.getElementById('controlsComment').style.display = 'none';

		document.getElementById('loadingComment').style.display = 'block';

		

		suscribirse = document.getElementById('suscribirse').checked;	

		goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/saveComment.php&gear='+gear+'&ajax=true&id_gear='+id_gear+'&comment='+escape(document.getElementById('comment').value)+'&suscribirse='+suscribirse+'&titleObj='+escape(document.title)+'&urlObj='+escape(document.location.href),'document.getElementById(\'resultBody\').innerHTML = respuesta; document.getElementById(\'controlsComment\').style.display = \'block\';document.getElementById(\'loadingComment\').style.display = \'none\';','','0','0');	

	}

	return false;

}



function gcomments_getCommentsPag(pagcomment,gear,id_gear){

	Tips.hideAll();

	goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/getCommentPag.php&gear='+gear+'&ajax=true&id_gear='+id_gear+'&pagcomment=' + pagcomment,'document.getElementById(\'resultBody\').innerHTML = respuesta;','','0','0');

	return false;

}



function gcomments_getOrder(order,gear,id_gear){

	Tips.hideAll();	

	goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/getCommentOrder.php&gear='+gear+'&ajax=true&id_gear='+id_gear+'&order=' + order,'document.getElementById(\'resultBody\').innerHTML = respuesta;','','0','0');

	return false;

}



function gcomments_rateComment(id, val){

	Tips.hideAll();

	goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/rateComment.php&comment_id=' + id + '&val=' + val,'document.getElementById(\'rateComment'+id+'\').innerHTML = \'\';document.getElementById(\'valoracion'+id+'\').innerHTML = respuesta;','','0','0');

	return false;

}



function gcomments_cerrarForms(){

	elements = document.getElementsByTagName('div');

	total = elements.length;

	for(i=0;i<total;i++){

		if(isDefined(elements.item(i))){

			if(elements.item(i).className == "operacionM"){

				elements.item(i).innerHTML = "";

			}

		}

	}

}



function gcomments_responseTo(id,gear,id_gear){

	gcomments_cerrarForms();

	Tips.hideAll();

	document.getElementById('operacionM'+id).innerHTML = gcomments_getFormMini(id,gear,id_gear);

	content = '<div onmouseover="getPosFocus(\'comment'+id+'\');"><form id="puEditITagLink_Form'+ id +'"><p>URL:</p><p><input type="text" id="urlIncludeLink'+ id +'" name="url" value="http://" style="width:250px;" /></p><p>Texto del enlace:</p><p><input type="text" id="textoIncludeLink'+ id +'" name="texto" value="" style="width:250px;" /></p><p style="padding-top:10px;"><input type="button" name="enviar" value="Aceptar" onClick="okIncludeLink(\'comment'+ id +'\',\'puEditITagLink_'+ id +'\',\''+ id +'\');$(\'puEditITagLink_Form'+ id +'\').reset();">&nbsp;&nbsp;&nbsp;<input type="button" name="cancelar" value="Cancelar" onClick="cancelIncludeLink(\'puEditITagLink_'+ id +'\');$(\'puEditITagLink_Form'+ id +'\').reset();"></p></form></div>';

	puEditITagLinkTT('comment'+ id,$('puEditITagLink_'+ id),content);

	url = document.location.href;

	urls = url.split("#");

	document.location.href = urls[0] + "#respuesta" + id;

}

function gcomments_cancelTo(id){

	Tips.hideAll();

	document.getElementById('operacionM'+id).innerHTML = "";

}

function gcomments_responseComments(id, gear, id_gear){

	Tips.hideAll();

	if(document.getElementById('comment' + id).value != ""){

		document.getElementById('controlsComment' + id).style.display = 'none';

		document.getElementById('loadingComment' + id).style.display = 'block';

		goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/saveComment.php&gear='+gear+'&ajax=true&id_gear='+id_gear+'&comment_id='+ id +'&comment='+escape(document.getElementById('comment' + id).value)+'&titleObj='+escape(document.title)+'&urlObj='+escape(document.location.href),'document.getElementById(\'resultBody\').innerHTML = respuesta; document.getElementById(\'controlsComment' + id + '\').style.display = \'block\'; document.getElementById(\'loadingComment' + id + '\').style.display = \'none\';','','0','0');

	}

	return false;

}

function gcomments_getFormMini(id,gear,id_gear){

	return '<div class="miniFormRespuesta"><form method="post" action="." class="editor" enctype="multipart/form-data"><div id="dejarMsgAviso" style="display:none;" class="msg_amarillo"></div><div class="botonera"><div class="colores"> <a href="" class="btn_c00" onclick="return puEditITagColor(\'comment'+id+'\',\'e46add\');"></a> <a href="" class="btn_c01" onclick="return puEditITagColor(\'comment'+id+'\',\'865bc2\');"></a> <a href="" class="btn_c02" onclick="return puEditITagColor(\'comment'+id+'\',\'5785c2\');"></a> <a href="" class="btn_c03" onclick="return puEditITagColor(\'comment'+id+'\',\'4094bf\');"></a> <a href="" class="btn_c04" onclick="return puEditITagColor(\'comment'+id+'\',\'70b250\');"></a> <a href="" class="btn_c05" onclick="return puEditITagColor(\'comment'+id+'\',\'efd41c\');"></a> <a href="" class="btn_c06" onclick="return puEditITagColor(\'comment'+id+'\',\'f7bd58\');"></a> <a href="" class="btn_c07" onclick="return puEditITagColor(\'comment'+id+'\',\'ed5757\');"></a> </div>   <a name="respuesta'+ id +'"></a>  <div class="botones"> <a href="" class="btn_negrita" onclick="return puEditITag(\'comment'+id+'\',\'[b]\',\'[/b]\');"></a> <a href="" class="btn_cursiva" onclick="return puEditITag(\'comment'+id+'\',\'[em]\',\'[/em]\');"></a> <a href="" class="btn_link" onclick="return false;" id="puEditITagLink_'+id+'"></a> <a href="" class="btn_cita" onclick="return puEditITag(\'comment'+id+'\',\'[blockquote]\',\'[/blockquote]\');"></a></div></div> <input type="hidden" id="posIcomment'+id+'" value="-1" /><input type="hidden" id="posFcomment'+id+'" value="-1" /><div class="txt"><textarea class="textarea" name="comment'+id+'" id="comment'+id+'" onmouseover="rebootPos(\'comment'+id+'\');"></textarea></div> <div id="loadingComment'+id+'" style="display:none;"><img src="gears/default/img/loading.gif" /></div>    <div id="controlsComment'+id+'"><div class="btnsComment">    <div class="btnAddComment"><a href="#" onclick="if($(\'comment'+id+'\').value!=\'\'){gcomments_responseComments(\''+id+'\',\''+gear+'\',\''+id_gear+'\');}return false;">Enviar respuesta</a></div> <div class="btnCancelComment"><a href="#" onclick="gcomments_cancelTo(\''+id+'\');return false;">Cancelar</a></div>    </div></div></form></div><div style="clear:both;"></div><br /><br />';

}   

	

function gcomments_reportComment(id, type, gear, id_gear){

	Tips.hideAll();

	goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/reportComment.php&comment_id=' + id + '&type=' + type+'&gear='+gear+'&id_gear='+id_gear,'if(respuesta!=\'\'){document.getElementById(\'resultBody\').innerHTML = respuesta;}','','0','0');

	return false;

}

function gcomments_cambiarViewMore(orientacion, id, count){

	Tips.hideAll();

	if(orientacion){

	    document.getElementById('responses' + id).className = 'responseListHidden';

		if(count>1){

			if(count<10)

				plural = "s&nbsp;";

			else

				plural = "s";

		}else

			plural = "&nbsp;&nbsp;&nbsp;";

		//document.getElementById('viewmore' + id).innerHTML = '<a href="#" onclick="gcomments_cambiarViewMore(false,\''+id+'\',\''+count+'\');return false;" class="btnViewAll">'+count+' Respuesta'+plural+' <span class="blue">Ver</span></a>';

		

		document.getElementById('viewmore' + id).innerHTML = '<a href="#" onclick="gcomments_cambiarViewMore(false,\''+id+'\',\''+count+'\');return false;" class="btnViewAll"><strong>Ver todas las respuestas</strong></a>';

	}else{

    	document.getElementById('responses' + id).className = 'responseList';

        //document.getElementById('viewmore' + id).innerHTML = '<a href="#" onclick="gcomments_cambiarViewMore(true,\''+id+'\',\''+count+'\');return false;" class="btnHiddenAll">Ocultar</a>';

		document.getElementById('viewmore' + id).innerHTML = '<a href="#" onclick="gcomments_cambiarViewMore(true,\''+id+'\',\''+count+'\');return false;" class="btnHiddenAll"><strong>Ocultar las respuestas</strong></a>';

	}

}

/*gear comments*********************************************************************************/



function cambiarHREF(element){

	rutas =  element.href;

	rutasAr = rutas.split("#");

	ruta = rutasAr[0];

	

	document.location.href = ruta + "&web_data=" + escape(document.location.href + "#comments");

	return false;

}



function comments_deleteComment(comment_id, gear, id_gear){

	Tips.hideAll();

	if(confirm('Confirme la operaci\u00f3n de borrado. No podra deshacer esta acci\u00f3n')){

		goAJAX('comment','ajax.php','gearAbsolute=gears/common/comment/deleteComment.php&comment_id='+ comment_id + '&gear=' +gear+ '&id_gear=' +id_gear,'document.getElementById(\'resultBody\').innerHTML = respuesta;','','0','0');	

	}

	return false;

}
