function cambia_sesion_info(id){
	parent.ajaxload("sesion_info","ajax/sesion_info.php?id="+id+"");
	if(parent.document.getElementById("web20")){
		parent.ajaxload("web20","ajax/botones_web20.php");
	}
}

function cambia_rubro(rubro_id){
	ajaxload("bloque_buscador","ajax/bloque_buscador.php?r="+rubro_id+"","cambia_lista('"+rubro_id+"');	");
	var buscador_opciones=document.getElementById("buscador_opciones");
	var anchors = buscador_opciones.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		if(rubro_id==anchors[i].id){
			anchors[i].className = "activo";
		}else{
			anchors[i].className = "";
		}
	}
}

function cambia_lista(rubro_id){
	if(document.getElementById("bloque_localidades")){
		var provincia_id=document.getElementById("provincia_id").innerHTML;
		ajaxload("bloque_localidades","ajax/bloque_localidades.php?r="+rubro_id+"&p="+provincia_id+"");
		document.getElementById("rubro_titulo").innerHTML=document.getElementById(rubro_id).innerHTML;
	}
}

function select_geo(superior,presel,n_campo){
	if(document.getElementById("agregar_"+n_campo+"")){
		if(superior.value!=-1){
			document.getElementById("box_agregar_"+n_campo+"").style.display="block";
			document.getElementById("agregar_"+n_campo+"").style.display="block";
			document.getElementById("agregar_"+n_campo+"").innerHTML="agregar localidad en "+superior.options[superior.selectedIndex].text;
			document.getElementById("agregar_"+n_campo+"").href="forms/agregar_localidad.php?provincia_id="+superior.value+"&campo=sel_"+n_campo;
			if(window.frameElement){
			var ifid=window.frameElement.id;
			if(document.getElementById("main")&&parent.document.getElementById(ifid)){
				var alto=document.getElementById("main").scrollHeight;
				parent.document.getElementById(ifid).height=alto+"px";
			
			}
	}

		}else{
			document.getElementById("box_agregar_"+n_campo+"").style.display="none";
		}
	}
	if(!presel){presel=-1;}
	ajaxload("sel_"+n_campo+"","ajax/select_localidad.php?superior="+superior.value+"&presel="+presel+"&n_campo="+n_campo+"");
}

function agregar_localidad_fin(provincia_id,localidad_id,campo){
	parent.ajaxload(campo,"ajax/select_localidad.php?superior="+provincia_id+"&presel="+localidad_id+"&n_campo=sel_geo_id");
	parent.fauxpopup();
}

function insertar_imagen(a) {
	var titulo=a.title;
	var src=a.href;
	var imagen="<img src='"+src+"' alt='"+titulo+"' title='"+titulo+"' style='float:left; margin: 2px 5px 5px 0;' />";
	parent.tinyMCE.execCommand('mceInsertContent',false,imagen);
	parent.fauxpopup();
}

function agregar_visitado(){
	var cantidad=document.getElementById("cant_visitados").value*1+1;
	document.getElementById("cant_visitados").value=cantidad;
	var caja = document.getElementById("lugares_visitados");
	var nueva_caja = document.createElement("div");
	nueva_caja.setAttribute("id","visitado"+cantidad+"");
	caja.appendChild(nueva_caja);
	if(window.frameElement){
		var ifid=window.frameElement.id;
		if(document.getElementById("main")&&parent.document.getElementById(ifid)){
			var alto=document.getElementById("main").scrollHeight+40;
			parent.document.getElementById(ifid).height=alto+"px";
		
		}
	}
	ajaxload("visitado"+cantidad+"","ajax/agregar_visitado.php?indice="+cantidad+"");
}

function imagen_tool(textarea){
	document.getElementById("ifpopup").src="forms/usuarios_imagenes.php"
	document.getElementById("ifpopup").width="500px";
	document.getElementById("ifpopup").height="500px";
	document.getElementById("fauxpp").style.width="500px";
	document.getElementById("fauxpp").style.height="700px";
	var arr_pagesize=getPageSize();
	var left=(arr_pagesize[0]-500)/2;
	document.getElementById("fauxpp").style.left=left+"px";
}

function ver_imagen(a){
	document.getElementById("ifpopup").src=a.href;
	document.getElementById("ifpopup").width="700px";
	document.getElementById("ifpopup").height="700px";
	document.getElementById("fauxpp").style.width="700px";
	document.getElementById("fauxpp").style.height="700px";
	var arr_pagesize=getPageSize();
	var left=(arr_pagesize[0]-700)/2;
	document.getElementById("fauxpp").style.left=left+"px";
}


