var xmlhttp;
var box;

function stateChanged(){ 
	if(xmlhttp.responseText=='no'){
		location.href='login.php';
	}
	if (xmlhttp.readyState==4){ 
		document.getElementById(box).innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
		//code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function carregar_foto(id){
	var imgStage = document.getElementById('srcIM');	
	var imgWay = document.getElementById('img'+id).value;
	var leg = document.getElementById('leg'+id).value;
	var divleg = document.getElementById('dfea_legenda');
	if(imgWay!=''){
		document.getElementById('img_container').style.display='block';		
		document.getElementById('update_container').style.display='none';
		imgStage.src=imgWay;
		divleg.innerHTML=leg;
		
	}else{
		document.getElementById('img_container').style.display='none';	
		//document.getElementById('update_container').style.display='block';
	}
	for (var x = 1; x <= 6; x++){
		document.getElementById('fotos_aba_'+x).style.backgroundColor='#e5e4f4';
	}
	document.getElementById('fotos_aba_'+id).style.backgroundColor='#a9c3de';
	linkf = document.getElementById('link_na_capa');
	linkfValue = document.getElementById('href_link_da_capa_value').value;

	if(id=='1'){ linkf.href=linkfValue;}
	else{ linkf.href="javascript:no_link()";}
	coments=document.getElementById('coment'+id).value;
	div_coments=document.getElementById('fotos_comentar');
	if(coments=='0'){
		div_coments.innerHTML="<a href=\"javascript:comentar('"+id+"')\">Comentar</a>";
		
	}else if(coments>0){
		div_coments.innerHTML="<a href=\"javascript:comentar('"+id+"','1')\"' id='link_comentarios_q_some'>Coment&aacute;rios (<span id='qts_coments'>"+coments+"</span>)</a></a>";
	}
	//document.getElementById('iframe_comentatios_fotos').src='';
	document.getElementById('fotos_comentarios_div').style.display='none';		
	document.getElementById('fotos_comentar_div').style.display='none';
	//document.getElementById('link_comentarios_q_some').style.display='none';
	//document.getElementById('link_comentarios_q_some').style.display='block';
}
function comentar(id,pos){
	document.getElementById('fotos_comentar_div_id').value=id;
	coments=document.getElementById('coment'+id).value;
	if(coments=='0'){
		document.getElementById('fotos_comentarios_div').style.display='none';
		document.getElementById('fotos_comentar_div').style.display='block';
	}
	else if(coments>0){
		document.getElementById('fotos_comentar_div').style.display='none';
		document.getElementById('fotos_comentarios_div').style.display='block';
		box='fotos_comentarios_div_int';
			xmlhttp=GetXmlHttpObject();	
		if (xmlhttp==null){
			alert ("Browser does not support HTTP Request");
			return;
		}
		var id_da_destinataria=document.getElementById('id_da_destinataria').value;
		url='agregados/minha_conta_carrega_comentarios_foto.php?usuaria='+id_da_destinataria+'&foto='+id+'&coment='+pos;
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		//document.getElementById('iframe_comentatios_fotos').src='agregados/minha_conta_carrega_comentarios_foto.php?usuaria='+id_da_destinataria+'&foto='+id+'&coment=1';
//		document.getElementById('link_comentarios_q_some').style.display='none';
//		document.getElementById('link_comentarios_q_some').style.display='block';
//		div_coments=document.getElementById('fotos_comentar');
//		//div_coments.innerHTML="<a href=\"javascript:comentar('"+id+"','1')\"' id='link_comentarios_q_some'>Coment&aacute;rios (<span id='qts_coments'>1</span>)</a></a>";
//		div_coments.style.display='none';
//		div_coments.style.display='block';
//		div_coments.style.display='none';
//		div_coments.style.display='block';
	}
}
function fazer_comentario(){
	//document.getElementById('iframe_comentatios_fotos').src='';
	document.getElementById('fotos_comentarios_div').style.display='none';		
	document.getElementById('fotos_comentar_div').style.display='block';
}
function ler_comentario(){
	document.getElementById('fotos_comentar_div').style.display='none';
	document.getElementById('fotos_comentarios_div').style.display='block';
	var id_da_destinataria=document.getElementById('id_da_destinataria').value;
	//document.getElementById('iframe_comentatios_fotos').src='agregados/minha_conta_carrega_comentarios_foto.php?usuaria='+id_da_destinataria+'&foto='+id+'&coment=1';	
}
function no_link(){ }
function chage_imagem(id){
	var fonte_img=document.getElementById('fonte_img_'+id).value;
	var legenda_img=document.getElementById('fonte_leg_'+id).value;
	document.getElementById('foto_grandona').src=fonte_img;
	document.getElementById('inp_foto_manager_leg').value=legenda_img;
	document.getElementById('imp_numFoto').value=id;
	document.getElementById('foto_pos').value=id;
	for (var x = 1; x <= 6; x++){
		document.getElementById('link_foto_'+x).style.fontWeight='normal';
		document.getElementById('fotinho_4_exiB_'+x).style.border='0px solid #ccc';
		
	}
	document.getElementById('link_foto_'+id).style.fontWeight='Bold';
	document.getElementById('fotinho_4_exiB_'+id).style.border='2px solid #D0B0D0';
	contar_legenda();

}
function contar_legenda(){
	ta = document.getElementById('inp_foto_manager_leg');
	co = document.getElementById('contador_legenda');
	if(ta.value.length > 45){
		var va = ta.value.substring(0,45);
		ta.value=va;
	}
	co.value=ta.value.length + ' de 45';
}
function contar_comentario(){
	ta = document.getElementById('fotos_comentar_div_ta');
	co = document.getElementById('fotos_comentar_div_ta_contador');
	if(ta.value.length > 150){
		var va = ta.value.substring(0,150);
		ta.value=va;
	}
	co.value=ta.value.length + ' de 150';	
}
function salvar_comentario_foto(){
	box='fotos_comentarios_div_int';
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	var id_da_destinataria=document.getElementById('id_da_destinataria').value;
	var id_do_recado=document.getElementById('fotos_comentar_div_id').value;
	var recado_novo = document.getElementById('fotos_comentar_div_ta').value;
	var pos=recado_novo.search(/\n/);	
	while (pos>=0){
		recado_novo=recado_novo.replace(/\n/, '|BR|');
		pos=recado_novo.search(/\n/);	
	} 
	var pos=recado_novo.search(/&/);	
	while (pos>=0){
		recado_novo=recado_novo.replace(/&/, '|EcomerCiales|');
		pos=recado_novo.search(/&/);	
	} 
	var pos=recado_novo.search(/=/);	
	while (pos>=0){
		recado_novo=recado_novo.replace(/=/, '|Igualis|');
		pos=recado_novo.search(/=/);	
	} 
	url='agregados/minha_conta_carrega_comentarios_foto.php?usuaria='+id_da_destinataria+'&foto='+id_do_recado+'&coment=1&recado='+recado_novo;
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	document.getElementById('fotos_comentar_div_ta').value='';	
	//document.getElementById('formulario_de_foto_comentarios').submit();
	document.getElementById('fotos_comentar_div').style.display='none';
	document.getElementById('fotos_comentarios_div').style.display='block';
	var id=document.getElementById('fotos_comentar_div_id').value;
	var coments=document.getElementById('coment'+id).value;
	coments=parseInt(coments)+1;	
	document.getElementById('coment'+id).value=coments;
	var div_qts_coments = document.getElementById('qts_coments');
	if(div_qts_coments){
		div_qts_coments.innerHTML=coments
	}else{
		var fc = parent.document.getElementById('fotos_comentar');
		if(fc){
			fc.innerHTML='<a href="javascript:comentar(\'1\')">Coment&aacute;rios (<span id="qts_coments">1</span>)</a>';
		}
	}
}
function salvar_alteracoes(){
	document.getElementById('formulario_de_foto_alteracoes').submit();		
}
function definir_como_capa(){
	document.getElementById('salva_fotos').value='nao';		
	document.getElementById('definir_como_capa').value='sim';		
	salvar_alteracoes()
}
function excluir_esta_foto(){
	document.getElementById('salva_fotos').value='nao';		
	document.getElementById('excluir_foto').value='sim';		
	salvar_alteracoes()
}
function fechar_comentarios(){
	//document.getElementById('iframe_comentatios_fotos').src='';
	document.getElementById('fotos_comentarios_div').style.display='none';		
	document.getElementById('fotos_comentar_div').style.display='none';	
}
function excluir_comentario_foto(id){
	var pos = document.getElementById('pos_da_foto').value;
	var url = 'funcoes/excluir_comentario_foto.php?foto='+id+'&pos='+pos;
	document.getElementById('iframe_das_acoes_C').src=url;
}
function ler_todos_comentarios(){
	var id = document.getElementById('fotos_comentar_div_id').value;
	document.getElementById('comentarios_da_foto').value=id;
	document.getElementById('form_comentarios_da_foto').submit();
}
function excluir_este_recado(id,pos){
	box='fotos_comentarios_div_int';
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	var id_da_destinataria=document.getElementById('id_da_destinataria').value;
	var id_do_recado=document.getElementById('fotos_comentar_div_id').value;
	url='agregados/minha_conta_carrega_comentarios_foto.php?usuaria='+id_da_destinataria+'&foto='+id_do_recado+'&coment='+pos+'&excluir='+id;
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);	
	document.getElementById('fotos_comentar_div').style.display='none';
	document.getElementById('fotos_comentarios_div').style.display='block';
	var id=document.getElementById('fotos_comentar_div_id').value;
	var coments=document.getElementById('coment'+id).value;
	coments=parseInt(coments)-1;	
	document.getElementById('coment'+id).value=coments;
	var div_qts_coments = document.getElementById('qts_coments');
	if(div_qts_coments){
		div_qts_coments.innerHTML=coments
	}else{
		var fc = parent.document.getElementById('fotos_comentar');
		if(fc){
			fc.innerHTML='<a href="javascript:comentar(\'1\')">Coment&aacute;rios (<span id="qts_coments">1</span>)</a>';
		}
	}
}






