function makeOptionList(objeto, name,value, sel) {
	var o=new Option( name,value);
	objeto.options[objeto.length]=o;
	if( sel == 1 )
		objeto.selectedIndex = objeto.length-1;
}

function validar_eliminar( mensaje, pagina ) {
    if ( confirm( mensaje ) ) {
        location.href = pagina;
    }
}

var myWin;
function open_estore(myPath) {
	if(myWin && !myWin.closed){
		myWin.close();
	}
	myWin = window.open(myPath);
	myWin.focus();
} 

var popUpWin=0;
function open_popUpWin(URLStr, left, top, width, height){
	if(myWin && !myWin.closed){
		myWin.close();
	}
	myWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	myWin.focus();

}

function view_costos() {

	open_popUpWin("costos_despacho.php", 10, 10, 550, 590);
	
}

function agregar_producto( pro_id ) {
    if( pro_id == '' )
        ver_mensaje( 'Se ha encontrado un problema con el producto.' );
    else {
        ver_mensaje_wait('Espere...');
    	var url = "add_bolsa.php?action=add&pro_id="+pro_id;
    	exec_AJAXRPC('GET', url, 'agregar_producto_vuelta');
    }
    
}

function agregar_producto_vuelta( texto ) {
    if( texto != '' ) {
		var lineas = texto.split("##");
		var datos = '';
		
		// Revisar primera línea
		datos = lineas[0].split("|");
		if(  datos[0] == 0 ) {
			ver_mensaje( datos[1] );
			return;
		}
		
		// Eliminar filas de la tabla
		var tbl = document.getElementById('tabla_carro');
		var numFilas = tbl.rows.length;
		for( i = 0; i < numFilas-2; i++) {
			tbl.deleteRow(0);
		}
		// Agregar filas de la tabla
		for( i = 0; i < lineas.length-1; i++ ) {	
			datos = lineas[i].split("|");
			var row = tbl.insertRow(tbl.rows.length-2);
			var cell2 = row.insertCell(0);
			var cell1 = row.insertCell(0);
			cell1.innerHTML = "<a href='ficha.php?pro_id="+datos[7]+"' class='link_carro_compras' title='"+datos[8]+"'>" + datos[4] + "</a>";
			cell2.innerHTML = datos[5] + 'x' + datos[6];
			cell2.style.textAlign="right";

			document.getElementById('CC_CANT_ITEM').innerHTML= datos[2]+' item';
			document.getElementById('CC_SUB_TOTAL').innerHTML= datos[3];            
		}
    }
}

function ver_mensaje( texto ) {
		alert( texto );
}

function ver_mensaje_wait( texto ) {
	
	document.getElementById('SUBIR').className="loading_image";
	setTimeout(function(){
		document.getElementById('SUBIR').className="";
	}, 1500);

}


