// JavaScript Document
function inputCheck(inputName){
    var checks = document.getElementsByName(inputName);
    var num = checks.length;
    for (i = 0; i < num; i++){
        if (checks[i].checked == false){
            checks[i].checked = true;
        }else{
            checks[i].checked = false;
        }
    }
}

function evalDisplay(obj, state){
	var ObjDisplay= document.getElementById(obj);
	ObjDisplay.style.display = state;
}

function openConfirm(idConfirm, title, content, functionExt){
	Dialog.confirm(title, content, 
		{width:400, height:140, okLabel: "Aceptar", cancelLabel: "Cancelar",
		buttonClass: "moonBotonDel",
		id: idConfirm,
		cancel:function(win) {},
		ok:function(win) {eval(functionExt); return true;}
	});
}

function openWindowModal(page, titleValue, widthValue, heightValue){
	var win = new Window({className: "WinOpenModal", title: "" + titleValue + "", 
						 width:widthValue, height:heightValue, minimizable:false, maximizable:false, 
						 url: "" + page + "", showEffectOptions: {duration:1.5}});
	win.setStatusBar('MOON FrameWork');
	win.showCenter(true);
	win.show();
}

function openAlert(title, content){
	Dialog.alert(title, content,
		{width:350, height:115, okLabel: "Aceptar", 
		buttonClass: "moonBotonDel",
		id: "openAlert_click_button",
		ok:function(win) {return true;}
	});
}

function open_window(id,page,width,height,parameters) {
	var url_page = page+"?"+parameters;
	var pos_x = 0; 
	var pos_y = 0;
	var w = window.open(url_page,id,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',top='+pos_y+',left='+pos_x+'');
	w.focus();
	return true;
}

function compareDate(date_first, date_last, message){
    var date1 = date_first.value.split("/");
    var date2 = date_last.value.split("/");
    var result= false;

    year1=date1[2];
    month1=date1[1];
    day1=date1[0];

    year2=date2[2];
    month2=date2[1];
    day2=date2[0];

    if (year2 < year1) {
        result = true;
    }
    if((year1 == year2) && (month2 < month1))  {
        result = true;
    }
    if((year1 == year2) && (month1 == month2) && (day2 < day1))  {
        result = true;
    }
    if (result){
        if(message != "") alert(message);
        return true;
    }else{
        return false;
    }
}


//Code for Insert Row FrameWork MOON
//Important remember: for (var i = 0; i < RowCount; i++) alert(Rows[i].rowIndex);
function numRows(idTable){
	var Rows = document.getElementById(idTable).tBodies[0].getElementsByTagName('tr');
	var RowCount = Rows.length;
	return RowCount;
}

function getIndex(idTr){
	var Row = document.getElementById(idTr);
	return Row.rowIndex;
}

function removeRow(idTable, idTr){
	var table = document.getElementById(idTable);
	var index = getIndex(idTr);
    table.deleteRow(index);
}

function removeTfoot(idTable){
	var table = document.getElementById(idTable);
    table.deleteTFoot();
}

function insertRow(idTable, idTr, idTrNew, cells){
	//index = getIndex(idTr) + 1;
	index = getIndex(idTr);
	nrows = numRows(idTable);
	if (index > nrows){
		index = -1;
	}

	var newCell
	var table = document.getElementById(idTable).tBodies[0];
	var newRow = table.insertRow(index);
	newRow.id = idTrNew;

	for (var i = 0; i < cells.length; i++) {
		var arrTmp;
		newCell = newRow.insertCell(i)
		arrTmp=cells[i];
		newCell.innerHTML = arrTmp["innerHTML"];
		newCell.style.backgroundColor = arrTmp["backgroundColor"];
	}
}

function insertRowLast(idTable, idTrNew, cells){
	var table = document.getElementById(idTable).tBodies[0];
	var newRow = table.insertRow(-1);
	newRow.id = idTrNew;

	var newCell
	for (var i = 0; i < cells.length; i++) {
		var arrTmp;
		newCell = newRow.insertCell(i)
		arrTmp=cells[i];
		newCell.innerHTML = arrTmp["innerHTML"];
		newCell.style.backgroundColor = arrTmp["backgroundColor"];
	}
}

function insertTfoot(idTable, idTrNew, cells){
	var newCell
	var table = document.getElementById(idTable);
	//var newThead = table.createTHead();
	var newTfoot = table.createTFoot();
	newTfoot.id = idTrNew;
	var newRow = newTfoot.insertRow(-1);

	for (var i = 0; i < cells.length; i++) {
		var arrTmp;
		newCell = newRow.insertCell(i)
		arrTmp=cells[i];
		newCell.innerHTML = arrTmp["innerHTML"];
		newCell.style.backgroundColor = arrTmp["backgroundColor"];
	}
}
//END Code for Insert Row FrameWork MOON



//DONT USE, NO RELEASE*******************************************************************************
function closeConfirmTEMP(objDiv){
    var Div = document.getElementById(objDiv);
    /*objDiv.style.visibility = "hidden";*/
    var padre = Div.parentNode;
    padre.removeChild(Div);
}

function openConfirmTEMP(Text, funcx){
	var objDiv = document.getElementById('WinConfirm');
	if(objDiv == null || objDiv == undefined){
		var divWinConfirm = document.createElement("div");
		divWinConfirm.id="WinConfirm";
		divWinConfirm.className= "WinConfirm";
		divWinConfirm.style.visivility = "hidden";
		document.body.appendChild(divWinConfirm);
		
		objDivHtml = "<DIV id=\"WinConf\" class=\"popup_elim\">";
		objDivHtml +="<TABLE class=\"tbl_layer\" width=\"100%\" cellSpacing=0 cellPadding=0>";
		objDivHtml +="<TBODY>";
		objDivHtml +="<TR>";
		objDivHtml +="<TH vAlign=top width=\"90%\"><DIV align=left>&nbsp;Advertencia</DIV></TH>";
		objDivHtml +="<TH vAlign=top width=\"10%\"><A onclick=\"closeConfirm('"+ divWinConfirm.id +"');\">Cerrar</A></TH>";
		objDivHtml +="</TR>";
		objDivHtml +="<TD colSpan=2><div align=\"center\">¿Está seguro que desea continuar con la operación?<br />"+ Text +"</div></TD>";
		objDivHtml +="</TR>";
		objDivHtml +="<TR>";
		objDivHtml +="<TD colSpan=2><div align=\"center\">";
		objDivHtml +="<input class=\"moonBotonDel\" type=\"button\" name=\"btnYes\" id=\"btnYes\" value=\"Aceptar\" onclick=\"closeConfirm('"+ divWinConfirm.id +"');"+ funcx +";\" />&nbsp;";
		objDivHtml +="<input class=\"moonBotonDel\" type=\"button\" name=\"btnNo\" id=\"btnNo\" value=\"Cancelar\" onclick=\"closeConfirm('"+ divWinConfirm.id +"');\" />";
		objDivHtml +="</div></TD>";
		objDivHtml +="</TR>";
		objDivHtml +="</TBODY>";
		objDivHtml +="</TABLE>";
		objDivHtml +="</DIV>";
		divWinConfirm.innerHTML = objDivHtml;
	}
}