function activa_servicio(i){
	if(document.getElementById("servicio"+i+"").value==1){var nuevo=0;}else{var nuevo=1;}
	document.getElementById("servicio"+i+"").value=nuevo;
	document.getElementById("img_servicio"+i+"").className="ico"+nuevo+"";
}

function enciende_servicio(i,act){
	if(document.getElementById("servicio"+i+"").value==0){
		document.getElementById("img_servicio"+i+"").className="ico"+act+"";
	}
}

function check_form_ficha(rubro,nivel){
	var rubro_id=document.getElementById(rubro).value;
	if((rubro_id==6) || (rubro_id==7)){
		document.getElementById("nivel_box").style.visibility="hidden";
		document.getElementById(nivel).value=1;
	}
	else if(rubro_id>3){
		document.getElementById("nivel_box").style.visibility="hidden";
		document.getElementById(nivel).value=2;
	}else{
		document.getElementById("nivel_box").style.visibility="visible";
	}
	
	if(document.getElementById(nivel).value==2){
		document.getElementById("contrato").style.display="block";
	}else{
		document.getElementById("contrato").style.display="none";
	}
}

function activa_servicio(i){
	if(document.getElementById("servicio"+i+"").value==1){var nuevo=0;}else{var nuevo=1;}
	document.getElementById("servicio"+i+"").value=nuevo;
	document.getElementById("img_servicio"+i+"").className="ico"+nuevo+"";
}

function enciende_servicio(i,act){
	if(document.getElementById("servicio"+i+"").value==0){
		document.getElementById("img_servicio"+i+"").className="ico"+act+"";
	}
}


function showhide(divid){
	if(document.getElementById(divid).style.display=="none"){
		document.getElementById(divid).style.display="block";
	}else{
		document.getElementById(divid).style.display="none";
	}
}

function fauxpopup(ancho,alto){
	if(document.getElementById("capa").style.display=="block"){
		document.getElementById("fauxpp").innerHTML="<iframe src='' width='0' height='0' class='iframe' frameborder='0' scrolling='no' id='ifpopup' name='ifpopup' allowtransparency='true'></iframe>"
		document.getElementById("capa").style.display="none";
		document.getElementById("fauxpp").style.display="none";
		document.getElementById("fauxpp").style.width="400px";
		document.getElementById("fauxpp").style.height="200px";
		var arr_pagesize=getPageSize();
		var left=(arr_pagesize[0]-400)/2;
		document.getElementById("fauxpp").style.left=left+"px";
		var oSelects=document.getElementsByTagName("select");
		for(var i=0;i<oSelects.length;i++){
			oSelects[i].className=oSelects[i].className.replace(" selHide","");
			oSelects[i].className=oSelects[i].className.replace("selHide","");
		}
	}else{
		var arr_pagesize=getPageSize();
		var arr_pagescroll=getPageScroll();
		var top=arr_pagescroll[1]+50;
		document.getElementById("fauxpp").style.top=top+"px";
		document.getElementById("capa").style.height=arr_pagesize[1]+"px";
		
		document.getElementById("capa").style.display="block";
		document.getElementById("fauxpp").style.display="block";
		
		var oSelects=document.getElementsByTagName("select");
		for(var i=0;i<oSelects.length;i++){
			oSelects[i].className+=" selHide";
		}
	}
}

function ajaxnoload(url) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Su navegador no soporta AJAX!");
	  return;
	 } 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

var divid="";
var afterload="";

function ajaxload(caja,url,postfunction) {
	afterload=postfunction;
	divid=caja;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Su navegador no soporta AJAX!");
	  return;
	 } 
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
function GetXmlHttpObject() {
  var xmlHttp=null;
  try{// Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
   }
  catch (e){ // Internet Explorer
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
   }
  return xmlHttp;
}

function stateChanged() {
/*
	if (xmlHttp.readyState==1){//request seteado
		document.getElementById(divid).innerHTML="<p>cargando...</p>";
	}
	if (xmlHttp.readyState==2){//request enviado
		document.getElementById(divid).innerHTML="<p>cargando...</p>";
	}
	if (xmlHttp.readyState==3){//requesten proceso
		document.getElementById(divid).innerHTML="<p>cargando...</p>";
	}
*/
	if (xmlHttp.readyState==4){//request completo
		document.getElementById(divid).innerHTML=xmlHttp.responseText;
		eval(afterload);

	}
}

function getPageScroll(){
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




