$(document).ready(function(){
	$("a.detalles").bind("click", function(){
		var href = $(this).attr("href");
		$.get(href, function(data){
			$("#popup .content").html(data);
			$("#popup").fadeIn();
			centralize();
		});
		return false;
	});
	$(window).resize(function(){
		centralize();
	});
});
function centralize()
{
	$("#popup .box").css({
		position: "absolute",
		left: ($(window).width() - $('.box').outerWidth()) / 2,
		top: ($(window).height() - $('.box').outerHeight()) / 2
	});
}

function closePop(){
	$("#popup").fadeOut(function(){
		$("#popup .content").html("");
	});
}

function confirmLink(theLink, theText){
    if (theText == '' || typeof(window.opera) != 'undefined') {return true;}
    var is_confirmed = confirm(theText);
    if (is_confirmed) {
        theLink.href += '&confirmado=1';
    }
    return is_confirmed;
}
//------------------------------------------------------------------------
function doPreview(wich, where){
	var objFile = document.getElementById(wich); //imagen
	var objImg = document.getElementById(where); //preview

	objImg.src = objFile.value;
}
//------------------------------------------------------------------------
var id_textarea;
function set_texto(id){
	id_textarea = id;
	var newWindow = openWin('../../cOmmOns/editor/editor_html.php',620,500,'HTMLEditor');	
	newWindow.focus();
}
function get_texto(){return document.getElementById(id_textarea).value;}
function rec_texto(html){document.getElementById(id_textarea).value = html;}
//------------------------------------------------------------------------
function openWin(ventana,popW,popH,nombre_ventana){
	if (nombre_ventana == undefined){var nom = 'Window';} else {var nom = nombre_ventana;}
	var w = 0, h = 0;

   	w = screen.width;
   	h = screen.height;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    popupWindow=open(''+ventana+'',nom,'resizable=no,scrollbars=yes,width='+popW+',height='+popH+',top='+topPos+',left='+leftPos);
    if (popupWindow.opener == null){popupWindow.opener = self;}
}
//------------------------------------------------------------------------
function highlight_div(checkbox_node){
    label_node = checkbox_node.parentNode;

    if (checkbox_node.checked){
		label_node.style.backgroundColor='#6C6B53';
		label_node.style.color='#ffffff';
	} else {
		label_node.style.backgroundColor='#ffffff';
		label_node.style.color='#000000';
	}
}
//------------------------------------------------------------------------
function checkAll(caja){
	var qEstado = false;
	var cantidad= caja.length;
	if (document.getElementById('check_todos').checked){
		qEstado = true;
	}
	for (i=0; i<cantidad; i++){caja[i].checked = qEstado;}
}
//------------------------------------------------------------------------
function onlyDecimal(InputText, evt) {
	var strValue = '';
	var charCode = evt.which?evt.which:evt.keyCode;
  	var selectionStart = getSelectionStart(InputText);
  	var selectionEnd = getSelectionEnd(InputText);
  	strValue = InputText.value.substring(0, selectionStart) + String.fromCharCode(charCode) + InputText.value.substring(selectionEnd);

  	if (!isDecimal(strValue) && charCode > 40) {return false;}
	return true;
}
//------------------------------------------------------------------------
function isDecimal(inputVal) {
	oneDecimal = false;
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (oneChar == "-") {return false;}
		if (oneChar == "." && !oneDecimal) {oneDecimal = true; continue;}
		if (oneChar < "0" || oneChar > "9") {return false;}
	}
	return true;
}
