////////////////////////////////////////////////////
// Conciliación: gestión de conciliación de activos
// Version: 1.0
//
// Copyright (C) 2014  Eustotem Multimedia, S.L.
//
// License: MIT, see LICENSE
////////////////////////////////////////////////////


function changeRowStatus(param){
	var fila=document.getElementById("row_"+param);
	fila.style.backgroundColor="#FFE864";
}
function resetRowStatus(param){
	var fila=document.getElementById("row_"+param);
	fila.style.backgroundColor="";
}

function template4_expandTextArea(param){
	param.style.zIndex="6100";
	param.style.position="absolute";
	param.className="textarea_max";
}
function template4_shrinkTextArea(param){
	param.style.zIndex="0";
	param.style.position="relative";
	param.className="textarea_min";
	param.scrollTop=0;
}




var dataform_callback_failure=function(o){
	var cadena="Ha habido un fallo al recibir los datos\nInténtalo de nuevo o ponte en contacto con el soporte técnico.\n" + o.status + "\n" + o.statusText;
	page_overlay.hide();
	alert(cadena);
}

var dataform_saveChanges_callback_success = function(o){ 
	if(o.responseText !== undefined){
		var cadena=o.responseText.split('<?xml version="1.0" encoding="utf-8"?>').join('');
		cadena=cadena.split("{@@@}");
		if(cadena[0]=="error"){
			alert(cadena[1]);
			page_overlay.hide();
			return;
		}
		var fila=document.getElementById("row_" + cadena[0]),form=document.getElementById("dataform");
		resetRowStatus(cadena[0]);
	} 
	page_overlay.hide();
}

var dataform_inertNew_callback_sucess=function(o){
	if(o.responseText !== undefined){
		var cadena=o.responseText.split('<?xml version="1.0" encoding="utf-8"?>').join('');
		cadena=cadena.split("{@@@}");
		if(cadena[0]=="error"){
			alert(cadena[1]);
			page_overlay.hide();
			return;
		}
		location.reload(true);
	} 
	page_overlay.hide();
}


var dataform_saveChanges_callback = { 
	success: dataform_saveChanges_callback_success, 
	failure: dataform_callback_failure
};
var dataform_inertNew_callback = { 
	success: dataform_inertNew_callback_sucess, 
	failure: dataform_callback_failure
};


	function dataform_saveChanges(param,resId){
		page_overlay.show();
		var fila=document.getElementById("row_" + param),form=document.getElementById("dataform");
		var cadena="id=" + param + "&resId="+resId + "&_action=edit";
		for(i=0;i<form.elements.length;i++){
			var el=form.elements[i];
			var temp=el.id;
			var yuyu=temp.split("_");
			if(yuyu[1]==param.toString()){
				var nombre=yuyu[2];
				cadena+="&"+nombre+"=";
				switch(el.type){
					case "text":
						cadena+=el.value;
						break;
					case "textarea":
						cadena+=el.value.split("\n").join("<br />");
						break;
					case "select-one":
						cadena+=el.options[el.selectedIndex].value;
						break;
					case "checkbox":
						cadena+=el.checked;
						break;
				}
			}
		}
		var transaction = YAHOO.util.Connect.asyncRequest('POST', "../core/template_master_4_control.php", dataform_saveChanges_callback, cadena); 
	}


	function dataform_insertNew(param,resId){
		page_overlay.show();
		var fila=document.getElementById("row_" + param),form=document.getElementById("dataform");
		var cadena="id=" + param + "&resId="+resId + "&_action=insert";
		for(i=0;i<form.elements.length;i++){
			var el=form.elements[i];
			var temp=el.id;
			var yuyu=temp.split("_");
			if(yuyu[1]==param.toString()){
				var nombre=yuyu[2];
				cadena+="&"+nombre+"=";
				switch(el.type){
					case "text":
						cadena+=el.value;
						break;
					case "textarea":
						cadena=el.value;
						break;
					case "select-one":
						cadena+=el.options[el.selectedIndex].value;
						break;
					case "checkbox":
						cadena+=el.checked;
						break;
				}
			}
		}
		var transaction = YAHOO.util.Connect.asyncRequest('POST', "../core/template_master_4_control.php", dataform_inertNew_callback, cadena); 
	}
