function onOverRow(obj, color)
{
	obj._oldBGColor = obj.style.backgroundColor;
	obj.style.backgroundColor = color;
	document._lastRow = obj;
}
function onOutRow(obj)
{
	obj.style.backgroundColor = obj._oldBGColor;
}

function minimizeDiv(btn, div)
{
	objDiv = document.getElementById(div);
	btn = document.getElementById(btn);
	
	if(objDiv.style.display == "block" || objDiv.style.display == "")
	{
		objDiv.style.display = "none";
		btn.style.backgroundImage = "url(images/menu_win_maximize.gif)";
	}
	else
	{
		objDiv.style.display = "block";
		btn.style.backgroundImage = "url(images/menu_win_minimize.gif)";
	}
		
}

function GotoDir(dir)
{
	self.location.href = dir;
} 

function openwindow(dir)
{
	window.open(dir);
} 

function openwindowex(Url,NombreVentana,width,height,extras) 
{
	var largo 		= width;
	var altura 		= height;
	var adicionales	= extras;
	var top 		= (screen.height - altura) / 2;
	var izquierda 	= (screen.width - largo) / 2; 
	
	
	window.open(''+ Url + '','_blank','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',' + adicionales + '');
	
}
 

function Logout()
{
	self.location.href = "?logout=1";
}



function text_onChange(control, counter, max)
{
	
	var len = control.value.length;

	if(len > max)
	{
		control.value = control.value.substr(1, max);
	}

	obj = document.getElementById(counter);
	
	if(obj.innerHTML)
		obj.innerHTML = (max - len);
} 

function largeText(div)
{
	obj = document.getElementById(div);
	
	if(obj != null)
	{
		if(obj.style.fontSize == "")
			obj.style.fontSize = "11px";
			
		obj.style.fontSize = (parseInt(obj.style.fontSize) + 1) + "px";
	}
}

function smallText(div)
{
	obj = document.getElementById(div);
	
	if(obj != null)
	{
		if(obj.style.fontSize == "")
			obj.style.fontSize = "11px";
			
		obj.style.fontSize = (parseInt(obj.style.fontSize) - 1) + "px";
	}
}


function comentario_submit(id)
{
	form = document.forms.formComentario;
		

	var iduser 	= form.idusuario.value;
	var id		= document.forms.comment_bar_vars.id.value;

	var name = "";
	var mail = "";
	
	if(iduser == 0 || iduser == "")
	{
		name 	= form.nombre.value;
		mail 	= form.correo.value;
	}

	var comment = nl2br(form.descripcion.value, false);
		
	if(comment.length == 0)
		return;
	
	if(form.idusuario.value == 0)
	{
		if(form.nombre.value == "")
		{
			document.getElementById("err_nombre").innerHTML = "* Debe ingresar un nombre";
			form.nombre.focus();
			return;
		}
		
		if(form.correo.value == "")
		{
			document.getElementById("err_correo").innerHTML = "* Debe ingresar un correo";
			form.correo.focus();
			return;
		}
	}
	
		
	obj = document.getElementById('list_comentarios');

	
	myajax = new MyAjax();
	myajax.RegisterEvents(
	{
		onStart: function()
		{
			document.getElementById('enviando_comentario').style.display = "block";
			obj.style.display = "none";				
		},
		onComplete: function()
		{
			changeCommentPage(1);
				
			span = document.getElementById("comentariosCount");
			span.innerHTML = parseInt(span.innerHTML) + 1; 
		}
	});
	

	myajax.Send("?section=" + document._section + "&action=addcoment&id=" + id + "&nombre=" + name + "&correo=" + mail + "&descripcion=" + comment, "POST");
	form.descripcion.value = "";
}


function changeCommentPage(page)
{
	
	obj = document.getElementById('list_comentarios');

	
	myajax = new MyAjax();
	myajax.RegisterEvents(
	{
		onStart: function()
		{
			document.getElementById('enviando_comentario').style.display = "block";
			obj.style.display = "none";				
		},
		onComplete: function()
		{
			document.getElementById('enviando_comentario').style.display = "none";
			obj.style.display = "block";
		
		}
	});

	form = document.forms.comment_bar_vars;
	form.compage.value = page;
	//form.gopage.value = page;
	myajax.SendFormAndLoad("?section=" + document._section + "&action=listcomments&type=" + form.comtype.value + "&id=" + form.id.value + "&commentpag=" + page, "list_comentarios", form);

}

function backCommentPage()
{
	form = document.forms.comment_bar_vars;
	
	if(form.compage.value <= 1)
		return;
		
	form.compage.value--;
	
	changeCommentPage(form.compage.value);
}

function nextCommentPage()
{
	form = document.forms.comment_bar_vars;
	
	if(form.compage.value >= form.compages.value)
		return;
		
	form.compage.value++;
	
	changeCommentPage(form.compage.value);	
}

function firstCommentPage()
{
	form = document.forms.comment_bar_vars;
	
	changeCommentPage(1);
}

function lastCommentPage()
{
	changeCommentPage(form.compages.value);	
}


function error(div, mensaje)
{
	try
	{
		var obj = document.getElementById(div);
		obj.innerHTML = '<div style="color: #FF0000;">' + mensaje + '</div>';
	}
	catch(e)
	{
	}
}

function onOverRow(obj, color)
{
	obj._oldBGColor = obj.style.background;
	obj.style.background = color;
	document._lastRow = obj;
}
function onOutRow(obj)
{
	obj.style.background = obj._oldBGColor;
} 

function printer(obj)
{
	if(!window.print)	
	{
		alert("Su navegador no soporta esta opción.");
		return;
	}
	
	obj.style.display = "none";
	
	window.print();
}

function getAbsoluteLeftInput(o) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTopInput(o) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
} 

function nl2br (str, is_xhtml) 
{
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '-br-';
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
